Switchboard SDK
Loading...
Searching...
No Matches
switchboard::SBAnyMap Class Reference

Map class to store and retrieve values. More...

#include <SBAny.hpp>

Public Types

using iterator = std::map<std::string, SBAny>::iterator
using const_iterator = std::map<std::string, SBAny>::const_iterator

Public Member Functions

 SBAnyMap ()
 SBAnyMap (const std::string &jsonString)
 SBAnyMap (const SBAnyMap &other)
SBAnyMapoperator= (const SBAnyMap &other)
 SBAnyMap (std::initializer_list< std::pair< std::string, SBAny > > init)
 ~SBAnyMap ()
bool hasKey (const std::string &key) const
bool empty () const
size_t size () const
SBAny getAny (const std::string &key) const
SBAny at (const std::string &key) const
template<typename T>
get (const std::string &key) const
void set (const std::string &key, const SBAny &value)
void erase (const std::string &key)
iterator begin ()
iterator end ()
const_iterator begin () const
const_iterator end () const
SBAnyoperator[] (const std::string &key)
const SBAnyoperator[] (const std::string &key) const

Static Public Member Functions

template<typename T>
static T get (const SBAnyMap &map, const std::string &key, std::optional< T > defaultValue=std::nullopt)
static SBAnyMap jsonToMap (const std::string &jsonString)
static std::string mapToJson (const SBAnyMap &map)

Detailed Description

Map class to store and retrieve values.

Constructor & Destructor Documentation

◆ SBAnyMap() [1/4]

switchboard::SBAnyMap::SBAnyMap ( )

Default constructor, creates an empty map.

◆ SBAnyMap() [2/4]

switchboard::SBAnyMap::SBAnyMap ( const std::string & jsonString)

Constructor.

Parameters
jsonStringThe JSON string.

◆ SBAnyMap() [3/4]

switchboard::SBAnyMap::SBAnyMap ( const SBAnyMap & other)

Copy constructor.

Parameters
otherThe SBAnyMap to copy from.

◆ SBAnyMap() [4/4]

switchboard::SBAnyMap::SBAnyMap ( std::initializer_list< std::pair< std::string, SBAny > > init)

Constructor with initializer list.

Parameters
initInitializer list of key-value pairs.

◆ ~SBAnyMap()

switchboard::SBAnyMap::~SBAnyMap ( )

Destructor.

Member Function Documentation

◆ at()

SBAny switchboard::SBAnyMap::at ( const std::string & key) const
nodiscard

Gets a value from the map.

Parameters
keyThe key.
Returns
The value as SBAny.

◆ empty()

bool switchboard::SBAnyMap::empty ( ) const
nodiscard

Checks if the map is empty.

Returns
True if the map is empty, false otherwise.

◆ erase()

void switchboard::SBAnyMap::erase ( const std::string & key)

Erases a key from the map.

Parameters
keyThe key.

◆ get() [1/2]

template<typename T>
T switchboard::SBAnyMap::get ( const SBAnyMap & map,
const std::string & key,
std::optional< T > defaultValue = std::nullopt )
static

Gets a value from the map with an optional default value.

Template Parameters
TThe type of the value.
Parameters
mapThe map.
keyThe key.
defaultValueThe default value if the key is not found.
Returns
The value if found, otherwise the default value.

◆ get() [2/2]

template<typename T>
T switchboard::SBAnyMap::get ( const std::string & key) const
nodiscard

Gets a value from the map.

Template Parameters
TThe type of the value.
Parameters
keyThe key.
Returns
The value.

◆ getAny()

SBAny switchboard::SBAnyMap::getAny ( const std::string & key) const
nodiscard

Gets a value from the map.

Parameters
keyThe key.
Returns
The value as SBAny.

◆ hasKey()

bool switchboard::SBAnyMap::hasKey ( const std::string & key) const
nodiscard

Checks if a key exists in the map.

Parameters
keyThe key to check.
Returns
True if the key exists, false otherwise.

◆ jsonToMap()

SBAnyMap switchboard::SBAnyMap::jsonToMap ( const std::string & jsonString)
static

Converts a JSON string to a map.

Parameters
jsonStringThe JSON string.
Returns
The map.

◆ mapToJson()

std::string switchboard::SBAnyMap::mapToJson ( const SBAnyMap & map)
static

Converts a map to a JSON string.

Parameters
mapThe map.
Returns
The JSON string.

◆ operator=()

SBAnyMap & switchboard::SBAnyMap::operator= ( const SBAnyMap & other)

Assignment operator.

Parameters
otherThe other SBAnyMap to assign from.
Returns
Reference to the assigned SBAnyMap.

◆ set()

void switchboard::SBAnyMap::set ( const std::string & key,
const SBAny & value )

Sets a value in the map.

Parameters
keyThe key.
valueThe value as SBAny.

◆ size()

size_t switchboard::SBAnyMap::size ( ) const
nodiscard

Gets the size of the map.

Returns
The size of the map.

The documentation for this class was generated from the following file: