#pragma once #include #include #include #include struct X { int a; int b; }; BOOST_HANA_ADAPT_STRUCT(X, a, b); struct X2 { int a; int b; }; namespace configpp { struct ConfigStructure{}; class Config { Config(std::string subdir, std::string filename = "config.json"); boost::property_tree::ptree config; std::string subdir; std::string filename; static std::unique_ptr config_ptr; void set(std::string const& key, std::string const& value, boost::property_tree::ptree& base) const { base.put(key, value); } public: Config() = delete; Config(Config const&) = delete; Config(Config&&) = delete; Config& operator=(Config const&) = delete; Config& operator=(Config&&) = delete; ~Config(); static Config& get(std::string subdir, std::string filename = "config.json") { if(!config_ptr) { config_ptr.reset(new Config(subdir, filename)); } return *config_ptr; } void set(std::string const& key, std::string const& value) { set(key, value, config); } template ::value>::type* = nullptr> void set(std::string const & key, T const& value) { std::ostringstream oss; oss << value; set(key, oss.str()); } template ::value>::type* = nullptr> void set(std::string const& key, T const& value) { auto top_element = config.get_child_optional(key); if(!top_element) { boost::property_tree::ptree array; config.add_child(key, array); top_element = config.get_child(key); } boost::hana::for_each(value, boost::hana::fuse([&top_element, this](auto&& key, auto&& value) { std::ostringstream oss; oss << value; set(boost::hana::to(key), oss.str(), *top_element); })); } template void get(std::string key, T const& value) { } }; } //namespace configpp //configpp::Config& config = configpp::Config::get({});