10#include "switchboard/export.h"
15#include <initializer_list>
23namespace switchboard {
32enum class SBAnyType : uint32_t {
52class SWITCHBOARDSDK_EXPORT SBAny final {
56 SBAny(std::monostate);
68 static constexpr bool int_is_distinct = !std::is_same<int, int32_t>::value && !std::is_same<int, int64_t>::value;
69 template <bool Enable = int_is_distinct, typename std::enable_if<Enable, int>::type = 0>
70 SBAny(
int value) : SBAny(
static_cast<int64_t
>(value)) {}
72 static constexpr bool uint_is_distinct =
73 !std::is_same<unsigned int, uint32_t>::value && !std::is_same<unsigned int, uint64_t>::value;
74 template <bool Enable = uint_is_distinct, typename std::enable_if<Enable, int>::type = 0>
75 SBAny(
unsigned int value) : SBAny(
static_cast<uint64_t
>(value)) {}
82 SBAny(
const char* utf8);
83 SBAny(
const std::string& str);
86 SBAny(std::initializer_list<std::pair<std::string, SBAny>> init);
92 explicit SBAny(std::initializer_list<SBAny> init);
96 SBAny(std::function<SBAny()> init);
98 SBAny(std::function<
void(
const SBAny&)> init);
106 SBAny& operator=(
const SBAny&);
115 SBAnyType
type() const noexcept;
139 template <typename T>
179 template <
typename Iterator>
190 template <
typename T>
193 for (
const auto& item : vec) {
222 [[nodiscard]]
size_t size()
const;
259 using iterator = std::vector<SBAny>::iterator;
260 using const_iterator = std::vector<SBAny>::const_iterator;
264 const_iterator begin()
const;
265 const_iterator end()
const;
309 SBAnyMap(std::initializer_list<std::pair<std::string, SBAny>> init);
323 [[nodiscard]]
bool hasKey(
const std::string& key)
const;
337 [[nodiscard]]
size_t size()
const;
355 [[nodiscard]]
SBAny at(
const std::string& key)
const;
365 template <
typename T>
366 [[nodiscard]] T
get(
const std::string& key)
const;
377 template <
typename T>
378 [[nodiscard]] T
get(
const std::string& key, std::optional<T> defaultValue)
const;
386 void set(
const std::string& key,
const SBAny& value);
407 template <
typename T>
408 static T
get(
const SBAnyMap& map,
const std::string& key, std::optional<T> defaultValue = std::nullopt);
429 using iterator = std::map<std::string, SBAny>::iterator;
430 using const_iterator = std::map<std::string, SBAny>::const_iterator;
434 const_iterator begin()
const;
435 const_iterator end()
const;
438 SBAny& operator[](
const std::string& key);
439 const SBAny& operator[](
const std::string& key)
const;
Represents the result of an operation that can either succeed or fail.
Definition Result.hpp:39
A versatile container class that can hold values of various types.
Definition SBAny.hpp:52
SBAnyType type() const noexcept
static T convert(const SBAny &value)
Map class to store and retrieve values.
Definition SBAny.hpp:275
bool hasKey(const std::string &key) const
static T get(const SBAnyMap &map, const std::string &key, std::optional< T > defaultValue=std::nullopt)
SBAny getAny(const std::string &key) const
SBAnyMap(const std::string &jsonString)
SBAnyMap(const SBAnyMap &other)
void set(const std::string &key, const SBAny &value)
void erase(const std::string &key)
SBAny at(const std::string &key) const
T get(const std::string &key) const
SBAnyMap(std::initializer_list< std::pair< std::string, SBAny > > init)
T get(const std::string &key, std::optional< T > defaultValue) const
SBAnyMap & operator=(const SBAnyMap &other)
static std::string mapToJson(const SBAnyMap &map)
static SBAnyMap jsonToMap(const std::string &jsonString)
Vector of SBAny values, used for representing lists or arrays of values.
Definition SBAny.hpp:150
SBAnyVector(const SBAnyVector &init)
Copy constructor for SBAnyVector.
void push_back(const SBAny &value)
Adds a new SBAny value to the end of the vector.
void emplace_back(const SBAny &value)
Adds a new SBAny value to the end of the vector.
const SBAny & operator[](size_t index) const
Accesses an element in the vector by index (const version).
SBAnyVector(const std::vector< T > &vec)
Constructor for SBAnyVector from a std::vector of arbitrary type T.
Definition SBAny.hpp:191
SBAnyVector()
Default constructor for SBAnyVector, initializes an empty vector.
size_t size() const
Gets the number of elements in the vector.
SBAny & operator[](size_t index)
Accesses an element in the vector by index.
~SBAnyVector()
Destructor for SBAnyVector, cleans up any resources used by the vector.
void reserve(size_t newCapacity)
Reserves space in the vector for a specified number of elements.
SBAnyVector(Iterator first, Iterator last)
Constructor for SBAnyVector from a range of iterators.
SBAnyVector(std::initializer_list< SBAny > init)
Constructor for SBAnyVector from an initializer list of SBAny values.
SBAnyVector & operator=(const SBAnyVector &other)
Assignment operator for SBAnyVector.