Status & Roadmap
Authors & License
Funding U++
Search on this site

SourceForge.net Logo

SourceForge.net Logo

GitHub Logo

Discord Logo



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



Default constructor.



ValueMap(const ValueMap& v)

Copy constructor.



ValueMap(const ValueArray& va)

Creates ValueMap from ValueArray. ValueArray elements become values with keys equal to indices.



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

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



ValueMap(VectorMap<Value, Value>&& 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(std::initializer_list<std::pair<Value, Value>> init)

C++11 initialization.



ValueMap& operator=(const ValueMap& v)




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.



int Find(const Value& keyconst

Returns the index of first key or -1 if not present.



int FindNext(int iiconst

Returns the index of next key with the same value as key at index ii or -1 if not present.



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& GetAdd(const Value& key)

Returns a reference of element at key key, if there is none, it is created as Void Value. The reference returned is invalidated by any further use of originating Value.



Value& operator()(const Value& key)

Value& operator()(const String& key)

Value& operator()(const char *key)

Value& operator()(const int key)

Value& operator()(const Id& key)

Same as GetAdd(key).



Value& At(int i)

Returns a reference of value at index i. The reference returned is invalidated by any further use of originating Value.



Value GetAndClear(const Value& key)

If key is not present, returns ErrorValue (which is Void and Null), 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.



bool IsSame(const ValueMap& bconst

ValueMap is ordered and is compared as such, which means that even if values of keys are the same, if order is different, ValueMaps or Values containing them are not considered equal (as with operator==). This method provides and alternative comparison of Values which treats contained ValueMaps as unordered. It goes recursively through any contained ValueMaps and ValueArrays too, for other Value types than ValueMap it uses the normal operator==.



Do you want to contribute?