New cpp folder structure

Signed-off-by: Alexander Borsuk <me@alex.bio>
This commit is contained in:
Alexander Borsuk
2025-07-17 22:35:52 +03:00
committed by Konstantin Pastbin
parent c9cbb64f12
commit 76ffc99abd
2390 changed files with 345 additions and 339 deletions

View File

@@ -0,0 +1,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