-
-
Notifications
You must be signed in to change notification settings - Fork 997
/
Copy pathproducts.hpp
64 lines (49 loc) · 1.32 KB
/
products.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#pragma once
#include <string>
#include <vector>
#include <optional>
#include <mutex>
namespace products {
struct ProductsConfig
{
struct Product
{
private:
std::string m_title;
std::string m_link;
public:
Product(std::string const & title, std::string const & link)
: m_title(title), m_link(link)
{}
std::string const & GetTitle() const { return m_title; }
std::string const & GetLink() const { return m_link; }
};
private:
std::string m_placePagePrompt;
std::vector<Product> m_products;
public:
std::string const GetPlacePagePrompt() const { return m_placePagePrompt; }
std::vector<Product> const & GetProducts() const { return m_products; }
bool HasProducts() const { return !m_products.empty(); }
static std::optional<ProductsConfig> Parse(std::string const & jsonStr);
};
class ProductsSettings
{
private:
ProductsSettings();
std::optional<ProductsConfig> m_productsConfig;
mutable std::mutex m_mutex;
public:
static ProductsSettings & Instance();
void Update(std::string const & jsonStr);
std::optional<ProductsConfig> Get();
};
inline void Update(std::string const & jsonStr)
{
ProductsSettings::Instance().Update(jsonStr);
}
inline std::optional<ProductsConfig> GetProductsConfiguration()
{
return ProductsSettings::Instance().Get();
}
} // namespace products