Cantera 2.6.0
|
A map of string keys to values whose type can vary at runtime. More...
#include <AnyMap.h>
Classes | |
class | Iterator |
Defined to allow use with range-based for loops. More... | |
class | OrderedIterator |
Defined to allow the OrderedProxy class to be used with range-based for loops. More... | |
class | OrderedProxy |
Proxy for iterating over an AnyMap in the defined output ordering. More... | |
Public Member Functions | |
std::string | toYamlString () const |
AnyValue & | operator[] (const std::string &key) |
Get the value of the item stored in key . More... | |
const AnyValue & | operator[] (const std::string &key) const |
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 occurs at the specified line and column within the string. More... | |
const AnyValue & | at (const std::string &key) const |
Get the value of the item stored in key . More... | |
bool | empty () const |
Return boolean indicating whether AnyMap is empty. More... | |
bool | hasKey (const std::string &key) const |
Returns true if the map contains an item named key . More... | |
void | erase (const std::string &key) |
Erase the value held by key . More... | |
void | clear () |
Erase all items in the mapping. More... | |
void | update (const AnyMap &other, bool keepExisting=true) |
Add items from other to this AnyMap. More... | |
std::string | keys_str () const |
Return a string listing the keys in this AnyMap, for use in error messages, for example. More... | |
void | setMetadata (const std::string &key, const AnyValue &value) |
Set a metadata value that applies to this AnyMap and its children. More... | |
void | copyMetadata (const AnyMap &other) |
Copy metadata including input line/column from an existing AnyMap. More... | |
void | propagateMetadata (shared_ptr< AnyMap > &file) |
Propagate metadata to any child elements. More... | |
bool | getBool (const std::string &key, bool default_) const |
If key exists, return it as a bool , otherwise return default_ . More... | |
long int | getInt (const std::string &key, long int default_) const |
If key exists, return it as a long int , otherwise return default_ . More... | |
double | getDouble (const std::string &key, double default_) const |
If key exists, return it as a double , otherwise return default_ . More... | |
const std::string & | getString (const std::string &key, const std::string &default_) const |
If key exists, return it as a string , otherwise return default_ . More... | |
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 . More... | |
double | convert (const std::string &key, const Units &units) const |
double | convert (const std::string &key, const std::string &units, double default_) const |
Convert the item stored by the given key to the units specified in units . More... | |
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. More... | |
Iterator | begin () const |
Defined to allow use with range-based for loops. More... | |
Iterator | end () const |
Defined to allow use with range-based for loops. More... | |
OrderedProxy | ordered () const |
size_t | size () const |
Returns the number of elements in this map. More... | |
bool | operator== (const AnyMap &other) const |
bool | operator!= (const AnyMap &other) const |
const UnitSystem & | units () const |
Return the default units that should be used to convert stored values. More... | |
void | applyUnits () |
Use the supplied UnitSystem to set the default units, and recursively process overrides from nodes named units . More... | |
void | applyUnits (shared_ptr< UnitSystem > &units) |
void | setUnits (const UnitSystem &units) |
Set the unit system for this AnyMap. More... | |
void | setFlowStyle (bool flow=true) |
Use "flow" style when outputting this AnyMap to YAML. More... | |
Public Member Functions inherited from AnyBase | |
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. More... | |
const AnyValue & | getMetadata (const std::string &key) const |
Get a value from the metadata applicable to the AnyMap tree containing this node. More... | |
Static Public Member Functions | |
static AnyMap | fromYamlFile (const std::string &name, const std::string &parent_name="") |
Create an AnyMap from a YAML file. More... | |
static AnyMap | fromYamlString (const std::string &yaml) |
Create an AnyMap from a string containing a YAML document. More... | |
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. More... | |
static void | clearCachedFile (const std::string &filename) |
Remove the specified file from the input cache if it is present. More... | |
Private Attributes | |
std::unordered_map< std::string, AnyValue > | m_data |
The stored data. More... | |
std::shared_ptr< UnitSystem > | m_units |
The default units that are used to convert stored values. More... | |
Static Private Attributes | |
static std::unordered_map< std::string, std::pair< AnyMap, int > > | s_cache |
Cache for previously-parsed input (YAML) files. More... | |
static std::unordered_map< std::string, std::vector< std::string > > | s_headFields |
Information about fields that should appear first when outputting to YAML. More... | |
static std::unordered_map< std::string, std::vector< std::string > > | s_tailFields |
Information about fields that should appear last when outputting to YAML. More... | |
Friends | |
class | AnyValue |
YAML::Emitter & | YAML::operator<< (YAML::Emitter &out, const AnyMap &rhs) |
Additional Inherited Members | |
Protected Attributes inherited from AnyBase | |
int | m_line |
The line where this value occurs in the input file. More... | |
int | m_column |
If m_line >= 0, the column where this value occurs in the input file. More... | |
shared_ptr< AnyMap > | m_metadata |
Metadata relevant to an entire AnyMap tree, such as information about. More... | |
A map of string keys to values whose type can vary at runtime.
Values in an AnyMap are held by instances of AnyValue. Instances of AnyMap can be nested to form a tree.
AnyMap | ( | ) |
Definition at line 1336 of file AnyMap.cpp.
|
static |
Create an AnyMap from a YAML file.
Searches the directory containing the optionally-specified parent file first, followed by the current working directory and the Cantera include path.
Definition at line 1743 of file AnyMap.cpp.
References Cantera::findInputFile(), Cantera::npos, AnyMap::s_cache, AnyBase::setLoc(), AnyMap::setMetadata(), and AnyBase::warn_deprecated.
Referenced by Phase::addElement(), Cantera::addReactions(), RedlichKwongMFTP::getCoeff(), IonsFromNeutralVPSSTP::initThermo(), ThermoPhase::initThermoFile(), Cantera::newInterface(), Cantera::newKinetics(), Cantera::newPhase(), Cantera::newSolution(), Sim1D::restore(), and Cantera::setupPhase().
|
static |
Create an AnyMap from a string containing a YAML document.
Definition at line 1727 of file AnyMap.cpp.
References AnyMap::applyUnits(), AnyBase::setLoc(), and AnyMap::setMetadata().
std::string toYamlString | ( | ) | const |
Definition at line 1802 of file AnyMap.cpp.
AnyValue & operator[] | ( | const std::string & | key | ) |
Get the value of the item stored in key
.
Definition at line 1341 of file AnyMap.cpp.
References AnyBase::m_column, AnyMap::m_data, AnyBase::m_metadata, AnyValue::propagateMetadata(), AnyValue::setKey(), and AnyBase::setLoc().
const AnyValue & operator[] | ( | const std::string & | key | ) | const |
Definition at line 1367 of file AnyMap.cpp.
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
occurs at the specified line and column within the string.
Definition at line 1377 of file AnyMap.cpp.
References AnyMap::m_data, AnyBase::m_metadata, AnyValue::propagateMetadata(), AnyValue::setKey(), and AnyBase::setLoc().
const AnyValue & at | ( | const std::string & | key | ) | const |
Get the value of the item stored in key
.
Raises an exception if the value does not exist.
Definition at line 1391 of file AnyMap.cpp.
References AnyMap::keys_str(), and AnyMap::m_data.
Referenced by Cantera::addReactions(), AnyMap::convert(), AnyMap::convertVector(), AnyValue::getMapWhere(), Cantera::newReactionRate(), and Cantera::setupPhase().
bool empty | ( | ) | const |
Return boolean indicating whether AnyMap is empty.
Definition at line 1401 of file AnyMap.cpp.
References AnyMap::m_data.
Referenced by FalloffRate::getParameters(), ArrheniusBase::getParameters(), GasKinetics::setDerivativeSettings(), Reaction::setParameters(), ThreeBodyReaction3::setParameters(), FalloffReaction3::setParameters(), FalloffRate::setParameters(), TroeRate::setParameters(), SriRate::setParameters(), and TsangRate::setParameters().
bool hasKey | ( | const std::string & | key | ) | const |
Returns true
if the map contains an item named key
.
Definition at line 1406 of file AnyMap.cpp.
References AnyMap::m_data.
Referenced by Cantera::addReactions(), AnyValue::applyUnits(), AnyMap::applyUnits(), InterfaceReaction2::calculateRateCoeffUnits(), Reaction::checkSpecies(), AnyMap::convert(), AnyMap::getBool(), AnyMap::getDouble(), AnyMap::getInt(), Reaction::getParameters(), AnyMap::getString(), BinarySolutionTabulatedThermo::initThermo(), DebyeHuckel::initThermo(), HMWSoln::initThermo(), IdealMolalSoln::initThermo(), IdealSolidSolnPhase::initThermo(), IdealSolnGasVPSS::initThermo(), IonsFromNeutralVPSSTP::initThermo(), LatticePhase::initThermo(), LatticeSolidPhase::initThermo(), MargulesVPSSTP::initThermo(), MetalPhase::initThermo(), PDSS_ConstVol::initThermo(), PDSS_HKFT::initThermo(), PDSS_IonsFromNeutral::initThermo(), PDSS_SSVol::initThermo(), PureFluidPhase::initThermo(), RedlichKisterVPSSTP::initThermo(), StoichSubstance::initThermo(), SurfPhase::initThermo(), Cantera::newPhase(), Cantera::newSolution(), Cantera::newSpecies(), TransportFactory::newTransport(), Reaction::Reaction(), Domain1D::restore(), StFlow::restore(), Sim1D::restore(), GasKinetics::setDerivativeSettings(), ThirdBody::setEfficiencies(), InterfaceRateBase::setParameters(), Reaction::setParameters(), FalloffRate::setParameters(), ArrheniusBase::setParameters(), ChebyshevRate::setParameters(), PlogRate::setParameters(), PlasmaPhase::setParameters(), LatticePhase::setSiteDensity(), MolalityVPSSTP::setState(), SurfPhase::setState(), ThermoPhase::setState(), StickingCoverage::setStickingParameters(), AnyMap::setUnits(), Cantera::setupPhase(), YamlWriter::toYamlString(), and AnyMap::update().
void erase | ( | const std::string & | key | ) |
Erase the value held by key
.
Definition at line 1411 of file AnyMap.cpp.
References AnyMap::m_data.
Referenced by LatticeSolidPhase::getParameters(), Reaction::getParameters(), InterfaceReaction2::getParameters(), and ThermoPhase::setState().
void clear | ( | ) |
Erase all items in the mapping.
Definition at line 1416 of file AnyMap.cpp.
References AnyMap::m_data.
Referenced by FalloffRate::getParameters().
void update | ( | const AnyMap & | other, |
bool | keepExisting = true |
||
) |
Add items from other
to this AnyMap.
If keys in other
also exist in this AnyMap, the keepExisting
option determines which item is used.
Definition at line 1421 of file AnyMap.cpp.
References AnyMap::hasKey().
Referenced by Reaction::getParameters(), TransportData::parameters(), Reaction::parameters(), SpeciesThermoInterpType::parameters(), and ThermoPhase::parameters().
std::string keys_str | ( | ) | const |
Return a string listing the keys in this AnyMap, for use in error messages, for example.
Definition at line 1430 of file AnyMap.cpp.
References AnyMap::begin(), and AnyMap::end().
Referenced by AnyMap::at().
void setMetadata | ( | const std::string & | key, |
const AnyValue & | value | ||
) |
Set a metadata value that applies to this AnyMap and its children.
Mainly for internal use in reading or writing from files.
Definition at line 1453 of file AnyMap.cpp.
References AnyBase::m_metadata, and AnyMap::propagateMetadata().
Referenced by AnyMap::fromYamlFile(), AnyMap::fromYamlString(), Solution::setSource(), and YamlWriter::toYamlString().
void copyMetadata | ( | const AnyMap & | other | ) |
Copy metadata including input line/column from an existing AnyMap.
Definition at line 1465 of file AnyMap.cpp.
References AnyBase::m_column, AnyBase::m_line, AnyBase::m_metadata, and AnyMap::propagateMetadata().
Referenced by Reaction::setParameters().
void propagateMetadata | ( | shared_ptr< AnyMap > & | file | ) |
Propagate metadata to any child elements.
Definition at line 1445 of file AnyMap.cpp.
References AnyMap::m_data, and AnyBase::m_metadata.
Referenced by AnyMap::copyMetadata(), and AnyMap::setMetadata().
bool getBool | ( | const std::string & | key, |
bool | default_ | ||
) | const |
If key
exists, return it as a bool
, otherwise return default_
.
Definition at line 1487 of file AnyMap.cpp.
References AnyMap::hasKey(), and AnyMap::m_data.
Referenced by Cantera::addReactions(), AnyValue::applyUnits(), Mu0Poly::getParameters(), PDSS_IonsFromNeutral::initThermo(), StickingCoverage::setContext(), GasKinetics::setDerivativeSettings(), InterfaceRateBase::setParameters(), Reaction::setParameters(), FalloffRate::setParameters(), ArrheniusBase::setParameters(), StickingCoverage::setStickingParameters(), and Cantera::setupPhase().
long int getInt | ( | const std::string & | key, |
long int | default_ | ||
) | const |
If key
exists, return it as a long int
, otherwise return default_
.
Definition at line 1497 of file AnyMap.cpp.
References AnyMap::hasKey(), and AnyMap::m_data.
double getDouble | ( | const std::string & | key, |
double | default_ | ||
) | const |
If key
exists, return it as a double
, otherwise return default_
.
Definition at line 1492 of file AnyMap.cpp.
References AnyMap::hasKey(), and AnyMap::m_data.
Referenced by Cantera::newSpecies(), ReactingSurf1D::restore(), StFlow::restore(), GasKinetics::setDerivativeSettings(), and ThirdBody::setEfficiencies().
const std::string & getString | ( | const std::string & | key, |
const std::string & | default_ | ||
) | const |
If key
exists, return it as a string
, otherwise return default_
.
Definition at line 1502 of file AnyMap.cpp.
References AnyMap::hasKey(), and AnyMap::m_data.
Referenced by Cantera::addReactions(), VPStandardStateTP::getSpeciesParameters(), IonsFromNeutralVPSSTP::initThermo(), Cantera::newKinetics(), Cantera::newSolution(), Cantera::newTransportData(), Reaction::setParameters(), StickingCoverage::setStickingParameters(), and Cantera::setupPhase().
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
.
If the stored value is a double, convert it using the default units. If the input is a string, treat this as a dimensioned value, such as '988 kg/m^3' and convert from the specified units.
Definition at line 1508 of file AnyMap.cpp.
References AnyMap::at(), UnitSystem::convert(), and AnyMap::units().
Referenced by Phase::addElement(), DebyeHuckel::addSpecies(), LatticePhase::initThermo(), MetalPhase::initThermo(), PDSS_ConstVol::initThermo(), PDSS_HKFT::initThermo(), StoichSubstance::initThermo(), SurfPhase::initThermo(), and PlasmaPhase::setParameters().
double convert | ( | const std::string & | key, |
const Units & | units | ||
) | const |
Definition at line 1513 of file AnyMap.cpp.
double convert | ( | const std::string & | key, |
const std::string & | units, | ||
double | default_ | ||
) | const |
Convert the item stored by the given key
to the units specified in units
.
If the stored value is a double, convert it using the default units. If the input is a string, treat this as a dimensioned value, such as '988 kg/m^3' and convert from the specified units. If the key is missing, the default_
value is returned.
Definition at line 1518 of file AnyMap.cpp.
References AnyMap::at(), UnitSystem::convert(), AnyMap::hasKey(), and AnyMap::units().
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.
For each item in the vector, if the stored value is a double, convert it using the default units. If the value is a string, treat it as a dimensioned value, such as '988 kg/m^3', and convert from the specified units.
key | Location of the vector in this AnyMap |
units | Units to convert to |
nMin | Minimum allowed length of the vector. If nMax is not specified, this is also taken to be the maximum length. An exception is thrown if this condition is not met. |
nMax | Maximum allowed length of the vector. An exception is thrown if this condition is not met. |
Definition at line 1528 of file AnyMap.cpp.
References AnyMap::at(), UnitSystem::convert(), and AnyMap::units().
Referenced by BinarySolutionTabulatedThermo::initThermo().
|
inline |
Defined to allow use with range-based for loops.
Definition at line 531 of file AnyMap.h.
References AnyMap::m_data.
Referenced by AnyMap::keys_str().
|
inline |
Defined to allow use with range-based for loops.
Definition at line 536 of file AnyMap.h.
References AnyMap::m_data.
Referenced by AnyMap::keys_str().
|
inline |
|
inline |
Returns the number of elements in this map.
Definition at line 590 of file AnyMap.h.
References AnyMap::m_data.
Referenced by IdealMolalSoln::getParameters(), DebyeHuckel::getSpeciesParameters(), BinarySolutionTabulatedThermo::initThermo(), ThermoPhase::setState(), and YamlWriter::toYamlString().
bool operator== | ( | const AnyMap & | other | ) | const |
Definition at line 1642 of file AnyMap.cpp.
bool operator!= | ( | const AnyMap & | other | ) | const |
Definition at line 1660 of file AnyMap.cpp.
|
inline |
Return the default units that should be used to convert stored values.
Definition at line 598 of file AnyMap.h.
References AnyMap::m_units.
Referenced by AnyMap::applyUnits(), AnyMap::convert(), AnyMap::convertVector(), PDSS_HKFT::initThermo(), PDSS_SSVol::initThermo(), PengRobinson::initThermo(), RedlichKwongMFTP::initThermo(), Cantera::newReactionRate(), Cantera::newSpecies(), InterfaceRateBase::setParameters(), FalloffRate::setParameters(), ArrheniusBase::setParameters(), ChebyshevRate::setParameters(), PlogRate::setParameters(), and AnyMap::setUnits().
void applyUnits | ( | ) |
Use the supplied UnitSystem to set the default units, and recursively process overrides from nodes named units
.
If a units
node is present in a map that contains other keys, the specified units are taken to be the defaults for that map. If the map contains only a units
node, and is the first item in a list of maps, then the specified units are taken to be the defaults for all the maps in the list.
After being processed, the units
nodes are removed. This function is called automatically by the fromYamlFile() and fromYamlString() constructors.
Definition at line 1665 of file AnyMap.cpp.
References AnyMap::applyUnits(), and AnyMap::m_units.
Referenced by AnyMap::applyUnits(), AnyValue::applyUnits(), and AnyMap::fromYamlString().
void applyUnits | ( | shared_ptr< UnitSystem > & | units | ) |
Definition at line 1670 of file AnyMap.cpp.
References AnyMap::hasKey(), AnyMap::m_data, AnyMap::m_units, and AnyMap::units().
void setUnits | ( | const UnitSystem & | units | ) |
Set the unit system for this AnyMap.
The applyUnits() method should be called on the root AnyMap object after all desired calls to setUnits() in the tree have been made.
Definition at line 1686 of file AnyMap.cpp.
References UnitSystem::getDelta(), AnyMap::hasKey(), AnyMap::m_data, AnyMap::m_units, and AnyMap::units().
Referenced by YamlWriter::toYamlString().
void setFlowStyle | ( | bool | flow = true | ) |
Use "flow" style when outputting this AnyMap to YAML.
Definition at line 1698 of file AnyMap.cpp.
Referenced by TroeRate::getParameters(), SriRate::getParameters(), TsangRate::getParameters(), Arrhenius2::getParameters(), ThermoPhase::getParameters(), ThreeBodyReaction2::getParameters(), FalloffReaction2::getParameters(), ThreeBodyReaction3::getParameters(), FalloffReaction3::getParameters(), and ArrheniusBase::getRateParameters().
|
static |
Add global rules for setting the order of elements when outputting AnyMap objects to YAML.
Enables specifying keys that should appear at either the beginning or end of the generated YAML mapping. Only programmatically-added keys are rearranged. Keys which come from YAML input retain their existing ordering, and are output after programmatically-added keys.
This function should be called exactly once for any given spec that is to be added. To facilitate this, the method returns a bool so that it can be called as part of initializing a static variable. To avoid spurious compiler warnings about unused variables, the following structure can be used:
objectType | Apply rules to maps where the hidden __type__ key has the corresponding value. |
specs | A list of rule specifications. Each rule consists of two strings. The first string is either "head" or "tail", and the second string is the name of a key |
true
, to facilitate static initialization Definition at line 1702 of file AnyMap.cpp.
References AnyMap::s_headFields, and AnyMap::s_tailFields.
Referenced by ThermoPhase::getParameters(), and Reaction::parameters().
|
static |
Remove the specified file from the input cache if it is present.
Definition at line 1719 of file AnyMap.cpp.
References Cantera::findInputFile(), and AnyMap::s_cache.
|
private |
The stored data.
Definition at line 666 of file AnyMap.h.
Referenced by AnyMap::applyUnits(), AnyMap::at(), AnyMap::begin(), AnyMap::clear(), AnyMap::createForYaml(), AnyMap::empty(), AnyMap::end(), AnyMap::erase(), AnyMap::getBool(), AnyMap::getDouble(), AnyMap::getInt(), AnyMap::getString(), AnyMap::hasKey(), AnyMap::operator[](), AnyMap::propagateMetadata(), AnyMap::setUnits(), and AnyMap::size().
|
private |
The default units that are used to convert stored values.
Definition at line 669 of file AnyMap.h.
Referenced by AnyMap::applyUnits(), AnyMap::setUnits(), and AnyMap::units().
|
staticprivate |
Cache for previously-parsed input (YAML) files.
The key is the full path to the file, and the second element of the value is the last-modified time for the file, which is used to enable change detection.
Definition at line 674 of file AnyMap.h.
Referenced by AnyMap::clearCachedFile(), and AnyMap::fromYamlFile().
|
staticprivate |
Information about fields that should appear first when outputting to YAML.
Keys in this map are matched to __type__
keys in AnyMap objects, and values are a list of field names.
Definition at line 679 of file AnyMap.h.
Referenced by AnyMap::addOrderingRules().
|
staticprivate |
Information about fields that should appear last when outputting to YAML.
Keys in this map are matched to __type__
keys in AnyMap objects, and values are a list of field names.
Definition at line 684 of file AnyMap.h.
Referenced by AnyMap::addOrderingRules().