PVData C++  8.0.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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 >::type
ref ()
 
template<typename T >
meta::decorate_const< typename
detail::any_storage_type
< typename meta::strip_const
< T >::type >::type >::type
ref () const
 
template<typename T >
as () const
 

Friends

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

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

Construct empty

Postcondition
empty()==true

Definition at line 100 of file anyscalar.h.

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

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.

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
void epics::pvData::AnyScalar::clear ( )

Reset internal state.

Version
Added after 7.0.0
Postcondition
empty()==true
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.

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: