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 const std::string &GetExeName() const
inline size_t GetComboID() const
inline const vector<std::string> &GetUnusedArgs() const
inline const std::string &GetErrors() 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[])
template<typename ...Ts>
inline void PrintHelp(const Ts&... examples) const

Private Members

std::string exe_name = ""
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)

vector<size_t> cur_combo

Which combo settings are we currently using?

size_t combo_id = 0

Unique value indicating which combination we are on.

vector<std::string> unused_args
std::string errors
struct ActionFlag

A setting that is just a flag with an action function to run if it’s called.

Public Members

std::string name

Name for this flag.

std::string desc

Description of flag.

char flag

Command-line flag (‘\0’ for none)

std::function<void()> fun

Function to be called if flag is set.

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 std::string AsString() const override
inline std::string AsString(size_t id) const override
inline bool FromString(const std::string_view &input) override
inline bool SetValueID(size_t id) override
inline bool IsComboSetting() override
inline size_t GetID() const override

Public Members

vector<T> values

Set of values to use for this setting.

Ptr<T> var_ptr = nullptr

Pointer to variable to set as combos change.

size_t id

Unique ID/position for this setting.

struct SettingBase

Base class to describe information about a single setting.

Public Functions

inline SettingBase(const std::string &_name, const std::string &_desc, const char _flag, const std::string &_args_label)
inline virtual ~SettingBase()
virtual size_t GetSize() const = 0

How many values are available?

virtual std::string AsString() const = 0

All values, as a single string.

virtual std::string AsString(size_t) const = 0

A specified value as a string.

virtual bool FromString(const std::string_view&) = 0

Convert string to set of settings.

inline bool IsOptionMatch(const std::string &test_option) const
inline bool IsFlagMatch(const char test_flag) const

Public Members

std::string name

Name for this setting.

std::string desc

Description of setting.

char flag

Command-line flag (‘\0’ for none)

std::string option

Command-line longer option.

std::string args_label

Label for option arguments (used in &#8212;help)

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 std::string AsString() const override
inline std::string AsString(size_t id) const override
inline bool FromString(const std::string_view &input) override

Public Members

T value
Ptr<T> var_ptr = nullptr