open62541pp 0.16.0
C++ wrapper of open62541
Loading...
Searching...
No Matches
opcua::Variant Class Reference

#include <types.hpp>

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 887 of file types.hpp.

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 (const NodeId &id) const noexcept
 
template<typename T >
bool isType () const noexcept
 
const UA_DataTypegetDataType () const noexcept
 
void * data () noexcept
 
const void * data () const noexcept
 
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
 
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< UA_Variant >
constexpr Wrapper ()=default
 
constexpr Wrapper (const UA_Variant &native)
 
constexpr Wrapper (UA_Variant &&native) noexcept
 
constexpr operator UA_Variant & () noexcept
 
constexpr operator const UA_Variant & () const noexcept
 
constexpr UA_Variantoperator-> () noexcept
 
constexpr const UA_Variantoperator-> () const noexcept
 
constexpr UA_Varianthandle () noexcept
 
constexpr const UA_Varianthandle () 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< UA_Variant >
using NativeType
 
- Protected Member Functions inherited from opcua::TypeWrapper< UA_Variant, UA_TYPES_VARIANT >
constexpr void clear () noexcept
 
- Protected Member Functions inherited from opcua::Wrapper< UA_Variant >
constexpr const UA_Variantnative () const noexcept
 
constexpr UA_Variantnative () noexcept
 

Member Function Documentation

◆ fromScalar() [1/2]

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

Create Variant from scalar value.

Template Parameters
PolicyPolicy (VariantPolicy) how to store the scalar inside the variant
Examples
method/client_method_async.cpp.

Definition at line 894 of file types.hpp.

Referenced by opcua::DataValue::fromScalar(), and opcua::Node< Connection >::writeValueScalar().

◆ fromScalar() [2/2]

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

Create Variant from scalar value with custom data type.

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

Definition at line 903 of file types.hpp.

◆ fromArray() [1/4]

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

Create Variant from array.

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

Definition at line 912 of file types.hpp.

Referenced by opcua::DataValue::fromArray(), opcua::Node< Connection >::writeValueArray(), and opcua::Node< Connection >::writeValueArray().

◆ fromArray() [2/4]

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

Create Variant from array with custom data type.

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

Definition at line 926 of file types.hpp.

◆ fromArray() [3/4]

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

Create Variant from range of elements (copy required).

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

Definition at line 940 of file types.hpp.

◆ fromArray() [4/4]

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

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 949 of file types.hpp.

◆ isEmpty()

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

Check if the variant is empty.

Definition at line 958 of file types.hpp.

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 963 of file types.hpp.

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 971 of file types.hpp.

◆ isType() [1/4]

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 976 of file types.hpp.

◆ isType() [2/4]

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 984 of file types.hpp.

◆ isType() [3/4]

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 989 of file types.hpp.

◆ isType() [4/4]

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

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

Definition at line 995 of file types.hpp.

Referenced by isType(), and isType().

◆ getDataType()

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

Get data type.

Definition at line 1000 of file types.hpp.

◆ 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 1007 of file types.hpp.

Referenced by opcua::services::detail::AttributeHandler< AttributeId::NodeClass >::fromDataValue(), 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 1012 of file types.hpp.

◆ getScalar() [1/4]

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`.
Examples
custom_datatypes/client_custom_datatypes.cpp, method/client_method_async.cpp, and typeconversion.cpp.

Definition at line 1019 of file types.hpp.

Referenced by getScalar(), and getScalar().

◆ getScalar() [2/4]

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 1028 of file types.hpp.

◆ getScalar() [3/4]

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 1037 of file types.hpp.

◆ getScalar() [4/4]

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 1043 of file types.hpp.

◆ 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 1050 of file types.hpp.

◆ 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 1056 of file types.hpp.

◆ getArrayDimensions()

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

Get array dimensions.

Definition at line 1061 of file types.hpp.

◆ getArray() [1/2]

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`.
Examples
custom_datatypes/client_custom_datatypes.cpp.

Definition at line 1068 of file types.hpp.

◆ getArray() [2/2]

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 1078 of file types.hpp.

◆ 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 1088 of file types.hpp.

◆ setScalar() [1/2]

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

Assign scalar value to variant (no copy).

Definition at line 1095 of file types.hpp.

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 1102 of file types.hpp.

◆ 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 1119 of file types.hpp.

◆ 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 1130 of file types.hpp.

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 1142 of file types.hpp.

◆ 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 1168 of file types.hpp.

◆ 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 1176 of file types.hpp.

◆ 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 1190 of file types.hpp.

◆ TypeWrapper() [1/5]

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

◆ TypeWrapper() [2/5]

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

Constructor with native object (deep copy).

Definition at line 31 of file typewrapper.hpp.

◆ TypeWrapper() [3/5]

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

Constructor with native object (move rvalue).

Definition at line 35 of file typewrapper.hpp.

◆ TypeWrapper() [4/5]

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

Copy constructor (deep copy).

Definition at line 43 of file typewrapper.hpp.

◆ TypeWrapper() [5/5]

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

Move constructor.

Definition at line 47 of file typewrapper.hpp.