17 #include <unordered_map>
38 void setLoc(
int line,
int column);
86 bool operator==(
const AnyValue& other)
const;
87 bool operator!=(
const AnyValue& other)
const;
95 bool hasKey(
const std::string& key)
const;
99 void setKey(
const std::string& key);
112 const std::type_info&
type()
const;
125 explicit AnyValue(
const std::string& value);
126 explicit AnyValue(
const char* value);
127 AnyValue& operator=(
const std::string& value);
128 AnyValue& operator=(
const char* value);
130 const std::string&
asString()
const;
131 bool operator==(
const std::string& other)
const;
132 bool operator!=(
const std::string& other)
const;
133 friend bool operator==(
const std::string& lhs,
const AnyValue& rhs);
134 friend bool operator!=(
const std::string& lhs,
const AnyValue& rhs);
142 bool operator==(
const double& other)
const;
143 bool operator!=(
const double& other)
const;
144 friend bool operator==(
const double& lhs,
const AnyValue& rhs);
145 friend bool operator!=(
const double& lhs,
const AnyValue& rhs);
151 const bool&
asBool()
const;
155 AnyValue& operator=(
long int value);
159 const long int&
asInt()
const;
160 bool operator==(
const long int& other)
const;
161 bool operator!=(
const long int& other)
const;
162 bool operator==(
const int& other)
const;
163 bool operator!=(
const int& other)
const;
164 friend bool operator==(
const long int& lhs,
const AnyValue& rhs);
165 friend bool operator!=(
const long int& lhs,
const AnyValue& rhs);
166 friend bool operator==(
const int& lhs,
const AnyValue& rhs);
167 friend bool operator!=(
const int& lhs,
const AnyValue& rhs);
170 AnyValue& operator=(
const std::vector<T>& value);
185 AnyValue& operator=(
const std::unordered_map<std::string, T> items);
188 AnyValue& operator=(
const std::map<std::string, T> items);
193 std::map<std::string, T>
asMap()
const;
204 std::unordered_map<std::string, const AnyMap*>
asMap(
const std::string& name)
const;
205 std::unordered_map<std::string, AnyMap*>
asMap(
const std::string& name);
218 AnyMap&
getMapWhere(
const std::string& key,
const std::string& value,
bool create=
false);
219 const AnyMap&
getMapWhere(
const std::string& key,
const std::string& value)
const;
222 bool hasMapWhere(
const std::string& key,
const std::string& value)
const;
228 std::string demangle(
const std::type_info&
type)
const;
231 void checkSize(
const std::vector<T>& v,
size_t nMin,
size_t nMax)
const;
243 typedef bool (*Comparer)(
const boost::any&,
const boost::any&);
246 template <
typename T>
247 static bool eq_comparer(
const boost::any& lhs,
const boost::any& rhs);
251 template<
class T,
class U>
252 static bool vector_eq(
const boost::any& lhs,
const boost::any& rhs);
257 template<
class T,
class U>
258 static bool vector2_eq(
const boost::any& lhs,
const boost::any& rhs);
260 mutable Comparer m_equals;
265 const std::vector<AnyValue>& AnyValue::asVector<AnyValue>(
size_t nMin,
size_t nMax)
const;
268 std::vector<AnyValue>& AnyValue::asVector<AnyValue>(
size_t nMin,
size_t nMax);
272 const std::vector<double>& AnyValue::asVector<double>(
size_t nMin,
size_t nMax)
const;
275 std::vector<double>& AnyValue::asVector<double>(
size_t nMin,
size_t nMax);
279 const std::vector<vector_fp>& AnyValue::asVector<vector_fp>(
size_t nMin,
size_t nMax)
const;
282 std::vector<vector_fp>& AnyValue::asVector<vector_fp>(
size_t nMin,
size_t nMax);
287 const std::vector<AnyMap>& AnyValue::asVector<AnyMap>(
size_t nMin,
size_t nMax)
const;
290 std::vector<AnyMap>& AnyValue::asVector<AnyMap>(
size_t nMin,
size_t nMax);
371 const std::string& parent_name=
"");
382 const AnyValue&
at(
const std::string& key)
const;
385 bool hasKey(
const std::string& key)
const;
388 void erase(
const std::string& key);
405 bool getBool(
const std::string& key,
bool default_)
const;
408 long int getInt(
const std::string& key,
long int default_)
const;
411 double getDouble(
const std::string& key,
double default_)
const;
414 const std::string&
getString(
const std::string& key,
415 const std::string& default_)
const;
421 double convert(
const std::string& key,
const std::string&
units)
const;
429 double convert(
const std::string& key,
const std::string&
units,
430 double default_)
const;
448 size_t nMin=
npos,
size_t nMax=
npos)
const;
454 Iterator(
const std::unordered_map<std::string, AnyValue>::const_iterator& start,
455 const std::unordered_map<std::string, AnyValue>::const_iterator& stop);
457 const std::pair<const std::string, AnyValue>& operator*()
const {
460 const std::pair<const std::string, AnyValue>* operator->()
const {
463 bool operator!=(
const Iterator& right)
const {
464 return m_iter != right.m_iter;
469 std::unordered_map<std::string, AnyValue>::const_iterator m_iter;
470 std::unordered_map<std::string, AnyValue>::const_iterator m_stop;
488 bool operator==(
const AnyMap& other)
const;
489 bool operator!=(
const AnyMap& other)
const;
514 std::unordered_map<std::string, AnyValue>
m_data;
522 static std::unordered_map<std::string, std::pair<AnyMap, int>>
s_cache;
544 template <
typename... Args>
546 const std::string& message,
const Args&... args)
549 formatError(
fmt::format(message, args...),
550 node.m_line, node.m_column, node.m_metadata))
557 template <
typename... Args>
559 const AnyBase& node2,
const std::string& message,
563 formatError2(
fmt::format(message, args...),
564 node1.m_line, node1.m_column, node1.m_metadata,
565 node2.m_line, node2.m_column, node2.m_metadata))
571 return "InputFileError";
574 static std::string formatError(
const std::string& message,
575 int line,
int column,
576 const shared_ptr<AnyMap>& metadata);
577 static std::string formatError2(
const std::string& message,
578 int line1,
int column1,
const shared_ptr<AnyMap>& metadata1,
579 int line2,
int column2,
const shared_ptr<AnyMap>& metadata2);
584 #ifndef CANTERA_API_NO_BOOST
Header for unit conversion utilities, which are used to translate user input from input files (See In...
Base class defining common data possessed by both AnyMap and AnyValue objects.
const AnyValue & getMetadata(const std::string &key) const
Get a value from the metadata applicable to the AnyMap tree containing this node.
int m_column
Column where this node occurs in the input file.
void setLoc(int line, int column)
For values which are derived from an input file, set the line and column of this value in that file.
int m_line
Line where this node occurs in the input file.
shared_ptr< AnyMap > m_metadata
Metadata relevant to an entire AnyMap tree, such as information about.
Defined to allow use with range-based for loops.
A map of string keys to values whose type can vary at runtime.
AnyValue & operator[](const std::string &key)
Get the value of the item stored in key.
Iterator begin() const
Defined to allow use with range-based for loops.
size_t size() const
Returns the number of elements in this map.
std::unordered_map< std::string, AnyValue > m_data
The stored data.
vector_fp convertVector(const std::string &key, const std::string &units, size_t nMin=npos, size_t nMax=npos) const
Convert a vector of dimensional values.
const AnyValue & at(const std::string &key) const
Get the value of the item stored in key.
double convert(const std::string &key, const std::string &units) const
Convert the item stored by the given key to the units specified in units.
UnitSystem m_units
The default units that are used to convert stored values.
Iterator end() const
Defined to allow use with range-based for loops.
const std::string & getString(const std::string &key, const std::string &default_) const
If key exists, return it as a string, otherwise return default_.
bool getBool(const std::string &key, bool default_) const
If key exists, return it as a bool, otherwise return default_.
static AnyMap fromYamlFile(const std::string &name, const std::string &parent_name="")
Create an AnyMap from a YAML file.
long int getInt(const std::string &key, long int default_) const
If key exists, return it as a long int, otherwise return default_.
void erase(const std::string &key)
Erase the value held by key.
double getDouble(const std::string &key, double default_) const
If key exists, return it as a double, otherwise return default_.
void propagateMetadata(shared_ptr< AnyMap > &file)
Propagate metadata to any child elements.
std::string keys_str() const
Return a string listing the keys in this AnyMap, e.g.
static std::unordered_map< std::string, std::pair< AnyMap, int > > s_cache
Cache for previously-parsed input (YAML) files.
void clear()
Erase all items in the mapping.
static AnyMap fromYamlString(const std::string &yaml)
Create an AnyMap from a string containing a YAML document.
bool hasKey(const std::string &key) const
Returns true if the map contains an item named key.
const UnitSystem & units() const
Return the default units that should be used to convert stored values.
void applyUnits(const UnitSystem &units)
Use the supplied UnitSystem to set the default units, and recursively process overrides from nodes na...
void setMetadata(const std::string &key, const AnyValue &value)
Set a metadata value that applies to this AnyMap and its children.
A wrapper for a variable whose type is determined at runtime.
AnyValue & operator[](const std::string &key)
If this AnyValue is an AnyMap, return the value stored in key.
bool hasMapWhere(const std::string &key, const std::string &value) const
Returns true when getMapWhere() would succeed.
void setKey(const std::string &key)
Set the name of the key storing this value in an AnyMap.
std::unique_ptr< boost::any > m_value
The held value.
const std::string & asString() const
Return the held value, if it is a string.
bool & asBool()
Return the held value, if it is a bool.
const std::vector< T > & asVector(size_t nMin=npos, size_t nMax=npos) const
Return the held value, if it is a vector of type T.
static std::map< std::string, std::string > s_typenames
Human-readable names for some common types, for use when boost::demangle is not available.
long int & asInt()
Return the held value, if it is a long int.
const std::type_info & type() const
Returns the type of the held value.
double & asDouble()
Return the held value as a double, if it is a double or a long int.
static bool eq_comparer(const boost::any &lhs, const boost::any &rhs)
Equality comparison function used when lhs is of type T
bool isScalar() const
Returns true if the held value is a scalar type (e.g.
std::string type_str() const
Returns a string specifying the type of the held value.
static bool vector2_eq(const boost::any &lhs, const boost::any &rhs)
Helper function for comparing nested vectors of different (but comparable) types, e....
void propagateMetadata(shared_ptr< AnyMap > &file)
Propagate metadata to any child elements.
static bool vector_eq(const boost::any &lhs, const boost::any &rhs)
Helper function for comparing vectors of different (but comparable) types, e.g.
std::string m_key
Key of this value in a parent AnyMap
bool is() const
Returns true if the held value is of the specified type.
AnyMap & getMapWhere(const std::string &key, const std::string &value, bool create=false)
Treating the value as vector<AnyMap>, return the item where the given key has the specified value.
bool hasKey(const std::string &key) const
Returns true if this AnyValue is an AnyMap and that map contains a key with the given name.
std::map< std::string, T > asMap() const
Return the held AnyMap as a std::map where all of the values have the specified type.
void applyUnits(const UnitSystem &units)
const T & as() const
Get the value of this key as the specified type.
Base class for exceptions thrown by Cantera classes.
A representation of the units associated with a dimensional quantity.
This file contains definitions of terms that are used in internal routines and are unlikely to need m...
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
This file contains definitions for utility functions and text for modules, inputfiles,...
const size_t npos
index returned by functions to indicate "no position"
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
Namespace for the Cantera kernel.
Versions 6.2.0 and 6.2.1 of fmtlib do not include this define before they include windows....