13#include <unordered_map>
44 void setLoc(
int line,
int column);
65 const string& message);
93 bool operator==(
const AnyValue& other)
const;
94 bool operator!=(
const AnyValue& other)
const;
102 bool hasKey(
const string& key)
const;
106 void setKey(
const string& key);
119 const std::type_info&
type()
const;
163 explicit AnyValue(
const string& value);
164 explicit AnyValue(
const char* value);
165 AnyValue& operator=(
const string& value);
166 AnyValue& operator=(
const char* value);
169 bool operator==(
const string& other)
const;
170 bool operator!=(
const string& other)
const;
171 friend bool operator==(
const string& lhs,
const AnyValue& rhs);
172 friend bool operator!=(
const string& lhs,
const AnyValue& rhs);
184 void setQuantity(
double value,
const string& units,
bool is_act_energy=
false);
192 void setQuantity(
const vector<double>& values,
const string& units);
207 bool operator==(
const double& other)
const;
208 bool operator!=(
const double& other)
const;
209 friend bool operator==(
const double& lhs,
const AnyValue& rhs);
210 friend bool operator!=(
const double& lhs,
const AnyValue& rhs);
216 const bool&
asBool()
const;
220 AnyValue& operator=(
long int value);
224 const long int&
asInt()
const;
225 bool operator==(
const long int& other)
const;
226 bool operator!=(
const long int& other)
const;
227 bool operator==(
const int& other)
const;
228 bool operator!=(
const int& other)
const;
229 friend bool operator==(
const long int& lhs,
const AnyValue& rhs);
230 friend bool operator!=(
const long int& lhs,
const AnyValue& rhs);
231 friend bool operator==(
const int& lhs,
const AnyValue& rhs);
232 friend bool operator!=(
const int& lhs,
const AnyValue& rhs);
235 AnyValue& operator=(
const vector<T>& value);
250 AnyValue& operator=(
const std::unordered_map<string, T> items);
253 AnyValue& operator=(
const map<string, T> items);
261 map<string, T>
asMap()
const;
272 std::unordered_map<string, const AnyMap*>
asMap(
const string& name)
const;
273 std::unordered_map<string, AnyMap*>
asMap(
const string& name);
290 bool hasMapWhere(
const string& key,
const string& value)
const;
293 pair<int, int>
order()
const;
296 void applyUnits(shared_ptr<UnitSystem>& units);
303 void checkSize(
const vector<T>& v,
size_t nMin,
size_t nMax)
const;
311 typedef bool (*Comparer)(
const std::any&,
const std::any&);
314 template <
typename T>
315 static bool eq_comparer(
const std::any& lhs,
const std::any& rhs);
319 template<
class T,
class U>
320 static bool vector_eq(
const std::any& lhs,
const std::any& rhs);
325 template<
class T,
class U>
326 static bool vector2_eq(
const std::any& lhs,
const std::any& rhs);
328 mutable Comparer m_equals;
330 friend YAML::Emitter& YAML::operator<<(YAML::Emitter& out,
const AnyValue& rhs);
335const vector<AnyValue>& AnyValue::asVector<AnyValue>(
size_t nMin,
size_t nMax)
const;
338vector<AnyValue>& AnyValue::asVector<AnyValue>(
size_t nMin,
size_t nMax);
342const vector<double>& AnyValue::asVector<double>(
size_t nMin,
size_t nMax)
const;
345vector<double>& AnyValue::asVector<double>(
size_t nMin,
size_t nMax);
349const vector<vector<double>>& AnyValue::asVector<vector<double>>(
size_t nMin,
353vector<vector<double>>& AnyValue::asVector<vector<double>>(
size_t nMin,
size_t nMax);
358const vector<AnyMap>& AnyValue::asVector<AnyMap>(
size_t nMin,
size_t nMax)
const;
361vector<AnyMap>& AnyValue::asVector<AnyMap>(
size_t nMin,
size_t nMax);
443 const string& parent_name=
"");
448 string toYamlString()
const;
467 bool hasKey(
const string& key)
const;
470 void erase(
const string& key);
478 void update(
const AnyMap& other,
bool keepExisting=
true);
482 void exclude(
const string& key);
490 set<string>
keys()
const;
503 bool getBool(
const string& key,
bool default_)
const;
506 long int getInt(
const string& key,
long int default_)
const;
509 double getDouble(
const string& key,
double default_)
const;
512 const string&
getString(
const string& key,
513 const string& default_)
const;
519 double convert(
const string& key,
const string&
units)
const;
528 double default_)
const;
546 size_t nMin=
npos,
size_t nMax=
npos)
const;
553 Iterator(
const std::unordered_map<string, AnyValue>::const_iterator& start,
554 const std::unordered_map<string, AnyValue>::const_iterator& stop);
556 const pair<const string, AnyValue>& operator*()
const {
559 const pair<const string, AnyValue>* operator->()
const {
562 bool operator!=(
const Iterator& right)
const {
563 return m_iter != right.m_iter;
568 std::unordered_map<string, AnyValue>::const_iterator m_iter;
569 std::unordered_map<string, AnyValue>::const_iterator m_stop;
582 class OrderedIterator;
595 const pair<const string, AnyValue>*>> OrderVector;
598 OrderVector m_ordered;
599 unique_ptr<pair<const string, AnyValue>> m_units;
607 OrderedIterator(
const AnyMap::OrderedProxy::OrderVector::const_iterator& start,
608 const AnyMap::OrderedProxy::OrderVector::const_iterator& stop);
610 const pair<const string, AnyValue>& operator*()
const {
611 return *m_iter->second;
613 const pair<const string, AnyValue>* operator->()
const {
614 return &(*m_iter->second);
617 return m_iter != right.m_iter;
622 OrderedProxy::OrderVector::const_iterator m_iter;
623 OrderedProxy::OrderVector::const_iterator m_stop;
637 bool operator==(
const AnyMap& other)
const;
638 bool operator!=(
const AnyMap& other)
const;
706 const vector<vector<string>>& specs);
713 std::unordered_map<string, AnyValue>
m_data;
721 static std::unordered_map<string,
722 pair<AnyMap, std::filesystem::file_time_type>>
s_cache;
735 friend YAML::Emitter& YAML::operator<<(YAML::Emitter& out,
const AnyMap& rhs);
755 template <
typename... Args>
757 const string& message,
const Args&... args)
761 (sizeof...(args) == 0) ? message
762 : fmt::format(fmt::runtime(message), args...),
763 node.m_line, node.m_column, node.m_metadata))
770 template <
typename... Args>
772 const AnyBase& node2,
const string& message,
777 (sizeof...(args) == 0) ? message
778 : fmt::format(fmt::runtime(message), args...),
779 node1.m_line, node1.m_column, node1.m_metadata,
780 node2.m_line, node2.m_column, node2.m_metadata))
785 return "InputFileError";
788 static string formatError(
const string& message,
int line,
int column,
789 const shared_ptr<AnyMap>& metadata);
790 static string formatError2(
const string& message,
791 int line1,
int column1,
const shared_ptr<AnyMap>& metadata1,
792 int line2,
int column2,
const shared_ptr<AnyMap>& metadata2);
797 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.
void exclude(const string &key)
Mark key as excluded from 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.
OrderedProxy ordered(bool withUnits=false) const
Return a proxy object that allows iteration in an order determined by the order of insertion,...
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.
static AnyValue exclude()
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.