refactor(serif): fixed typos and updated names to reflect 4DSSE->SERiF

This commit is contained in:
2025-06-12 09:04:03 -04:00
parent 9f73aebf29
commit af5df1d452
2 changed files with 178 additions and 181 deletions

View File

@@ -29,19 +29,18 @@
#include "config.h" #include "config.h"
namespace serif { namespace serif::config {
namespace config {
Config::Config() {} Config::Config() {}
Config::~Config() {} Config::~Config() {}
Config& Config::getInstance() { Config& Config::getInstance() {
static Config instance; static Config instance;
return instance; return instance;
} }
bool Config::loadConfig(const std::string& configFile) { bool Config::loadConfig(const std::string& configFile) {
configFilePath = configFile; configFilePath = configFile;
try { try {
yamlRoot = YAML::LoadFile(configFile); yamlRoot = YAML::LoadFile(configFile);
@@ -51,21 +50,21 @@ bool Config::loadConfig(const std::string& configFile) {
} }
m_loaded = true; m_loaded = true;
return true; return true;
} }
bool Config::isKeyInCache(const std::string &key) { bool Config::isKeyInCache(const std::string &key) {
return configMap.find(key) != configMap.end(); return configMap.find(key) != configMap.end();
} }
void Config::addToCache(const std::string &key, const YAML::Node &node) { void Config::addToCache(const std::string &key, const YAML::Node &node) {
configMap[key] = node; configMap[key] = node;
} }
void Config::registerUnknownKey(const std::string &key) { void Config::registerUnknownKey(const std::string &key) {
unknownKeys.push_back(key); unknownKeys.push_back(key);
} }
bool Config::has(const std::string &key) { bool Config::has(const std::string &key) {
if (!m_loaded) { if (!m_loaded) {
throw std::runtime_error("Error! Config file not loaded"); throw std::runtime_error("Error! Config file not loaded");
} }
@@ -85,27 +84,26 @@ bool Config::has(const std::string &key) {
// Key exists and is of the requested type // Key exists and is of the requested type
addToCache(key, node); addToCache(key, node);
return true; return true;
} }
void recurse_keys(const YAML::Node& node, std::vector<std::string>& keyList, const std::string& path = "") { void recurse_keys(const YAML::Node& node, std::vector<std::string>& keyList, const std::string& path = "") {
if (node.IsMap()) { if (node.IsMap()) {
for (const auto& it : node) { for (const auto& it : node) {
std::string key = it.first.as<std::string>(); auto key = it.first.as<std::string>();
std::string new_path = path.empty() ? key : path + ":" + key; auto new_path = path.empty() ? key : path + ":" + key;
recurse_keys(it.second, keyList, new_path); recurse_keys(it.second, keyList, new_path);
} }
} else { } else {
keyList.push_back(path); keyList.push_back(path);
} }
} }
std::vector<std::string> Config::keys() const { std::vector<std::string> Config::keys() const {
std::vector<std::string> keyList; std::vector<std::string> keyList;
YAML::Node node = YAML::Clone(yamlRoot); YAML::Node node = YAML::Clone(yamlRoot);
recurse_keys(node, keyList); recurse_keys(node, keyList);
return keyList; return keyList;
} }
} // namespace config }
} // namespace serif

View File

@@ -32,18 +32,18 @@
#include "yaml-cpp/yaml.h" #include "yaml-cpp/yaml.h"
// -- Forward Def of Resource manager to let it act as a friend of Config -- // -- Forward Def of Resource manager to let it act as a friend of Config --
namespace serif { namespace resource { class ResourceManager; } } // Forward declaration namespace serif::resource { class ResourceManager; }
class configTestPrivateAccessor; // Forward declaration for test utility class configTestPrivateAccessor; // Forward declaration for test utility
namespace serif { namespace serif::config {
namespace config {
/** /**
* @class Config * @class Config
* @brief Singleton class to manage configuration settings loaded from a YAML file. * @brief Singleton class to manage configuration settings loaded from a YAML file.
*/ */
class Config { class Config {
private: private:
/** /**
* @brief Private constructor to prevent instantiation. * @brief Private constructor to prevent instantiation.
*/ */
@@ -117,7 +117,7 @@ private:
} }
} }
public: public:
/** /**
* @brief Get the singleton instance of the Config class. * @brief Get the singleton instance of the Config class.
* @return Reference to the Config instance. * @return Reference to the Config instance.
@@ -160,7 +160,7 @@ public:
template <typename T> template <typename T>
T get(const std::string &key, T defaultValue) { T get(const std::string &key, T defaultValue) {
if (!m_loaded) { if (!m_loaded) {
// ONLY THROW ERROR IF HARSH OR WARN CONFIGURATION // ONLY THROW ERROR IF HARSH OR WARN CONFIGURATION
#if defined(CONFIG_HARSH) #if defined(CONFIG_HARSH)
throw std::runtime_error("Error! Config file not loaded. To disable this error, recompile with CONFIG_HARSH=0"); throw std::runtime_error("Error! Config file not loaded. To disable this error, recompile with CONFIG_HARSH=0");
#elif defined(CONFIG_WARN) #elif defined(CONFIG_WARN)
@@ -240,7 +240,6 @@ public:
friend class ::configTestPrivateAccessor; // Friend declaration for global test accessor friend class ::configTestPrivateAccessor; // Friend declaration for global test accessor
// -- Resource Manager is a friend of config so it can create a seperate instance // -- Resource Manager is a friend of config so it can create a seperate instance
friend class serif::resource::ResourceManager; // Adjusted friend declaration friend class serif::resource::ResourceManager; // Adjusted friend declaration
}; };
} // namespace config }
} // namespace serif