10#include "switchboard/export.h"
11#include <initializer_list>
24namespace switchboard {
33enum class SBAnyType : uint32_t {
53class SWITCHBOARDSDK_EXPORT SBAny final {
57 SBAny(std::monostate);
69 static constexpr bool int_is_distinct =
70 !std::is_same<int, int32_t>::value &&
71 !std::is_same<int, int64_t>::value;
72 template<
bool Enable = int_is_distinct,
73 typename std::enable_if<Enable, int>::type = 0>
74 SBAny(
int value) : SBAny(
static_cast<int64_t
>(value)) {}
76 static constexpr bool uint_is_distinct =
77 !std::is_same<unsigned int, uint32_t>::value &&
78 !std::is_same<unsigned int, uint64_t>::value;
79 template<
bool Enable = uint_is_distinct,
80 typename std::enable_if<Enable, int>::type = 0>
81 SBAny(
unsigned int value) : SBAny(
static_cast<uint64_t
>(value)) {}
88 SBAny(
const char* utf8);
89 SBAny(
const std::string& str);
92 SBAny(std::initializer_list<std::pair<std::string, SBAny>> init);
98 explicit SBAny(std::initializer_list<SBAny> init);
102 SBAny(std::function<SBAny()> init);
104 SBAny(std::function<
void(
const SBAny&)> init);
112 SBAny& operator=(
const SBAny&);
121 SBAnyType
type() const noexcept;
145 template <typename T>
185 template<
typename Iterator>
199 for (
const auto& item : vec) {
228 [[nodiscard]]
size_t size()
const;
265 using iterator = std::vector<SBAny>::iterator;
266 using const_iterator = std::vector<SBAny>::const_iterator;
270 const_iterator begin()
const;
271 const_iterator end()
const;
315 SBAnyMap(std::initializer_list<std::pair<std::string, SBAny>> init);
329 [[nodiscard]]
bool hasKey(
const std::string& key)
const;
343 [[nodiscard]]
size_t size()
const;
361 [[nodiscard]]
SBAny at(
const std::string& key)
const;
371 template <
typename T>
372 [[nodiscard]] T
get(
const std::string& key)
const;
380 void set(
const std::string& key,
const SBAny& value);
399 template <
typename T>
400 static T
get(
const SBAnyMap& map,
const std::string& key, std::optional<T> defaultValue = std::nullopt);
421 using iterator = std::map<std::string, SBAny>::iterator;
422 using const_iterator = std::map<std::string, SBAny>::const_iterator;
426 const_iterator begin()
const;
427 const_iterator end()
const;
430 SBAny& operator[](
const std::string& key);
431 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:53
SBAnyType type() const noexcept
static T convert(const SBAny &value)
Map class to store and retrieve values.
Definition SBAny.hpp:281
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)
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:156
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:197
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.