config.hpp

Maintains a set of configuration options.

This file defines a master configuration option Config, whose values can be loaded at runtime or else set as constant values throughout the code.

Assuming you have an Config object called config, you can:

access a setting value: config.SETTING_NAME() adjust a setting value: config.SETTING_NAME(new_value) determine if a setting is locked: config.SETTING_NAME_is_const() lookup a setting dynamically: config(“SETTING_NAME”) adjust a setting dynamically: config(“SETTING_NAME”, “new_value”)

load settings from a stream: config.Read(stream); load settings from a file: config.Read(filename); save settings to a stream: config.Write(stream); save settings to a file: config.Write(filename); generate a query string: config.WriteUrlQueryString(stream);

write settings macros to a stream: config.WriteMacros(stream); write settings macros to a file: config.WriteMacros(filename);

The configuration files generated can use the following keywords in order to configure this object: include OTHER_FILENAME — Load in all data from another file. set SETTING_NAME VALUE — Set a basic configuration setting. new OBJECT_TYPE OBJECT_NAME — Create a new config object of a managed class. use OBJECT_TYPE OBJECT_NAME — Use a previouly created configuration object.

class ConfigEntry
#include <config.hpp>

Base class for all configuration settings.

Subclassed by Config::ConfigLiveEntry, Config::tConfigConstEntry< VAR_TYPE >, Config::tConfigEntry< VAR_TYPE >

Public Functions

inline ConfigEntry(const std::string _name, const std::string _type, const std::string _d_val, const std::string _desc)
inline virtual ~ConfigEntry()
inline const std::string &GetName() const
inline const std::string &GetType() const
inline const std::string &GetDefault() const
inline const std::string &GetDescription() const
inline ConfigEntry &SetName(const std::string &_in)
inline ConfigEntry &SetType(const std::string &_in)
inline ConfigEntry &SetDefault(const std::string &_in)
inline ConfigEntry &SetDescription(const std::string &_in)
inline ConfigEntry &AddAlias(const std::string &_in)

Alert this setting that it is aliased to alternate possible names.

inline bool HasAlias(const std::string &_in)

Are there any alternate names for this setting?

inline bool IsMatch(const std::string &_in)

Will the provided name match this setting?

inline const std::unordered_set<std::string> &GetAliases()

Retrieve the full set of aliases.

virtual std::string GetValue() const = 0

Retrieve the value of this setting as a string.

virtual std::string GetLiteralValue() const = 0

Conver the value of this setting into a literal that C++ would recognize as its current value.

virtual ConfigEntry &SetValue(const std::string &in_val, std::stringstream &warnings) = 0

Use a string to set the value of this setting.

virtual bool IsConst() const = 0

Identify if this setting is fixed at compile time.

Protected Attributes

std::string name
std::string type
std::string default_val
std::string desc
std::unordered_set<std::string> alias_set
class Config
#include <config.hpp>

Master configuration class that manages all of the settings.

Public Functions

inline Config(const std::string &in_version = "")
inline ~Config()
inline ConfigEntry *operator[](const std::string &name)
inline auto begin() -> decltype(var_map.begin())
inline auto end() -> decltype(var_map.end())
inline const ConfigEntry *operator[](const std::string &name) const
inline auto cbegin() -> decltype(var_map.cbegin())
inline auto cend() -> decltype(var_map.cend())
inline auto begin() const -> const decltype(var_map.begin())
inline auto end() const -> const decltype(var_map.end())
inline Config &SetExpandOK(bool ok = true)
inline bool Has(const std::string &setting_name) const
inline bool ResolveAlias(std::string &setting_name) const
inline std::string Get(std::string setting_name)
inline Config &Set(std::string setting_name, const std::string &new_value, const std::string &in_desc = "")
inline std::string operator()(const std::string &setting_name)
inline Config &operator()(const std::string &setting_name, const std::string &new_value)
inline void AddAlias(const std::string &base_name, const std::string &alias_name)
inline void Write(std::ostream &out) const
inline void Write(std::string filename) const
inline void WriteUrlQueryString(std::ostream &out) const
inline void WriteMacros(std::ostream &out, bool as_const = false) const
inline void WriteMacros(std::string filename, bool as_const = false) const
inline bool Read(std::istream &input, const std::string &cur_namespace = "")

Read in from a text representation (typically a file) to set the state of Config. Return success state.

inline bool Read(std::string filename, bool error_on_missing_file = true)
inline void AddNameSpace(Config &config, const std::string &namespace_name)
inline void AddCommand(const std::string &command_name, std::function<bool(std::string)> command_fun)
inline void AddNewCallback(const std::string &type_name, std::function<bool(std::string)> new_fun)
inline void AddUseCallback(const std::string &type_name, std::function<bool(std::string)> use_fun)
template<class MANAGED_TYPE>
inline void AddManagedType(const std::string &type_keyword, const std::string &command_keyword, std::function<bool(MANAGED_TYPE&, std::string)> fun_callback)
inline vector<ConfigGroup*> GetGroupSet()

Access group_set using this method since it is protected.

Protected Functions

inline ConfigGroup *GetActiveGroup()
inline ConfigEntry *GetActiveEntry()
inline bool IsVarChar(const char c)
inline void ProcessLine(std::string &cur_line, std::string &extras)

Protected Attributes

vector<std::string> class_names
unordered_map<std::string, ConfigEntry*> var_map
std::string version_id
vector<ConfigGroup*> group_set
std::stringstream warnings
int delay_warnings
unordered_map<std::string, std::string> alias_map
unordered_map<std::string, Config*> namespace_map
unordered_map<std::string, ConfigManager_Base*> type_manager_map
unordered_map<std::string, std::function<bool(std::string)>> command_map
unordered_map<std::string, std::function<bool(std::string)>> new_map
unordered_map<std::string, std::function<bool(std::string)>> use_map
bool expand_ok
class ConfigGroup
#include <config.hpp>

Information about a sub-group of settings.

Public Functions

inline ConfigGroup(const std::string &_name, const std::string &_desc)
inline ~ConfigGroup()
inline size_t GetSize() const
inline std::string GetName() const
inline std::string GetDesc() const
inline ConfigEntry *GetEntry(size_t id)
inline ConfigEntry *GetLastEntry()
inline void Add(ConfigEntry *new_entry)
inline void Write(std::ostream &out) const
inline void WriteUrlQueryString(std::ostream &out) const
inline void WriteMacros(std::ostream &out, bool as_const) const

Protected Attributes

std::string name
std::string desc
vector<ConfigEntry*> entry_set
class ConfigLiveEntry : public ConfigEntry
#include <config.hpp>

Special settings entry for settings created during the run (only accissibly dynamically)

Public Functions

inline ConfigLiveEntry(const std::string _name, const std::string _type, const std::string _d_val, const std::string _desc)
inline ~ConfigLiveEntry()
inline virtual std::string GetValue() const

Retrieve the value of this setting as a string.

inline virtual std::string GetLiteralValue() const

Conver the value of this setting into a literal that C++ would recognize as its current value.

inline virtual ConfigEntry &SetValue(const std::string &in_val, std::stringstream &warnings)

Use a string to set the value of this setting.

inline virtual bool IsConst() const

Identify if this setting is fixed at compile time.

template<class VAR_TYPE>
class tConfigConstEntry : public ConfigEntry
#include <config.hpp>

Type-specific and CONST versions of ConfigEntry class to manage fixed settings.

Public Functions

inline tConfigConstEntry(const std::string _name, const std::string _type, const std::string _d_val, const std::string _desc, const VAR_TYPE &_literal_val)
inline ~tConfigConstEntry()
inline virtual std::string GetValue() const

Retrieve the value of this setting as a string.

inline virtual std::string GetLiteralValue() const

Conver the value of this setting into a literal that C++ would recognize as its current value.

inline virtual ConfigEntry &SetValue(const std::string &in_val, std::stringstream &warnings)

Use a string to set the value of this setting.

inline virtual bool IsConst() const

Identify if this setting is fixed at compile time.

Protected Attributes

const VAR_TYPE literal_val
template<class VAR_TYPE>
class tConfigEntry : public ConfigEntry
#include <config.hpp>

Type-specific versions of ConfigEntry class to manage settings.

Public Functions

inline tConfigEntry(const std::string _name, const std::string _type, const std::string _d_val, const std::string _desc, VAR_TYPE &_ref)
inline ~tConfigEntry()
inline virtual std::string GetValue() const

Retrieve the value of this setting as a string.

inline virtual std::string GetLiteralValue() const

Conver the value of this setting into a literal that C++ would recognize as its current value.

inline virtual ConfigEntry &SetValue(const std::string &in_val, std::stringstream&)

Use a string to set the value of this setting.

inline virtual bool IsConst() const

Identify if this setting is fixed at compile time.

Protected Attributes

VAR_TYPE &entry_ref
namespace placeholders