Zakero's C++ Header Libraries
A collection of reusable C++ libraries
|
A Key/Value collection of Objects. More...
Public Member Functions | |
const Object & | at (const Object &) const noexcept |
Get the value of a key. More... | |
Object & | at (Object &) noexcept |
Get the value of a key. More... | |
void | clear () noexcept |
Remove the contents of the Map. More... | |
void | erase (const Object &) noexcept |
Erase a key/value pair. More... | |
bool | keyExists (const Object &) const noexcept |
Check if a key exists. More... | |
std::error_code | set (const Object &, const Object &) noexcept |
Set a key/value pair. More... | |
std::error_code | set (Object &, Object &) noexcept |
Set a key/value pair. More... | |
size_t | size () const noexcept |
Get the size of the Map. More... | |
The MessagePack specification allows any Object to be the "key" of a map.
As interesting as it would be to having a Map as the key to another Map, programmatically, it is not practical. This implementation limits the types of the "keys" to include all MessagePack types except Array, Binary, Ext, and Map.
The Map uses several std::map's to hold the "values". While it is possible to directly access these std::map's, it is recommended to use Map's methods since they ensure the uniqueness of the key and other checks.
Objects can be tested to find out if they are Map by using Object::isMap() and converted into a Map with Object::asMap(). A Map can not be converted into an Object. However, an Object can be constructed using a Map.
The value associated with the provided key
will be returned. If the key
does not exist, then a reference to the key
will be returned.
key | The key |
The value associated with the provided key
will be returned. If the key
does not exist, then a reference to the key
will be returned.
Checking if the key exists (keyExists()) is more reliable than using this error handling.
key | The key |
|
inlinenoexcept |
All of the key/value pairs will be removed.
|
noexcept |
If the specified key
exists, the key
and matching value will be removed frame the Map.
key | The key |
|
noexcept |
Search the Map and return true
if the key
exists. If the key
was not found, return false
.
true | The key exists. |
false | The key does not exist. |
key | The key Object |
|
inlinenoexcept |