13#include <unordered_map>
42 void setLoc(
int line,
int column);
63 const string& message);
91 bool operator==(
const AnyValue& other)
const;
92 bool operator!=(
const AnyValue& other)
const;
100 bool hasKey(
const string& key)
const;
104 void setKey(
const string& key);
117 const std::type_info&
type()
const;
161 explicit AnyValue(
const string& value);
162 explicit AnyValue(
const char* value);
163 AnyValue& operator=(
const string& value);
164 AnyValue& operator=(
const char* value);
167 bool operator==(
const string& other)
const;
168 bool operator!=(
const string& other)
const;
169 friend bool operator==(
const string& lhs,
const AnyValue& rhs);
170 friend bool operator!=(
const string& lhs,
const AnyValue& rhs);
182 void setQuantity(
double value,
const string& units,
bool is_act_energy=
false);
190 void setQuantity(
const vector<double>& values,
const string& units);
205 bool operator==(
const double& other)
const;
206 bool operator!=(
const double& other)
const;
207 friend bool operator==(
const double& lhs,
const AnyValue& rhs);
208 friend bool operator!=(
const double& lhs,
const AnyValue& rhs);
214 const bool&
asBool()
const;
218 AnyValue& operator=(
long int value);
222 const long int&
asInt()
const;
223 bool operator==(
const long int& other)
const;
224 bool operator!=(
const long int& other)
const;
225 bool operator==(
const int& other)
const;
226 bool operator!=(
const int& other)
const;
227 friend bool operator==(
const long int& lhs,
const AnyValue& rhs);
228 friend bool operator!=(
const long int& lhs,
const AnyValue& rhs);
229 friend bool operator==(
const int& lhs,
const AnyValue& rhs);
230 friend bool operator!=(
const int& lhs,
const AnyValue& rhs);
233 AnyValue& operator=(
const vector<T>& value);
248 AnyValue& operator=(
const std::unordered_map<string, T> items);
251 AnyValue& operator=(
const map<string, T> items);
256 map<string, T>
asMap()
const;
267 std::unordered_map<string, const AnyMap*>
asMap(
const string& name)
const;
268 std::unordered_map<string, AnyMap*>
asMap(
const string& name);
285 bool hasMapWhere(
const string& key,
const string& value)
const;
288 pair<int, int>
order()
const;
291 void applyUnits(shared_ptr<UnitSystem>& units);
298 void checkSize(
const vector<T>& v,
size_t nMin,
size_t nMax)
const;
306 typedef bool (*Comparer)(
const std::any&,
const std::any&);
309 template <
typename T>
310 static bool eq_comparer(
const std::any& lhs,
const std::any& rhs);
314 template<
class T,
class U>
315 static bool vector_eq(
const std::any& lhs,
const std::any& rhs);
320 template<
class T,
class U>
321 static bool vector2_eq(
const std::any& lhs,
const std::any& rhs);
323 mutable Comparer m_equals;
325 friend YAML::Emitter& YAML::operator<<(YAML::Emitter& out,
const AnyValue& rhs);
330const vector<AnyValue>& AnyValue::asVector<AnyValue>(
size_t nMin,
size_t nMax)
const;
333vector<AnyValue>& AnyValue::asVector<AnyValue>(
size_t nMin,
size_t nMax);
337const vector<double>& AnyValue::asVector<double>(
size_t nMin,
size_t nMax)
const;
340vector<double>& AnyValue::asVector<double>(
size_t nMin,
size_t nMax);
344const vector<vector<double>>& AnyValue::asVector<vector<double>>(
size_t nMin,
348vector<vector<double>>& AnyValue::asVector<vector<double>>(
size_t nMin,
size_t nMax);
353const vector<AnyMap>& AnyValue::asVector<AnyMap>(
size_t nMin,
size_t nMax)
const;
356vector<AnyMap>& AnyValue::asVector<AnyMap>(
size_t nMin,
size_t nMax);
438 const string& parent_name=
"");
443 string toYamlString()
const;
462 bool hasKey(
const string& key)
const;
465 void erase(
const string& key);
472 void update(
const AnyMap& other,
bool keepExisting=
true);
480 set<string>
keys()
const;
493 bool getBool(
const string& key,
bool default_)
const;
496 long int getInt(
const string& key,
long int default_)
const;
499 double getDouble(
const string& key,
double default_)
const;
502 const string&
getString(
const string& key,
503 const string& default_)
const;
509 double convert(
const string& key,
const string&
units)
const;
518 double default_)
const;
536 size_t nMin=
npos,
size_t nMax=
npos)
const;
543 Iterator(
const std::unordered_map<string, AnyValue>::const_iterator& start,
544 const std::unordered_map<string, AnyValue>::const_iterator& stop);
546 const pair<const string, AnyValue>& operator*()
const {
549 const pair<const string, AnyValue>* operator->()
const {
552 bool operator!=(
const Iterator& right)
const {
553 return m_iter != right.m_iter;
558 std::unordered_map<string, AnyValue>::const_iterator m_iter;
559 std::unordered_map<string, AnyValue>::const_iterator m_stop;
572 class OrderedIterator;
585 const pair<const string, AnyValue>*>> OrderVector;
588 OrderVector m_ordered;
589 unique_ptr<pair<const string, AnyValue>> m_units;
597 OrderedIterator(
const AnyMap::OrderedProxy::OrderVector::const_iterator& start,
598 const AnyMap::OrderedProxy::OrderVector::const_iterator& stop);
600 const pair<const string, AnyValue>& operator*()
const {
601 return *m_iter->second;
603 const pair<const string, AnyValue>* operator->()
const {
604 return &(*m_iter->second);
607 return m_iter != right.m_iter;
612 OrderedProxy::OrderVector::const_iterator m_iter;
613 OrderedProxy::OrderVector::const_iterator m_stop;
626 bool operator==(
const AnyMap& other)
const;
627 bool operator!=(
const AnyMap& other)
const;
694 const vector<vector<string>>& specs);
701 std::unordered_map<string, AnyValue>
m_data;
709 static std::unordered_map<string,
710 pair<AnyMap, std::filesystem::file_time_type>>
s_cache;
723 friend YAML::Emitter& YAML::operator<<(YAML::Emitter& out,
const AnyMap& rhs);
743 template <
typename... Args>
745 const string& message,
const Args&... args)
749 (sizeof...(args) == 0) ? message : fmt::format(message, args...),
750 node.m_line, node.m_column, node.m_metadata))
757 template <
typename... Args>
759 const AnyBase& node2,
const string& message,
764 (sizeof...(args) == 0) ? message : fmt::format(message, args...),
765 node1.m_line, node1.m_column, node1.m_metadata,
766 node2.m_line, node2.m_column, node2.m_metadata))
771 return "InputFileError";
774 static string formatError(
const string& message,
int line,
int column,
775 const shared_ptr<AnyMap>& metadata);
776 static string formatError2(
const string& message,
777 int line1,
int column1,
const shared_ptr<AnyMap>& metadata1,
778 int line2,
int column2,
const shared_ptr<AnyMap>& metadata2);
783 const string& message);
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.
int m_column
If m_line >= 0, the column where this value 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
The line where this value occurs in the input file.
friend void warn_deprecated(const string &source, const AnyBase &node, const string &message)
A deprecation warning for syntax in an input file.
const AnyValue & getMetadata(const string &key) const
Get a value from the metadata applicable to the AnyMap tree containing this node.
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.
Defined to allow the OrderedProxy class to be used with range-based for loops.
Proxy for iterating over an AnyMap in the defined output ordering.
A map of string keys to values whose type can vary at runtime.
static AnyMap fromYamlString(const string &yaml)
Create an AnyMap from a string containing a YAML document.
Iterator begin() const
Defined to allow use with range-based for loops.
AnyValue & createForYaml(const string &key, int line, int column)
Used to create a new item which will be populated from a YAML input string, where the item with key o...
set< string > keys() const
Return an unordered set of keys.
size_t size() const
Returns the number of elements in this map.
long int getInt(const string &key, long int default_) const
If key exists, return it as a long int, otherwise return default_.
void copyMetadata(const AnyMap &other)
Copy metadata including input line/column from an existing AnyMap.
static std::unordered_map< string, pair< AnyMap, std::filesystem::file_time_type > > s_cache
Cache for previously-parsed input (YAML) files.
double getDouble(const string &key, double default_) const
If key exists, return it as a double, otherwise return default_.
bool hasKey(const 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.
Iterator end() const
Defined to allow use with range-based for loops.
bool empty() const
Return boolean indicating whether AnyMap is empty.
static void clearCachedFile(const string &filename)
Remove the specified file from the input cache if it is present.
void applyUnits()
Use the supplied UnitSystem to set the default units, and recursively process overrides from nodes na...
shared_ptr< UnitSystem > unitsShared() const
Return the default units that should be used to convert stored values.
static std::unordered_map< string, vector< string > > s_headFields
Information about fields that should appear first when outputting to YAML.
double convert(const string &key, const string &units) const
Convert the item stored by the given key to the units specified in units.
void setMetadata(const string &key, const AnyValue &value)
Set a metadata value that applies to this AnyMap and its children.
AnyValue & operator[](const string &key)
Get the value of the item stored in key.
void setFlowStyle(bool flow=true)
Use "flow" style when outputting this AnyMap to YAML.
void propagateMetadata(shared_ptr< AnyMap > &file)
Propagate metadata to any child elements.
bool getBool(const string &key, bool default_) const
If key exists, return it as a bool, otherwise return default_.
static std::unordered_map< string, vector< string > > s_tailFields
Information about fields that should appear last when outputting to YAML.
void clear()
Erase all items in the mapping.
shared_ptr< UnitSystem > m_units
The default units that are used to convert stored values.
const string & getString(const string &key, const string &default_) const
If key exists, return it as a string, otherwise return default_.
void erase(const string &key)
Erase the value held by key.
static AnyMap fromYamlFile(const string &name, const string &parent_name="")
Create an AnyMap from a YAML file.
std::unordered_map< string, AnyValue > m_data
The stored data.
const AnyValue & at(const string &key) const
Get the value of the item stored in key.
void update(const AnyMap &other, bool keepExisting=true)
Add items from other to this AnyMap.
static bool addOrderingRules(const string &objectType, const vector< vector< string > > &specs)
Add global rules for setting the order of elements when outputting AnyMap objects to YAML.
void setUnits(const UnitSystem &units)
Set the unit system for this AnyMap.
string keys_str() const
Return a string listing the keys in this AnyMap, for use in error messages, for example.
vector< double > convertVector(const string &key, const string &units, size_t nMin=npos, size_t nMax=npos) const
Convert a vector of dimensional values.
A wrapper for a variable whose type is determined at runtime.
const string & asString() const
Return the held value, if it is a string.
bool isVector() const
Returns true if the held value is a vector of the specified type, such as vector<double>.
void setKey(const string &key)
Set the name of the key storing this value in an AnyMap.
pair< int, int > order() const
Return values used to determine the sort order when outputting to YAML.
bool hasMapWhere(const string &key, const string &value) const
Returns true when getMapWhere() would succeed.
void setQuantity(double value, const string &units, bool is_act_energy=false)
Assign a scalar quantity with units as a string, for example {3.0, "m^2"}.
bool hasKey(const string &key) const
Returns true if this AnyValue is an AnyMap and that map contains a key with the given name.
map< string, T > asMap() const
Return the held AnyMap as a map where all of the values have the specified type.
bool & asBool()
Return the held value, if it is a bool.
bool empty() const
Return boolean indicating whether AnyValue is empty.
pair< size_t, size_t > matrixShape() const
Returns rows and columns of a matrix.
static bool vector2_eq(const std::any &lhs, const std::any &rhs)
Helper function for comparing nested vectors of different (but comparable) types, for example vector<...
bool isMatrix(size_t cols=npos) const
Returns true if the held value is a matrix of the specified type and a consistent number of columns,...
size_t vectorSize() const
Returns size of the held vector.
long int & asInt()
Return the held value, if it is a long int.
void applyUnits(shared_ptr< UnitSystem > &units)
See AnyMap::applyUnits()
static bool eq_comparer(const std::any &lhs, const std::any &rhs)
Equality comparison function used when lhs is of type T
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.
bool isScalar() const
Returns true if the held value is a scalar type (such as double, long int, string,...
AnyValue & operator[](const string &key)
If this AnyValue is an AnyMap, return the value stored in key.
string m_key
Key of this value in a parent AnyMap
AnyMap & getMapWhere(const string &key, const string &value, bool create=false)
Treating the value as vector<AnyMap>, return the item where the given key has the specified value.
void setFlowStyle(bool flow=true)
See AnyMap::setFlowStyle()
void propagateMetadata(shared_ptr< AnyMap > &file)
Propagate metadata to any child elements.
std::any m_value
The held value.
bool is() const
Returns true if the held value is of the specified type.
const 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 bool vector_eq(const std::any &lhs, const std::any &rhs)
Helper function for comparing vectors of different (but comparable) types, for example vector<double>...
const T & as() const
Get the value of this key as the specified type.
string type_str() const
Returns a string specifying the type of the held value.
Base class for exceptions thrown by Cantera classes.
A representation of the units associated with a dimensional quantity.
This file contains definitions of constants, types and terms that are used in internal routines and a...
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
Namespace for the Cantera kernel.
const size_t npos
index returned by functions to indicate "no position"
void warn_deprecated(const string &source, const AnyBase &node, const string &message)
A deprecation warning for syntax in an input file.