28#include "neml2/misc/string_utils.h"
29#include "neml2/misc/defaults.h"
56 static const std::vector<std::
string>
sections;
67 const std::
string & additional_input =
"") const = 0;
76 if constexpr (std::is_same_v<T, bool>)
77 return "Failed to parse '" + raw_str +
78 "' as a boolean. Only 'true' and 'false' (case-sensitive) are recognized.";
80 if constexpr (std::is_same_v<T, TensorShape>)
81 return "Failed to parse '" + raw_str +
82 "' as a tensor shape. Tensor shapes must be of the form "
83 "'(d1,d2,...,dn)': It must begin with '(' and end with ')', d1, d2, "
84 "... must be integers, and there must be no white spaces.";
91parse_(T & val,
const std::string & raw_str)
93 std::stringstream ss(
trim(raw_str));
91parse_(T & val,
const std::string & raw_str) {
…}
103 auto success =
parse_(val, raw_str);
113 auto tokens =
split(raw_str,
" \t\n\v\f\r");
114 if constexpr (std::is_same_v<T, Device>)
115 vals.resize(tokens.size(),
kCPU);
117 vals.resize(tokens.size());
118 for (
size_t i = 0; i < tokens.size(); i++)
120 auto success =
parse_<T>(vals[i], tokens[i]);
134 throw ParserException(
"Failed to parse '" + raw_str +
"' as a vector of " +
143 auto token_vecs =
split(raw_str,
";");
144 vals.resize(token_vecs.size());
145 for (
size_t i = 0; i < token_vecs.size(); i++)
155std::vector<std::vector<T>>
158 std::vector<std::vector<T>> vals;
161 throw ParserException(
"Failed to parse '" + raw_str +
"' as a vector of vector of " +
Selection of an enum value from a list of candidates.
Definition EnumSelection.h:41
The accessor containing all the information needed to access an item in a LabeledAxis.
Definition LabeledAxisAccessor.h:56
Selection of multiple enum value from a list of candidates.
Definition MultiEnumSelection.h:41
A data structure that holds options of multiple objects.
Definition OptionCollection.h:38
virtual OptionCollection parse(const std::filesystem::path &filename, const std::string &additional_input="") const =0
Deserialize a file.
static const std::vector< std::string > sections
Known top-level sections in the input file.
Definition Parser.h:56
Parser(const Parser &)=default
Parser(Parser &&) noexcept=default
Device parse(const std::string &raw_str)
Definition Parser.cxx:108
std::string trim(const std::string &str, const std::string &white_space)
Definition string_utils.cxx:73
std::string parse_failure_message(const std::string &raw_str)
Definition Parser.h:74
bool parse_vector_vector_(std::vector< std::vector< T > > &vals, const std::string &raw_str)
Definition Parser.h:141
bool parse_vector_(std::vector< bool > &vals, const std::string &raw_str)
Definition Parser.cxx:62
std::string demangle(const char *name)
Demangle a piece of cxx abi type information.
Definition string_utils.cxx:32
std::vector< T > parse_vector(const std::string &raw_str)
Definition Parser.h:129
std::vector< std::vector< T > > parse_vector_vector(const std::string &raw_str)
Definition Parser.h:156
std::vector< std::string > split(const std::string &str, const std::string &delims)
Definition string_utils.cxx:52
bool parse_(bool &val, const std::string &raw_str)
Definition Parser.cxx:38
Definition DiagnosticsInterface.cxx:30
c10::Device Device
Definition types.h:66
c10::SmallVector< Size, 8 > TensorShape
Definition types.h:71
std::string name(ElasticConstant p)
Definition ElasticityConverter.cxx:30
LabeledAxisAccessor VariableName
Definition LabeledAxisAccessor.h:185
constexpr auto kCPU
Definition types.h:56