NEML2 1.4.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

struct  Metadata
 
class  Option
 
class  OptionBase
 

Public Member Functions

 OptionSet ()=default
 
 OptionSet (const OptionSet &)
 Copy constructor. Deep copy.
 
virtual ~OptionSet ()=default
 
OptionSetoperator= (const OptionSet &source)
 Assignment operator. Deep copy.
 
void operator+= (const OptionSet &source)
 
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.
 
template<typename T >
bool contains (const std::string &) const
 
bool contains (const std::string &) const
 
std::size_t size () const
 
virtual void clear ()
 Clear internal data structures & frees any allocated memory.
 
void print (std::ostream &os=std::cout) const
 Print the contents.
 
template<typename T >
const T & get (const std::string &) const
 
const OptionBaseget (const std::string &) const
 
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

typedef std::map< std::string, std::unique_ptr< OptionBase >, std::less<> > map_type
 The type of the map that we store internally.
 
typedef map_type::iterator iterator
 Option map iterator.
 
typedef map_type::const_iterator 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

typedef map_type::const_iterator const_iterator

Constant option map iterator.

◆ iterator

typedef map_type::iterator iterator

Option map iterator.

◆ map_type

typedef std::map<std::string, std::unique_ptr<OptionBase>, std::less<> > map_type

The type of the map that we store internally.

Constructor & Destructor Documentation

◆ OptionSet() [1/2]

OptionSet ( )
default

◆ OptionSet() [2/2]

Copy constructor. Deep copy.

◆ ~OptionSet()

virtual ~OptionSet ( )
virtualdefault

Member Function Documentation

◆ begin() [1/2]

Iterator pointing to the beginning of the set of options.

◆ begin() [2/2]

OptionSet::const_iterator begin ( ) const

Iterator pointing to the beginning of the set of options.

◆ clear()

void clear ( )
virtual

Clear internal data structures & frees any allocated memory.

◆ contains() [1/2]

template<typename T >
bool contains ( const std::string & name) const
Returns
true if an option of type T with a specified name exists, false otherwise.

◆ contains() [2/2]

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

We return true if an option of specified name exists regardless of its type.

◆ 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 pointing to the end of the set of options.

◆ end() [2/2]

Iterator pointing to the end of the set of options.

◆ get() [1/2]

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

◆ get() [2/2]

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

◆ 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+=()

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.

◆ operator=()

Assignment operator. Deep copy.

◆ 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.

◆ print()

void print ( std::ostream & os = std::cout) const

Print the contents.

◆ 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]

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() [2/2]

OptionSet::OptionBase & set ( const std::string & name)

◆ 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 & name)

◆ set_output()

LabeledAxisAccessor & set_output ( const std::string & name)

◆ 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

◆ 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.

Member Data Documentation

◆ _metadata

struct neml2::OptionSet::Metadata _metadata
protected

◆ _values

map_type _values
protected

Data structure to map names with values.