PVData C++ 8.0.7
Loading...
Searching...
No Matches
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< typenamemeta::strip_const< T >::type >::typeref ()
 
template<typename T >
meta::decorate_const< typenamedetail::any_storage_type< typenamemeta::strip_const< T >::type >::type >::typeref () const
 
template<typename T >
as () const
 

Friends

std::ostream & operator<< (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
int32_t int32
Definition pvType.h:83

Definition at line 51 of file anyscalar.h.

Constructor & Destructor Documentation

◆ AnyScalar() [1/3]

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

Construct empty

Postcondition
empty()==true

Definition at line 100 of file anyscalar.h.

◆ AnyScalar() [2/3]

template<typename T >
epics::pvData::AnyScalar::AnyScalar ( T v)
inlineexplicit

Construct from provided value.

Definition at line 104 of file anyscalar.h.

◆ AnyScalar() [3/3]

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

◆ ~AnyScalar()

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

Definition at line 129 of file anyscalar.h.

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

◆ empty()

bool epics::pvData::AnyScalar::empty ( ) const
inline

Definition at line 165 of file anyscalar.h.

◆ operator bool_type()

epics::pvData::AnyScalar::operator bool_type ( ) const
inline

Definition at line 173 of file anyscalar.h.

◆ operator=() [1/2]

AnyScalar & epics::pvData::AnyScalar::operator= ( const AnyScalar & o)
inline

Definition at line 131 of file anyscalar.h.

◆ operator=() [2/2]

template<typename T >
AnyScalar & epics::pvData::AnyScalar::operator= ( T v)
inline

Definition at line 137 of file anyscalar.h.

◆ ref() [1/2]

template<typename T >
detail::any_storage_type< typenamemeta::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);
uint32_t uint32
Definition pvType.h:99

Definition at line 194 of file anyscalar.h.

◆ ref() [2/2]

template<typename T >
meta::decorate_const< typenamedetail::any_storage_type< typenamemeta::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.

◆ type()

ScalarType epics::pvData::AnyScalar::type ( ) const
inline

Type code of contained value. Or (ScalarType)-1 is empty.

Definition at line 158 of file anyscalar.h.

◆ unsafe() [1/2]

void * epics::pvData::AnyScalar::unsafe ( )
inline

Definition at line 162 of file anyscalar.h.

◆ unsafe() [2/2]

const void * epics::pvData::AnyScalar::unsafe ( ) const
inline

Definition at line 163 of file anyscalar.h.


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