Web Analytics Made Easy - Statcounter
Skip to content

Class SBCMetaValueMap#

ClassList > 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.

SBCMetaValueMap::SBCMetaValueMap () noexcept


function SBCMetaValueMap [2/8]#

Creates a new map.

explicit SBCMetaValueMap::SBCMetaValueMap (
    unsigned int nElements
) 

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:

  • nElements The number of elements to reserve space for.

function SBCMetaValueMap [3/8]#

Copy constructor.

SBCMetaValueMap::SBCMetaValueMap (
    const SBCMetaValueMap & other
) 

Constructs a new map as a copy of other.

All key-value pairs from other are copied into the new map.

Parameters:

  • other The source map to copy from.

function SBCMetaValueMap [4/8]#

Move constructor.

SBCMetaValueMap::SBCMetaValueMap (
    SBCMetaValueMap && other
) noexcept

Constructs a new map by moving the contents of other.

After the move, other is left in a valid but unspecified state.

Parameters:

  • other The source map to move from.

function SBCMetaValueMap [5/8]#

Creates a new map from the given hash map.

explicit SBCMetaValueMap::SBCMetaValueMap (
    const SBHashMap< std::string, SBValue > & hashMap
) 

Constructs a map from the given hash map.

The resulting map contains all key-value pairs from hashMap.

Parameters:

  • hashMap The source hash map.

function SBCMetaValueMap [6/8]#

Creates a new map from the given std::map.

explicit SBCMetaValueMap::SBCMetaValueMap (
    const std::map< std::string, SBValue > & map
) 

Constructs a map from the given std::map.

All entries from map are inserted into the new map.

Parameters:

  • map The 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:

  • map The 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:

  • init Initializer list containing pairs of keys and values.

function at [1/2]#

Access a value by key; throws std::out_of_range if missing.

SBValue & SBCMetaValueMap::at (
    const std::string & key
) 

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:

  • key The 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.

const SBValue & SBCMetaValueMap::at (
    const std::string & key
) const

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:

  • key The key whose value to access.

Returns:

Const reference to the value associated with key.


function clear#

Erases all entries in the map.

void SBCMetaValueMap::clear () 

Removes all entries from the map, leaving it empty.


function contains#

Returns true if thekey has an associated value.

bool SBCMetaValueMap::contains (
    const std::string & key
) const

Checks whether the map contains an entry with the given key.

Parameters:

  • key The 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).

SBHashMap< std::string, SBValue > & SBCMetaValueMap::data () noexcept

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).

const SBHashMap< std::string, SBValue > & SBCMetaValueMap::data () noexcept const

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.

bool SBCMetaValueMap::empty () const

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.

bool SBCMetaValueMap::erase (
    const std::string & key
) 

Erases the entry with the specified key.

If an entry with key exists, it is removed.

Parameters:

  • key The key of the entry to erase.

Returns:

true if an entry was erased; otherwise false.


function get#

Returns value if present, else returns SBValue() __

SBValue SBCMetaValueMap::get (
    const std::string & key
) const

Retrieves the value associated with key.

If key is not present, an empty value is returned.

Parameters:

  • key The 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() __

SBCMetaValueMap SBCMetaValueMap::getValueMap (
    const std::string & key
) const

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:

  • key The 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.

bool SBCMetaValueMap::insert (
    const std::string & key,
    const SBValue & value
) 

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:

  • key The key for the new entry.
  • value The 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.

bool SBCMetaValueMap::insert (
    const std::pair< std::string, SBValue > & keyValuePair
) 

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:

  • keyValuePair Pair containing the key and value to insert.

Returns:

true if insertion succeeded; false if the key already existed.


function operator=#

Copy assignment.

SBCMetaValueMap & SBCMetaValueMap::operator= (
    const SBCMetaValueMap & other
) 

Assigns the contents of other to this map.

All existing entries in this map are replaced with copies of the entries from other.

Parameters:

  • other The source map to copy from.

Returns:

Reference to this map.


function operator=#

Move assignment.

SBCMetaValueMap & SBCMetaValueMap::operator= (
    SBCMetaValueMap && other
) noexcept

Moves the contents of other into this map.

After the move, other is left in a valid but unspecified state.

Parameters:

  • other The source map to move from.

Returns:

Reference to this map.


function operator[]#

Access/insertion; inserts a default-constructed SBValue if key doesn't exist.

SBValue & SBCMetaValueMap::operator[] (
    const std::string & key
) 

Provides access to the value for key, inserting a default-constructed value if the key is not present.

Parameters:

  • key The 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.

SBValue & SBCMetaValueMap::operator[] (
    std::string && key
) 

Provides access to the value for key (rvalue), inserting a default-constructed value if the key is not present.

Parameters:

  • key The key to access (rvalue reference).

Returns:

Reference to the value associated with key.


function set#

Sets (overwrites) a value.

void SBCMetaValueMap::set (
    std::string key,
    SBValue value
) 

Sets the value for key, overwriting any existing entry.

If the map does not exist, it is created.

Parameters:

  • key The key to set.
  • value The value to associate with key.

function size#

The number of entries in the map.

unsigned int SBCMetaValueMap::size () const

Returns the number of entries in the map.

Returns:

The number of key-value pairs stored.


function swap#

Swaps maps in O(1)

void SBCMetaValueMap::swap (
    SBCMetaValueMap & other
) noexcept

Swaps the contents of this map with other in constant time.

Parameters:

  • other The map to swap with.

function ~SBCMetaValueMap#

Destructor.

virtual SBCMetaValueMap::~SBCMetaValueMap () 

Destroys the map and releases all associated resources.


Protected Attributes Documentation#

variable dataPointer#

A pointer to the private data.

SBCMetaValueMapData* SBCMetaValueMap::dataPointer;