13#include <unordered_map>
43 void setLoc(
int line,
int column);
64 const string& message);
92 bool operator==(
const AnyValue& other)
const;
93 bool operator!=(
const AnyValue& other)
const;
101 bool hasKey(
const string& key)
const;
105 void setKey(
const string& key);
118 const std::type_info&
type()
const;
162 explicit AnyValue(
const string& value);
163 explicit AnyValue(
const char* value);
164 AnyValue& operator=(
const string& value);
165 AnyValue& operator=(
const char* value);
168 bool operator==(
const string& other)
const;
169 bool operator!=(
const string& other)
const;
170 friend bool operator==(
const string& lhs,
const AnyValue& rhs);
171 friend bool operator!=(
const string& lhs,
const AnyValue& rhs);
183 void setQuantity(
double value,
const string& units,
bool is_act_energy=
false);
191 void setQuantity(
const vector<double>& values,
const string& units);
206 bool operator==(
const double& other)
const;
207 bool operator!=(
const double& other)
const;
208 friend bool operator==(
const double& lhs,
const AnyValue& rhs);
209 friend bool operator!=(
const double& lhs,
const AnyValue& rhs);
215 const bool&
asBool()
const;
219 AnyValue& operator=(
long int value);
223 const long int&
asInt()
const;
224 bool operator==(
const long int& other)
const;
225 bool operator!=(
const long int& other)
const;
226 bool operator==(
const int& other)
const;
227 bool operator!=(
const int& other)
const;
228 friend bool operator==(
const long int& lhs,
const AnyValue& rhs);
229 friend bool operator!=(
const long int& lhs,
const AnyValue& rhs);
230 friend bool operator==(
const int& lhs,
const AnyValue& rhs);
231 friend bool operator!=(
const int& lhs,
const AnyValue& rhs);
234 AnyValue& operator=(
const vector<T>& value);
249 AnyValue& operator=(
const std::unordered_map<string, T> items);
252 AnyValue& operator=(
const map<string, T> items);
260 map<string, T>
asMap()
const;
271 std::unordered_map<string, const AnyMap*>
asMap(
const string& name)
const;
272 std::unordered_map<string, AnyMap*>
asMap(
const string& name);
289 bool hasMapWhere(
const string& key,
const string& value)
const;
292 pair<int, int>
order()
const;
295 void applyUnits(shared_ptr<UnitSystem>& units);
302 void checkSize(
const vector<T>& v,
size_t nMin,
size_t nMax)
const;
310 typedef bool (*Comparer)(
const std::any&,
const std::any&);
313 template <
typename T>
314 static bool eq_comparer(
const std::any& lhs,
const std::any& rhs);
318 template<
class T,
class U>
319 static bool vector_eq(
const std::any& lhs,
const std::any& rhs);
324 template<
class T,
class U>
325 static bool vector2_eq(
const std::any& lhs,
const std::any& rhs);
327 mutable Comparer m_equals;
329 friend YAML::Emitter& YAML::operator<<(YAML::Emitter& out,
const AnyValue& rhs);
334const vector<AnyValue>& AnyValue::asVector<AnyValue>(
size_t nMin,
size_t nMax)
const;
337vector<AnyValue>& AnyValue::asVector<AnyValue>(
size_t nMin,
size_t nMax);
341const vector<double>& AnyValue::asVector<double>(
size_t nMin,
size_t nMax)
const;
344vector<double>& AnyValue::asVector<double>(
size_t nMin,
size_t nMax);
348const vector<vector<double>>& AnyValue::asVector<vector<double>>(
size_t nMin,
352vector<vector<double>>& AnyValue::asVector<vector<double>>(
size_t nMin,
size_t nMax);
357const vector<AnyMap>& AnyValue::asVector<AnyMap>(
size_t nMin,
size_t nMax)
const;
360vector<AnyMap>& AnyValue::asVector<AnyMap>(
size_t nMin,
size_t nMax);
442 const string& parent_name=
"");
447 string toYamlString()
const;
466 bool hasKey(
const string& key)
const;
469 void erase(
const string& key);
477 void update(
const AnyMap& other,
bool keepExisting=
true);
481 void exclude(
const string& key);
489 set<string>
keys()
const;
502 bool getBool(
const string& key,
bool default_)
const;
505 long int getInt(
const string& key,
long int default_)
const;
508 double getDouble(
const string& key,
double default_)
const;
511 const string&
getString(
const string& key,
512 const string& default_)
const;
518 double convert(
const string& key,
const string&
units)
const;
527 double default_)
const;
545 size_t nMin=
npos,
size_t nMax=
npos)
const;
552 Iterator(
const std::unordered_map<string, AnyValue>::const_iterator& start,
553 const std::unordered_map<string, AnyValue>::const_iterator& stop);
555 const pair<const string, AnyValue>& operator*()
const {
558 const pair<const string, AnyValue>* operator->()
const {
561 bool operator!=(
const Iterator& right)
const {
562 return m_iter != right.m_iter;
567 std::unordered_map<string, AnyValue>::const_iterator m_iter;
568 std::unordered_map<string, AnyValue>::const_iterator m_stop;
581 class OrderedIterator;
594 const pair<const string, AnyValue>*>> OrderVector;
597 OrderVector m_ordered;
598 unique_ptr<pair<const string, AnyValue>> m_units;
606 OrderedIterator(
const AnyMap::OrderedProxy::OrderVector::const_iterator& start,
607 const AnyMap::OrderedProxy::OrderVector::const_iterator& stop);
609 const pair<const string, AnyValue>& operator*()
const {
610 return *m_iter->second;
612 const pair<const string, AnyValue>* operator->()
const {
613 return &(*m_iter->second);
616 return m_iter != right.m_iter;
621 OrderedProxy::OrderVector::const_iterator m_iter;
622 OrderedProxy::OrderVector::const_iterator m_stop;
636 bool operator==(
const AnyMap& other)
const;
637 bool operator!=(
const AnyMap& other)
const;
705 const vector<vector<string>>& specs);
712 std::unordered_map<string, AnyValue>
m_data;
720 static std::unordered_map<string,
721 pair<AnyMap, std::filesystem::file_time_type>>
s_cache;
734 friend YAML::Emitter& YAML::operator<<(YAML::Emitter& out,
const AnyMap& rhs);
754 template <
typename... Args>
756 const string& message,
const Args&... args)
760 (sizeof...(args) == 0) ? message
761 : fmt::format(fmt::runtime(message), args...),
762 node.m_line, node.m_column, node.m_metadata))
769 template <
typename... Args>
771 const AnyBase& node2,
const string& message,
776 (sizeof...(args) == 0) ? message
777 : fmt::format(fmt::runtime(message), args...),
778 node1.m_line, node1.m_column, node1.m_metadata,
779 node2.m_line, node2.m_column, node2.m_metadata))
784 return "InputFileError";
787 static string formatError(
const string& message,
int line,
int column,
788 const shared_ptr<AnyMap>& metadata);
789 static string formatError2(
const string& message,
790 int line1,
int column1,
const shared_ptr<AnyMap>& metadata1,
791 int line2,
int column2,
const shared_ptr<AnyMap>& metadata2);
796 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.