libpnicore
Public Member Functions | Private Types | Private Member Functions | Private Attributes
pni::core::value Class Reference

type erasure for POD data

#include <value.hpp>

Public Member Functions

 value ()
 default constructor
 
template<typename T , typename = typename enable_primitive<T>::type>
 value (T v)
 template constructor from value More...
 
 value (const value &o)
 copy constructor
 
 value (value &&o)
 move constructor
 
template<typename VT >
valueoperator= (const VT &v)
 copy assignment from value More...
 
valueoperator= (const value &o)
 copy assignment
 
valueoperator= (value &&o)
 move assignment operator
 
valueoperator= (const value_ref &v)
 copy construction from a value reference
 
template<typename T >
as () const
 get the stored value More...
 
type_id_t type_id () const
 get type id More...
 

Private Types

typedef std::unique_ptr
< value_holder_interface
pointer_type
 internal pointer type
 
template<typename T >
using enable_primitive = std::enable_if< is_primitive_type< T >::value >
 

Private Member Functions

template<typename T , typename S >
_get () const
 return value More...
 
template<typename S , typename T >
void _set (const T &v) const
 set value More...
 

Private Attributes

pointer_type _ptr
 pointer holding the value stored
 

Constructor & Destructor Documentation

template<typename T , typename = typename enable_primitive<T>::type>
pni::core::value::value ( v)
inlineexplicit

This constructor accepts all primitive types from libpnicore.

Template Parameters
Tprimitive type
Parameters
vvalue to store in the type erasure

Member Function Documentation

template<typename T , typename S >
T pni::core::value::_get ( ) const
inlineprivate

Return the value of the variable the reference refers to. T denotes the data type requested by the user. S denotes the type of the variable the reference points to.

Exceptions
type_errorif the conversion is not possible
range_errorif the value
Template Parameters
Ttarget type
Ssource type
Returns
value as T
template<typename S , typename T >
void pni::core::value::_set ( const T &  v) const
inlineprivate

Sets the value of the variable the reference points to.

Exceptions
type_errorif the conversion is not possible
range_errorif the passed value does not fit in the target type
Template Parameters
Stype of the variable
Ttype of the value the user passed
Parameters
vvalue to set
template<typename T >
T pni::core::value::as ( ) const

Return the stored value as type T. If the value instance has not been initialized before an exception is thrown. In addition, if the data type passed as a template parameter does not fit the type used to store the data an exception will be thrown.

Exceptions
memory_not_allocate_errorif value is uninitialized
type_errorif T does not match the original data type
range_errorif the value stored does not fit into the requested type.
Returns
value of type T
template<typename VT >
value & pni::core::value::operator= ( const VT &  v)
Parameters
vreference to the new value
Returns
instance of value
type_id_t pni::core::value::type_id ( ) const

Returns the ID of the stored data type.

Exceptions
memory_not_allocated_errorif value is not initialized
Returns
type ID.

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