Class AnyScalar

Nested Relationships

Nested Types

Class Documentation

class AnyScalar

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

Public Functions

inline AnyScalar()

Construct empty

Post

empty()==true

template<typename T>
inline explicit AnyScalar(T v)

Construct from provided value.

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(const AnyScalar &o)
inline ~AnyScalar()
inline AnyScalar &operator=(const AnyScalar &o)
template<typename T>
inline AnyScalar &operator=(T v)
void clear()

Reset internal state.

Version

Added after 7.0.0

Post

empty()==true

void swap(AnyScalar &o)
inline ScalarType type() const

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

inline void *unsafe()
inline const void *unsafe() const
inline bool empty() const
inline operator bool_type() const
const void *bufferUnsafe() const

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

Version

Added after 7.0.0

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

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

Throws

bad_cast – when the requested type does not match the stored type

AnyScalar v(42);
v.ref<uint32>() = 43;
assert(v.ref<uint32>() == 43);

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

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

Throws

bad_cast – when the requested type does not match the stored type

const AnyScalar v(42);
assert(v.ref<uint32>() == 42);

template<typename T>
inline T as() const

copy out wrapped value, with a value conversion.

Throws

bad_cast – when empty()==true

struct bad_cast : public exception

Public Functions

inline bad_cast()
inline virtual ~bad_cast()
inline virtual const char *what() const