Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Language
English













SourceForge.net Logo

Title

 

class ValueMap

ValueMap is a map of key-value pairs, where both key and value are of Value type. Key has to be rich Value type with operator== and GetHashValue defined (actually, GetHashValue does not have to be defined if performance is not critical). It is fully Rich Value compatible.

 

All key-value pairs added to ValueMap are also assigned indices in order of Adding them to ValueMap and elements are also accessible using these indices.

 

ValueMap is also compatible with ValueArray (in the similar way how Time is compatible with Date). Assigning Value containing ValueMap to ValueArray assigns it a ValueArray representing values of ValueMap. Assigning ValueArray to ValueMap creates map where keys are number 0, 1, ... GetCount() - 1 and values contain elements with corresponding indices.

 

Not that Value provides operator[] methods to directly access ValueArray elements contained in Value with text keys (if Value does not contain ValueMap or requested key, Void Value is returned).

 

 

Public Method List

 

ValueMap()

Default constructor.

 


 

ValueMap(const ValueMap& v)

Copy constructor.

 


 

ValueMap(Index<Valuerval_ k, Vector<Valuerval_ v)

Creates ValueMap by picking Index a Vector of Values (efficient but sources are destroyed).

 


 

ValueMap(VectorMap<Value, Valuerval_ m)

Creates ValueMap by picking VectorMap (efficient but source is destroyed).

 


 

ValueMap(const Index<Value>& k, const Vector<Value>& v, int deep)

Creates ValueMap by deep copying Index a Vector of Values.

 


 

ValueMap(const VectorMap<Value, Value>& m, int deep)

Creates ValueMap by deep copying VectorMap.

 


 

~ValueMap()

Destructor.

 


 

ValueMap& operator=(const ValueMap& v)

Assignment.

 


 

ValueMap& operator=(VectorMap<Value, Valuerval_ m)

Pick assignment - efficient, destroying the source.

 


 

operator Value() const

Conversion to Value.

 


 

ValueMap(const Value& src)

Conversion from Value.

 


 

ValueMap(const Nuller&)

Null assignment. ValueMap is considered Null if it contains no elements.

 


 

bool IsNullInstance() const

Same as GetCount() == 0.

 


 

void Clear()

Removes all elements from ValueMap.

 


 

int GetCount() const

Returns number of elements in ValueMap.

 


 

bool IsEmpty() const

Same as GetCount() == 0.

 


 

const Value& GetKey(int iconst

Returns key at index i.

 


 

const Value& GetValue(int iconst

Returns value at index i.

 


 

void Add(const Value& key, const Value& value)

void Add(const String& key, const Value& value)

void Add(const char *key, const Value& value)

void Add(int key, const Value& value)

void Add(Id key, const Value& value)

Adds a new key-value pair to ValueMap. ValueMap can contain multiple same keys. Note: multiple overloads are required to make Id and SqlId work with ValueMap.

 


 

ValueMap& operator()(const Value& key, const Value& value)

ValueMap& operator()(const String& key, const Value& value)

ValueMap& operator()(const char *key, const Value& value)

ValueMap& operator()(int key, const Value& value)

ValueMap& operator()(Id key, const Value& value)

Same as Add(key, value).

 


 

void Set(const Value& key, const Value& value)

void Set(const String& s, const Value& value)

void Set(const char *s, const Value& value)

void Set(int q, const Value& value)

void Set(Id id, const Value& value)

If there is key in ValueMap, its associated Value is replaced by value. If there is none such key, key-value is added. If there is more than single such key, only first one (the one with lowest index) is replaced. Note: multiple overloads are required to make Id and SqlId work with ValueMap.

 


 

void SetAt(int i, const Value& v)

Replaces value at given index.

 


 

void SetKey(int i, const Value& key)

void SetKey(int i, const String& key)

void SetKey(int i, const char* key)

void SetKey(int i, int key)

void SetKey(int i, Id key)

Replaces key at given index. Note: multiple overloads are required to make Id and SqlId work with ValueMap.

 


 

int RemoveKey(const Value& key)

int RemoveKey(const String& key)

int RemoveKey(const char* key)

int RemoveKey(int key)

int RemoveKey(Id key)

Removes all key-value pairs with given key. Slow O(n) operation.

 


 

void Remove(int i)

Removes key-value pair at index i.

 


 

const Index<Value>& GetKeys() const

Returns keys.

 


 

ValueArray GetValues() const

Returns values.

 


 

operator ValueArray() const

Same as GetValues.

 


 

VectorMap<Value, ValuePick()

Picks the content - fast, ValueMap is cleared.

 


 

const Value& operator[](const Value& keyconst

const Value& operator[](const String& sconst

const Value& operator[](const char *keyconst

const Value& operator[](const Id& keyconst

const Value& operator[](const int keyconst

Returns value for key. If key is not present, returns ErrorValue (which is also void and Null Value). Note: multiple overloads are required to make Id and SqlId work with ValueMap.

 


 

Value GetAndClear(const Value& key)

If key is not present, returns void Value, otherwise returns value for key and sets it to void Value. The purpose of this processing is to optimize copying in situation when complex value (e.g. ValueArray) is about to be changed after retrieval, without clearing it in ValueMap the deep copy of complex structure would have to be performed when changing it.

 


 

unsigned GetHashValue() const

Returns hashing value.

 


 

void Serialize(Stream& s)

Binary serialization.

 


 

void Jsonize(JsonIO& jio)

JSON serialization support.

 


 

void Xmlize(XmlIO& xio)

XML serialization support.

 


 

String ToString() const

Conversion to text.

 


 

bool operator==(const ValueMap& vconst

Equality comparison, two ValueMap are equal when they contain same key-value pairs in the same order.

 


 

bool operator!=(const ValueMap& vconst

Same as !operator==(v).

 


 

int Compare(const ValueMap& bconst

bool operator<=(const ValueMap& xconst

bool operator>=(const ValueMap& xconst

bool operator<(const ValueMap& xconst

bool operator>(const ValueMap& xconst

Compares two ValueMaps. Performs ordered (as ValueMap has order of key-value pairs) comparison of key-value pairs.

 

 

Last edit by cxl on 04/23/2014. Do you want to contribute?. T++