27#include "neml2/misc/error.h"
28#include "neml2/misc/types.h"
29#include "neml2/misc/parser_utils.h"
48void print_helper(std::ostream & os,
const std::vector<P> *);
50void print_helper(std::ostream & os,
const std::vector<std::vector<P>> *);
103 template <
typename T>
104 bool contains(
const std::string &)
const;
111 bool contains(
const std::string &)
const;
117 virtual void clear();
120 void print(std::ostream &
os = std::cout)
const;
155 virtual void print(std::ostream &)
const = 0;
161 virtual std::unique_ptr<OptionBase>
clone()
const = 0;
226 template <
typename T>
242 const T &
get()
const {
return _value; }
247 T &
set() {
return _value; }
249 virtual void print(std::ostream &)
const override;
251 virtual std::unique_ptr<OptionBase>
clone()
const override;
262 template <
typename T>
263 const T &
get(
const std::string &)
const;
265 const OptionBase &
get(
const std::string &)
const;
272 template <
typename T>
273 T &
set(
const std::string &);
275 OptionBase &
set(
const std::string &);
278 typedef std::map<std::string, std::unique_ptr<OptionBase>, std::less<>>
map_type;
398std::unique_ptr<OptionSet::OptionBase>
401 auto copy = std::make_unique<Option<T>>(this->name());
402 copy->_value = this->_value;
403 copy->_metadata = this->_metadata;
415 if (
dynamic_cast<const Option<T> *
>(
it->second.get()))
425 "ERROR: no option named \"",
427 "\" found.\n\nKnown options:\n",
481 for (
const auto &
p :
pv)
The wrapper (decorator) for cross-referencing unresolved values at parse time.
Definition CrossRef.h:52
Definition OptionSet.h:126
virtual void print(std::ostream &) const =0
const std::string & name() const
A readonly reference to the option's name.
Definition OptionSet.h:134
const std::string & type() const
A readonly reference to the option's type.
Definition OptionSet.h:137
virtual ~OptionBase()=default
const bool & suppressed() const
A readonly reference to the option's suppression status.
Definition OptionSet.h:146
struct neml2::OptionSet::OptionBase::Metadata _metadata
virtual bool operator==(const OptionBase &other) const =0
Test for option equality.
const std::string & doc() const
A readonly reference to the option's docstring.
Definition OptionSet.h:140
virtual std::unique_ptr< OptionBase > clone() const =0
std::string & doc()
A writable reference to the option's docstring.
Definition OptionSet.h:143
bool & suppressed()
A writable reference to the option's suppression status.
Definition OptionSet.h:149
Definition OptionSet.h:228
virtual void print(std::ostream &) const override
Definition OptionSet.h:391
T & set()
Definition OptionSet.h:247
virtual std::unique_ptr< OptionBase > clone() const override
Definition OptionSet.h:399
virtual bool operator==(const OptionBase &other) const override
Test for option equality.
Definition OptionSet.h:379
Option(const std::string &name)
Definition OptionSet.h:230
const T & get() const
Definition OptionSet.h:242
A custom map-like data structure. The keys are strings, and the values can be nonhomogeneously typed.
Definition OptionSet.h:59
map_type _values
Data structure to map names with values.
Definition OptionSet.h:374
virtual ~OptionSet()=default
const std::string & name() const
A readonly reference to the option set's name.
Definition OptionSet.h:79
const std::string & type() const
A readonly reference to the option set's type.
Definition OptionSet.h:83
std::string & name()
A writable reference to the option set's name.
Definition OptionSet.h:81
std::string & type()
A writable reference to the option set's type.
Definition OptionSet.h:85
const std::string & doc() const
A readonly reference to the option set's docstring.
Definition OptionSet.h:91
map_type::const_iterator const_iterator
Constant option map iterator.
Definition OptionSet.h:284
const std::string & section() const
A readonly reference to the option set's section.
Definition OptionSet.h:95
std::map< std::string, std::unique_ptr< OptionBase >, std::less<> > map_type
The type of the map that we store internally.
Definition OptionSet.h:278
iterator begin()
Iterator pointing to the beginning of the set of options.
Definition OptionSet.cxx:129
iterator end()
Iterator pointing to the end of the set of options.
Definition OptionSet.cxx:141
const std::string & path() const
A readonly reference to the option set's path.
Definition OptionSet.h:87
std::string & doc()
A writable reference to the option set's docstring.
Definition OptionSet.h:93
virtual void operator+=(const OptionSet &source)
Definition OptionSet.cxx:78
const T & get(const std::string &) const
Definition OptionSet.h:422
struct neml2::OptionSet::Metadata _metadata
virtual void clear()
Clear internal data structures & frees any allocated memory.
Definition OptionSet.cxx:63
std::string & path()
A writable reference to the option set's path.
Definition OptionSet.h:89
T & set(const std::string &)
Definition OptionSet.h:436
std::string & section()
A writable reference to the option set's section.
Definition OptionSet.h:97
std::size_t size() const
Definition OptionSet.h:114
void print(std::ostream &os=std::cout) const
Print the contents.
Definition OptionSet.cxx:88
virtual OptionSet & operator=(const OptionSet &source)
Assignment operator. Deep copy.
Definition OptionSet.cxx:69
bool contains(const std::string &) const
Definition OptionSet.h:411
map_type::iterator iterator
Option map iterator.
Definition OptionSet.h:281
std::string demangle(const char *name)
Definition parser_utils.cxx:46
Definition CrossRef.cxx:32
std::ostream & operator<<(std::ostream &os, const OptionCollection &p)
Definition OptionCollection.cxx:37
void print_helper(std::ostream &os, const P *)
Definition OptionSet.h:447
void neml_assert(bool assertion, Args &&... args)
Definition error.h:73