Map class to store and retrieve values.
More...
#include <SBAny.hpp>
|
|
using | iterator = std::map<std::string, SBAny>::iterator |
|
using | const_iterator = std::map<std::string, SBAny>::const_iterator |
|
| | SBAnyMap () |
| | SBAnyMap (const std::string &jsonString) |
| | SBAnyMap (const SBAnyMap &other) |
| SBAnyMap & | operator= (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> |
| 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 |
|
SBAny & | operator[] (const std::string &key) |
|
const SBAny & | operator[] (const std::string &key) const |
|
| 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) |
Map class to store and retrieve values.
◆ SBAnyMap() [1/4]
| switchboard::SBAnyMap::SBAnyMap |
( |
| ) |
|
Default constructor, creates an empty map.
◆ SBAnyMap() [2/4]
| switchboard::SBAnyMap::SBAnyMap |
( |
const std::string & | jsonString | ) |
|
Constructor.
- Parameters
-
| jsonString | The JSON string. |
◆ SBAnyMap() [3/4]
| switchboard::SBAnyMap::SBAnyMap |
( |
const SBAnyMap & | other | ) |
|
Copy constructor.
- Parameters
-
◆ SBAnyMap() [4/4]
| switchboard::SBAnyMap::SBAnyMap |
( |
std::initializer_list< std::pair< std::string, SBAny > > | init | ) |
|
Constructor with initializer list.
- Parameters
-
| init | Initializer list of key-value pairs. |
◆ ~SBAnyMap()
| switchboard::SBAnyMap::~SBAnyMap |
( |
| ) |
|
◆ at()
| SBAny switchboard::SBAnyMap::at |
( |
const std::string & | key | ) |
const |
|
nodiscard |
Gets a value from the map.
- Parameters
-
- 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
-
◆ 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
-
- Parameters
-
| map | The map. |
| key | The key. |
| defaultValue | The 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
-
- Parameters
-
- Returns
- The value.
◆ getAny()
| SBAny switchboard::SBAnyMap::getAny |
( |
const std::string & | key | ) |
const |
|
nodiscard |
Gets a value from the map.
- Parameters
-
- 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
-
- 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
-
| jsonString | The JSON string. |
- Returns
- The map.
◆ mapToJson()
| std::string switchboard::SBAnyMap::mapToJson |
( |
const SBAnyMap & | map | ) |
|
|
static |
Converts a map to a JSON string.
- Parameters
-
- Returns
- The JSON string.
◆ operator=()
Assignment operator.
- Parameters
-
- 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
-
| key | The key. |
| value | The 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: