diff --git a/examples/config/SettingCombos.cc b/examples/config/SettingCombos.cc index e6ab755eea..a53eb9dabc 100644 --- a/examples/config/SettingCombos.cc +++ b/examples/config/SettingCombos.cc @@ -17,7 +17,7 @@ int main() config_set.AddSetting("int1") = { 1, 2, 3, 4 }; config_set.AddSetting("string") = { "a", "b", "cde" }; config_set.AddSetting("int2") = { 5 }; - config_set.AddSetting("double", "A double value!", "-d") = { 1.1, 2.2 }; + config_set.AddSetting("double", "A double value!", '-d') = { 1.1, 2.2 }; do { std::cout << config_set.CurString() << std::endl; diff --git a/examples/config/SettingConfig.cc b/examples/config/SettingConfig.cc index 39cfa476f6..cc7e749720 100644 --- a/examples/config/SettingConfig.cc +++ b/examples/config/SettingConfig.cc @@ -18,6 +18,9 @@ int main() config_set.AddComboSetting("string") = { "a", "b", "cde" }; config_set.AddComboSetting("int2") = { 5 }; config_set.AddComboSetting("double", "A double value!", 'd') = { 1.1, 2.2 }; + config_set.AddSetting("test_non_combo") = {5.5}; + + std::cout << "Non-combo setting: " << config_set.GetValue("test_non_combo") << std::endl; do { std::cout << config_set.CurComboString() << std::endl; @@ -25,8 +28,7 @@ int main() std::cout << "------------ Process Args ------------\n"; - auto out_args = - config_set.ProcessOptions( { "testing", "--int1", "5,6,7", "unused", "-d", "3.3,4.4,5.5"} ); + config_set.ProcessOptions( { "testing", "--int1", "5,6,7", "unused", "-d", "3.3,4.4,5.5"} ); do { std::cout << config_set.CurComboString() << std::endl; @@ -34,6 +36,6 @@ int main() std::cout << "Remaining Args:\n"; - for (auto x : out_args) std::cout << " " << x << std::endl; + for (auto x : config_set.GetUnusedArgs()) std::cout << " " << x << std::endl; } diff --git a/source/config/SettingConfig.h b/source/config/SettingConfig.h index e605e7250c..417b8a2928 100644 --- a/source/config/SettingConfig.h +++ b/source/config/SettingConfig.h @@ -235,6 +235,19 @@ namespace emp { return new_ptr->value; } + /// Add a new setting not linked to a variable + + template + T & AddSetting(const std::string & name, + const std::string & desc="", + const char option_flag='\0') + { + emp_assert(!emp::Has(setting_map, name)); + auto new_ptr = emp::NewPtr>(name, desc, option_flag, "Value"); + setting_map[name] = new_ptr; + return new_ptr->value; + } + /// Add a new setting of a specified type. Returns the (initially empty) vector of values /// to allow easy setting. /// Example: diff --git a/tests/config/Makefile b/tests/config/Makefile index 1b75fafc7e..610c3ef8ca 100644 --- a/tests/config/Makefile +++ b/tests/config/Makefile @@ -1,4 +1,4 @@ -TEST_NAMES = ArgManager command_line config_utils config ConfigManager SettingCombos +TEST_NAMES = ArgManager command_line config_utils config ConfigManager SettingCombos SettingConfig # -O3 -Wl,--stack,8388608 -ftrack-macro-expansion=0 FLAGS = -std=c++17 -pthread -Wall -Wno-unused-function -Wno-unused-private-field -I../../source/ -I../../ -I../../third-party/cereal/include/ diff --git a/tests/config/SettingCombos.cc b/tests/config/SettingCombos.cc index 552021b81d..81aad33339 100644 --- a/tests/config/SettingCombos.cc +++ b/tests/config/SettingCombos.cc @@ -5,5 +5,6 @@ TEST_CASE("Test SettingCombos", "[config]") { + emp::SettingCombos config_set; } diff --git a/tests/config/SettingConfig.cc b/tests/config/SettingConfig.cc new file mode 100644 index 0000000000..c5d39ef987 --- /dev/null +++ b/tests/config/SettingConfig.cc @@ -0,0 +1,13 @@ +#define CATCH_CONFIG_MAIN +#include "third-party/Catch/single_include/catch2/catch.hpp" + +#include "config/SettingConfig.h" + +TEST_CASE("Test SettingConfig", "[config]") +{ + emp::SettingConfig config_set; + config_set.AddSetting("test_non_combo") = 5; + + CHECK(config_set.GetValue("test_non_combo") == 5); + +}