* @param config visitable structure to fill
*/
template <class Config>
-void loadFromString(const std::string& jsonString, Config& config)
+void loadFromJsonString(const std::string& jsonString, Config& config)
{
static_assert(isVisitable<Config>::value, "Use CONFIG_REGISTER macro");
config.accept(visitor);
}
-
/**
* Creates a string representation of the configuration in json format
*
* @param config visitable structure to convert
*/
template <class Config>
-std::string saveToString(const Config& config)
+std::string saveToJsonString(const Config& config)
{
static_assert(isVisitable<Config>::value, "Use CONFIG_REGISTER macro");
* @param config visitable structure to load
*/
template <class Config>
-void loadFromFile(const std::string& filename, Config& config)
+void loadFromJsonFile(const std::string& filename, Config& config)
{
std::string content;
if (!fsutils::readFileContent(filename, content)) {
throw ConfigException("Could not load " + filename);
}
try {
- loadFromString(content, config);
+ loadFromJsonString(content, config);
} catch (ConfigException& e) {
throw ConfigException("Error in " + filename + ": " + e.what());
}
* @param config visitable structure to save
*/
template <class Config>
-void saveToFile(const std::string& filename, const Config& config)
+void saveToJsonFile(const std::string& filename, const Config& config)
{
- const std::string content = saveToString(config);
+ const std::string content = saveToJsonString(config);
if (!fsutils::saveFileContent(filename, content)) {
throw ConfigException("Could not save " + filename);
}
* @param configName name of the configuration inside the KVStore db
*/
template <class Config>
-void loadFromKVStore(const std::string& filename, Config& config, const std::string& configName = "")
+void loadFromKVStore(const std::string& filename, Config& config, const std::string& configName)
{
static_assert(isVisitable<Config>::value, "Use CONFIG_REGISTER macro");
* @param configName name of the config inside the KVStore db
*/
template <class Config>
-void saveToKVStore(const std::string& filename, const Config& config, const std::string& configName = "")
+void saveToKVStore(const std::string& filename, const Config& config, const std::string& configName)
{
static_assert(isVisitable<Config>::value, "Use CONFIG_REGISTER macro");
* @param kvfile path to the KVStore db
* @param jsonfile path to json file with defaults
* @param config visitable structure to save
+ * @param kvConfigName name of the config inside the KVStore db
*/
template <class Config>
-void loadFromKVStoreWithJson(const std::string& kvfile, const std::string& json, Config& config)
+void loadFromKVStoreWithJson(const std::string& kvfile,
+ const std::string& json,
+ Config& config,
+ const std::string& kvConfigName)
{
static_assert(isVisitable<Config>::value, "Use CONFIG_REGISTER macro");
- FromKVJsonVisitor visitor(kvfile, json);
+ FromKVJsonVisitor visitor(kvfile, json, kvConfigName);
config.accept(visitor);
}
+
/**
* Load the config from KVStore with defaults given in json file
*
* @param kvfile path to the KVStore db
* @param jsonfile path to json file with defaults
* @param config visitable structure to save
+ * @param kvConfigName name of the config inside the KVStore db
*/
template <class Config>
-void loadFromKVStoreWithJsonFile(const std::string& kvfile, const std::string& jsonfile, Config& config)
+void loadFromKVStoreWithJsonFile(const std::string& kvfile,
+ const std::string& jsonfile,
+ Config& config,
+ const std::string& kvConfigName)
{
- static_assert(isVisitable<Config>::value, "Use CONFIG_REGISTER macro");
-
std::string content;
if (!fsutils::readFileContent(jsonfile, content)) {
throw ConfigException("Could not load " + jsonfile);
}
try {
- loadFromKVStoreWithJson(kvfile, content, config);
+ loadFromKVStoreWithJson(kvfile, content, config, kvConfigName);
} catch (ConfigException& e) {
throw ConfigException("Error in " + jsonfile + ": " + e.what());
}