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:
- Scalar, if
T
is:
- Array, if
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:
auto value = var.to<int>();
std::array<int>
array{1, 2, 3};
auto vec = var.to<std::vector<int>>();
UA_Variant wrapper class.
Span< T > array()
Get reference to array with given template type (only native or wrapper types).
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:
auto str = var.to<std::string>();
constexpr const UA_Variant & native() const noexcept
- Examples
- custom_datatypes/client_custom_datatypes.cpp, server_accesscontrol.cpp, server_datasource.cpp, and typeconversion.cpp.
Definition at line 1176 of file types.hpp.
|
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 |
|
|
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) |
|
|
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 |
|
|
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 UA_Variant &native) noexcept |
|
constexpr | Wrapper (UA_Variant &&native) noexcept |
|
constexpr Wrapper & | operator= (const UA_Variant &native) noexcept |
|
constexpr Wrapper & | operator= (UA_Variant &&native) noexcept |
|
constexpr | operator UA_Variant & () noexcept |
|
constexpr | operator const UA_Variant & () const noexcept |
|
constexpr UA_Variant * | operator-> () noexcept |
|
constexpr const UA_Variant * | operator-> () const noexcept |
|
constexpr UA_Variant * | handle () noexcept |
|
constexpr const UA_Variant * | handle () const noexcept |
|
constexpr void | swap (Wrapper &other) noexcept |
|
constexpr void | swap (UA_Variant &native) noexcept |
|