* Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
#include "functions/Configuration.h"
Configuration::Configuration() {
confData = new HashMap();
}
Configuration::Configuration(bool standardYaml): standardYaml(standardYaml) {
}
Configuration::Configuration(const Configuration &other) {
standardYaml = other.standardYaml;
}
Configuration::~Configuration()
{
delete confData;
}
void Configuration::setString(std::string key, String * value) {
}
void Configuration::setString(std::string key, std::string value) {
}
void Configuration::setString(String * key, std::string value) {
}
void Configuration::setString(String * key, String * value) {
}
void Configuration::setInteger(std::string key, int32_t value) {
}
void Configuration::setBoolean(std::string key, bool value) {
}
bool Configuration::containsKey(std::string key) {
return {};
}
String* Configuration::getString(std::string key, std::string defaultValue) {
return {};
}
String* Configuration::getString(String * key, std::string defaultValue) {
return {};
}
String* Configuration::getString(std::string key, String * defaultValue) {
return {};
}
String* Configuration::getString(String * key, String * defaultValue) {
return {};
}
int32_t Configuration::getInteger(std::string key, int32_t defaultValue) {
return {};
}
bool Configuration::getBoolean(std::string key, bool defaultValue) {
return {};
}
HashMap* Configuration::getMap() {
return confData;
}
Configuration* Configuration::TM_CONFIG = new Configuration();
Object *Configuration::getValue(ConfigOption *configOption)
{
if (confData == nullptr) {
return returnDefaultValue(configOption);
}
auto str = reinterpret_cast<String*>(confData->get(configOption->GetKey()));
if (str == nullptr) {
return returnDefaultValue(configOption);
}
auto result = configOption->GetDefaultValue()->clone();
result->setValue(str->getData());
return result;
}
Object *Configuration::returnDefaultValue(ConfigOption *configOption)
{
if (configOption->hasDefaultValue()) {
return configOption->GetDefaultValue()->clone();
}
return nullptr;
}
void Configuration::setConfiguration(nlohmann::json config)
{
for (auto& [keyS, valueS]: config.items()) {
std::string key = keyS;
std::string value = valueS;
if (value == "") {
continue;
}
confData->put(new String(key), new String(value));
}
}
Object* Configuration::getValue(const std::unique_ptr<ConfigOption> &configOption)
{
return getValue(configOption.get());
}