31#include "neml2/base/Option.h"
32#include "neml2/misc/errors.h"
33#include "neml2/misc/string_utils.h"
114 template <
typename T>
115 T
get(
const std::string &)
const;
135 template <
typename K,
typename V>
136 std::map<K, V>
get_map(
const std::string &,
const std::string &)
const;
144 template <
typename T, FType f = FType::NONE>
145 T &
set(
const std::string &);
154 template <
typename T>
157 template <
typename T>
161 using map_type = std::map<std::string, std::unique_ptr<OptionBase>, std::less<>>;
264 throw NEMLException(
"ERROR: no option named \"" +
name +
"\" found.\n\nKnown options:\n" +
268 auto ptr =
dynamic_cast<Option<T> *
>(opt_base);
271 "\" is not of the requested type: " + opt_base->type());
275template <
typename K,
typename V>
281 if (keys.size() != values.size())
282 throw NEMLException(
"Trying to build a map from '" + key_option +
"' and '" + value_option +
283 "' with " + std::to_string(keys.size()) +
" keys and " +
284 std::to_string(values.size()) +
" values.");
285 std::map<K, V> result;
286 for (
size_t i = 0; i < keys.size(); i++)
288 if (result.find(keys[i]) != result.end())
289 throw NEMLException(
"Trying to build a map from '" + key_option +
"' and '" + value_option +
291 result[keys[i]] = values[i];
296template <
typename T, FType F>
The accessor containing all the information needed to access an item in a LabeledAxis.
Definition LabeledAxisAccessor.h:56
Definition OptionBase.h:44
A custom map-like data structure. The keys are strings, and the values can be nonhomogeneously typed.
Definition OptionSet.h:52
map_type::iterator iterator
Option map iterator.
Definition OptionSet.h:163
map_type _values
Data structure to map names with values.
Definition OptionSet.h:252
std::map< K, V > get_map(const std::string &, const std::string &) const
Get two options and bind them to find a map.
Definition OptionSet.h:277
T & set_buffer(const std::string &)
Convenient method to request a buffer.
Definition OptionSet.h:316
const std::string & name() const
A readonly reference to the option set's name.
Definition OptionSet.h:75
const_iterator begin() const
Iterator pointing to the beginning of the set of options.
const std::string & type() const
A readonly reference to the option set's type.
Definition OptionSet.h:79
OptionBase & set(const std::string &)
LabeledAxisAccessor & set_output(const std::string &)
OptionSet(const OptionSet &)
std::string to_str() const
Print the contents.
T get(const std::string &) const
Definition OptionSet.h:261
map_type::const_iterator const_iterator
Constant option map iterator.
Definition OptionSet.h:165
std::map< std::string, std::unique_ptr< OptionBase >, std::less<> > map_type
The type of the map that we store internally.
Definition OptionSet.h:161
std::string & name()
A writable reference to the option set's name.
Definition OptionSet.h:77
LabeledAxisAccessor & set_input(const std::string &)
const OptionBase & get(const std::string &) const
Get a const reference to the specified option value.
std::string & type()
A writable reference to the option set's type.
Definition OptionSet.h:81
const std::string & doc() const
A readonly reference to the option set's docstring.
Definition OptionSet.h:87
const std::string & section() const
A readonly reference to the option set's section.
Definition OptionSet.h:91
T & set_parameter(const std::string &)
Convenient method to request a parameter.
Definition OptionSet.h:309
const std::string & path() const
A readonly reference to the option set's path.
Definition OptionSet.h:83
std::string & doc()
A writable reference to the option set's docstring.
Definition OptionSet.h:89
bool user_specified(const std::string &name) const
struct neml2::OptionSet::Metadata _metadata
void clear()
Clear internal data structures & frees any allocated memory.
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.
std::string & path()
A writable reference to the option set's path.
Definition OptionSet.h:85
iterator begin()
Iterator pointing to the beginning of the set of options.
std::string & section()
A writable reference to the option set's section.
Definition OptionSet.h:93
std::size_t size() const
Definition OptionSet.h:102
bool contains(const std::string &) const
T & set(const std::string &)
Definition OptionSet.h:298
OptionSet(OptionSet &&) noexcept
std::string stringify(const T &t)
Definition string_utils.h:70
Definition DiagnosticsInterface.h:31
std::ostream & operator<<(std::ostream &, const EnumSelection &)
bool options_compatible(const OptionSet &opts, const OptionSet &additional_opts)