xentara-utils v1.2.1
Xentara utilities library
Loading...
Searching...
No Matches
xentara::utils::windows::com::Variant Class Referencefinal

A COM variant object. More...

#include <windows/com/Variant.hpp>

Classes

class  Setter
 

Public Types

template<VARTYPE Type>
using NativeType = typename variantTypes::detail::VariantNativeType< Type >::Type
 Facility to determine the native type for a variant type.
 

Public Member Functions

 Variant () noexcept
 Default constructor.
 
internal Variant (VARIANT &&variant) noexcept
 Constructor that takes ownership of a native variant.
 
auto operator= (VARIANT &&variant) noexcept -> Variant &
 Assignment operator that takes ownership of a native variant.
 
auto type () const -> VARTYPE
 Returns the variant type.
 
auto convert (VARTYPE type) const -> Variant
 Converts the variant to a different type.
 
template<VARTYPE kType>
auto get () const -> NativeType< kType >
 Gets the value of the variant.
 
template<VARTYPE kType>
auto as () const -> NativeType< kType >
 Converts the value of the variant to a certain type.
 
auto setter () noexcept -> Setter
 Gets a setter for use as an output parameter for C functions.
 

Detailed Description

A COM variant object.

This class wraps a COM VARIANT structure.

Member Typedef Documentation

◆ NativeType

template<VARTYPE Type>
using xentara::utils::windows::com::Variant::NativeType = typename variantTypes::detail::VariantNativeType<Type>::Type

Facility to determine the native type for a variant type.

Constructor & Destructor Documentation

◆ Variant() [1/2]

xentara::utils::windows::com::Variant::Variant ( )
noexcept

Default constructor.

This constructor creates an empty variant

◆ Variant() [2/2]

internal xentara::utils::windows::com::Variant::Variant ( VARIANT &&  variant)
noexcept

Constructor that takes ownership of a native variant.

variant The native variant. The variant is cleared.

Member Function Documentation

◆ as()

template<VARTYPE kType>
auto xentara::utils::windows::com::Variant::as ( ) const -> NativeType< kType >

Converts the value of the variant to a certain type.

Returns
The value as the given type
Exceptions
std::runtime_errorThe value cannet be converted to the specified type

◆ convert()

auto xentara::utils::windows::com::Variant::convert ( VARTYPE  type) const -> Variant

Converts the variant to a different type.

Returns
The value as the given type
Exceptions
std::runtime_errorThe variant could not be converted

◆ get()

template<VARTYPE kType>
auto xentara::utils::windows::com::Variant::get ( ) const -> NativeType< kType >

Gets the value of the variant.

This function does not perform any type conversion. Use as() to get the type using conversion.

Returns
The value
Exceptions
std::runtime_errorThe value is not of the specified type

◆ operator=()

auto xentara::utils::windows::com::Variant::operator= ( VARIANT &&  variant) -> Variant &
noexcept

Assignment operator that takes ownership of a native variant.

variant The native variant. The variant is cleared.

Returns
A reference to this object

◆ setter()

auto xentara::utils::windows::com::Variant::setter ( ) -> Setter
noexcept

Gets a setter for use as an output parameter for C functions.

This function returns a helper object that can be passed to a function that takes a VARIANT * as output parameter, like e.g. IWbemClassObject::Get(). This provides a safe way of creating objects using such a function without running the risk of leaking the created object.

IWbemClassObject::Get() can be called like this, for example:

object->Get(myPropertyName, 0, variant.setter(), nullptr, nullptr);
A COM variant object.
Definition Variant.hpp:324
auto setter() noexcept -> Setter
Gets a setter for use as an output parameter for C functions.
Definition Variant.hpp:542

◆ type()

auto xentara::utils::windows::com::Variant::type ( ) const -> VARTYPE

Returns the variant type.

Returns
The variant type. The type will be one of the VT_* type codes, possibly ORed together with VT_ARRAY. The value VT_BYREF is masked out.