PVData C++  8.0.3
Classes | Public Member Functions | Friends | List of all members
epics::pvData::AnyScalar Class Reference

#include <misc/pv/anyscalar.h>

Classes

struct  bad_cast
 

Public Member Functions

 AnyScalar ()
 
template<typename T >
 AnyScalar (T v)
 Construct from provided value.
 
 AnyScalar (ScalarType type, const void *buf)
 
 AnyScalar (const AnyScalar &o)
 
AnyScalaroperator= (const AnyScalar &o)
 
template<typename T >
AnyScalaroperator= (T v)
 
void clear ()
 
void swap (AnyScalar &o)
 
ScalarType type () const
 Type code of contained value. Or (ScalarType)-1 is empty.
 
void * unsafe ()
 
const void * unsafe () const
 
bool empty () const
 
 operator bool_type () const
 
const void * bufferUnsafe () const
 
template<typename T >
detail::any_storage_type< typename meta::strip_const< T >::type >::typeref ()
 
template<typename T >
meta::decorate_const< typename detail::any_storage_type< typename meta::strip_const< T >::type >::type >::typeref () const
 
template<typename T >
as () const
 

Friends

epicsShareFunc std::ostreamoperator<< (std::ostream &strm, const AnyScalar &v)
 

Detailed Description

A type-safe variant union capable of holding any of the PVD scalar types (POD or string)

AnyScalar A(5);
assert(A.type()==pvInt);
assert(A.ref<int32>()==5);
assert(A.as<int32>()==5);
assert(A.as<double>()==5.0);
assert(A.ref<double>()==5.0); // throws AnyScalar::bad_cast

Definition at line 51 of file anyscalar.h.

Constructor & Destructor Documentation

◆ AnyScalar() [1/2]

epics::pvData::AnyScalar::AnyScalar ( )
inline

Construct empty

Postcondition
empty()==true

Definition at line 100 of file anyscalar.h.

◆ AnyScalar() [2/2]

epics::pvData::AnyScalar::AnyScalar ( ScalarType  type,
const void *  buf 
)

Construct from un-typed pointer. Caller is responsible to ensure that buf actually points to the provided type

Version
Added after 7.0.0

Member Function Documentation

◆ as()

template<typename T >
T epics::pvData::AnyScalar::as ( ) const
inline

copy out wrapped value, with a value conversion.

Exceptions
bad_castwhen empty()==true

Definition at line 230 of file anyscalar.h.

◆ bufferUnsafe()

const void* epics::pvData::AnyScalar::bufferUnsafe ( ) const

Provide read-only access to underlying buffer. For a string this is std::string::c_str().

Version
Added after 7.0.0

◆ clear()

void epics::pvData::AnyScalar::clear ( )

Reset internal state.

Version
Added after 7.0.0
Postcondition
empty()==true

◆ ref() [1/2]

template<typename T >
detail::any_storage_type<typename meta::strip_const<T>::type>::type& epics::pvData::AnyScalar::ref ( )
inline

Return typed reference to wrapped value. Non-const reference allows value modification

Exceptions
bad_castwhen the requested type does not match the stored type
AnyScalar v(42);
v.ref<uint32>() = 43;
assert(v.ref<uint32>() == 43);

Definition at line 194 of file anyscalar.h.

◆ ref() [2/2]

template<typename T >
meta::decorate_const<typename detail::any_storage_type<typename meta::strip_const<T>::type>::type>::type& epics::pvData::AnyScalar::ref ( ) const
inline

Return typed reference to wrapped value. Const reference does not allow modification.

Exceptions
bad_castwhen the requested type does not match the stored type
const AnyScalar v(42);
assert(v.ref<uint32>() == 42);

Definition at line 215 of file anyscalar.h.


The documentation for this class was generated from the following file: