From c21404a6c3892f623b3c2c32532dfc51d364f80d Mon Sep 17 00:00:00 2001 From: Emily Dolson Date: Thu, 25 Jun 2020 13:16:32 -0400 Subject: [PATCH 1/4] Add new version of AddSetting --- examples/config/SettingCombos.cc | 2 +- examples/config/SettingConfig.cc | 8 +++++--- source/config/SettingConfig.h | 13 +++++++++++++ 3 files changed, 19 insertions(+), 4 deletions(-) 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: From 6a4b844ddf0b3e193bd25827853745203425d39a Mon Sep 17 00:00:00 2001 From: Emily Dolson Date: Thu, 25 Jun 2020 13:22:48 -0400 Subject: [PATCH 2/4] Add tests for new SettingConfig method --- tests/config/SettingConfig.cc | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 tests/config/SettingConfig.cc diff --git a/tests/config/SettingConfig.cc b/tests/config/SettingConfig.cc new file mode 100644 index 0000000000..fe6ec72f0a --- /dev/null +++ b/tests/config/SettingConfig.cc @@ -0,0 +1,13 @@ +#define CATCH_CONFIG_MAIN +#include "third-party/Catch/single_include/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); + +} From 2efb33bff85a0d8e02c9d090699e626f1814239e Mon Sep 17 00:00:00 2001 From: Emily Dolson Date: Fri, 26 Jun 2020 15:09:36 -0400 Subject: [PATCH 3/4] Fix tests --- tests/config/Makefile | 2 +- tests/config/SettingCombos.cc | 1 + tests/config/SettingConfig.cc | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/config/Makefile b/tests/config/Makefile index e4d9916a04..d448c8d955 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 416e470a51..6e806224f8 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 index fe6ec72f0a..9f2792f807 100644 --- a/tests/config/SettingConfig.cc +++ b/tests/config/SettingConfig.cc @@ -6,8 +6,8 @@ TEST_CASE("Test SettingConfig", "[config]") { emp::SettingConfig config_set; - config_set.AddSetting("test_non_combo") = {5}; + config_set.AddSetting("test_non_combo") = 5; - CHECK(config_set.GetValue("test_non_combo") == 5); + CHECK(config_set.GetValue("test_non_combo") == 5); } From 987124546a85112970f302fd2c25740fa987da50 Mon Sep 17 00:00:00 2001 From: Emily Dolson Date: Thu, 30 Jul 2020 03:49:41 -0400 Subject: [PATCH 4/4] Update path to catch --- tests/config/SettingConfig.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/config/SettingConfig.cc b/tests/config/SettingConfig.cc index 9f2792f807..c5d39ef987 100644 --- a/tests/config/SettingConfig.cc +++ b/tests/config/SettingConfig.cc @@ -1,5 +1,5 @@ #define CATCH_CONFIG_MAIN -#include "third-party/Catch/single_include/catch.hpp" +#include "third-party/Catch/single_include/catch2/catch.hpp" #include "config/SettingConfig.h"