Sen API
Sen Libraries
Loading...
Searching...
No Matches
var.h File Reference
#include "sen/core/base/assert.h"
#include "sen/core/base/duration.h"
#include "sen/core/base/numbers.h"
#include "sen/core/base/timestamp.h"
#include "sen/core/meta/type_traits.h"
#include <cstdlib>
#include <map>
#include <memory>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <variant>
#include <vector>

Go to the source code of this file.

Classes

struct  sen::Var
 Can hold any supported value type. Wraps std::variant to allow recursion and implements some helpers. More...
struct  sen::IsVariantMember< T, Var >

Namespaces

namespace  sen

Typedefs

using sen::VarList = std::vector<Var>
 A list of vars to represent sequences.
using sen::VarMap = std::map<std::string, Var, std::less<>>
 A map of vars to represent structures.
using sen::KeyedVar = std::tuple<uint32_t, std::shared_ptr<Var>>
 A key-var tuple, to represent variants.

Functions

std::string sen::toJson (const Var &var, int indent=2)
 Converts a variant into its Json representation. See https://www.Json.org/Json-en.html for details.
Var sen::fromJson (const std::string &str)
 Inverse as toJson.
std::vector< std::uint8_t > sen::toBson (const Var &var)
 Converts a variant into its bson (Binary JSON) representation. See https://bsonspec.org/ for details.
Var sen::fromBson (const std::vector< std::uint8_t > &bson)
 Inverse as toBson.
std::vector< std::uint8_t > sen::toCbor (const Var &var)
 Converts a variant into its MessagePack representation. See https://msgpack.org/ for details.
Var sen::fromCbor (const std::vector< std::uint8_t > &cbor)
 Inverse as toCbor.
std::vector< std::uint8_t > sen::toMsgpack (const Var &var)
 Converts a variant into its msgpack representation. See https://cbor.io/ for details.
Var sen::fromMsgpack (const std::vector< std::uint8_t > &msgpack)
 Inverse as toMsgpack.
std::vector< std::uint8_t > sen::toUbjson (const Var &var)
 Converts a variant into its UBJSON (Universal Binary JSON Specification) representation. See https://ubjson.org/ for details.
Var sen::fromUbjson (const std::vector< std::uint8_t > &ubson)
 Inverse as toUbjson.
Duration sen::stringToDuration (const std::string &str)
 Converts a string to a duration.
template<typename To, bool checkedConversion = false>
To sen::getCopyAs (const Var &var)
 Tries to transform the stored value to T. For expensive types, like strings, maps or lists is better use:
const Varsen::findElement (const VarMap &map, const std::string &key, const std::string &errorMessage)
 Finds an element in a map or throws std::exception containing the provided string otherwise.
template<typename T>
sen::findElementAs (const VarMap &map, const std::string &key, const std::string &errorMessage)
 Finds an element in a map or throws std::exception containing the provided string otherwise.

Variables

template<typename T>
constexpr bool sen::isVarTypeMemberV = IsVariantMember<T, Var>::value