27#include "neml2/misc/utils.h"
40class LabeledAxisAccessor;
74void _print_helper(std::ostream & os,
const P *);
76void _print_helper(std::ostream & os,
const std::vector<P> *);
78void _print_helper(std::ostream & os,
const std::vector<std::vector<P>> *);
81void _print_helper(std::ostream & os,
const char *);
84void _print_helper(std::ostream & os,
const unsigned char *);
92std::ostream &
operator<<(std::ostream & os,
const OptionSet & p);
144 template <
typename T>
145 bool contains(
const std::string &)
const;
152 bool contains(
const std::string &)
const;
158 virtual void clear();
161 void print(std::ostream &
os = std::cout)
const;
205 virtual void print(std::ostream &)
const = 0;
211 virtual std::unique_ptr<OptionBase>
clone()
const = 0;
289 template <
typename T>
307 const T &
get()
const {
return _value; }
312 T &
set() {
return _value; }
314 virtual void print(std::ostream &)
const override;
316 virtual std::unique_ptr<OptionBase>
clone()
const override;
327 template <
typename T>
328 const T &
get(
const std::string &)
const;
330 const OptionBase &
get(
const std::string &)
const;
338 template <
typename T, FType f = FType::NONE>
339 T &
set(
const std::string &);
340 OptionBase &
set(
const std::string &);
348 template <
typename T>
351 template <
typename T>
355 typedef std::map<std::string, std::unique_ptr<OptionBase>, std::less<>>
map_type;
469 return !(*
this ==
other);
477 details::_print_helper(
os,
static_cast<const T *
>(&_value));
482std::unique_ptr<OptionSet::OptionBase>
485 auto copy = std::make_unique<Option<T>>(this->name());
486 copy->_value = this->_value;
487 copy->_metadata = this->_metadata;
497 if (
dynamic_cast<const Option<T> *
>(
it->second.get()))
507 "ERROR: no option named \"",
509 "\" found.\n\nKnown options:\n",
516template <
typename T, FType F>
546_print_helper(std::ostream &
os,
const P *
option)
553_print_helper(std::ostream & os,
const char * option)
555 os << static_cast<int>(*option);
560_print_helper(std::ostream & os,
const unsigned char * option)
562 os << static_cast<int>(*option);
567_print_helper(std::ostream & os,
const std::vector<P> * option)
569 for (
const auto & p : *option)
575_print_helper(std::ostream & os,
const std::vector<std::vector<P>> * option)
577 for (
const auto & pv : *option)
578 for (const auto & p : pv)
The wrapper (decorator) for cross-referencing unresolved values at parse time.
Definition CrossRef.h:56
The accessor containing all the information needed to access an item in a LabeledAxis.
Definition LabeledAxisAccessor.h:47
Definition OptionSet.h:167
virtual void print(std::ostream &) const =0
const std::string & name() const
A readonly reference to the option's name.
Definition OptionSet.h:178
FType & ftype()
A writable reference to the option's ftype.
Definition OptionSet.h:187
const std::string & type() const
A readonly reference to the option's type.
Definition OptionSet.h:181
virtual ~OptionBase()=default
const bool & suppressed() const
A readonly reference to the option's suppression status.
Definition OptionSet.h:196
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:190
virtual std::unique_ptr< OptionBase > clone() const =0
std::string & doc()
A writable reference to the option's docstring.
Definition OptionSet.h:193
bool & suppressed()
A writable reference to the option's suppression status.
Definition OptionSet.h:199
virtual bool operator!=(const OptionBase &other) const =0
Test for option inequality.
const FType & ftype() const
A readonly reference to the option's ftype.
Definition OptionSet.h:184
Definition OptionSet.h:291
virtual void print(std::ostream &) const override
Definition OptionSet.h:475
T & set()
Definition OptionSet.h:312
virtual std::unique_ptr< OptionBase > clone() const override
Definition OptionSet.h:483
virtual bool operator==(const OptionBase &other) const override
Test for option equality.
Definition OptionSet.h:456
virtual bool operator!=(const OptionBase &other) const override
Test for option inequality.
Definition OptionSet.h:467
Option(const std::string &name)
Definition OptionSet.h:293
const T & get() const
Definition OptionSet.h:307
A custom map-like data structure. The keys are strings, and the values can be nonhomogeneously typed.
Definition OptionSet.h:100
map_type _values
Data structure to map names with values.
Definition OptionSet.h:451
T & set_buffer(const std::string &)
Convenient method to request a buffer.
Definition OptionSet.h:536
virtual ~OptionSet()=default
const std::string & name() const
A readonly reference to the option set's name.
Definition OptionSet.h:120
const std::string & type() const
A readonly reference to the option set's type.
Definition OptionSet.h:124
LabeledAxisAccessor & set_output(const std::string &)
Definition OptionSet.cxx:80
std::string & name()
A writable reference to the option set's name.
Definition OptionSet.h:122
LabeledAxisAccessor & set_input(const std::string &)
Definition OptionSet.cxx:74
std::string & type()
A writable reference to the option set's type.
Definition OptionSet.h:126
const std::string & doc() const
A readonly reference to the option set's docstring.
Definition OptionSet.h:132
map_type::const_iterator const_iterator
Constant option map iterator.
Definition OptionSet.h:361
const std::string & section() const
A readonly reference to the option set's section.
Definition OptionSet.h:136
std::map< std::string, std::unique_ptr< OptionBase >, std::less<> > map_type
The type of the map that we store internally.
Definition OptionSet.h:355
T & set_parameter(const std::string &)
Convenient method to request a parameter.
Definition OptionSet.h:529
iterator begin()
Iterator pointing to the beginning of the set of options.
Definition OptionSet.cxx:172
iterator end()
Iterator pointing to the end of the set of options.
Definition OptionSet.cxx:184
const std::string & path() const
A readonly reference to the option set's path.
Definition OptionSet.h:128
std::string & doc()
A writable reference to the option set's docstring.
Definition OptionSet.h:134
void operator+=(const OptionSet &source)
Definition OptionSet.cxx:101
const T & get(const std::string &) const
Definition OptionSet.h:504
struct neml2::OptionSet::Metadata _metadata
virtual void clear()
Clear internal data structures & frees any allocated memory.
Definition OptionSet.cxx:86
std::string & path()
A writable reference to the option set's path.
Definition OptionSet.h:130
std::string & section()
A writable reference to the option set's section.
Definition OptionSet.h:138
std::size_t size() const
Definition OptionSet.h:155
T & set(const std::string &)
Definition OptionSet.h:518
void print(std::ostream &os=std::cout) const
Print the contents.
Definition OptionSet.cxx:111
OptionSet & operator=(const OptionSet &source)
Assignment operator. Deep copy.
Definition OptionSet.cxx:92
bool contains(const std::string &) const
Definition OptionSet.h:493
map_type::iterator iterator
Option map iterator.
Definition OptionSet.h:358
std::string demangle(const char *name)
Demangle a piece of cxx abi type information.
Definition utils.cxx:33
Definition CrossRef.cxx:30
bool options_compatible(const OptionSet &opts, const OptionSet &additional_opts)
Definition OptionSet.cxx:31
FType
Role in a function definition.
Definition OptionSet.h:52
std::ostream & operator<<(std::ostream &os, const EnumSelection &es)
Definition EnumSelection.cxx:31
void neml_assert(bool assertion, Args &&... args)
Definition error.h:64