Manual for OpenFLUID 2.1.11

Public Types | Public Member Functions | List of all members
openfluid::core::MapValue Class Reference

Detailed Description

MapValue is a container for a key => value map, where keys are strings and values can be any type derived from openfluid::core::Value.

See also
Value

Example : declaration

// declaration of a MapValue, empty by default

Example : setting the contained values

// using the generic set method (notice the new operator)
Val1.set("myvalue1",new openfluid::core::DoubleValue(18.05));
// using a specific set method
Val1.setDouble("myvalue2",openfluid::core::DoubleValue(0.005));
// using a specific set method
Val1.setMatrixValue("myvalue3",openfluid::core::MatrixValue(3,3,1.99));

Example : getting the contained values

double DblTmp1;
// using the generic at method
Tmp1 = Val1.at("myvalue1").asDoubleValue();
// using specific get methods
Tmp1 = Val1.getDouble("myvalue1");
DblTmp1 = Val1.getDouble("myvalue1");
// or using the [] operator
Tmp1 = Val1["myvalue1"].asDoubleValue();

Example : testing the contained elements

// testing if a key exist
Val1.isKeyExist("myvalue1"); // true in this case;
// testing if a key exist and the contained value type
Val1.isKeyExist("myvalue2") && Val1["myvalue2"].getType() == openfluid::core::Value::BOOLEAN; // false in this case

Example : conversion from string

// to MapValue, using a string values separator
StringVal.set("{\"myvalue1\":toto,\"myvalue2\":12.56,\"myvalue3\":17,\"myvalue4\":false}");
StringVal.toMapValue(Val2);
// all values are stored as strings, that can be converted to other types
Val2.at("myvalue3").asStringValue().toIntegerValue(TmpInt);

Example : conversion to string

std::string StdStrVal = Val1.toString();

#include <core/MapValue.hpp>

Public Types

typedef std::map< std::string, std::shared_ptr< Value > > Map_t
 
typedef Map_t::iterator iterator
 
typedef Map_t::const_iterator const_iterator
 
- Public Types inherited from openfluid::core::Value
enum  Type {
  NONE, BOOLEAN, INTEGER, DOUBLE,
  STRING, VECTOR, MATRIX, MAP,
  TREE, NULLL
}
 

Public Member Functions

 MapValue ()
 
 MapValue (const MapValue &Val)
 
 MapValue (MapValue &&Val)
 
 MapValue (const Map_t &Val)
 
MapValue & operator= (const Value &Other) override
 
MapValue & operator= (Value &&Other) override
 
MapValue & operator= (const MapValue &Other)=default
 
MapValue & operator= (MapValue &&Other)=default
 
 ~MapValue ()
 
Type getType () const override
 
Value * clone () const override
 
void writeToStream (std::ostream &OutStm) const override
 
void writeQuotedToStream (std::ostream &OutStm) const override
 
void set (const std::string &Key, Value *Element)
 
void setDouble (const std::string &Key, const double &Val)
 
void setInteger (const std::string &Key, const long &Val)
 
void setBoolean (const std::string &Key, const bool &Val)
 
void setString (const std::string &Key, const std::string &Val)
 
void setVectorValue (const std::string &Key, const VectorValue &Val)
 
void setMatrixValue (const std::string &Key, const MatrixValue &Val)
 
void setMapValue (const std::string &Key, const MapValue &Val)
 
Value & operator[] (const std::string &Key)
 
Value & at (const std::string &Key)
 
const Value & at (const std::string &Key) const
 
double getDouble (const std::string &Key) const
 
long getInteger (const std::string &Key) const
 
bool getBoolean (const std::string &Key) const
 
std::string getString (const std::string &Key) const
 
VectorValue getVectorValue (const std::string &Key) const
 
MatrixValue getMatrixValue (const std::string &Key) const
 
MapValue getMapValue (const std::string &Key) const
 
bool remove (const std::string &Key)
 
unsigned long getSize () const
 
unsigned long size () const
 
bool isKeyExist (const std::string &Key) const
 
std::vector< std::string > getKeys () const
 
void clear ()
 
iterator begin ()
 
const_iterator begin () const
 
iterator end ()
 
const_iterator end () const
 
- Public Member Functions inherited from openfluid::core::CompoundValue
bool isSimple () const override
 
bool isCompound () const override
 
- Public Member Functions inherited from openfluid::core::Value
 Value ()=default
 
 Value (const Value &)=default
 
 Value (Value &&)=default
 
virtual ~Value ()=default
 
virtual bool convert (Value &) const
 
bool isDoubleValue () const
 
const DoubleValue & asDoubleValue () const
 
DoubleValue & asDoubleValue ()
 
bool isIntegerValue () const
 
const IntegerValue & asIntegerValue () const
 
IntegerValue & asIntegerValue ()
 
bool isBooleanValue () const
 
const BooleanValue & asBooleanValue () const
 
BooleanValue & asBooleanValue ()
 
bool isStringValue () const
 
const StringValue & asStringValue () const
 
StringValue & asStringValue ()
 
bool isNullValue () const
 
const NullValue & asNullValue () const
 
NullValue & asNullValue ()
 
bool isVectorValue () const
 
const VectorValue & asVectorValue () const
 
VectorValue & asVectorValue ()
 
bool isMatrixValue () const
 
const MatrixValue & asMatrixValue () const
 
MatrixValue & asMatrixValue ()
 
bool isMapValue () const
 
const MapValue & asMapValue () const
 
MapValue & asMapValue ()
 
bool isTreeValue () const
 
const TreeValue & asTreeValue () const
 
TreeValue & asTreeValue ()
 
std::string toString () const
 

Additional Inherited Members

- Static Public Member Functions inherited from openfluid::core::Value
static bool getValueTypeFromString (const std::string &ValueTypeString, Value::Type &ValueType)
 
static std::string getStringFromValueType (const Value::Type ValueType)
 
Inheritance diagram for openfluid::core::MapValue:
Inheritance graph
[legend]
Collaboration diagram for openfluid::core::MapValue:
Collaboration graph
[legend]

Member Typedef Documentation

◆ const_iterator

typedef Map_t::const_iterator openfluid::core::MapValue::const_iterator

◆ iterator

typedef Map_t::iterator openfluid::core::MapValue::iterator

◆ Map_t

typedef std::map<std::string,std::shared_ptr<Value> > openfluid::core::MapValue::Map_t

Constructor & Destructor Documentation

◆ MapValue() [1/4]

openfluid::core::MapValue::MapValue ( )
inline

Default constructor

◆ MapValue() [2/4]

openfluid::core::MapValue::MapValue ( const MapValue &  Val)

Copy constructor

◆ MapValue() [3/4]

openfluid::core::MapValue::MapValue ( MapValue &&  Val)

Move constructor

◆ MapValue() [4/4]

openfluid::core::MapValue::MapValue ( const Map_t &  Val)
inline

◆ ~MapValue()

openfluid::core::MapValue::~MapValue ( )

Member Function Documentation

◆ at() [1/2]

Value& openfluid::core::MapValue::at ( const std::string &  Key)

Returns a reference to the value of the map at the given key

Parameters
[in]Keythe key of the requested value
Returns
the value at the given key

◆ at() [2/2]

const Value& openfluid::core::MapValue::at ( const std::string &  Key) const

Returns a const reference to the value of the map at the given key

Parameters
[in]Keythe key of the requested value
Returns
the value at the given key

◆ begin() [1/2]

iterator openfluid::core::MapValue::begin ( )
inline

Returns an iterator referring to the first element in the map

Returns
an iterator to the first element in the map

◆ begin() [2/2]

const_iterator openfluid::core::MapValue::begin ( ) const
inline

Returns a constant iterator referring to the first element in the map

Returns
a constant iterator to the first element in the map

◆ clear()

void openfluid::core::MapValue::clear ( )

Clears the map by removing all values

◆ clone()

Value* openfluid::core::MapValue::clone ( ) const
inlineoverridevirtual

Reimplemented from openfluid::core::Value.

◆ end() [1/2]

iterator openfluid::core::MapValue::end ( )
inline

Returns an iterator referring to the past-the-end element in the map

Returns
an iterator to the past-the-end element in the map

◆ end() [2/2]

const_iterator openfluid::core::MapValue::end ( ) const
inline

Returns a constant iterator referring to the past-the-end element in the map

Returns
a constant iterator to the past-the-end element in the map

◆ getBoolean()

bool openfluid::core::MapValue::getBoolean ( const std::string &  Key) const
inline

Returns the boolean value of the map at the given key

Parameters
[in]Keythe key of the requested value
Returns
the value at the given key

◆ getDouble()

double openfluid::core::MapValue::getDouble ( const std::string &  Key) const
inline

Returns the double value of the map at the given key

Parameters
[in]Keythe key of the requested value
Returns
the value at the given key

◆ getInteger()

long openfluid::core::MapValue::getInteger ( const std::string &  Key) const
inline

Returns the long value of the map at the given key

Parameters
[in]Keythe key of the requested value
Returns
the value at the given key

◆ getKeys()

std::vector<std::string> openfluid::core::MapValue::getKeys ( ) const

Returns the list of keys of the map

Returns
a std::vector of std::string containing the keys of the map

◆ getMapValue()

MapValue openfluid::core::MapValue::getMapValue ( const std::string &  Key) const
inline

Returns the MapValue value of the map at the given key

Parameters
[in]Keythe key of the requested value
Returns
the value at the given key

◆ getMatrixValue()

MatrixValue openfluid::core::MapValue::getMatrixValue ( const std::string &  Key) const
inline

Returns the MatrixValue value of the map at the given key

Parameters
[in]Keythe key of the requested value
Returns
the value at the given key

◆ getSize()

unsigned long openfluid::core::MapValue::getSize ( ) const
inline

Returns the size of the map

Returns
size of the map

◆ getString()

std::string openfluid::core::MapValue::getString ( const std::string &  Key) const
inline

Returns the string value of the map at the given key

Parameters
[in]Keythe key of the requested value
Returns
the value at the given key

◆ getType()

Type openfluid::core::MapValue::getType ( ) const
inlineoverridevirtual

◆ getVectorValue()

VectorValue openfluid::core::MapValue::getVectorValue ( const std::string &  Key) const
inline

Returns the VectorValue value of the map at the given key

Parameters
[in]Keythe key of the requested value
Returns
the value at the given key

◆ isKeyExist()

bool openfluid::core::MapValue::isKeyExist ( const std::string &  Key) const
inline

Checks if the given key exists

Parameters
[in]Keythe key to check
Returns
true if the given key is present

◆ operator=() [1/4]

MapValue& openfluid::core::MapValue::operator= ( const MapValue &  Other)
default

◆ operator=() [2/4]

MapValue& openfluid::core::MapValue::operator= ( const Value &  )
overridevirtual

Assignment operator

Reimplemented from openfluid::core::Value.

◆ operator=() [3/4]

MapValue& openfluid::core::MapValue::operator= ( MapValue &&  Other)
default

◆ operator=() [4/4]

MapValue& openfluid::core::MapValue::operator= ( Value &&  )
overridevirtual

Move operator

Reimplemented from openfluid::core::Value.

◆ operator[]()

Value& openfluid::core::MapValue::operator[] ( const std::string &  Key)

Operator to get/set a value at a key given between []

Returns
the value at the given key

◆ remove()

bool openfluid::core::MapValue::remove ( const std::string &  Key)

Removes the value corresponding to the given key

Parameters
[in]Keythe key to remove

◆ set()

void openfluid::core::MapValue::set ( const std::string &  Key,
Value *  Element 
)

Sets a new value at the given key

Parameters
[in]Keythe key to add
[in]Elementthe element to add, must be derived from openfluid::core::Value

◆ setBoolean()

void openfluid::core::MapValue::setBoolean ( const std::string &  Key,
const bool &  Val 
)
inline

Sets a new boolean value at the given key

Parameters
[in]Keythe key to add
[in]Valthe value to add

◆ setDouble()

void openfluid::core::MapValue::setDouble ( const std::string &  Key,
const double &  Val 
)
inline

Sets a new double value at the given key

Parameters
[in]Keythe key to add
[in]Valthe value to add

◆ setInteger()

void openfluid::core::MapValue::setInteger ( const std::string &  Key,
const long &  Val 
)
inline

Sets a new long value at the given key

Parameters
[in]Keythe key to add
[in]Valthe value to add

◆ setMapValue()

void openfluid::core::MapValue::setMapValue ( const std::string &  Key,
const MapValue &  Val 
)
inline

Sets a new MapValue value at the given key

Parameters
[in]Keythe key to add
[in]Valthe value to add

◆ setMatrixValue()

void openfluid::core::MapValue::setMatrixValue ( const std::string &  Key,
const MatrixValue &  Val 
)
inline

Sets a new MatrixValue value at the given key

Parameters
[in]Keythe key to add
[in]Valthe value to add

◆ setString()

void openfluid::core::MapValue::setString ( const std::string &  Key,
const std::string &  Val 
)
inline

Sets a new string value at the given key

Parameters
[in]Keythe key to add
[in]Valthe value to add

◆ setVectorValue()

void openfluid::core::MapValue::setVectorValue ( const std::string &  Key,
const VectorValue &  Val 
)
inline

Sets a new VectorValue value at the given key

Parameters
[in]Keythe key to add
[in]Valthe value to add

◆ size()

unsigned long openfluid::core::MapValue::size ( ) const
inline

Returns the size of the map

Returns
size of the map

◆ writeQuotedToStream()

void openfluid::core::MapValue::writeQuotedToStream ( std::ostream &  OutStm) const
inlineoverridevirtual

◆ writeToStream()

void openfluid::core::MapValue::writeToStream ( std::ostream &  OutStm) const
overridevirtual

The documentation for this class was generated from the following file:
openfluid::core::MatrixValue
Definition: MatrixValue.hpp:84
openfluid::core::StringValue::set
void set(const std::string &Val)
Definition: StringValue.hpp:200
openfluid::core::Value::toString
std::string toString() const
openfluid::core::StringValue::toIntegerValue
bool toIntegerValue(IntegerValue &Val) const
openfluid::core::MapValue::getDouble
double getDouble(const std::string &Key) const
Definition: MapValue.hpp:259
openfluid::core::Value::asStringValue
const StringValue & asStringValue() const
openfluid::core::MapValue
Definition: MapValue.hpp:92
openfluid::core::StringValue::toMapValue
bool toMapValue(MapValue &Val) const
openfluid::core::IntegerValue
Definition: IntegerValue.hpp:79
openfluid::core::MapValue::set
void set(const std::string &Key, Value *Element)
openfluid::core::MapValue::isKeyExist
bool isKeyExist(const std::string &Key) const
Definition: MapValue.hpp:353
openfluid::core::DoubleValue
Definition: DoubleValue.hpp:80
openfluid::core::MapValue::setMatrixValue
void setMatrixValue(const std::string &Key, const MatrixValue &Val)
Definition: MapValue.hpp:219
openfluid::core::MapValue::at
Value & at(const std::string &Key)
openfluid::core::Value::asDoubleValue
const DoubleValue & asDoubleValue() const
openfluid::core::MapValue::getType
Type getType() const override
Definition: MapValue.hpp:139
openfluid::core::MapValue::setDouble
void setDouble(const std::string &Key, const double &Val)
Definition: MapValue.hpp:168
openfluid::core::StringValue
Definition: StringValue.hpp:76
openfluid::core::Value::BOOLEAN
@ BOOLEAN
Definition: Value.hpp:66