open62541pp 0.18.0
C++ wrapper of open62541
|
#include <types.hpp>
UA_Variant wrapper class.
Variants may contain scalar values or arrays of any type together with a type definition. The standard mandates that variants contain built-in data types only. open62541 transparently handles this wrapping in the encoding layer. If the type is unknown to the receiver, the variant stores the original ExtensionObject in binary or XML encoding.
open62541pp enhances variant handling with the following features:
Type category detection: Identifies whether T
is scalar or array:
T
is:T
is a container type (e.g. std::vector
or std::list
) and does not satisfy the criterias of a scalar type.Applied in constructors, assign, and to functions:
Type definition retrieval: Automatically retrieves UA_DataType via TypeRegistry. For every registered type T
, the type definition parameter can be omitted:
Type conversion: Convert non-native types using TypeConverter. Native UA_*
types can be assigned and retrieved to/from variants without any conversion, because their binary layout is described by the type definition (UA_DataType). The same is true for wrapper types, that share the exact memory layout as their wrapped native type. Non-native types, like std::string
from the STL, may not be describeable by UA_DataType because their memory layout is an implementation detail. Instead, the conversion between non-native and native types can be defined with template specializations of TypeConverter. If a type is convertible (TypeConverter specialization), the Variant automatically manages the conversion, requiring a copy:
Public Member Functions | |
template<typename T , typename = std::enable_if_t<!std::is_const_v<T>>> | |
Variant (T *ptr) noexcept | |
template<typename T , typename = std::enable_if_t<!std::is_const_v<T>>> | |
Variant (T *ptr, const UA_DataType &type) noexcept | |
template<typename T , typename = std::enable_if_t<!isVariant<T>>> | |
Variant (const T &value) | |
template<typename T > | |
Variant (const T &value, const UA_DataType &type) | |
template<typename InputIt > | |
Variant (InputIt first, InputIt last) | |
template<typename InputIt > | |
Variant (InputIt first, InputIt last, const UA_DataType &type) | |
constexpr | TypeWrapper () noexcept=default |
constexpr | TypeWrapper (const T &native) |
constexpr | TypeWrapper (T &&native) noexcept |
constexpr | TypeWrapper (const TypeWrapper &other) |
constexpr | TypeWrapper (TypeWrapper &&other) noexcept |
Modifiers | |
Modify internal scalar/array value. | |
void | assign (std::nullptr_t ptr) noexcept=delete |
void | assign (std::nullptr_t ptr, const UA_DataType &type) noexcept=delete |
template<typename T , typename = std::enable_if_t<!std::is_const_v<T>>> | |
void | assign (T *ptr) noexcept |
template<typename T , typename = std::enable_if_t<!std::is_const_v<T>>> | |
void | assign (T *ptr, const UA_DataType &type) noexcept |
template<typename T > | |
void | assign (const T &value) |
template<typename T > | |
void | assign (const T &value, const UA_DataType &type) |
template<typename InputIt > | |
void | assign (InputIt first, InputIt last) |
template<typename InputIt > | |
void | assign (InputIt first, InputIt last, const UA_DataType &type) |
template<typename T , typename = std::enable_if_t<!isVariant<T>>> | |
Variant & | operator= (T *value) noexcept |
template<typename T , typename = std::enable_if_t<!isVariant<T>>> | |
Variant & | operator= (const T &value) |
template<typename T , typename... Args> | |
void | setScalar (T &value, Args &&... args) noexcept |
template<typename T , typename... Args> | |
void | setScalarCopy (const T &value, Args &&... args) |
template<typename T , typename... Args> | |
void | setArray (T &array, Args &&... args) noexcept |
template<typename T , typename... Args> | |
void | setArrayCopy (const T &array, Args &&... args) |
template<typename InputIt , typename... Args> | |
void | setArrayCopy (InputIt first, InputIt last, Args &&... args) |
Observers | |
Check the type category, type definition and array structure of the internal value. | |
bool | empty () const noexcept |
bool | isEmpty () const noexcept |
bool | isScalar () const noexcept |
bool | isArray () const noexcept |
bool | isType (const UA_DataType *type) const noexcept |
bool | isType (const UA_DataType &type) const noexcept |
bool | isType (const NodeId &id) const noexcept |
template<typename T > | |
bool | isType () const noexcept |
const UA_DataType * | type () const noexcept |
const UA_DataType * | getDataType () const noexcept |
size_t | arrayLength () const noexcept |
size_t | getArrayLength () const noexcept |
Span< const uint32_t > | arrayDimensions () const noexcept |
Span< const uint32_t > | getArrayDimensions () const noexcept |
Accessors | |
Access and convert internal scalar/array value. | |
void * | data () noexcept |
const void * | data () const noexcept |
template<typename T > | |
T & | scalar () & |
template<typename T > | |
const T & | scalar () const & |
template<typename T > | |
T && | scalar () && |
template<typename T > | |
const T && | scalar () const && |
template<typename T > | |
T & | getScalar () |
template<typename T > | |
const T & | getScalar () const |
template<typename T > | |
T | getScalarCopy () const |
template<typename T > | |
Span< T > | array () |
template<typename T > | |
Span< const T > | array () const |
template<typename T > | |
Span< T > | getArray () |
template<typename T > | |
Span< const T > | getArray () const |
template<typename T > | |
std::vector< T > | getArrayCopy () const |
template<typename T > | |
T | to () const |
![]() | |
constexpr | TypeWrapper () noexcept=default |
constexpr | TypeWrapper (const UA_Variant &native) |
constexpr | TypeWrapper (UA_Variant &&native) noexcept |
constexpr | TypeWrapper (const TypeWrapper &other) |
constexpr | TypeWrapper (TypeWrapper &&other) noexcept |
~TypeWrapper () | |
constexpr TypeWrapper & | operator= (const TypeWrapper &other) |
constexpr TypeWrapper & | operator= (const UA_Variant &native) |
constexpr TypeWrapper & | operator= (TypeWrapper &&other) noexcept |
constexpr TypeWrapper & | operator= (UA_Variant &&native) noexcept |
![]() | |
constexpr | Wrapper () noexcept=default |
constexpr | Wrapper (const T &native) noexcept |
constexpr | Wrapper (T &&native) noexcept |
constexpr Wrapper & | operator= (const T &native) noexcept |
constexpr Wrapper & | operator= (T &&native) noexcept |
constexpr | operator T& () noexcept |
constexpr | operator const T & () const noexcept |
constexpr T * | operator-> () noexcept |
constexpr const T * | operator-> () const noexcept |
constexpr T * | handle () noexcept |
constexpr const T * | handle () const noexcept |
constexpr void | swap (Wrapper &other) noexcept |
constexpr void | swap (T &native) noexcept |
Static Public Member Functions | |
template<VariantPolicy Policy = VariantPolicy::Copy, typename T , typename... Args> | |
static Variant | fromScalar (T &&value, Args &&... args) |
template<VariantPolicy Policy = VariantPolicy::Copy, typename T , typename... Args> | |
static Variant | fromArray (T &&array, Args &&... args) |
template<VariantPolicy Policy = VariantPolicy::Copy, typename InputIt , typename... Args> | |
static Variant | fromArray (InputIt first, InputIt last, Args &&... args) |
![]() | |
static constexpr TypeIndex | typeIndex () |
Additional Inherited Members | |
![]() | |
using | NativeType = T |
![]() | |
constexpr void | clear () noexcept |
![]() | |
constexpr const T & | native () const noexcept |
constexpr T & | native () noexcept |
![]() | |
String | toString (const UA_Variant &object, const UA_DataType &type) |
String | toString (const UA_Variant &object) |
![]() | |
template<typename WrapperType , typename NativeType = typename WrapperType::NativeType> | |
constexpr WrapperType * | asWrapper (NativeType *native) noexcept |
template<typename WrapperType , typename NativeType = typename WrapperType::NativeType> | |
constexpr const WrapperType * | asWrapper (const NativeType *native) noexcept |
template<typename WrapperType , typename NativeType = typename WrapperType::NativeType> | |
constexpr WrapperType & | asWrapper (NativeType &native) noexcept |
template<typename WrapperType , typename NativeType = typename WrapperType::NativeType> | |
constexpr const WrapperType & | asWrapper (const NativeType &native) noexcept |
template<typename WrapperType , typename NativeType = typename WrapperType::NativeType> | |
constexpr NativeType * | asNative (WrapperType *wrapper) noexcept |
template<typename WrapperType , typename NativeType = typename WrapperType::NativeType> | |
constexpr const NativeType * | asNative (const WrapperType *wrapper) noexcept |
template<typename WrapperType , typename NativeType = typename WrapperType::NativeType> | |
constexpr NativeType & | asNative (WrapperType &wrapper) noexcept |
template<typename WrapperType , typename NativeType = typename WrapperType::NativeType> | |
constexpr const NativeType & | asNative (const WrapperType &wrapper) noexcept |
|
inlineexplicitnoexcept |
Create Variant from a pointer to a scalar/array (no copy).
|
inlinenoexcept |
Create Variant from a pointer to a scalar/array with a custom data type (no copy).
|
inlineexplicit |
Create Variant from a scalar/array (copy).
|
inline |
Create Variant from a scalar/array with a custom data type (copy).
|
inline |
Create Variant from a range of elements (copy).
|
inline |
Create Variant from a range of elements with a custom data type (copy).
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
deletenoexcept |
Referenced by assign(), assign(), operator=(), operator=(), setArray(), setArrayCopy(), setArrayCopy(), setScalar(), setScalarCopy(), Variant(), Variant(), Variant(), Variant(), Variant(), and Variant().
|
deletenoexcept |
|
inlinenoexcept |
Assign pointer to scalar/array to variant (no copy).
The object will not be deleted when the Variant is destructed.
ptr | Non-const pointer to a value to assign to the variant. This can be:
|
|
inlinenoexcept |
Assign pointer to scalar/array to variant with custom data type (no copy).
The object will not be deleted when the Variant is destructed.
ptr | Non-const pointer to a value to assign to the variant. This can be:
|
type | Custom data type. |
|
inline |
Assign scalar/array to variant (copy and convert if required).
value | Value to copy to the variant. It can be:
|
|
inline |
Assign scalar/array to variant with custom data type (copy).
value | Value to copy to the variant. It can be:
|
type | Custom data type. |
|
inline |
|
inline |
|
inlinenoexcept |
Assign pointer to scalar/array to variant (no copy).
|
inline |
Assign scalar/array to variant (copy and convert if required).
|
inlinenoexcept |
|
inline |
|
inlinenoexcept |
|
inline |
|
inline |
|
inlinenoexcept |
Check if the variant is empty.
Definition at line 1445 of file types.hpp.
Referenced by isArray(), isEmpty(), and isScalar().
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
Check if the variant is an array.
|
inlinenoexcept |
Check if the variant type is equal to the provided data type.
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
Get array length or 0 if variant is not an array.
Definition at line 1503 of file types.hpp.
Referenced by array(), array(), getArrayLength(), and isScalar().
|
inlinenoexcept |
|
inlinenoexcept |
Get array dimensions.
Definition at line 1514 of file types.hpp.
Referenced by getArrayDimensions().
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inline |
Get reference to scalar value with given template type (only native or wrapper types).
BadVariantAccess | If the variant is not a scalar or not of type `T`. |
|
inline |
Get reference to scalar value with given template type (only native or wrapper types).
BadVariantAccess | If the variant is not a scalar or not of type `T`. |
|
inline |
Get reference to scalar value with given template type (only native or wrapper types).
BadVariantAccess | If the variant is not a scalar or not of type `T`. |
|
inline |
Get reference to scalar value with given template type (only native or wrapper types).
BadVariantAccess | If the variant is not a scalar or not of type `T`. |
|
inline |
|
inline |
|
inline |
|
inline |
Get reference to array with given template type (only native or wrapper types).
BadVariantAccess | If the variant is not an array or not of type `T`. |
Definition at line 1597 of file types.hpp.
Referenced by fromArray(), setArray(), and setArrayCopy().
|
inline |
Get reference to array with given template type (only native or wrapper types).
BadVariantAccess | If the variant is not an array or not of type `T`. |
|
inline |
|
inline |
|
inline |
|
inline |
Converts the variant to the specified type T
with automatic conversion if required.
Determines the type category (scalar or array) based on the characteristics of T
using type category detection. If T
is a container, it must be constructible from an iterator pair.
BadVariantAccess | If the variant is not convertible to `T`. |
|
constexprdefaultnoexcept |
|
inlineexplicitconstexpr |
Constructor with native object (deep copy).
Definition at line 31 of file typewrapper.hpp.
|
inlineconstexprnoexcept |
Constructor with native object (move rvalue).
Definition at line 35 of file typewrapper.hpp.
|
inlineconstexpr |
Copy constructor (deep copy).
Definition at line 43 of file typewrapper.hpp.
|
inlineconstexprnoexcept |
Move constructor.
Definition at line 47 of file typewrapper.hpp.