Chemical Data Processing Library C++ API - Version 1.1.1
Classes | Public Member Functions | List of all members
CDPL::Base::Any Class Referencefinal

A safe, type checked container for arbitrary data of variable type. More...

#include <Any.hpp>

Public Member Functions

 Any () noexcept
 Constructs an object of type Any with an empty state. More...
 
 Any (const Any &rhs)
 Constructs an object of type Any with an equivalent state as rhs. More...
 
 Any (Any &&rhs) noexcept
 Constructs an object of type Any with a state equivalent to the original state of rhs. More...
 
 ~Any ()
 Destructor. More...
 
template<typename ValueType , typename = typename std::enable_if<!std::is_same<typename std::decay<ValueType>::type, Any>::value>::type>
 Any (ValueType &&val)
 Constructs an object of type Any that contains an object of type ValueType direct-initialized with std::forward<ValueType>(val). More...
 
Anyoperator= (const Any &rhs)
 Has the same effect as Any(rhs).swap(*this). No effects if an exception is thrown. More...
 
Anyoperator= (Any &&rhs) noexcept
 Has the same effect as Any(std::move(rhs)).swap(*this). More...
 
template<typename ValueType , typename = typename std::enable_if<!std::is_same<typename std::decay<ValueType>::type, Any>::value>::type>
Anyoperator= (ValueType &&val)
 Has the same effect as Any(std::forward<ValueType>(val)).swap(*this). No effect if a exception is thrown. More...
 
void clear () noexcept
 If not empty, destroys the contained object. More...
 
bool isEmpty () const noexcept
 Tells whether the Any instance stores any data. More...
 
const std::type_info & getTypeID () const noexcept
 Returns information about the type of the stored object. More...
 
void swap (Any &rhs) noexcept
 Exchange the states of *this and rhs. More...
 
template<typename ValueType >
const ValueType & getData () const
 Returns a const reference to the stored object of type ValueType, or *this if ValueType is Any. More...
 
const void * getDataPointer () const noexcept
 Returns a raw pointer to the memory occupied by the stored data. More...
 
template<>
const AnygetData () const
 

Detailed Description

A safe, type checked container for arbitrary data of variable type.

The code is based on the std::experimental::any (N4562, merged into C++17) implementation for C++11 compilers by Denilson das Mercês Amorim. Any provides an optimization for small objects objects with a size of up to 2 words such as int, float and std::shared_ptr. Storing those objects in the container will not trigger a dynamic allocation.

For more details see [ANY].

Constructor & Destructor Documentation

◆ Any() [1/4]

CDPL::Base::Any::Any ( )
inlinenoexcept

Constructs an object of type Any with an empty state.

Exceptions
None.

◆ Any() [2/4]

CDPL::Base::Any::Any ( const Any rhs)
inline

Constructs an object of type Any with an equivalent state as rhs.

Parameters
rhsThe other Any instance.

◆ Any() [3/4]

CDPL::Base::Any::Any ( Any &&  rhs)
inlinenoexcept

Constructs an object of type Any with a state equivalent to the original state of rhs.

Parameters
rhsThe other Any instance.
Postcondition
The state of *this is equivalent to the original state of rhs and rhs is left in a valid but otherwise unspecified state.
Exceptions
None.

◆ ~Any()

CDPL::Base::Any::~Any ( )
inline

Destructor.

Has the same effect as this->clear().

◆ Any() [4/4]

template<typename ValueType , typename = typename std::enable_if<!std::is_same<typename std::decay<ValueType>::type, Any>::value>::type>
CDPL::Base::Any::Any ( ValueType &&  val)
inline

Constructs an object of type Any that contains an object of type ValueType direct-initialized with std::forward<ValueType>(val).

ValueType shall satisfy the CopyConstructible requirements, otherwise the program is ill-formed. This is because an Any may be copy constructed into another Any at any time, so a copy should always be allowed.

Parameters
valThe value to store.

Member Function Documentation

◆ operator=() [1/3]

Any& CDPL::Base::Any::operator= ( const Any rhs)
inline

Has the same effect as Any(rhs).swap(*this). No effects if an exception is thrown.

Parameters
rhsThe other Any instance.
Returns
A reference to itself.

◆ operator=() [2/3]

Any& CDPL::Base::Any::operator= ( Any &&  rhs)
inlinenoexcept

Has the same effect as Any(std::move(rhs)).swap(*this).

Parameters
rhsThe other Any instance.
Returns
A reference to itself.
Postcondition
The state of *this is equivalent to the original state of rhs and rhs is left in a valid but otherwise unspecified state.
Exceptions
None.

◆ operator=() [3/3]

template<typename ValueType , typename = typename std::enable_if<!std::is_same<typename std::decay<ValueType>::type, Any>::value>::type>
Any& CDPL::Base::Any::operator= ( ValueType &&  val)
inline

Has the same effect as Any(std::forward<ValueType>(val)).swap(*this). No effect if a exception is thrown.

ValueType shall satisfy the CopyConstructible requirements, otherwise the program is ill-formed. This is because an Any may be copy constructed into another Any at any time, so a copy should always be allowed.

Parameters
valThe value to store.
Returns
A reference to itself.

◆ clear()

void CDPL::Base::Any::clear ( )
inlinenoexcept

If not empty, destroys the contained object.

Exceptions
None.

◆ isEmpty()

bool CDPL::Base::Any::isEmpty ( ) const
inlinenoexcept

Tells whether the Any instance stores any data.

Returns
false if the Any instance is not empty, and true otherwise.
Exceptions
None.

◆ getTypeID()

const std::type_info& CDPL::Base::Any::getTypeID ( ) const
inlinenoexcept

Returns information about the type of the stored object.

Returns
If non-empty, a reference to the std::type_info object describing the type of the stored object, and typeid(void) otherwise.
Exceptions
None.

◆ swap()

void CDPL::Base::Any::swap ( Any rhs)
inlinenoexcept

Exchange the states of *this and rhs.

Parameters
rhsThe other Any instance.
Exceptions
None.

◆ getData() [1/2]

template<typename ValueType >
const ValueType& CDPL::Base::Any::getData ( ) const
inline

Returns a const reference to the stored object of type ValueType, or *this if ValueType is Any.

Returns
A const reference to the contained object of type ValueType, or *this if ValueType is Any.
Exceptions
Base::BadCastif the Any instance is empty, or the stored object is not of type ValueType.

◆ getDataPointer()

const void* CDPL::Base::Any::getDataPointer ( ) const
inlinenoexcept

Returns a raw pointer to the memory occupied by the stored data.

Returns
A void pointer to the storage occupied by the held data, or nullptr if the Any instance is empty.
Exceptions
None.

◆ getData() [2/2]

template<>
const Any& CDPL::Base::Any::getData ( ) const
inline

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