SettingCombos.hpp

A tool for exploring all parameter combinations.

Note

Status: ALPHA

class SettingCombos
#include <SettingCombos.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

SettingCombos() = default
inline ~SettingCombos()
inline size_t GetComboID() const
inline void Reset()

Start over stepping through all combinations of parameter values.

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 vector<T> &AddSetting(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: combos.AddSetting(“pop_size”) = {100,200,400,800};

template<typename T>
inline vector<T> &AddSetting(const std::string &name, const std::string &desc, const char option_flag, T &var, const std::string &args_label = "Values...", size_t cap = (size_t)-1)

A setting can also be linked to a value that is kept up-to-date.

template<typename T>
inline vector<T> &AddSingleSetting(const std::string &name, const std::string &desc, const char option_flag, T &var, const std::string &args_label = "Value")

A SingleSetting must have exactly one value, not multiple.

inline void AddAction(const std::string &name, const std::string &desc, const char flag, std::function<void()> fun)
template<typename T>
inline vector<T> &Values(const std::string &name)

Access ALL values for a specified setting, to be modified freely.

template<typename T>
inline void AddValue(const std::string &name, T &&val)

Add a single new value to the specified setting.

template<typename T1, typename ...Ts>
inline void SetValues(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 Next()

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 GetHeaders(const std::string &separator = ",", bool include_fixed = false)

Get the set of headers used for the CSV file. By default, don’t include settings capped at one value.

inline std::string CurString(const std::string &separator = ",", bool include_fixed = false) const

Convert all of the current values into a comma-separated string.

inline size_t FindOptionMatch(const std::string &option_name)

Scan through all settings for a match option and return ID.

inline size_t FindFlagMatch(const char symbol)

Scan through all settings for a match option and return ID.

inline vector<std::string> ProcessOptions(const vector<std::string> &args)

Take an input set of config options, process them, and return set of unprocessed ones.

template<typename ...Ts>
inline void PrintHelp(const Ts&... examples) const

Private Members

std::string exe_name = ""
vector<Ptr<SettingBase>> settings

Order to be varied.

std::map<std::string, Ptr<SettingBase>> setting_map

Settings by name.

std::map<std::string, ActionFlag> action_map

Available flags.

vector<size_t> cur_combo

Which settings are we currently using?

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.

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.

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, const size_t _cap)
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.

virtual void SetValueID(size_t) = 0

Setup cur value in linked variable.

virtual bool OK() const = 0

Any problems with this setting?

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

Public Members

size_t id

Unique ID/position for this setting.

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)

size_t cap = (size_t)-1

Max number of settings allowed in combo.

template<typename T>
struct SettingInfo : public SettingCombos::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 &_args_label, const size_t _cap, Ptr<T> _var = nullptr)
inline size_t GetSize() const override
inline std::string AsString() const override
inline std::string AsString(size_t id) const override
inline bool OK() const override
inline bool FromString(const std::string_view &input) override
inline void SetValueID(size_t id) override

Public Members

vector<T> values
Ptr<T> var_ptr = nullptr