27#include "neml2/misc/utils.h"
40class LabeledAxisAccessor;
56void _print_helper(std::ostream & os,
const P *);
58void _print_helper(std::ostream & os,
const std::vector<P> *);
61void _print_helper(std::ostream & os,
const std::vector<bool> *);
63void _print_helper(std::ostream & os,
const std::vector<std::vector<P>> *);
66void _print_helper(std::ostream & os,
const char *);
69void _print_helper(std::ostream & os,
const unsigned char *);
77std::ostream &
operator<<(std::ostream & os,
const OptionSet & p);
132 template <
typename T>
133 bool contains(
const std::string &)
const;
140 bool contains(
const std::string &)
const;
149 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;
299 template <
typename T>
317 const T &
get()
const {
return _value; }
322 T &
set() {
return _value; }
324 void print(std::ostream &)
const override;
326 std::unique_ptr<OptionBase>
clone()
const override;
337 template <
typename T>
338 const T &
get(
const std::string &)
const;
340 const OptionBase &
get(
const std::string &)
const;
348 template <
typename T, FType f = FType::NONE>
349 T &
set(
const std::string &);
350 OptionBase &
set(
const std::string &);
358 template <
typename T>
361 template <
typename T>
365 using map_type = std::map<std::string, std::unique_ptr<OptionBase>, std::less<>>;
474 return !(*
this ==
other);
482 details::_print_helper(
os,
static_cast<const T *
>(&_value));
487std::unique_ptr<OptionSet::OptionBase>
490 auto copy = std::make_unique<Option<T>>(this->
name());
491 copy->_value = this->_value;
492 copy->_metadata = this->_metadata;
502 if (
dynamic_cast<const Option<T> *
>(
it->second.get()))
512 "ERROR: no option named \"",
514 "\" found.\n\nKnown options:\n",
521template <
typename T, FType F>
551_print_helper(std::ostream &
os,
const P *
option)
558_print_helper(std::ostream & os,
const char * option)
560 os << static_cast<int>(*option);
565_print_helper(std::ostream & os,
const unsigned char * option)
567 os << static_cast<int>(*option);
572_print_helper(std::ostream & os,
const std::vector<P> * option)
574 for (
const auto & p : *option)
580_print_helper(std::ostream & os,
const std::vector<bool> * option)
582 for (
const auto p : *option)
583 os << static_cast<bool>(p) <<
" ";
588_print_helper(std::ostream & os,
const std::vector<std::vector<P>> * option)
590 for (
const auto & pv : *option)
591 _print_helper(os, &pv);
The wrapper (decorator) for cross-referencing unresolved values at parse time.
Definition CrossRef.h:54
The accessor containing all the information needed to access an item in a LabeledAxis.
Definition LabeledAxisAccessor.h:58
Definition OptionSet.h:155
OptionBase & operator=(const OptionBase &)=delete
virtual void print(std::ostream &) const =0
const std::string & name() const
A readonly reference to the option's name.
Definition OptionSet.h:172
FType & ftype()
A writable reference to the option's ftype.
Definition OptionSet.h:181
bool & user_specified()
A writable reference to the option's user_specified status.
Definition OptionSet.h:199
OptionBase(OptionBase &&)=delete
const std::string & type() const
A readonly reference to the option's type.
Definition OptionSet.h:175
virtual ~OptionBase()=default
const bool & user_specified() const
A readonly reference to the option's user_specified status.
Definition OptionSet.h:196
const bool & suppressed() const
A readonly reference to the option's suppression status.
Definition OptionSet.h:190
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:184
virtual std::unique_ptr< OptionBase > clone() const =0
OptionBase(const OptionBase &)=delete
std::string & doc()
A writable reference to the option's docstring.
Definition OptionSet.h:187
OptionBase & operator=(OptionBase &&)=delete
bool & suppressed()
A writable reference to the option's suppression status.
Definition OptionSet.h:193
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:178
Definition OptionSet.h:301
void print(std::ostream &) const override
Definition OptionSet.h:480
T & set()
Definition OptionSet.h:322
std::unique_ptr< OptionBase > clone() const override
Definition OptionSet.h:488
bool operator==(const OptionBase &other) const override
Test for option equality.
Definition OptionSet.h:461
bool operator!=(const OptionBase &other) const override
Test for option inequality.
Definition OptionSet.h:472
Option(const std::string &name)
Definition OptionSet.h:303
const T & get() const
Definition OptionSet.h:317
A custom map-like data structure. The keys are strings, and the values can be nonhomogeneously typed.
Definition OptionSet.h:85
map_type::iterator iterator
Option map iterator.
Definition OptionSet.h:367
map_type _values
Data structure to map names with values.
Definition OptionSet.h:456
T & set_buffer(const std::string &)
Convenient method to request a buffer.
Definition OptionSet.h:541
const std::string & name() const
A readonly reference to the option set's name.
Definition OptionSet.h:108
const std::string & type() const
A readonly reference to the option set's type.
Definition OptionSet.h:112
LabeledAxisAccessor & set_output(const std::string &)
Definition OptionSet.cxx:80
map_type::const_iterator const_iterator
Constant option map iterator.
Definition OptionSet.h:369
std::map< std::string, std::unique_ptr< OptionBase >, std::less<> > map_type
The type of the map that we store internally.
Definition OptionSet.h:365
std::string & name()
A writable reference to the option set's name.
Definition OptionSet.h:110
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:114
const std::string & doc() const
A readonly reference to the option set's docstring.
Definition OptionSet.h:120
const std::string & section() const
A readonly reference to the option set's section.
Definition OptionSet.h:124
T & set_parameter(const std::string &)
Convenient method to request a parameter.
Definition OptionSet.h:534
iterator begin()
Iterator pointing to the beginning of the set of options.
Definition OptionSet.cxx:190
iterator end()
Iterator pointing to the end of the set of options.
Definition OptionSet.cxx:202
const std::string & path() const
A readonly reference to the option set's path.
Definition OptionSet.h:116
std::string & doc()
A writable reference to the option set's docstring.
Definition OptionSet.h:122
const T & get(const std::string &) const
Definition OptionSet.h:509
struct neml2::OptionSet::Metadata _metadata
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:118
std::string & section()
A writable reference to the option set's section.
Definition OptionSet.h:126
std::size_t size() const
Definition OptionSet.h:143
T & set(const std::string &)
Definition OptionSet.h:523
void print(std::ostream &os=std::cout) const
Print the contents.
Definition OptionSet.cxx:129
bool contains(const std::string &) const
Definition OptionSet.h:498
std::string demangle(const char *name)
Demangle a piece of cxx abi type information.
Definition utils.cxx:32
Definition CrossRef.cxx:31
bool options_compatible(const OptionSet &opts, const OptionSet &additional_opts)
Definition OptionSet.cxx:31
std::string name(ElasticConstant p)
Definition ElasticityConverter.cxx:30
FType
Role in a function definition.
Definition types.h:119
std::ostream & operator<<(std::ostream &os, const EnumSelection &es)
Definition EnumSelection.cxx:31
void neml_assert(bool assertion, Args &&... args)
Definition error.h:64