All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Types | Public Member Functions
openfluid::core::MapValue Class Reference

#include <core/MapValue.hpp>

Inheritance diagram for openfluid::core::MapValue:
openfluid::core::CompoundValue openfluid::core::Value

List of all members.

Public Types

typedef std::map< std::string,
boost::shared_ptr< Value > > 
Map_t

Public Member Functions

 MapValue ()
 MapValue (const MapValue &Val)
 MapValue (const Map_t &Val)
Valueoperator= (const Value &Other)
 ~MapValue ()
Type getType () const
Valueclone () const
void writeToStream (std::ostream &OutStm) const
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)
Valueoperator[] (const std::string &Key)
Valueget (const std::string &Key)
double getDouble (const std::string &Key)
long getInteger (const std::string &Key)
bool getBoolean (const std::string &Key)
std::string getString (const std::string &Key)
VectorValue getVectorValue (const std::string &Key)
MatrixValue getMatrixValue (const std::string &Key)
bool remove (const std::string &Key)
unsigned long getSize () const
unsigned long size () const
bool isKeyExist (const std::string &Key) const
void clear ()

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
  openfluid::core::MapValue Val1;

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.setDoubleValue("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

  openfluid::core::DoubleValue Tmp1;
  double DblTmp1;

  // using the generic get method
  Tmp1 = Val1.get("myvalue1").asDoubleValue();

  // using specific get methods
  Tmp1 = Val1.getDoubleValue("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

  openfluid::core::StringValue StringVal;
  openfluid::core::MapValue Val2;

  // to MapValue, using a string values separator
  StringVal.set("myvalue1=toto;myvalue2=12.56;myvalue3=17;myvalue3=false");
  StringVal.toMapValue(";",Val2);

  // all values are stored as strings, that can be converted to other types
  openfluid::core::IntegerValue TmpInt;
  Val2.get("myvalue3").asStringValue().toIntegerValue(TmpInt);

Example : conversion to string

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

Member Typedef Documentation

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

Constructor & Destructor Documentation

Default constructor

Copy constructor

openfluid::core::MapValue::MapValue ( const Map_t Val) [inline]

Member Function Documentation

Clears the map by removing all values

Value* openfluid::core::MapValue::clone ( ) const [inline, virtual]

Reimplemented from openfluid::core::Value.

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

Returns the value of the map at the given key

Parameters:
[in]Keythe key of the requested value
Returns:
the value at the given key
bool openfluid::core::MapValue::getBoolean ( const std::string &  Key) [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
double openfluid::core::MapValue::getDouble ( const std::string &  Key) [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
long openfluid::core::MapValue::getInteger ( const std::string &  Key) [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
MatrixValue openfluid::core::MapValue::getMatrixValue ( const std::string &  Key) [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
unsigned long openfluid::core::MapValue::getSize ( ) const [inline]

Returns the size of the map

Returns:
size of the map
std::string openfluid::core::MapValue::getString ( const std::string &  Key) [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
Type openfluid::core::MapValue::getType ( ) const [inline, virtual]
VectorValue openfluid::core::MapValue::getVectorValue ( const std::string &  Key) [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
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
Value& openfluid::core::MapValue::operator= ( const Value ) [virtual]

Assignment operator

Reimplemented from openfluid::core::Value.

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
bool openfluid::core::MapValue::remove ( const std::string &  Key)

Removes the value corresponding to the given key

Parameters:
[in]Keythe key to remove
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
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
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
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
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
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
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
unsigned long openfluid::core::MapValue::size ( ) const [inline]

Returns the size of the map

Returns:
size of the map
void openfluid::core::MapValue::writeToStream ( std::ostream &  OutStm) const [virtual]

The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines