Class SBCMetaValueMap#
This class describes a value map. More...
#include <SBCMetaValueMap.hpp>
Public Functions#
| Type | Name |
|---|---|
| SBCMetaValueMap () noexcept Creates an empty map; no allocation. |
|
| SBCMetaValueMap (unsigned int nElements) Creates a new map. |
|
| SBCMetaValueMap (const SBCMetaValueMap & other) Copy constructor. |
|
| SBCMetaValueMap (SBCMetaValueMap && other) noexcept Move constructor. |
|
| SBCMetaValueMap (const SBHashMap< std::string, SBValue > & hashMap) Creates a new map from the given hash map. |
|
| SBCMetaValueMap (const std::map< std::string, SBValue > & map) Creates a new map from the given std::map. |
|
| SBCMetaValueMap (const std::unordered_map< std::string, SBValue > & map) Creates a new map from the given std::unordered_map. |
|
| SBCMetaValueMap (std::initializer_list< std::pair< std::string, SBValue > > init) Creates a new map from the given initializer list. |
|
| SBValue & | at (const std::string & key) Access a value by key; throws std::out_of_range if missing. |
| const SBValue & | at (const std::string & key) const Access a value by key; throws std::out_of_range if missing. |
| void | clear () Erases all entries in the map. |
| bool | contains (const std::string & key) const Returns true if thekey has an associated value. |
| SBHashMap< std::string, SBValue > & | data () noexcept Access the underlying map pointer (may be nullptr only in moved-from state). |
| const SBHashMap< std::string, SBValue > & | data () noexcept const Access the underlying map pointer (may be nullptr only in moved-from state). |
| bool | empty () const Returns true when the map contains no entry. |
| bool | erase (const std::string & key) Attempts to erase an entry with a specific key and returnstrue if successful. |
| SBValue | get (const std::string & key) const Returns value if present, else returns SBValue() __ |
| SBCMetaValueMap | getValueMap (const std::string & key) const A convenience getter, that returns a value map stored at the key if present, else returnsSBValueMap() __ |
| bool | insert (const std::string & key, const SBValue & value) Inserts only if missing; returns true if inserted,false ifkey already existed. |
| bool | insert (const std::pair< std::string, SBValue > & keyValuePair) Inserts only if missing; returns true if inserted,false if thekey already existed. |
| SBCMetaValueMap & | operator= (const SBCMetaValueMap & other) Copy assignment. |
| SBCMetaValueMap & | operator= (SBCMetaValueMap && other) noexcept Move assignment. |
| SBValue & | operator[] (const std::string & key) Access/insertion; inserts a default-constructed SBValue if key doesn't exist. |
| SBValue & | operator[] (std::string && key) Access/insertion; inserts a default-constructed SBValue if key doesn't exist. |
| void | set (std::string key, SBValue value) Sets (overwrites) a value. |
| unsigned int | size () const The number of entries in the map. |
| void | swap (SBCMetaValueMap & other) noexcept Swaps maps in O(1) |
| virtual | ~SBCMetaValueMap () Destructor. |
Protected Attributes#
| Type | Name |
|---|---|
| SBCMetaValueMapData * | dataPointer A pointer to the private data. |
Detailed Description#
This is a convenience class that contains a map from std::string to SBValue, and can be used, for example, to pass into a function a map of parameters, or another data.
Public Functions Documentation#
function SBCMetaValueMap [1/8]#
Creates an empty map; no allocation.
function SBCMetaValueMap [2/8]#
Creates a new map.
Constructs a map reserving space for the given number of elements.
The map is initially empty but preallocates storage for the specified number of entries.
Parameters:
nElementsThe number of elements to reserve space for.
function SBCMetaValueMap [3/8]#
Copy constructor.
Constructs a new map as a copy of other.
All key-value pairs from other are copied into the new map.
Parameters:
otherThe source map to copy from.
function SBCMetaValueMap [4/8]#
Move constructor.
Constructs a new map by moving the contents of other.
After the move, other is left in a valid but unspecified state.
Parameters:
otherThe source map to move from.
function SBCMetaValueMap [5/8]#
Creates a new map from the given hash map.
Constructs a map from the given hash map.
The resulting map contains all key-value pairs from hashMap.
Parameters:
hashMapThe source hash map.
function SBCMetaValueMap [6/8]#
Creates a new map from the given std::map.
Constructs a map from the given std::map.
All entries from map are inserted into the new map.
Parameters:
mapThe source std::map of key-value pairs.
function SBCMetaValueMap [7/8]#
Creates a new map from the given std::unordered_map.
explicit SBCMetaValueMap::SBCMetaValueMap (
const std::unordered_map< std::string, SBValue > & map
)
Constructs a map from the given std::unordered_map.
All entries from map are inserted into the new map.
Parameters:
mapThe source std::unordered_map of key-value pairs.
function SBCMetaValueMap [8/8]#
Creates a new map from the given initializer list.
SBCMetaValueMap::SBCMetaValueMap (
std::initializer_list< std::pair< std::string, SBValue > > init
)
Constructs a map from an initializer list of key-value pairs.
If the initializer list contains duplicate keys, the last occurrence overwrites previous ones.
Parameters:
initInitializer list containing pairs of keys and values.
function at [1/2]#
Access a value by key; throws std::out_of_range if missing.
Returns a reference to the value associated with key.
Throws std::out_of_range if the map is not allocated or the key is not present.
Parameters:
keyThe key whose value to access.
Returns:
Reference to the value associated with key.
function at [2/2]#
Access a value by key; throws std::out_of_range if missing.
Returns a const reference to the value associated with key.
Throws std::out_of_range if the map is not allocated or the key is not present.
Parameters:
keyThe key whose value to access.
Returns:
Const reference to the value associated with key.
function clear#
Erases all entries in the map.
Removes all entries from the map, leaving it empty.
function contains#
Returns true if thekey has an associated value.
Checks whether the map contains an entry with the given key.
Parameters:
keyThe key to look for.
Returns:
true if the map contains the key; otherwise false.
function data [1/2]#
Access the underlying map pointer (may be nullptr only in moved-from state).
Returns a mutable reference to the underlying hash map.
The map is allocated if it does not already exist.
Returns:
Reference to the underlying hash map.
function data [2/2]#
Access the underlying map pointer (may be nullptr only in moved-from state).
Returns a const reference to the underlying hash map.
If the map has not been allocated, an empty map is returned.
Returns:
Const reference to the underlying hash map.
function empty#
Returns true when the map contains no entry.
Checks whether the map contains any entries.
Returns:
true if the map is empty; otherwise false.
function erase#
Attempts to erase an entry with a specific key and returnstrue if successful.
Erases the entry with the specified key.
If an entry with key exists, it is removed.
Parameters:
keyThe key of the entry to erase.
Returns:
true if an entry was erased; otherwise false.
function get#
Returns value if present, else returns SBValue() __
Retrieves the value associated with key.
If key is not present, an empty value is returned.
Parameters:
keyThe key whose value to retrieve.
Returns:
The value associated with key, or an empty value if the key is absent.
function getValueMap#
A convenience getter, that returns a value map stored at the key if present, else returnsSBValueMap() __
Retrieves a nested value map stored at key.
If key does not exist or does not contain a value map, an empty map is returned.
Parameters:
keyThe key whose associated value map to retrieve.
Returns:
The value map associated with key, or an empty map if unavailable.
function insert [1/2]#
Inserts only if missing; returns true if inserted,false ifkey already existed.
Inserts a new entry with key and value only if the key does not already exist.
Returns true if the entry was inserted; otherwise false.
Parameters:
keyThe key for the new entry.valueThe value for the new entry.
Returns:
true if insertion succeeded; false if the key already existed.
function insert [2/2]#
Inserts only if missing; returns true if inserted,false if thekey already existed.
Inserts a new entry from the given key-value pair only if the key does not already exist.
Returns true if the entry was inserted; otherwise false.
Parameters:
keyValuePairPair containing the key and value to insert.
Returns:
true if insertion succeeded; false if the key already existed.
function operator=#
Copy assignment.
Assigns the contents of other to this map.
All existing entries in this map are replaced with copies of the entries from other.
Parameters:
otherThe source map to copy from.
Returns:
Reference to this map.
function operator=#
Move assignment.
Moves the contents of other into this map.
After the move, other is left in a valid but unspecified state.
Parameters:
otherThe source map to move from.
Returns:
Reference to this map.
function operator[]#
Access/insertion; inserts a default-constructed SBValue if key doesn't exist.
Provides access to the value for key, inserting a default-constructed value if the key is not present.
Parameters:
keyThe key to access.
Returns:
Reference to the value associated with key.
function operator[]#
Access/insertion; inserts a default-constructed SBValue if key doesn't exist.
Provides access to the value for key (rvalue), inserting a default-constructed value if the key is not present.
Parameters:
keyThe key to access (rvalue reference).
Returns:
Reference to the value associated with key.
function set#
Sets (overwrites) a value.
Sets the value for key, overwriting any existing entry.
If the map does not exist, it is created.
Parameters:
keyThe key to set.valueThe value to associate with key.
function size#
The number of entries in the map.
Returns the number of entries in the map.
Returns:
The number of key-value pairs stored.
function swap#
Swaps maps in O(1)
Swaps the contents of this map with other in constant time.
Parameters:
otherThe map to swap with.
function ~SBCMetaValueMap#
Destructor.
Destroys the map and releases all associated resources.
Protected Attributes Documentation#
variable dataPointer#
A pointer to the private data.