C12Adapter Opensource C++ Interface
MDictionary Class Reference

Dictionary of keys and their values, associative collection. More...

Inheritance diagram for MDictionary:

Public Member Functions

 MDictionary ()
 Object constructor, creates an empty dictionary.
 
 MDictionary (const MStdString &properties)
 Object constructor that accepts the list of values. More...
 
 MDictionary (const MDictionary &other)
 Object copy constructor, creates an equivalent dictionary.
 
virtual ~MDictionary ()
 Object destructor, removes allocated resources from memory.
 
MDictionaryoperator= (const MDictionary &other)
 Assignment operator.
 
unsigned GetCount () const
 Return the number of entries in the dictionary.
 
MVariantGetMap ()
 Access the map object of the dictionary.
 
const MVariantGetMap () const
 Access the constant map object of the dictionary.
 
void Clear ()
 Make dictionary empty.
 
const MVariantItem (const MVariant &key) const
 Return value of the key specified. More...
 
void SetItem (const MVariant &key, const MVariant &val)
 Set (key, value) pair to the dictionary. More...
 
const MVariantoperator[] (const MVariant &key) const
 Get the value associated with the key. More...
 
MVariantoperator[] (const MVariant &key)
 Set or get the value associated with the key. More...
 
MVariant::VariantVector GetAllKeys () const
 Return the list of all available keys.
 
MVariant::VariantVector GetAllValues () const
 Return the list of all available values.
 
MStdString AsStringUnsorted () const
 Get the string with key=value pairs enumerated in the order of their insertion. More...
 
bool IsKeyPresent (const MVariant &key) const
 Return 'true' if the specified key exists.
 
bool IsValuePresent (const MVariant &val) const
 Return 'true' if the specified value exist.
 
MVariantGetValue (const MVariant &key)
 Get a value associated with the key, or NULL if the value does not exist.
 
const MVariantGetValue (const MVariant &key) const
 const variant of the same function (see above)
 
void Remove (const MVariant &key)
 Removes key and value pair from the dictionary. More...
 
bool RemoveIfPresent (const MVariant &key)
 Removes key and value pair from the dictionary, if such key is present. More...
 
void Merge (const MDictionary &dict)
 Merges the current dictionary with given one.
 
MDictionaryNewClone () const
 Reflection enabled object copy constructor.
 
MStdString AsString () const
 
void SetAsString (const MStdString &properties)
 
- Public Member Functions inherited from MObject
virtual ~MObject ()
 Object destructor.
 
virtual const MClassGetClass () const =0
 Get the final class of the object. More...
 
virtual unsigned GetEmbeddedSizeof () const
 For embedded object types, return the size of the class. More...
 
bool IsEmbeddedObject () const
 Tell if the object is of embedded kind. More...
 
SHOW_INTERNAL MVariant Call (const MStdString &name, const MVariant &params)
 Call the object service with parameters, given as variant. More...
 
MVariant Call0 (const MStdString &name)
 Call the object service with no parameters. More...
 
MVariant Call1 (const MStdString &name, const MVariant &p1)
 Call the object service with one parameter. More...
 
MVariant Call2 (const MStdString &name, const MVariant &p1, const MVariant &p2)
 Call the object service with two parameter. More...
 
MVariant Call3 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3)
 Call the object service with three parameter. More...
 
MVariant Call4 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3, const MVariant &p4)
 Call the object service with four parameter. More...
 
MVariant Call5 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3, const MVariant &p4, const MVariant &p5)
 Call the object service with five parameter. More...
 
MVariant Call6 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3, const MVariant &p4, const MVariant &p5, const MVariant &p6)
 Call the object service with six parameter. More...
 
virtual MVariant CallV (const MStdString &name, const MVariant::VariantVector &params)
 Call the object service with parameters, given as variant vector. More...
 
virtual bool IsPropertyPresent (const MStdString &name) const
 Tell if the property with the given name exists.
 
virtual bool IsServicePresent (const MStdString &name) const
 Tell if the service with the given name exists.
 
virtual MVariant GetProperty (const MStdString &name) const
 Get the property value using name of the property. More...
 
virtual void SetProperty (const MStdString &name, const MVariant &value)
 Set the property using name of the property, and value. More...
 
virtual MStdStringVector GetAllPropertyNames () const
 Return the list of publicly available properties, persistent or not. More...
 
virtual MStdStringVector GetAllPersistentPropertyNames () const
 Return the list of persistent properties. More...
 
virtual void SetPersistentPropertiesToDefault ()
 Set the persistent properties of the object to their default values. More...
 
virtual MVariant GetPersistentPropertyDefaultValue (const MStdString &name) const
 Get the default value of persistent property with the name given. More...
 
virtual void SetPersistentPropertyToDefault (const MStdString &name)
 Set the persistent property with the name given to default value. More...
 
virtual const char * GetType () const
 Get the name of the type for the object (could be the same as class name).
 
virtual void SetType (const MStdString &)
 Intentionally, it will set the name of the type for the object, but the service will not allow setting the name to anything other than the current name. More...
 
virtual void Validate ()
 Validate internal structures of the object. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from MObject
static const MClassGetStaticClass ()
 Get the declared class of this particular object. More...
 
static bool IsClassPresent (const MStdString &name)
 Tells if the given class name is available. More...
 
- Static Public Attributes inherited from MObject
static const MClass s_class
 Class of MObject.
 
- Protected Member Functions inherited from MObject
 MObject ()
 Object constructor, protected as the class is abstract.
 
void DoSetPersistentPropertiesToDefault (const MClass *staticClass)
 Set the persistent properties to their default values for one object provided the class for that object. More...
 

Detailed Description

Dictionary of keys and their values, associative collection.

This is how a dictionary represents itself within a string:

dictionary :== [ item1 [ ';' itemN ]+ ]?
item :== assignment | configuration-name
assignment :== key '=' value

This is how a dictionary represents itself within a J command (given as an example):

dictionary :== 'J00' item1 [itemN]+
item :== '[' key ':' value ']'

In case of a J command, value can be anything but the closing square brace.

Constructor & Destructor Documentation

MDictionary::MDictionary ( const MStdString properties)
explicit

Object constructor that accepts the list of values.

Initializes the dictionary by parsing the list of keys and values and looking in the configuration source for used configuration names.

Precondition
The given list of key-value pairs is correct, or multiple exceptions are thrown. The syntax is described at the MDictionary description. Configuration location shall have a valid format, but it is not necessarily present.

Member Function Documentation

MStdString MDictionary::AsString ( ) const

Access dictionary representation as string with key=value pairs.

When the property is got, the string returned will have keys sorted. When the property is set, the string can have key=value pairs in any order. The string has the following format:

KEY1=value1;KEY2=value2;KEY3=value3;....

Where KEY1, KEY2, ... are key names, value1, value2 ... are their values. In case the value is of string type, the correspondent value is enclosed in quotes, and it can have C-like escape sequences.

See also
AsStringUnsorted - returns key=value pairs in the order of their insertion
MStdString MDictionary::AsStringUnsorted ( ) const

Get the string with key=value pairs enumerated in the order of their insertion.

The order of appearance of keys will be the order at which the keys were added into the dictionary.

The string has the following format:

KEY2=value2;KEY1=value1;KEY3=value3;....

Where KEY1, KEY2, ... are key names, value1, value2 ... are their values. In case the value is of string type, the correspondent value is enclosed in quotes, and it can have C-like escape sequences.

See also
AsString - returns key=value pairs sorted by key
const MVariant& MDictionary::Item ( const MVariant key) const

Return value of the key specified.

Throw exception if the key doesn't exist.

Precondition
the key must be in the dictionary
const MVariant& MDictionary::operator[] ( const MVariant key) const
inline

Get the value associated with the key.

Precondition
The key must exist in the dictionary, or an exception takes place.
MVariant& MDictionary::operator[] ( const MVariant key)
inline

Set or get the value associated with the key.

If the key doesn't exist in the dictionary, it is created. The value of the key associated is created with default constructor.

Precondition
Type associated with 'value' in the dictionary must have default constructor
void MDictionary::Remove ( const MVariant key)

Removes key and value pair from the dictionary.

Precondition
Key must exist or an exception is thrown
bool MDictionary::RemoveIfPresent ( const MVariant key)

Removes key and value pair from the dictionary, if such key is present.

Return true if key was actually removed.

Precondition
Key must exist or an exception is thrown
void MDictionary::SetAsString ( const MStdString properties)

Access dictionary representation as string with key=value pairs.

When the property is got, the string returned will have keys sorted. When the property is set, the string can have key=value pairs in any order. The string has the following format:

KEY1=value1;KEY2=value2;KEY3=value3;....

Where KEY1, KEY2, ... are key names, value1, value2 ... are their values. In case the value is of string type, the correspondent value is enclosed in quotes, and it can have C-like escape sequences.

See also
AsStringUnsorted - returns key=value pairs in the order of their insertion
void MDictionary::SetItem ( const MVariant key,
const MVariant val 
)

Set (key, value) pair to the dictionary.

If key doesn't exist, it is created.