From bc6f86f752f02780339c4e1c2ad69c8f80228b66 Mon Sep 17 00:00:00 2001 From: Emily Boudreaux Date: Mon, 3 Mar 2025 09:53:42 -0500 Subject: [PATCH 1/5] fix(config): loaded flag and checks added added check to make sure that config file has been loaded before any config variables are accessed --- src/config/private/config.cpp | 1 + src/config/public/config.h | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/src/config/private/config.cpp b/src/config/private/config.cpp index 5eb3af6..bf39b37 100644 --- a/src/config/private/config.cpp +++ b/src/config/private/config.cpp @@ -26,6 +26,7 @@ bool Config::loadConfig(const std::string& configFile) { std::cerr << "Error: " << e.what() << std::endl; return false; } + loaded = true; return true; } diff --git a/src/config/public/config.h b/src/config/public/config.h index 9770eae..dff11d2 100644 --- a/src/config/public/config.h +++ b/src/config/public/config.h @@ -8,6 +8,7 @@ #include #include #include +#include #include "yaml-cpp/yaml.h" @@ -30,6 +31,7 @@ private: YAML::Node yamlRoot; ///< Root node of the YAML configuration. std::string configFilePath; ///< Path to the configuration file. bool debug = false; ///< Flag to enable debug output. + bool loaded = false; ///< Flag to indicate if the configuration has been loaded. std::map configMap; ///< Cache for the location of configuration settings. std::vector unknownKeys; ///< Cache for the existence of configuration settings. @@ -116,6 +118,9 @@ public: */ template T get(const std::string &key, T defaultValue) { + if (!loaded) { + throw std::runtime_error("Configuration file not loaded! This should be done at the very start of whatever main function you are using (and only done once!)"); + } // --- Check if the key has already been checked for existence if (std::find(unknownKeys.begin(), unknownKeys.end(), key) != unknownKeys.end()) { return defaultValue; // If the key has already been added to the unknown cache do not traverse the YAML tree or hit the cache From d9f33652531980681c1cdd8ffbd8f81b17c63f63 Mon Sep 17 00:00:00 2001 From: Emily Boudreaux Date: Fri, 18 Apr 2025 11:18:31 -0400 Subject: [PATCH 2/5] fix(yaml-cpp): locked cmake version for yaml-cpp --- build-config/yaml-cpp/meson.build | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/build-config/yaml-cpp/meson.build b/build-config/yaml-cpp/meson.build index 434a233..27c9332 100644 --- a/build-config/yaml-cpp/meson.build +++ b/build-config/yaml-cpp/meson.build @@ -1,5 +1,10 @@ +yaml_cpp_cmake_options = cmake.subproject_options() +yaml_cpp_cmake_options.add_cmake_defines({ + 'CMAKE_POLICY_VERSION_MINIMUM': '3.5' +}) yaml_cpp_sp = cmake.subproject( - 'yaml-cpp' + 'yaml-cpp', + options: yaml_cpp_cmake_options, ) yaml_cpp_dep = yaml_cpp_sp.dependency('yaml-cpp') add_project_arguments('-I' + meson.current_build_dir() + '/subprojects/yaml-cpp/__CMake_build', language: 'cpp') \ No newline at end of file From 477b73610bba229e212e1367c6004cb8c777cd5d Mon Sep 17 00:00:00 2001 From: Emily Boudreaux Date: Mon, 21 Apr 2025 08:56:45 -0400 Subject: [PATCH 3/5] docs(src): updated file headers --- src/config/private/config.cpp | 2 +- src/config/public/config.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/config/private/config.cpp b/src/config/private/config.cpp index 76e7d43..e7d15a3 100644 --- a/src/config/private/config.cpp +++ b/src/config/private/config.cpp @@ -2,7 +2,7 @@ // // Copyright (C) 2025 -- The 4D-STAR Collaboration // File Author: Emily Boudreaux -// Last Modified: February 21, 2025 +// Last Modified: March 20, 2025 // // 4DSSE is free software; you can use it and/or modify // it under the terms and restrictions the GNU General Library Public diff --git a/src/config/public/config.h b/src/config/public/config.h index fa04eea..4869e62 100644 --- a/src/config/public/config.h +++ b/src/config/public/config.h @@ -2,7 +2,7 @@ // // Copyright (C) 2025 -- The 4D-STAR Collaboration // File Author: Emily Boudreaux -// Last Modified: February 20, 2025 +// Last Modified: March 26, 2025 // // 4DSSE is free software; you can use it and/or modify // it under the terms and restrictions the GNU General Library Public From fcf1d169a67fbc50b874bb40b27b6dab80e61186 Mon Sep 17 00:00:00 2001 From: Emily Boudreaux Date: Wed, 11 Jun 2025 14:49:11 -0400 Subject: [PATCH 4/5] refactor(serif): refactored entire codebase into serif and sub namespaces --- src/config/private/config.cpp | 8 +++++++- src/config/public/config.h | 15 +++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/config/private/config.cpp b/src/config/private/config.cpp index e7d15a3..61fda9f 100644 --- a/src/config/private/config.cpp +++ b/src/config/private/config.cpp @@ -29,6 +29,9 @@ #include "config.h" +namespace serif { +namespace config { + Config::Config() {} Config::~Config() {} @@ -102,4 +105,7 @@ std::vector Config::keys() const { YAML::Node node = YAML::Clone(yamlRoot); recurse_keys(node, keyList); return keyList; -} \ No newline at end of file +} + +} // namespace config +} // namespace serif \ No newline at end of file diff --git a/src/config/public/config.h b/src/config/public/config.h index 4869e62..0e73436 100644 --- a/src/config/public/config.h +++ b/src/config/public/config.h @@ -34,7 +34,11 @@ #include "yaml-cpp/yaml.h" // -- Forward Def of Resource manager to let it act as a friend of Config -- -class ResourceManager; +namespace serif { namespace resource { class ResourceManager; } } // Forward declaration +class configTestPrivateAccessor; // Forward declaration for test utility + +namespace serif { +namespace config { /** * @class Config @@ -230,9 +234,12 @@ public: } // Setup gTest class as a friend - friend class configTestPrivateAccessor; + friend class ::configTestPrivateAccessor; // Friend declaration for global test accessor // -- Resource Manager is a friend of config so it can create a seperate instance - friend class ResourceManager; + friend class serif::resource::ResourceManager; // Adjusted friend declaration }; -#endif \ No newline at end of file +} // namespace config +} // namespace serif + +#endif From 4e4fc420b6a0d18bbf5a75f52227fed76ce582a1 Mon Sep 17 00:00:00 2001 From: Emily Boudreaux Date: Wed, 11 Jun 2025 14:49:26 -0400 Subject: [PATCH 5/5] refactor(serif): updated tests to reflect new serif namespaces --- tests/config/configTest.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/config/configTest.cpp b/tests/config/configTest.cpp index 717ce99..f919869 100644 --- a/tests/config/configTest.cpp +++ b/tests/config/configTest.cpp @@ -15,23 +15,23 @@ std::string EXAMPLE_FILENAME = std::string(getenv("MESON_SOURCE_ROOT")) + "/test class configTestPrivateAccessor { public: - static bool callIsKeyInCache(Config& config, const std::string& key) { + static bool callIsKeyInCache(serif::config::Config& config, const std::string& key) { return config.isKeyInCache(key); } - static int callCacheSize(Config& config) { + static int callCacheSize(serif::config::Config& config) { return config.configMap.size(); } - static void callAddToCache(Config& config, const std::string& key, const YAML::Node& node) { + static void callAddToCache(serif::config::Config& config, const std::string& key, const YAML::Node& node) { config.addToCache(key, node); } - static void callRegisterKeyNotFound(Config& config, const std::string& key) { + static void callRegisterKeyNotFound(serif::config::Config& config, const std::string& key) { config.registerUnknownKey(key); } - static bool CheckIfKeyUnknown(Config& config, const std::string& key) { + static bool CheckIfKeyUnknown(serif::config::Config& config, const std::string& key) { if (std::find(config.unknownKeys.begin(), config.unknownKeys.end(), key) == config.unknownKeys.end()) { return false; } @@ -48,22 +48,22 @@ class configTest : public ::testing::Test {}; * @brief Test the constructor of the Config class. */ TEST_F(configTest, constructor) { - EXPECT_NO_THROW(Config::getInstance()); + EXPECT_NO_THROW(serif::config::Config::getInstance()); } TEST_F(configTest, loadConfig) { - Config& config = Config::getInstance(); + serif::config::Config& config = serif::config::Config::getInstance(); EXPECT_TRUE(config.loadConfig(EXAMPLE_FILENAME)); } TEST_F(configTest, singletonTest) { - Config& config1 = Config::getInstance(); - Config& config2 = Config::getInstance(); + serif::config::Config& config1 = serif::config::Config::getInstance(); + serif::config::Config& config2 = serif::config::Config::getInstance(); EXPECT_EQ(&config1, &config2); } TEST_F(configTest, getTest) { - Config& config = Config::getInstance(); + serif::config::Config& config = serif::config::Config::getInstance(); config.loadConfig(EXAMPLE_FILENAME); int maxIter = config.get("opac:lowTemp:numeric:maxIter", 10); EXPECT_EQ(maxIter, 100); @@ -82,19 +82,19 @@ TEST_F(configTest, getTest) { } TEST_F(configTest, secondSingletonTest) { - Config& config = Config::getInstance(); + serif::config::Config& config = serif::config::Config::getInstance(); EXPECT_EQ(config.get("opac:lowTemp:numeric:maxIter", 10), 100); } TEST_F(configTest, isKeyInCacheTest) { - Config& config = Config::getInstance(); + serif::config::Config& config = serif::config::Config::getInstance(); config.loadConfig(EXAMPLE_FILENAME); EXPECT_TRUE(configTestPrivateAccessor::callIsKeyInCache(config, "opac:lowTemp:numeric:maxIter")); EXPECT_FALSE(configTestPrivateAccessor::callIsKeyInCache(config, "opac:lowTemp:numeric:maxIter2")); } TEST_F(configTest, cacheSize) { - Config& config = Config::getInstance(); + serif::config::Config& config = serif::config::Config::getInstance(); config.loadConfig(EXAMPLE_FILENAME); EXPECT_EQ(configTestPrivateAccessor::callCacheSize(config), 3); EXPECT_NE(configTestPrivateAccessor::callCacheSize(config), 4); @@ -103,9 +103,9 @@ TEST_F(configTest, cacheSize) { } TEST_F(configTest, unknownKeyTest) { - Config& config = Config::getInstance(); + serif::config::Config& config = serif::config::Config::getInstance(); config.loadConfig(EXAMPLE_FILENAME); config.get("opac:lowTemp:numeric:random", 10); EXPECT_FALSE(configTestPrivateAccessor::CheckIfKeyUnknown(config, "opac:lowTemp:numeric:maxIter")); EXPECT_TRUE(configTestPrivateAccessor::CheckIfKeyUnknown(config, "opac:lowTemp:numeric:random")); -} +} \ No newline at end of file