open62541++ 0.13.0
C++ wrapper of open62541
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
opcua::Variant Class Reference

#include <Variant.h>

Inheritance diagram for opcua::Variant:
[legend]

Detailed Description

UA_Variant wrapper class.

Examples
custom_datatypes/client_custom_datatypes.cpp, and typeconversion.cpp.

Definition at line 46 of file Variant.h.

Public Member Functions

bool isEmpty () const noexcept
 
bool isScalar () const noexcept
 
bool isArray () const noexcept
 
bool isType (const UA_DataType *dataType) const noexcept
 
bool isType (const UA_DataType &dataType) const noexcept
 
bool isType (Type type) const noexcept
 
bool isType (const NodeId &id) const noexcept
 
template<typename T >
bool isType () const noexcept
 
const UA_DataTypegetDataType () const noexcept
 
std::optional< TypegetVariantType () const noexcept
 
void * data () noexcept
 
const void * data () const noexcept
 
void * getScalar ()
 
const void * getScalar () const
 
template<typename T >
T & getScalar () &
 
template<typename T >
const T & getScalar () const &
 
template<typename T >
T && getScalar () &&
 
template<typename T >
const T && getScalar () const &&
 
template<typename T >
getScalarCopy () const
 
size_t getArrayLength () const noexcept
 
Span< const uint32_t > getArrayDimensions () const noexcept
 
void * getArray ()
 
const void * getArray () 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 >
void setScalar (T &value) noexcept
 
template<typename T >
void setScalar (T &value, const UA_DataType &dataType) noexcept
 
template<typename T >
void setScalarCopy (const T &value)
 
template<typename T >
void setScalarCopy (const T &value, const UA_DataType &dataType)
 
template<typename ArrayLike >
void setArray (ArrayLike &&array) noexcept
 
template<typename ArrayLike >
void setArray (ArrayLike &&array, const UA_DataType &dataType) noexcept
 
template<typename ArrayLike >
void setArrayCopy (const ArrayLike &array)
 
template<typename ArrayLike >
void setArrayCopy (const ArrayLike &array, const UA_DataType &dataType)
 
template<typename InputIt >
void setArrayCopy (InputIt first, InputIt last)
 
template<typename InputIt >
void setArrayCopy (InputIt first, InputIt last, const UA_DataType &dataType)
 
constexpr TypeWrapper ()=default
 
constexpr TypeWrapper (const T &native)
 
constexpr TypeWrapper (T &&native) noexcept
 
constexpr TypeWrapper (const TypeWrapper &other)
 
constexpr TypeWrapper (TypeWrapper &&other) noexcept
 
- Public Member Functions inherited from opcua::TypeWrapper< UA_Variant, UA_TYPES_VARIANT >
constexpr TypeWrapper ()=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 TypeWrapperoperator= (const TypeWrapper &other)
 
constexpr TypeWrapperoperator= (const UA_Variant &native)
 
constexpr TypeWrapperoperator= (TypeWrapper &&other) noexcept
 
constexpr TypeWrapperoperator= (UA_Variant &&native) noexcept
 
constexpr void swap (TypeWrapper &other) noexcept
 
constexpr void swap (UA_Variant &native) noexcept
 
- Public Member Functions inherited from opcua::Wrapper< T >
constexpr Wrapper ()=default
 
constexpr Wrapper (const T &native)
 
constexpr Wrapper (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
 

Static Public Member Functions

template<VariantPolicy Policy = VariantPolicy::Copy, typename T >
static Variant fromScalar (T &&value)
 
template<VariantPolicy Policy = VariantPolicy::Copy, typename T >
static Variant fromScalar (T &&value, const UA_DataType &dataType)
 
template<VariantPolicy Policy = VariantPolicy::Copy, typename ArrayLike >
static Variant fromArray (ArrayLike &&array)
 
template<VariantPolicy Policy = VariantPolicy::Copy, typename ArrayLike >
static Variant fromArray (ArrayLike &&array, const UA_DataType &dataType)
 
template<VariantPolicy Policy = VariantPolicy::Copy, typename InputIt >
static Variant fromArray (InputIt first, InputIt last)
 
template<VariantPolicy Policy = VariantPolicy::Copy, typename InputIt >
static Variant fromArray (InputIt first, InputIt last, const UA_DataType &dataType)
 
- Static Public Member Functions inherited from opcua::TypeWrapper< UA_Variant, UA_TYPES_VARIANT >
static constexpr TypeIndex getTypeIndex ()
 

Additional Inherited Members

- Public Types inherited from opcua::Wrapper< T >
using NativeType = T
 
- Protected Member Functions inherited from opcua::TypeWrapper< UA_Variant, UA_TYPES_VARIANT >
constexpr void clear () noexcept
 
- Protected Member Functions inherited from opcua::Wrapper< T >
constexpr const T & native () const noexcept
 
constexpr T & native () noexcept
 

Member Function Documentation

◆ fromScalar() [1/2]

template<VariantPolicy Policy = VariantPolicy::Copy, typename T >
static Variant opcua::Variant::fromScalar ( T && value)
inlinestatic

Create Variant from scalar value.

Template Parameters
PolicyPolicy (VariantPolicy) how to store the scalar inside the variant

Definition at line 53 of file Variant.h.

◆ fromScalar() [2/2]

template<VariantPolicy Policy = VariantPolicy::Copy, typename T >
static Variant opcua::Variant::fromScalar ( T && value,
const UA_DataType & dataType )
inlinestatic

Create Variant from scalar value with custom data type.

Template Parameters
PolicyPolicy (VariantPolicy) how to store the scalar inside the variant

Definition at line 62 of file Variant.h.

◆ fromArray() [1/4]

template<VariantPolicy Policy = VariantPolicy::Copy, typename ArrayLike >
static Variant opcua::Variant::fromArray ( ArrayLike && array)
inlinestatic

Create Variant from array.

Template Parameters
PolicyPolicy (VariantPolicy) how to store the array inside the variant

Definition at line 71 of file Variant.h.

◆ fromArray() [2/4]

template<VariantPolicy Policy = VariantPolicy::Copy, typename ArrayLike >
static Variant opcua::Variant::fromArray ( ArrayLike && array,
const UA_DataType & dataType )
inlinestatic

Create Variant from array with custom data type.

Template Parameters
PolicyPolicy (VariantPolicy) how to store the array inside the variant

Definition at line 85 of file Variant.h.

◆ fromArray() [3/4]

template<VariantPolicy Policy = VariantPolicy::Copy, typename InputIt >
static Variant opcua::Variant::fromArray ( InputIt first,
InputIt last )
inlinestatic

Create Variant from range of elements (copy required).

Template Parameters
PolicyPolicy (VariantPolicy) how to store the array inside the variant

Definition at line 99 of file Variant.h.

◆ fromArray() [4/4]

template<VariantPolicy Policy = VariantPolicy::Copy, typename InputIt >
static Variant opcua::Variant::fromArray ( InputIt first,
InputIt last,
const UA_DataType & dataType )
inlinestatic

Create Variant from range of elements with custom data type (copy required).

Template Parameters
PolicyPolicy (VariantPolicy) how to store the array inside the variant

Definition at line 108 of file Variant.h.

◆ isEmpty()

bool opcua::Variant::isEmpty ( ) const
inlinenoexcept

Check if the variant is empty.

Definition at line 117 of file Variant.h.

Referenced by isArray(), and isScalar().

◆ isScalar()

bool opcua::Variant::isScalar ( ) const
inlinenoexcept

Check if the variant is a scalar.

Examples
custom_datatypes/client_custom_datatypes.cpp.

Definition at line 122 of file Variant.h.

Referenced by isArray().

◆ isArray()

bool opcua::Variant::isArray ( ) const
inlinenoexcept

Check if the variant is an array.

Examples
custom_datatypes/client_custom_datatypes.cpp.

Definition at line 130 of file Variant.h.

◆ isType() [1/5]

bool opcua::Variant::isType ( const UA_DataType * dataType) const
inlinenoexcept

Check if the variant type is equal to the provided data type.

Examples
custom_datatypes/client_custom_datatypes.cpp.

Definition at line 135 of file Variant.h.

◆ isType() [2/5]

bool opcua::Variant::isType ( const UA_DataType & dataType) const
inlinenoexcept

Check if the variant type is equal to the provided data type.

Definition at line 143 of file Variant.h.

◆ isType() [3/5]

bool opcua::Variant::isType ( Type type) const
inlinenoexcept

Check if the variant type is equal to the provided type enum.

Deprecated
Use isType<T>() instead, the Type enum will be removed

Definition at line 150 of file Variant.h.

◆ isType() [4/5]

bool opcua::Variant::isType ( const NodeId & id) const
inlinenoexcept

Check if the variant type is equal to the provided data type node id.

Definition at line 155 of file Variant.h.

◆ isType() [5/5]

template<typename T >
bool opcua::Variant::isType ( ) const
inlinenoexcept

Check if the variant type is equal to the provided template type.

Definition at line 161 of file Variant.h.

Referenced by isType(), isType(), and isType().

◆ getDataType()

const UA_DataType * opcua::Variant::getDataType ( ) const
inlinenoexcept

Get data type.

Definition at line 166 of file Variant.h.

◆ getVariantType()

std::optional< Type > opcua::Variant::getVariantType ( ) const
inlinenoexcept

Get variant type.

Deprecated
Use getDataType() or isType<T>() instead, the Type enum will be removed

Definition at line 173 of file Variant.h.

◆ data() [1/2]

void * opcua::Variant::data ( )
inlinenoexcept

Get pointer to the underlying data.

Check the properties and data type before casting it to the actual type. Use the methods isScalar, isArray, isType / getDataType.

Examples
custom_datatypes/client_custom_datatypes.cpp.

Definition at line 186 of file Variant.h.

Referenced by getArray(), getArray(), and isScalar().

◆ data() [2/2]

const void * opcua::Variant::data ( ) const
inlinenoexcept

Get pointer to the underlying data.

Check the properties and data type before casting it to the actual type. Use the methods isScalar, isArray, isType / getDataType.

Definition at line 191 of file Variant.h.

◆ getScalar() [1/6]

void * opcua::Variant::getScalar ( )
inline
Deprecated
Use the methods isScalar() and data() instead
Examples
custom_datatypes/client_custom_datatypes.cpp, and typeconversion.cpp.

Definition at line 197 of file Variant.h.

◆ getScalar() [2/6]

const void * opcua::Variant::getScalar ( ) const
inline
Deprecated
Use the methods isScalar() and data() instead

Definition at line 204 of file Variant.h.

◆ getScalar() [3/6]

template<typename T >
T & opcua::Variant::getScalar ( ) &
inline

Get reference to scalar value with given template type (only native or wrapper types).

Exceptions
BadVariantAccessIf the variant is not a scalar or not of type `T`.

Definition at line 212 of file Variant.h.

◆ getScalar() [4/6]

template<typename T >
const T & opcua::Variant::getScalar ( ) const &
inline

Get reference to scalar value with given template type (only native or wrapper types).

Exceptions
BadVariantAccessIf the variant is not a scalar or not of type `T`.

Definition at line 221 of file Variant.h.

◆ getScalar() [5/6]

template<typename T >
T && opcua::Variant::getScalar ( ) &&
inline

Get reference to scalar value with given template type (only native or wrapper types).

Exceptions
BadVariantAccessIf the variant is not a scalar or not of type `T`.

Definition at line 230 of file Variant.h.

◆ getScalar() [6/6]

template<typename T >
const T && opcua::Variant::getScalar ( ) const &&
inline

Get reference to scalar value with given template type (only native or wrapper types).

Exceptions
BadVariantAccessIf the variant is not a scalar or not of type `T`.

Definition at line 236 of file Variant.h.

◆ getScalarCopy()

template<typename T >
T opcua::Variant::getScalarCopy ( ) const
inline

Get copy of scalar value with given template type.

Exceptions
BadVariantAccessIf the variant is not a scalar or not convertible to `T`.
Examples
client_subscription.cpp, server_datasource.cpp, and typeconversion.cpp.

Definition at line 243 of file Variant.h.

◆ getArrayLength()

size_t opcua::Variant::getArrayLength ( ) const
inlinenoexcept

Get array length or 0 if variant is not an array.

Examples
typeconversion.cpp.

Definition at line 249 of file Variant.h.

◆ getArrayDimensions()

Span< const uint32_t > opcua::Variant::getArrayDimensions ( ) const
inlinenoexcept

Get array dimensions.

Definition at line 254 of file Variant.h.

◆ getArray() [1/4]

void * opcua::Variant::getArray ( )
inline
Deprecated
Use the methods isArray() and data() instead
Examples
custom_datatypes/client_custom_datatypes.cpp.

Definition at line 260 of file Variant.h.

◆ getArray() [2/4]

const void * opcua::Variant::getArray ( ) const
inline
Deprecated
Use the methods isArray() and data() instead

Definition at line 267 of file Variant.h.

◆ getArray() [3/4]

template<typename T >
Span< T > opcua::Variant::getArray ( )
inline

Get array with given template type (only native or wrapper types).

Exceptions
BadVariantAccessIf the variant is not an array or not of type `T`.

Definition at line 275 of file Variant.h.

◆ getArray() [4/4]

template<typename T >
Span< const T > opcua::Variant::getArray ( ) const
inline

Get array with given template type (only native or wrapper types).

Exceptions
BadVariantAccessIf the variant is not an array or not of type `T`.

Definition at line 285 of file Variant.h.

◆ getArrayCopy()

template<typename T >
std::vector< T > opcua::Variant::getArrayCopy ( ) const
inline

Get copy of array with given template type and return it as a std::vector.

Exceptions
BadVariantAccessIf the variant is not an array or not convertible to `T`.

Definition at line 295 of file Variant.h.

◆ setScalar() [1/2]

template<typename T >
void opcua::Variant::setScalar ( T & value)
inlinenoexcept

Assign scalar value to variant (no copy).

Examples
server_datasource.cpp.

Definition at line 302 of file Variant.h.

Referenced by setScalar().

◆ setScalar() [2/2]

template<typename T >
void opcua::Variant::setScalar ( T & value,
const UA_DataType & dataType )
inlinenoexcept

Assign scalar value to variant with custom data type (no copy).

Definition at line 309 of file Variant.h.

◆ setScalarCopy() [1/2]

template<typename T >
void opcua::Variant::setScalarCopy ( const T & value)
inline

◆ setScalarCopy() [2/2]

template<typename T >
void opcua::Variant::setScalarCopy ( const T & value,
const UA_DataType & dataType )
inline

Copy scalar value to variant with custom data type.

Definition at line 326 of file Variant.h.

◆ setArray() [1/2]

template<typename ArrayLike >
void opcua::Variant::setArray ( ArrayLike && array)
inlinenoexcept

Assign array to variant (no copy).

Parameters
arrayContainer with a contiguous sequence of elements. For example std::array, std::vector or Span. The underlying array must be accessible with std::data and std::size.

Definition at line 337 of file Variant.h.

Referenced by setArray().

◆ setArray() [2/2]

template<typename ArrayLike >
void opcua::Variant::setArray ( ArrayLike && array,
const UA_DataType & dataType )
inlinenoexcept

Assign array to variant with custom data type (no copy).

Parameters
arrayContainer with a contiguous sequence of elements. For example std::array, std::vector or Span. The underlying array must be accessible with std::data and std::size.
dataTypeCustom data type.

Definition at line 349 of file Variant.h.

◆ setArrayCopy() [1/4]

template<typename ArrayLike >
void opcua::Variant::setArrayCopy ( const ArrayLike & array)
inline

◆ setArrayCopy() [2/4]

template<typename ArrayLike >
void opcua::Variant::setArrayCopy ( const ArrayLike & array,
const UA_DataType & dataType )
inline

Copy array to variant with custom data type.

Parameters
arrayIterable container, for example std::vector, std::list or Span. The container must implement begin() and end().
dataTypeCustom data type.

Definition at line 370 of file Variant.h.

◆ setArrayCopy() [3/4]

template<typename InputIt >
void opcua::Variant::setArrayCopy ( InputIt first,
InputIt last )
inline

Copy range of elements as array to variant.

Definition at line 378 of file Variant.h.

◆ setArrayCopy() [4/4]

template<typename InputIt >
void opcua::Variant::setArrayCopy ( InputIt first,
InputIt last,
const UA_DataType & dataType )
inline

Copy range of elements as array to variant with custom data type.

Definition at line 392 of file Variant.h.

◆ TypeWrapper() [1/5]

constexpr opcua::TypeWrapper< T, typeIndex >::TypeWrapper ( )
constexprdefault

◆ TypeWrapper() [2/5]

constexpr opcua::TypeWrapper< T, typeIndex >::TypeWrapper ( const T & native)
inlineexplicitconstexpr

Constructor with native object (deep copy).

Definition at line 36 of file TypeWrapper.h.

◆ TypeWrapper() [3/5]

constexpr opcua::TypeWrapper< T, typeIndex >::TypeWrapper ( T && native)
inlineconstexprnoexcept

Constructor with native object (move rvalue).

Definition at line 40 of file TypeWrapper.h.

◆ TypeWrapper() [4/5]

constexpr opcua::TypeWrapper< T, typeIndex >::TypeWrapper ( const TypeWrapper & other)
inlineconstexpr

Copy constructor (deep copy).

Definition at line 48 of file TypeWrapper.h.

◆ TypeWrapper() [5/5]

constexpr opcua::TypeWrapper< T, typeIndex >::TypeWrapper ( TypeWrapper && other)
inlineconstexprnoexcept

Move constructor.

Definition at line 52 of file TypeWrapper.h.