Sen API
Sen Libraries
Loading...
Searching...
No Matches
Type Manipulation Utilities

Helpers for working with meta types. More...

Collaboration diagram for Type Manipulation Utilities:

Classes

struct  sen::TypeMatchIssue
 Information about a type matching issue. More...
struct  sen::TypesMatch
 Types are compatible. More...
struct  sen::TypesDontMatch
 Types do not match. More...
class  sen::CustomTypeRegistry
 A registry of custom types. More...
class  sen::FullTypeVisitor
 A Visitor for constant types. This class is based on the GoF Visitor design pattern. You can use it to perform operations on types without having to do dynamic_casts (or switch-based casts). More...
class  sen::TypeVisitor
 All the apply virtual methods are overriden to empty methods. Use TypeVisitor if you only need to handle some of the types. More...
struct  sen::UnitSpec
 Data about a given unit definition. Given f, x, y: More...
class  sen::Unit
 Represents the definition of a unit. More...
class  sen::UnitRegistry
 A registry of units. More...
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 >

Typedefs

using sen::TypeMatch = Result<TypesMatch, TypesDontMatch>
 The result of a type matching analysis.
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.

Enumerations

enum class  sen::TypeMatchProblem { sen::TypeMatchProblem::compatible , sen::TypeMatchProblem::incompatible , sen::TypeMatchProblem::missing }
 Kind of problem found when matching types. More...
enum class  sen::UnitCategory {
  sen::UnitCategory::length , sen::UnitCategory::mass , sen::UnitCategory::time , sen::UnitCategory::angle ,
  sen::UnitCategory::temperature , sen::UnitCategory::density , sen::UnitCategory::pressure , sen::UnitCategory::area ,
  sen::UnitCategory::force , sen::UnitCategory::frequency , sen::UnitCategory::velocity , sen::UnitCategory::angularVelocity ,
  sen::UnitCategory::acceleration , sen::UnitCategory::angularAcceleration
}
 Type of measurement. More...

Functions

TypeMatch sen::canConvert (const Type &from, const Type &to)
 Analyze if a type can be converted to another.
void sen::iterateOverDependentTypes (const Type &type, std::function< void(ConstTypeHandle<> type)> &callback)
 Helper that iterates over dependent types. The callback function is invoked for all used sub-types recursively.
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

Detailed Description

Helpers for working with meta types.


Class Documentation

◆ sen::TypeMatchIssue

struct sen::TypeMatchIssue

Information about a type matching issue.

Class Members
TypeMatchProblem problem
string description

◆ sen::TypesMatch

struct sen::TypesMatch

Types are compatible.

Class Members
vector< TypeMatchIssue > issues

◆ sen::TypesDontMatch

struct sen::TypesDontMatch

Types do not match.

Class Members
vector< TypeMatchIssue > issues

Typedef Documentation

◆ TypeMatch

The result of a type matching analysis.

◆ VarList

using sen::VarList = std::vector<Var>

A list of vars to represent sequences.

◆ VarMap

using sen::VarMap = std::map<std::string, Var, std::less<>>

A map of vars to represent structures.

◆ KeyedVar

using sen::KeyedVar = std::tuple<uint32_t, std::shared_ptr<Var>>

A key-var tuple, to represent variants.

Enumeration Type Documentation

◆ TypeMatchProblem

enum class sen::TypeMatchProblem
strong

Kind of problem found when matching types.

Enumerator
compatible 

Not the same, but convertable.

incompatible 

Cannot be converted.

missing 

There is missing information.

◆ UnitCategory

enum class sen::UnitCategory
strong

Type of measurement.

Enumerator
length 
mass 
time 
angle 
temperature 
density 
pressure 
area 
force 
frequency 
velocity 
angularVelocity 
acceleration 
angularAcceleration 

Function Documentation

◆ canConvert()

TypeMatch sen::canConvert ( const Type & from,
const Type & to )

Analyze if a type can be converted to another.

◆ iterateOverDependentTypes()

void sen::iterateOverDependentTypes ( const Type & type,
std::function< void(ConstTypeHandle<> type)> & callback )

Helper that iterates over dependent types. The callback function is invoked for all used sub-types recursively.

◆ toJson()

std::string sen::toJson ( const Var & var,
int indent = 2 )
nodiscard

Converts a variant into its Json representation. See https://www.Json.org/Json-en.html for details.

◆ fromJson()

Var sen::fromJson ( const std::string & str)
nodiscard

Inverse as toJson.

◆ toBson()

std::vector< std::uint8_t > sen::toBson ( const Var & var)
nodiscard

Converts a variant into its bson (Binary JSON) representation. See https://bsonspec.org/ for details.

◆ fromBson()

Var sen::fromBson ( const std::vector< std::uint8_t > & bson)
nodiscard

Inverse as toBson.

◆ toCbor()

std::vector< std::uint8_t > sen::toCbor ( const Var & var)
nodiscard

Converts a variant into its MessagePack representation. See https://msgpack.org/ for details.

◆ fromCbor()

Var sen::fromCbor ( const std::vector< std::uint8_t > & cbor)
nodiscard

Inverse as toCbor.

◆ toMsgpack()

std::vector< std::uint8_t > sen::toMsgpack ( const Var & var)
nodiscard

Converts a variant into its msgpack representation. See https://cbor.io/ for details.

◆ fromMsgpack()

Var sen::fromMsgpack ( const std::vector< std::uint8_t > & msgpack)
nodiscard

Inverse as toMsgpack.

◆ toUbjson()

std::vector< std::uint8_t > sen::toUbjson ( const Var & var)
nodiscard

Converts a variant into its UBJSON (Universal Binary JSON Specification) representation. See https://ubjson.org/ for details.

◆ fromUbjson()

Var sen::fromUbjson ( const std::vector< std::uint8_t > & ubson)
nodiscard

Inverse as toUbjson.

◆ stringToDuration()

Duration sen::stringToDuration ( const std::string & str)
nodiscard

Converts a string to a duration.

◆ getCopyAs()

template<typename To, bool checkedConversion = false>
To sen::getCopyAs ( const Var & var)
inlinenodiscard

Tries to transform the stored value to T. For expensive types, like strings, maps or lists is better use:

  • a visitor, or
  • is<T>() together with tryGet<T>().

Rules:

  • Empty Vars generate T{}
  • Native type conversion use c++ rules.
  • If T is std::string and the var holds a bool, it returns "true" or "false"
  • If T is bool and the var holds a std::string, it returns true if the string is "true"
  • Durations can be converted to: strings (nanoseconds), timestamps and integrals
  • Timestamps can be converted to: strings (nanoseconds), durations and integrals
  • Lists and maps can only be converted to strings

Throws std::exception if the conversion could not be made

Template Parameters
Totype to transform to
checkedConversionwhether conversions should be checked against precision loss/truncation
Parameters
varVar containing the value that should be converted

◆ findElement()

const Var & sen::findElement ( const VarMap & map,
const std::string & key,
const std::string & errorMessage )
inlinenodiscard

Finds an element in a map or throws std::exception containing the provided string otherwise.

◆ findElementAs()

template<typename T>
T sen::findElementAs ( const VarMap & map,
const std::string & key,
const std::string & errorMessage )
nodiscard

Finds an element in a map or throws std::exception containing the provided string otherwise.

Variable Documentation

◆ isVarTypeMemberV

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