13#include <unordered_map>
41 void setLoc(
int line,
int column);
62 const std::string& message);
93 bool operator==(
const AnyValue& other)
const;
94 bool operator!=(
const AnyValue& other)
const;
102 bool hasKey(
const std::string& key)
const;
106 void setKey(
const std::string& key);
119 const std::type_info&
type()
const;
135 explicit AnyValue(
const std::string& value);
136 explicit AnyValue(
const char* value);
137 AnyValue& operator=(
const std::string& value);
138 AnyValue& operator=(
const char* value);
140 const std::string&
asString()
const;
141 bool operator==(
const std::string& other)
const;
142 bool operator!=(
const std::string& other)
const;
143 friend bool operator==(
const std::string& lhs,
const AnyValue& rhs);
144 friend bool operator!=(
const std::string& lhs,
const AnyValue& rhs);
156 void setQuantity(
double value,
const std::string& units,
bool is_act_energy=
false);
179 bool operator==(
const double& other)
const;
180 bool operator!=(
const double& other)
const;
181 friend bool operator==(
const double& lhs,
const AnyValue& rhs);
182 friend bool operator!=(
const double& lhs,
const AnyValue& rhs);
188 const bool&
asBool()
const;
192 AnyValue& operator=(
long int value);
196 const long int&
asInt()
const;
197 bool operator==(
const long int& other)
const;
198 bool operator!=(
const long int& other)
const;
199 bool operator==(
const int& other)
const;
200 bool operator!=(
const int& other)
const;
201 friend bool operator==(
const long int& lhs,
const AnyValue& rhs);
202 friend bool operator!=(
const long int& lhs,
const AnyValue& rhs);
203 friend bool operator==(
const int& lhs,
const AnyValue& rhs);
204 friend bool operator!=(
const int& lhs,
const AnyValue& rhs);
207 AnyValue& operator=(
const std::vector<T>& value);
222 AnyValue& operator=(
const std::unordered_map<std::string, T> items);
225 AnyValue& operator=(
const std::map<std::string, T> items);
230 std::map<std::string, T>
asMap()
const;
241 std::unordered_map<std::string, const AnyMap*>
asMap(
const std::string& name)
const;
242 std::unordered_map<std::string, AnyMap*>
asMap(
const std::string& name);
255 AnyMap&
getMapWhere(
const std::string& key,
const std::string& value,
bool create=
false);
256 const AnyMap&
getMapWhere(
const std::string& key,
const std::string& value)
const;
259 bool hasMapWhere(
const std::string& key,
const std::string& value)
const;
262 std::pair <int, int>
order()
const;
265 void applyUnits(shared_ptr<UnitSystem>& units);
272 void checkSize(
const std::vector<T>& v,
size_t nMin,
size_t nMax)
const;
280 typedef bool (*Comparer)(
const boost::any&,
const boost::any&);
283 template <
typename T>
284 static bool eq_comparer(
const boost::any& lhs,
const boost::any& rhs);
288 template<
class T,
class U>
289 static bool vector_eq(
const boost::any& lhs,
const boost::any& rhs);
294 template<
class T,
class U>
295 static bool vector2_eq(
const boost::any& lhs,
const boost::any& rhs);
297 mutable Comparer m_equals;
299 friend YAML::Emitter& YAML::operator<<(YAML::Emitter& out,
const AnyValue& rhs);
304const std::vector<AnyValue>& AnyValue::asVector<AnyValue>(
size_t nMin,
size_t nMax)
const;
307std::vector<AnyValue>& AnyValue::asVector<AnyValue>(
size_t nMin,
size_t nMax);
311const std::vector<double>& AnyValue::asVector<double>(
size_t nMin,
size_t nMax)
const;
314std::vector<double>& AnyValue::asVector<double>(
size_t nMin,
size_t nMax);
318const std::vector<vector_fp>& AnyValue::asVector<vector_fp>(
size_t nMin,
size_t nMax)
const;
321std::vector<vector_fp>& AnyValue::asVector<vector_fp>(
size_t nMin,
size_t nMax);
326const std::vector<AnyMap>& AnyValue::asVector<AnyMap>(
size_t nMin,
size_t nMax)
const;
329std::vector<AnyMap>& AnyValue::asVector<AnyMap>(
size_t nMin,
size_t nMax);
410 const std::string& parent_name=
"");
415 std::string toYamlString()
const;
428 const AnyValue&
at(
const std::string& key)
const;
434 bool hasKey(
const std::string& key)
const;
437 void erase(
const std::string& key);
444 void update(
const AnyMap& other,
bool keepExisting=
true);
461 bool getBool(
const std::string& key,
bool default_)
const;
464 long int getInt(
const std::string& key,
long int default_)
const;
467 double getDouble(
const std::string& key,
double default_)
const;
470 const std::string&
getString(
const std::string& key,
471 const std::string& default_)
const;
477 double convert(
const std::string& key,
const std::string&
units)
const;
485 double convert(
const std::string& key,
const std::string&
units,
486 double default_)
const;
504 size_t nMin=
npos,
size_t nMax=
npos)
const;
511 Iterator(
const std::unordered_map<std::string, AnyValue>::const_iterator& start,
512 const std::unordered_map<std::string, AnyValue>::const_iterator& stop);
514 const std::pair<const std::string, AnyValue>& operator*()
const {
517 const std::pair<const std::string, AnyValue>* operator->()
const {
520 bool operator!=(
const Iterator& right)
const {
521 return m_iter != right.m_iter;
526 std::unordered_map<std::string, AnyValue>::const_iterator m_iter;
527 std::unordered_map<std::string, AnyValue>::const_iterator m_stop;
540 class OrderedIterator;
551 typedef std::vector<std::pair<
553 const std::pair<const std::string, AnyValue>*>> OrderVector;
556 OrderVector m_ordered;
557 std::unique_ptr<std::pair<const std::string, AnyValue>> m_units;
565 OrderedIterator(
const OrderedProxy::OrderVector::const_iterator& start,
566 const OrderedProxy::OrderVector::const_iterator& stop);
568 const std::pair<const std::string, AnyValue>& operator*()
const {
569 return *m_iter->second;
571 const std::pair<const std::string, AnyValue>* operator->()
const {
572 return &(*m_iter->second);
575 return m_iter != right.m_iter;
580 OrderedProxy::OrderVector::const_iterator m_iter;
581 OrderedProxy::OrderVector::const_iterator m_stop;
594 bool operator==(
const AnyMap& other)
const;
595 bool operator!=(
const AnyMap& other)
const;
659 const std::vector<std::vector<std::string>>& specs);
666 std::unordered_map<std::string, AnyValue>
m_data;
674 static std::unordered_map<std::string, std::pair<AnyMap, int>>
s_cache;
679 static std::unordered_map<std::string, std::vector<std::string>>
s_headFields;
684 static std::unordered_map<std::string, std::vector<std::string>>
s_tailFields;
687 friend YAML::Emitter& YAML::operator<<(YAML::Emitter& out,
const AnyMap& rhs);
707 template <
typename... Args>
709 const std::string& message,
const Args&... args)
712 formatError(
fmt::format(message, args...),
713 node.m_line, node.m_column, node.m_metadata))
720 template <
typename... Args>
722 const AnyBase& node2,
const std::string& message,
726 formatError2(
fmt::format(message, args...),
727 node1.m_line, node1.m_column, node1.m_metadata,
728 node2.m_line, node2.m_column, node2.m_metadata))
734 return "InputFileError";
737 static std::string formatError(
const std::string& message,
738 int line,
int column,
739 const shared_ptr<AnyMap>& metadata);
740 static std::string formatError2(
const std::string& message,
741 int line1,
int column1,
const shared_ptr<AnyMap>& metadata1,
742 int line2,
int column2,
const shared_ptr<AnyMap>& metadata2);
747 const std::string& message);
751#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
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 std::string &source, const AnyBase &node, const std::string &message)
A deprecation warning for syntax in an 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.
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.
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.
void copyMetadata(const AnyMap &other)
Copy metadata including input line/column from an existing AnyMap.
static std::unordered_map< std::string, std::vector< std::string > > s_tailFields
Information about fields that should appear last when outputting to YAML.
std::shared_ptr< UnitSystem > m_units
The default units that are used to convert stored values.
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.
AnyValue & createForYaml(const std::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...
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.
void applyUnits()
Use the supplied UnitSystem to set the default units, and recursively process overrides from nodes na...
const std::string & getString(const std::string &key, const std::string &default_) const
If key exists, return it as a string, otherwise return default_.
static std::unordered_map< std::string, std::vector< std::string > > s_headFields
Information about fields that should appear first when outputting to YAML.
bool getBool(const std::string &key, bool default_) const
If key exists, return it as a bool, otherwise return default_.
static void clearCachedFile(const std::string &filename)
Remove the specified file from the input cache if it is present.
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_.
static bool addOrderingRules(const std::string &objectType, const std::vector< std::vector< std::string > > &specs)
Add global rules for setting the order of elements when outputting AnyMap objects to YAML.
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.
std::string keys_str() const
Return a string listing the keys in this AnyMap, for use in error messages, for example.
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.
void update(const AnyMap &other, bool keepExisting=true)
Add items from other to this AnyMap.
void setMetadata(const std::string &key, const AnyValue &value)
Set a metadata value that applies to this AnyMap and its children.
void setUnits(const UnitSystem &units)
Set the unit system for this AnyMap.
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.
void setQuantity(double value, const std::string &units, bool is_act_energy=false)
Assign a scalar quantity with units as a string, for example {3.0, "m^2"}.
bool & asBool()
Return the held value, if it is a bool.
bool empty() const
Return boolean indicating whether AnyValue is empty.
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.
long int & asInt()
Return the held value, if it is a long int.
void applyUnits(shared_ptr< UnitSystem > &units)
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 (such as double, long int, string,...
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, for example vector<...
std::pair< int, int > order() const
Return values used to determine the sort order when outputting to YAML.
void setFlowStyle(bool flow=true)
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, for example vector<double>...
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.
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 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 std::string &source, const AnyBase &node, const std::string &message)
A deprecation warning for syntax in an input file.
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
Versions 6.2.0 and 6.2.1 of fmtlib do not include this define before they include windows....