|
NEML2 2.1.0
|
A custom map-like data structure. The keys are strings, and the values can be nonhomogeneously typed. More...
A custom map-like data structure. The keys are strings, and the values can be nonhomogeneously typed.
#include <OptionSet.h>
Classes | |
| struct | Metadata |
Public Types | |
| using | map_type = std::map<std::string, std::unique_ptr<OptionBase>, std::less<>> |
| The type of the map that we store internally. | |
| using | iterator = map_type::iterator |
| Option map iterator. | |
| using | const_iterator = map_type::const_iterator |
| Constant option map iterator. | |
Public Member Functions | |
| OptionSet ()=default | |
| OptionSet (const OptionSet &) | |
| OptionSet (OptionSet &&) noexcept | |
| OptionSet & | operator= (const OptionSet &) |
| OptionSet & | operator= (OptionSet &&) noexcept |
| virtual | ~OptionSet ()=default |
| const std::string & | name () const |
| A readonly reference to the option set's name. | |
| std::string & | name () |
| A writable reference to the option set's name. | |
| const std::string & | type () const |
| A readonly reference to the option set's type. | |
| std::string & | type () |
| A writable reference to the option set's type. | |
| const std::string & | path () const |
| A readonly reference to the option set's path. | |
| std::string & | path () |
| A writable reference to the option set's path. | |
| const std::string & | doc () const |
| A readonly reference to the option set's docstring. | |
| std::string & | doc () |
| A writable reference to the option set's docstring. | |
| const std::string & | section () const |
| A readonly reference to the option set's section. | |
| std::string & | section () |
| A writable reference to the option set's section. | |
| bool | contains (const std::string &) const |
| bool | user_specified (const std::string &name) const |
| bool | defined (const std::string &name) const |
| void | suppress (const std::string &name) |
| Suppress an option. | |
| std::size_t | size () const |
| void | clear () |
| Clear internal data structures & frees any allocated memory. | |
| std::string | to_str () const |
| Print the contents. | |
| template<typename T> | |
| T | get (const std::string &) const |
| const OptionBase & | get (const std::string &) const |
| Get a const reference to the specified option value. | |
| template<typename K, typename V> | |
| std::map< K, V > | get_map (const std::string &, const std::string &) const |
| Get two options and bind them to form a map. | |
| template<typename T, FType f = FType::NONE> | |
| void | add (const std::string &name, const T &default_value, std::string doc) |
| Create an option with its default value and its docstring. | |
| template<typename T, FType f = FType::NONE> | |
| void | add (const std::string &name, std::string doc) |
| Create a required option with its docstring, without a default value. User must specify a value for this option from the input file. | |
| template<typename T, FType f = FType::NONE> | |
| void | add_optional (const std::string &name, std::string doc) |
| Create an optional option with its docstring, without a default value. | |
| template<typename T> | |
| void | add_private (const std::string &name, const T &default_value) |
| Create a private option with its default value. | |
| template<typename T> | |
| void | set (const std::string &name, const T &value) |
| Set an option. | |
| template<typename T> | |
| void | set_private (const std::string &name, const T &value) |
| Set a private option. | |
| iterator | begin () |
| Iterator pointing to the beginning of the set of options. | |
| const_iterator | begin () const |
| Iterator pointing to the beginning of the set of options. | |
| iterator | end () |
| Iterator pointing to the end of the set of options. | |
| const_iterator | end () const |
| Iterator pointing to the end of the set of options. | |
| void | operator+= (const OptionSet &source) |
| void | operator+= (OptionSet &&source) |
| void | add_input (const std::string &, const VariableName &, std::string) |
| void | add_input (const std::string &, std::string) |
| void | add_optional_input (const std::string &, std::string) |
| void | add_output (const std::string &, const VariableName &, std::string) |
| Convenient methods to add output variable. | |
| void | add_output (const std::string &, std::string) |
| void | add_optional_output (const std::string &, std::string) |
| template<typename T> | |
| void | add_parameter (const std::string &, const TensorName< T > &, std::string) |
| Convenient methods to add parameter. | |
| template<typename T> | |
| void | add_parameter (const std::string &, std::string) |
| template<typename T> | |
| void | add_buffer (const std::string &, const TensorName< T > &, std::string) |
| Convenient methods to add buffer. | |
| template<typename T> | |
| void | add_buffer (const std::string &, std::string) |
Protected Attributes | |
| struct neml2::OptionSet::Metadata | _metadata |
| map_type | _values |
| Data structure to map names with values. | |
| using const_iterator = map_type::const_iterator |
Constant option map iterator.
| using map_type = std::map<std::string, std::unique_ptr<OptionBase>, std::less<>> |
The type of the map that we store internally.
|
default |
| OptionSet | ( | const OptionSet & | ) |
|
noexcept |
|
virtualdefault |
| void add | ( | const std::string & | name, |
| const T & | default_value, | ||
| std::string | doc ) |
Create an option with its default value and its docstring.
Throws an exception if the option already exists.
Calling this method sets the following metadata for the option:
Note that later on when a Parser parses the input file, if the user has specified a value for this option, the option value will be overwritten and the user_specified flag will be set to true. If the user has not specified a value for this option, the default value will be used.
| T | Type of the option value |
| f | Option type (e.g., parameter, buffer, input, output) |
| void add | ( | const std::string & | name, |
| std::string | doc ) |
Create a required option with its docstring, without a default value. User must specify a value for this option from the input file.
Throws an exception if the option already exists.
Calling this method sets the following metadata for the option:
Note that later on when a Parser parses the input file, if the user has specified a value for this option, the option value will be overwritten and both the user_specified flag and the defined flag will be set to true. The Parser should consider it an error if the user has not specified a value for this option.
| T | Type of the option value |
| f | Option type (e.g., parameter, buffer, input, output) |
| void add_buffer | ( | const std::string & | name, |
| const TensorName< T > & | tensor_name, | ||
| std::string | doc ) |
Convenient methods to add buffer.
| void add_buffer | ( | const std::string & | name, |
| std::string | doc ) |
| void add_input | ( | const std::string & | , |
| const VariableName & | , | ||
| std::string | ) |
Convenient methods to add input variable
| void add_input | ( | const std::string & | , |
| std::string | ) |
| void add_optional | ( | const std::string & | name, |
| std::string | doc ) |
Create an optional option with its docstring, without a default value.
Throws an exception if the option already exists.
Calling this method sets the following metadata for the option:
Note that later on when a Parser parses the input file, if the user has specified a value for this option, the option value will be overwritten and both the user_specified flag and the defined flag will be set to true. If the user has not specified a value for this option, the option is considered undefined and an exception will be thrown when attempting to retrieve the option value.
| T | Type of the option value |
| f | Option type (e.g., parameter, buffer, input, output) |
| void add_optional_input | ( | const std::string & | , |
| std::string | ) |
| void add_optional_output | ( | const std::string & | , |
| std::string | ) |
| void add_output | ( | const std::string & | , |
| const VariableName & | , | ||
| std::string | ) |
Convenient methods to add output variable.
| void add_output | ( | const std::string & | , |
| std::string | ) |
| void add_parameter | ( | const std::string & | name, |
| const TensorName< T > & | tensor_name, | ||
| std::string | doc ) |
Convenient methods to add parameter.
| void add_parameter | ( | const std::string & | name, |
| std::string | doc ) |
| void add_private | ( | const std::string & | name, |
| const T & | default_value ) |
Create a private option with its default value.
Throws an exception if the option already exists.
Calling this method sets the following metadata for the option:
| T | Type of the option value |
| name | The name of the option |
| default_value | The default value to set |
| iterator begin | ( | ) |
Iterator pointing to the beginning of the set of options.
| const_iterator begin | ( | ) | const |
Iterator pointing to the beginning of the set of options.
| void clear | ( | ) |
Clear internal data structures & frees any allocated memory.
| bool contains | ( | const std::string & | ) | const |
| bool defined | ( | const std::string & | name | ) | const |
|
inline |
A writable reference to the option set's docstring.
|
inline |
A readonly reference to the option set's docstring.
| iterator end | ( | ) |
Iterator pointing to the end of the set of options.
| const_iterator end | ( | ) | const |
Iterator pointing to the end of the set of options.
| const OptionBase & get | ( | const std::string & | ) | const |
Get a const reference to the specified option value.
| T get | ( | const std::string & | name | ) | const |
| std::map< K, V > get_map | ( | const std::string & | key_option, |
| const std::string & | value_option ) const |
Get two options and bind them to form a map.
The two options are expected to be of type std::vector<K> and std::vector<V>, respectively. Keys shall be unique. Otherwise, an exception is thrown.
| K | Key type |
| V | Value type |
|
inline |
A writable reference to the option set's name.
|
inline |
A readonly reference to the option set's name.
| void operator+= | ( | const OptionSet & | source | ) |
Addition/Assignment operator. Inserts copies of all options from source. Any options of the same name already in this are replaced.
| void operator+= | ( | OptionSet && | source | ) |
|
inline |
A writable reference to the option set's path.
|
inline |
A readonly reference to the option set's path.
|
inline |
A writable reference to the option set's section.
|
inline |
A readonly reference to the option set's section.
| void set | ( | const std::string & | name, |
| const T & | value ) |
Set an option.
The option must already exist. Otherwise, an exception is thrown. The option value is overridden if it already exists.
Calling this method sets the following metadata for the option:
| T | Type of the option value |
| name | The name of the option |
| value | The value to set |
| void set_private | ( | const std::string & | name, |
| const T & | value ) |
Set a private option.
The option must already exist. Otherwise, an exception is thrown. The option value is overridden if it already exists.
Calling this method sets the following metadata for the option:
| T | Type of the option value |
| name | The name of the option |
| value | The value to set |
|
inline |
| void suppress | ( | const std::string & | name | ) |
Suppress an option.
| std::string to_str | ( | ) | const |
Print the contents.
|
inline |
A writable reference to the option set's type.
|
inline |
A readonly reference to the option set's type.
| bool user_specified | ( | const std::string & | name | ) | const |
|
protected |