Cantera
2.5.1
|
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... | |
Public Member Functions | |
AnyValue & | operator[] (const std::string &key) |
Get the value of the item stored in key . More... | |
const AnyValue & | operator[] (const std::string &key) const |
const AnyValue & | at (const std::string &key) const |
Get the value of the item stored in key . 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... | |
std::string | keys_str () const |
Return a string listing the keys in this AnyMap, e.g. More... | |
void | setMetadata (const std::string &key, const AnyValue &value) |
Set a metadata value that applies to this AnyMap and its children. 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... | |
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 (const UnitSystem &units) |
Use the supplied UnitSystem to set the default units, and recursively process overrides from nodes named units . 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... | |
Private Attributes | |
std::unordered_map< std::string, AnyValue > | m_data |
The stored data. More... | |
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... | |
Friends | |
class | AnyValue |
Additional Inherited Members | |
Protected Attributes inherited from AnyBase | |
int | m_line |
Line where this node occurs in the input file. More... | |
int | m_column |
Column where this node 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.
|
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 1156 of file AnyMap.cpp.
References Cantera::findInputFile(), Cantera::npos, AnyMap::s_cache, AnyBase::setLoc(), AnyMap::setMetadata(), and Cantera::warn_deprecated().
Referenced by IonsFromNeutralVPSSTP::initThermo(), and ThermoPhase::initThermoFile().
|
static |
Create an AnyMap from a string containing a YAML document.
Definition at line 1140 of file AnyMap.cpp.
References AnyMap::applyUnits(), AnyBase::setLoc(), and AnyMap::setMetadata().
AnyValue & operator[] | ( | const std::string & | key | ) |
Get the value of the item stored in key
.
Definition at line 942 of file AnyMap.cpp.
References AnyBase::m_column, AnyMap::m_data, AnyBase::m_line, 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 974 of file AnyMap.cpp.
References AnyMap::keys_str(), and AnyMap::m_data.
Referenced by Cantera::addReactions(), AnyMap::applyUnits(), AnyMap::convert(), AnyMap::convertVector(), and AnyValue::getMapWhere().
bool hasKey | ( | const std::string & | key | ) | const |
Returns true
if the map contains an item named key
.
Definition at line 984 of file AnyMap.cpp.
References AnyMap::m_data.
Referenced by Cantera::addReactions(), AnyMap::applyUnits(), AnyMap::convert(), AnyMap::getBool(), AnyMap::getDouble(), AnyMap::getInt(), AnyMap::getString(), BinarySolutionTabulatedThermo::initThermo(), ConstDensityThermo::initThermo(), DebyeHuckel::initThermo(), FixedChemPotSSTP::initThermo(), HMWSoln::initThermo(), IdealMolalSoln::initThermo(), IdealSolidSolnPhase::initThermo(), IdealSolnGasVPSS::initThermo(), IonsFromNeutralVPSSTP::initThermo(), LatticePhase::initThermo(), LatticeSolidPhase::initThermo(), MargulesVPSSTP::initThermo(), MetalPhase::initThermo(), PDSS_HKFT::initThermo(), PDSS_IonsFromNeutral::initThermo(), PDSS_SSVol::initThermo(), PureFluidPhase::initThermo(), RedlichKisterVPSSTP::initThermo(), StoichSubstance::initThermo(), SurfPhase::initThermo(), Cantera::newSpecies(), TransportFactory::newTransport(), LatticePhase::setSiteDensity(), MolalityVPSSTP::setState(), SurfPhase::setState(), ThermoPhase::setState(), and Cantera::setupPhase().
void erase | ( | const std::string & | key | ) |
Erase the value held by key
.
Definition at line 989 of file AnyMap.cpp.
References AnyMap::m_data.
Referenced by ThermoPhase::setState().
void clear | ( | ) |
Erase all items in the mapping.
Definition at line 994 of file AnyMap.cpp.
References AnyMap::m_data.
std::string keys_str | ( | ) | const |
Return a string listing the keys in this AnyMap, e.g.
for use in error messages
Definition at line 999 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 1022 of file AnyMap.cpp.
References AnyBase::m_metadata, and AnyMap::propagateMetadata().
Referenced by AnyMap::fromYamlFile(), and AnyMap::fromYamlString().
void propagateMetadata | ( | shared_ptr< AnyMap > & | file | ) |
Propagate metadata to any child elements.
Definition at line 1014 of file AnyMap.cpp.
References AnyMap::m_data, and AnyBase::m_metadata.
Referenced by 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 1034 of file AnyMap.cpp.
References AnyMap::hasKey(), and AnyMap::m_data.
Referenced by Cantera::addReactions(), PDSS_IonsFromNeutral::initThermo(), 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 1044 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 1039 of file AnyMap.cpp.
References AnyMap::hasKey(), and AnyMap::m_data.
Referenced by Cantera::newSpecies().
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 1049 of file AnyMap.cpp.
References AnyMap::hasKey(), and AnyMap::m_data.
Referenced by IonsFromNeutralVPSSTP::initThermo(), Cantera::newKinetics(), Cantera::newTransportData(), 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, e.g. '988 kg/m^3' and convert from the specified units.
Definition at line 1055 of file AnyMap.cpp.
References AnyMap::at(), UnitSystem::convert(), and AnyMap::units().
Referenced by DebyeHuckel::addSpecies(), ConstDensityThermo::initThermo(), FixedChemPotSSTP::initThermo(), LatticePhase::initThermo(), MetalPhase::initThermo(), PDSS_HKFT::initThermo(), StoichSubstance::initThermo(), and SurfPhase::initThermo().
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, e.g. '988 kg/m^3' and convert from the specified units. If the key is missing, the default_
value is returned.
Definition at line 1065 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, e.g. '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 1075 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 474 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 479 of file AnyMap.h.
References AnyMap::m_data.
Referenced by AnyMap::keys_str().
|
inline |
Returns the number of elements in this map.
Definition at line 484 of file AnyMap.h.
References AnyMap::m_data.
Referenced by BinarySolutionTabulatedThermo::initThermo(), and ThermoPhase::setState().
|
inline |
Return the default units that should be used to convert stored values.
Definition at line 492 of file AnyMap.h.
References AnyMap::m_units.
Referenced by AnyMap::applyUnits(), AnyMap::convert(), AnyMap::convertVector(), PDSS_HKFT::initThermo(), PDSS_SSVol::initThermo(), RedlichKwongMFTP::initThermo(), and Cantera::newSpecies().
void applyUnits | ( | const UnitSystem & | units | ) |
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, so this function should be called only once, on the root AnyMap. This function is called automatically by the fromYamlFile() and fromYamlString() constructors.
Definition at line 1128 of file AnyMap.cpp.
References AnyMap::at(), AnyMap::hasKey(), AnyMap::m_data, AnyMap::m_units, UnitSystem::setDefaults(), and AnyMap::units().
Referenced by AnyMap::fromYamlString().
|
private |
The stored data.
Definition at line 514 of file AnyMap.h.
Referenced by AnyMap::applyUnits(), AnyMap::at(), AnyMap::begin(), AnyMap::clear(), AnyMap::end(), AnyMap::erase(), AnyMap::getBool(), AnyMap::getDouble(), AnyMap::getInt(), AnyMap::getString(), AnyMap::hasKey(), AnyMap::operator[](), AnyMap::propagateMetadata(), and AnyMap::size().
|
private |
The default units that are used to convert stored values.
Definition at line 517 of file AnyMap.h.
Referenced by AnyMap::applyUnits(), 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 522 of file AnyMap.h.
Referenced by AnyMap::fromYamlFile().