SettingConfig.hpp
A tool for collecting settings, including from files and the command line.
Note
Status: DEPRECATED!
-
class SettingConfig
- #include <SettingConfig.hpp>
Class to take a set of value for each “setting” and then step through all combinations of those values for a factorial analysis.
Public Functions
-
SettingConfig() = default
-
inline ~SettingConfig()
-
inline size_t GetComboID() const
-
inline bool HasUnusedArgs() const
-
inline bool HasErrors() const
-
template<typename T>
inline const T &GetValue(const std::string &name) const Get the current value of a specified setting.
-
template<typename T>
inline T MaxValue(const std::string &name) const Scan through all values and return the maximum.
-
template<typename T>
inline T &AddSetting(const std::string &name, const std::string &desc, const char option_flag, T &var, const std::string &args_label = "Value") Add a new setting of a specified type. Returns the (initially empty) vector of values to allow easy setting. Example: config.AddSetting(“num_runs”) = 200;
-
template<typename T>
inline vector<T> &AddComboSetting(const std::string &name, const std::string &desc = "", const char option_flag = '\0') Add a new setting of a specified type. Returns the (initially empty) vector of values to allow easy setting. Example: config.AddComboSetting(“pop_size”) = { 100,200,400,800 };
-
template<typename T>
inline vector<T> &AddComboSetting(const std::string &name, const std::string &desc, const char option_flag, T &var, const std::string &args_label = "Values...") A setting can also be linked to a value that is kept up-to-date.
-
inline void AddAction(const std::string &name, const std::string &desc, const char flag, std::function<void()> fun)
-
template<typename T>
inline vector<T> &ComboValues(const std::string &name) Access ALL values for a specified setting, to be modified freely.
-
inline void ResetCombos()
Start over stepping through all combinations of parameter values.
-
template<typename T>
inline void AddComboValue(const std::string &name, T &&val) Add a single new value to the specified setting.
-
template<typename T1, typename ...Ts>
inline void SetComboValues(const std::string &name, T1 &&val1, Ts&&... vals) Set all values for the specified setting.
-
inline size_t CountCombos()
Determine how many unique combinations there currently are.
-
inline bool NextCombo()
Set the next combination of settings to be active. Return true if successful or false if we ran through all combinations and reset.
-
inline std::string GetSettingHeaders(const std::string &separator = ",")
Get the set of headers used for the CSV file.
-
inline std::string CurSettings(const std::string &separator = ",") const
Convert all of the current values into a comma-separated string.
-
inline std::string GetComboHeaders(const std::string &separator = ",")
Get the set of headers used for the CSV file.
-
inline std::string CurComboString(const std::string &separator = ",", bool use_labels = false, bool multi_only = false) const
Convert all of the current values into a comma-separated string.
- Parameters:
separator – Delimiter separating values in string
use_labels – Print name with each value?
multi_only – Only print values that can change?
-
inline Ptr<SettingBase> FindOptionMatch(const std::string &option_name)
Scan through all settings for a match option and return ID.
-
inline Ptr<SettingBase> FindFlagMatch(const char symbol)
Scan through all settings for a match option and return ID.
-
inline bool ProcessOptions(const vector<std::string> &args)
Take an input set of config options, process them, and track set of unprocessed ones.
-
inline bool ProcessOptions(int argc, char *argv[])
Private Members
-
std::map<std::string, Ptr<SettingBase>> setting_map
All settings by name.
-
std::map<std::string, ActionFlag> action_map
Action flags.
-
vector<Ptr<SettingBase>> combo_settings
Multi-value settings (in order)
-
size_t combo_id = 0
Unique value indicating which combination we are on.
-
struct ActionFlag
A setting that is just a flag with an action function to run if it’s called.
-
template<typename T>
struct ComboSettingInfo : public SettingConfig::SettingBase Allow a single setting to have multiple values specified that should be stepped through.
Public Functions
-
inline ComboSettingInfo(const std::string &_name, const std::string &_desc, const char _flag, const std::string &_args, Ptr<T> _var = nullptr)
- Parameters:
_name – Unique name for this setting.
_desc – Description of this setting (for help)
_flag – Char flag for easy access (e.g., “-h”)
_args – Label for option arguments (for help)
_var – Pointer to variable to set (optional)
-
inline size_t GetSize() const override
-
inline bool SetValueID(size_t id) override
-
inline bool IsComboSetting() override
-
inline size_t GetID() const override
-
inline ComboSettingInfo(const std::string &_name, const std::string &_desc, const char _flag, const std::string &_args, Ptr<T> _var = nullptr)
-
struct SettingBase
Base class to describe information about a single setting.
-
template<typename T>
struct SettingInfo : public SettingConfig::SettingBase Full details about a single setting, including type information and values.
Public Functions
-
inline SettingInfo(const std::string &_name, const std::string &_desc, const char _flag, const std::string &_arg, Ptr<T> _var = nullptr)
- Parameters:
_name – Unique name for this setting.
_desc – Description of this setting (for help)
_flag – Single char flag for easy access (e.g., “-h”)
_arg – Label for option argument (for help)
_var – Pointer to variable to set (optional)
-
inline size_t GetSize() const override
-
inline SettingInfo(const std::string &_name, const std::string &_desc, const char _flag, const std::string &_arg, Ptr<T> _var = nullptr)
-
SettingConfig() = default