SPH
|
Generic object containing various settings and parameters of the run. More...
#include <Settings.h>
Public Member Functions | |
Settings () | |
Initialize settings by settings all value to their defaults. More... | |
Settings (EmptySettingsTag) | |
Initialize empty settings object. More... | |
Settings (const Settings &other) | |
Settings (Settings &&other) | |
Settings & | operator= (std::initializer_list< Entry > list) |
Assigns a list of settings into the object, erasing all previous entries. More... | |
Settings & | operator= (const Settings &other) |
Settings & | operator= (Settings &&other) |
template<typename TValue > | |
Settings & | set (const TEnum idx, TValue &&value, std::enable_if_t<!std::is_enum< std::decay_t< TValue >>::value, int >=0) |
Saves a value into the settings. More... | |
template<typename TValue > | |
Settings & | set (const TEnum idx, TValue &&value, std::enable_if_t< std::is_enum< std::decay_t< TValue >>::value, int >=0) |
Saves a value into the settings. More... | |
template<typename TValue , typename = std::enable_if_t<std::is_enum<TValue>::value>> | |
Settings & | set (const TEnum idx, const Flags< TValue > flags) |
Saves flags into the settings. More... | |
Settings & | set (const TEnum idx, EmptyFlags) |
Clear flags of given parameter in settings. More... | |
Settings & | set (const TEnum idx, const EnumWrapper ew) |
Special setter for value of type EnumWrapper. More... | |
void | addEntries (const Settings &settings) |
Adds entries from different Settings object into this one, overriding current entries. More... | |
void | unset (const TEnum idx) |
Removes given parameter from settings. More... | |
template<typename TValue > | |
TValue | get (const TEnum idx, std::enable_if_t<!std::is_enum< std::decay_t< TValue >>::value, int >=0) const |
Returns a value of given type from the settings. More... | |
template<typename TValue > | |
TValue | get (const TEnum idx, std::enable_if_t< std::is_enum< std::decay_t< TValue >>::value, int >=0) const |
Returns a value of given type from the settings. More... | |
template<typename TValue > | |
Flags< TValue > | getFlags (const TEnum idx) const |
Returns Flags from underlying value stored in settings. More... | |
bool | has (const TEnum idx) const |
Checks if the given entry is stored in the settings. More... | |
template<typename TValue > | |
bool | hasType (const TEnum idx) const |
Checks if the given entry has specified type. More... | |
Outcome | saveToFile (const Path &path) const |
Saves all values stored in settings into file. More... | |
Outcome | loadFromFile (const Path &path) |
Loads the settings from file. More... | |
bool | tryLoadFileOrSaveCurrent (const Path &path, const Settings &overrides=EMPTY_SETTINGS) |
If the specified file exists, loads the settings from it, otherwise creates the file and saves the current values. More... | |
SettingsIterator< TEnum > | begin () const |
Iterator to the first entry of the settings storage. More... | |
SettingsIterator< TEnum > | end () const |
Iterator to the one-past-end entry the settings storage. More... | |
Size | size () const |
Returns the number of entries in the settings. More... | |
Static Public Member Functions | |
static Optional< std::string > | getEntryName (const TEnum idx) |
Returns the human-readable name of the entry with given index. More... | |
static Optional< int > | getEntryType (const TEnum idx) |
Returns the type of the entry with given index. More... | |
static std::string | typeToString (const int type) |
Returns the string name for given type index. More... | |
static Optional< std::string > | getEntryDesc (const TEnum idx) |
Returns a description of the entry with given index. More... | |
static Optional< TEnum > | getEntryId (const std::string &name) |
Returns an ID for given entry name. More... | |
static const Settings & | getDefaults () |
\brief Returns a reference to object containing default values of all settings. More... | |
Friends | |
template<typename > | |
class | SettingsIterator |
Generic object containing various settings and parameters of the run.
Settings is a storage containing pairs key-value objects, where key is one of predefined enums. The value can have multiple types within the same Settings object. Currently following types can be stored: bool, int, enums, float (or double), std::string, Interval, Vector, SymmetricTensor, TracelessTensor.
The template cannot be used directly as it is missing default values of parameters; instead specializations for specific enums should be used. The code defines two base specializations:
The object can be specialized for other usages, provided static member Settings::instance is created, see one of existing specializations.
Definition at line 108 of file Settings.h.
Initialize settings by settings all value to their defaults.
Definition at line 22 of file Settings.impl.h.
Settings< TEnum >::Settings | ( | EmptySettingsTag | ) |
Initialize empty settings object.
Definition at line 26 of file Settings.impl.h.
Definition at line 29 of file Settings.impl.h.
Definition at line 33 of file Settings.impl.h.
|
inline |
Adds entries from different Settings object into this one, overriding current entries.
Entries not stored in the given settings are kept unchanged.
InvalidSettingsAccess | if the settings share entries that differ in type. |
Definition at line 297 of file Settings.h.
SettingsIterator< TEnum > Settings< TEnum >::begin |
Iterator to the first entry of the settings storage.
Definition at line 342 of file Settings.impl.h.
SettingsIterator< TEnum > Settings< TEnum >::end |
Iterator to the one-past-end entry the settings storage.
Definition at line 347 of file Settings.impl.h.
|
inline |
Returns a value of given type from the settings.
Value must be stored in settings and must have corresponding type.
TValue | Type of the value we wish to return. This type must match the type of the saved quantity. |
idx | Key of the value. |
InvalidSettingsAccess | if value is not stored in the settings or has a different type. |
Definition at line 335 of file Settings.h.
|
inline |
Returns a value of given type from the settings.
Value must be stored in settings and must have corresponding type.
TValue | Type of the value we wish to return. This type must match the type of the saved quantity. |
idx | Key of the value. |
InvalidSettingsAccess | if value is not stored in the settings or has a different type. |
Definition at line 326 of file Settings.h.
\brief Returns a reference to object containing default values of all settings.
Definition at line 357 of file Settings.impl.h.
|
inlinestatic |
Returns a description of the entry with given index.
If the index does not correspond to any parameter, returns string NOTHING.
Definition at line 389 of file Settings.h.
|
inlinestatic |
Returns an ID for given entry name.
This is the inverse of function getEntryName.
Definition at line 403 of file Settings.h.
|
inlinestatic |
Returns the human-readable name of the entry with given index.
If the index does not correspond to any parameter, returns string NOTHING.
Definition at line 357 of file Settings.h.
|
inlinestatic |
Returns the type of the entry with given index.
If the index does not correspond to any parameter, returns NOTHING.
Definition at line 371 of file Settings.h.
|
inline |
Returns Flags from underlying value stored in settings.
Syntactic suggar, avoid cumbersome conversion to underlying type and then to Flags.
Definition at line 348 of file Settings.h.
|
inline |
Checks if the given entry is stored in the settings.
Definition at line 414 of file Settings.h.
|
inline |
Checks if the given entry has specified type.
InvalidSettingsAccess | if the entry is not in settings. |
Definition at line 422 of file Settings.h.
Loads the settings from file.
Previous values stored in settings are removed. The file must have a valid settings format.
path | Path to the file. The file must exist. |
Definition at line 200 of file Settings.impl.h.
Settings< TEnum > & Settings< TEnum >::operator= | ( | const Settings< TEnum > & | other | ) |
Definition at line 46 of file Settings.impl.h.
Settings< TEnum > & Settings< TEnum >::operator= | ( | Settings< TEnum > && | other | ) |
Definition at line 52 of file Settings.impl.h.
Settings< TEnum > & Settings< TEnum >::operator= | ( | std::initializer_list< Entry > | list | ) |
Assigns a list of settings into the object, erasing all previous entries.
Definition at line 37 of file Settings.impl.h.
Saves all values stored in settings into file.
path | Path (relative or absolute) to the file. The file will be created, any previous content will be overriden. |
Definition at line 241 of file Settings.impl.h.
|
inline |
Special setter for value of type EnumWrapper.
While usually the enum can be stored directly, this overload is useful for deserialization, etc.
InvalidSettingsAccess | if settings value of different type than the one currently stored. |
Definition at line 283 of file Settings.h.
|
inline |
Saves flags into the settings.
Flags are not considered as a different type, they are internally saved as enum wrapper.
InvalidSettingsAccess | if settings value of different type than the one currently stored. |
Definition at line 262 of file Settings.h.
|
inline |
Clear flags of given parameter in settings.
This function can be used only if the value is already stored in the settings.
InvalidSettingsAccess | if the value is not stored or has a different type. |
Definition at line 271 of file Settings.h.
|
inline |
Saves a value into the settings.
Any previous value of the same ID is overriden.
TValue | Type of the value to be saved. Does not have to be specified, type deduction can be used to determine it. Must be one of types listed in object description. Using other types will result in compile error. |
idx | Key identifying the value. This key can be used to retrive the value later. |
value | Value being stored into settings. |
InvalidSettingsAccess | if settings value of different type than the one currently stored. |
Definition at line 242 of file Settings.h.
|
inline |
Saves a value into the settings.
Any previous value of the same ID is overriden.
TValue | Type of the value to be saved. Does not have to be specified, type deduction can be used to determine it. Must be one of types listed in object description. Using other types will result in compile error. |
idx | Key identifying the value. This key can be used to retrive the value later. |
value | Value being stored into settings. |
InvalidSettingsAccess | if settings value of different type than the one currently stored. |
Definition at line 226 of file Settings.h.
Returns the number of entries in the settings.
This includes default entries in case the object was not constructed with EMPTY_SETTINGS tag.
Definition at line 352 of file Settings.impl.h.
bool Settings< TEnum >::tryLoadFileOrSaveCurrent | ( | const Path & | path, |
const Settings< TEnum > & | overrides = EMPTY_SETTINGS |
||
) |
If the specified file exists, loads the settings from it, otherwise creates the file and saves the current values.
This is a standard behavior of configuration files used in the simulation. First time the simulation is started, the configuration files are created with default values. The files can then be modified by the user and the next time simulation is started, the parameters are parsed and used instead of the defaults.
For convenience, it is possible to pass a set of overrides, which are used instead of the values loaded from the configuration file (or defaults, if the file does not exist). This can be used to specify settings as command-line parameters, for example.
path | Path to the configuration file. |
overrides | Set of overrides applied on the current values or after the settings are loaded. |
Exception | if loading of the file failed (invalid content, unknown parameters, ...). |
Definition at line 304 of file Settings.impl.h.
|
static |
Returns the string name for given type index.
Exception | for unknown type index |
Definition at line 322 of file Settings.impl.h.
|
inline |
Removes given parameter from settings.
If the parameter is not in settings, nothing happens (it isn't considered as an error).
Definition at line 313 of file Settings.h.
Definition at line 110 of file Settings.h.