NEML2 2.1.0
Loading...
Searching...
No Matches
OptionSet Class Reference

A custom map-like data structure. The keys are strings, and the values can be nonhomogeneously typed. More...

Detailed Description

A custom map-like data structure. The keys are strings, and the values can be nonhomogeneously typed.

#include <OptionSet.h>

Classes

Public Member Functions

 OptionSet ()=default
 OptionSet (const OptionSet &)
 OptionSet (OptionSet &&) noexcept
OptionSetoperator= (const OptionSet &)
OptionSetoperator= (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
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>
get (const std::string &) const
const OptionBaseget (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 find a map.
void operator+= (const OptionSet &source)
void operator+= (OptionSet &&source)
template<typename T, FType f = FType::NONE>
T & set (const std::string &)
OptionBaseset (const std::string &)
Convenient methods to request an input variable
LabeledAxisAccessorset_input (const std::string &)

Convenient methods to request an output variable

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.
struct neml2::OptionSet::Metadata _metadata
map_type _values
 Data structure to map names with values.
LabeledAxisAccessorset_output (const std::string &)
template<typename T>
T & set_parameter (const std::string &)
 Convenient method to request a parameter.
template<typename T>
T & set_buffer (const std::string &)
 Convenient method to request a buffer.
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.

Member Typedef Documentation

◆ const_iterator

using const_iterator = map_type::const_iterator

Constant option map iterator.

◆ iterator

using iterator = map_type::iterator

Option map iterator.

◆ map_type

using map_type = std::map<std::string, std::unique_ptr<OptionBase>, std::less<>>

The type of the map that we store internally.

Constructor & Destructor Documentation

◆ OptionSet() [1/3]

OptionSet ( )
default

◆ OptionSet() [2/3]

OptionSet ( const OptionSet & )

◆ OptionSet() [3/3]

OptionSet ( OptionSet && )
noexcept

◆ ~OptionSet()

virtual ~OptionSet ( )
virtualdefault

Member Function Documentation

◆ begin() [1/2]

iterator begin ( )

Iterator pointing to the beginning of the set of options.

◆ begin() [2/2]

const_iterator begin ( ) const

Iterator pointing to the beginning of the set of options.

◆ clear()

void clear ( )

Clear internal data structures & frees any allocated memory.

◆ contains()

bool contains ( const std::string & ) const
Returns
true if an option with a specified name exists, false otherwise.

◆ doc() [1/2]

std::string & doc ( )
inline

A writable reference to the option set's docstring.

◆ doc() [2/2]

const std::string & doc ( ) const
inline

A readonly reference to the option set's docstring.

◆ end() [1/2]

iterator end ( )

Iterator pointing to the end of the set of options.

◆ end() [2/2]

const_iterator end ( ) const

Iterator pointing to the end of the set of options.

◆ get() [1/2]

const OptionBase & get ( const std::string & ) const

Get a const reference to the specified option value.

◆ get() [2/2]

template<typename T>
T get ( const std::string & name) const
Returns
A copy of the specified option value. Requires, of course, that the option exists.

◆ get_map()

template<typename K, typename V>
std::map< K, V > get_map ( const std::string & key_option,
const std::string & value_option ) const

Get two options and bind them to find a map.

Get two options and bind them to find a map

Template Parameters
KKey type
VValue type

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.

Template Parameters
KKey type
VValue type
Returns
std::map<K, V>

◆ name() [1/2]

std::string & name ( )
inline

A writable reference to the option set's name.

◆ name() [2/2]

const std::string & name ( ) const
inline

A readonly reference to the option set's name.

◆ operator+=() [1/2]

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.

Note
This operator does not modify the metadata of the option set.

◆ operator+=() [2/2]

void operator+= ( OptionSet && source)

◆ operator=() [1/2]

OptionSet & operator= ( const OptionSet & )

◆ operator=() [2/2]

OptionSet & operator= ( OptionSet && )
noexcept

◆ path() [1/2]

std::string & path ( )
inline

A writable reference to the option set's path.

◆ path() [2/2]

const std::string & path ( ) const
inline

A readonly reference to the option set's path.

◆ section() [1/2]

std::string & section ( )
inline

A writable reference to the option set's section.

◆ section() [2/2]

const std::string & section ( ) const
inline

A readonly reference to the option set's section.

◆ set() [1/2]

OptionBase & set ( const std::string & )

◆ set() [2/2]

template<typename T, FType F>
T & set ( const std::string & name)
Returns
A writable reference to the specified option value. This method will create the option if it does not exist, so it can be used to define options which will later be accessed with the get() member.

◆ set_buffer()

template<typename T>
T & set_buffer ( const std::string & name)

Convenient method to request a buffer.

◆ set_input()

LabeledAxisAccessor & set_input ( const std::string & )

◆ set_output()

LabeledAxisAccessor & set_output ( const std::string & )

◆ set_parameter()

template<typename T>
T & set_parameter ( const std::string & name)

Convenient method to request a parameter.

◆ size()

std::size_t size ( ) const
inline
Returns
The total number of options

◆ to_str()

std::string to_str ( ) const

Print the contents.

◆ type() [1/2]

std::string & type ( )
inline

A writable reference to the option set's type.

◆ type() [2/2]

const std::string & type ( ) const
inline

A readonly reference to the option set's type.

◆ user_specified()

bool user_specified ( const std::string & name) const
Returns
true if an option is specified by the user (i.e., from the input file), false otherwise.

Member Data Documentation

◆ _metadata

struct neml2::OptionSet::Metadata _metadata
protected

◆ _values

map_type _values
protected

Data structure to map names with values.