Cantera  2.4.0
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
AnyValue Class Reference

A wrapper for a variable whose type is determined at runtime. More...

#include <AnyMap.h>

Public Member Functions

 AnyValue (AnyValue const &other)
 
 AnyValue (AnyValue &&other)
 
AnyValueoperator= (AnyValue const &other)
 
AnyValueoperator= (AnyValue &&other)
 
AnyValueoperator[] (const std::string &key)
 
bool hasKey (const std::string &key) const
 
void setKey (const std::string &key)
 
template<class T >
const T & as () const
 
template<class T >
T & as ()
 
const std::type_info & type ()
 
template<class T >
bool is () const
 
AnyValueoperator= (const std::string &value)
 
AnyValueoperator= (const char *value)
 
const std::string & asString () const
 
AnyValueoperator= (double value)
 
double asDouble () const
 
AnyValueoperator= (bool value)
 
bool asBool () const
 
AnyValueoperator= (long int value)
 
AnyValueoperator= (int value)
 
long int asInt () const
 
template<class T >
AnyValueoperator= (const std::vector< T > &value)
 
template<class T >
const std::vector< T > & asVector () const
 
template<class T >
std::vector< T > & asVector ()
 
AnyValueoperator= (const AnyMap &value)
 
AnyValueoperator= (AnyMap &&value)
 
template<class T >
AnyValueoperator= (const std::unordered_map< std::string, T > items)
 
template<class T >
AnyValueoperator= (const std::map< std::string, T > items)
 
template<class T >
std::map< std::string, T > asMap ()
 
template<>
AnyMapas ()
 

Private Member Functions

std::string demangle (const std::type_info &type) const
 

Private Attributes

std::string m_key
 
std::unique_ptr< boost::any > m_value
 

Static Private Attributes

static std::map< std::string, std::string > s_typenames
 

Detailed Description

A wrapper for a variable whose type is determined at runtime.

Instances of AnyValue are used as values in an AnyMap. Values are converted to a concrete type using the templated as() method or convenience methods such as asString() and asDouble(). See AnyMap for usage examples.

Elements are set using assignment, and the assignment operator has been overloaded for specific types so that only those types are allowed to be used in an AnyValue.

Definition at line 35 of file AnyMap.h.

Member Data Documentation

◆ s_typenames

std::map< std::string, std::string > s_typenames
staticprivate
Initial value:
= {
{typeid(double).name(), "double"},
{typeid(std::string).name(), "string"},
{typeid(std::vector<double>).name(), "vector<double>"},
{typeid(AnyMap).name(), "AnyMap"},
}

Definition at line 102 of file AnyMap.h.


The documentation for this class was generated from the following files: