A safe, type checked container for arbitrary data of variable type.
More...
#include <Any.hpp>
|
| 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...
|
|
Any & | operator= (const Any &rhs) |
| Has the same effect as Any(rhs).swap(*this) . No effects if an exception is thrown. More...
|
|
Any & | operator= (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> |
Any & | operator= (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 Any & | getData () const |
|
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].
◆ Any() [1/4]
Constructs an object of type Any
with an empty state.
- Exceptions
-
◆ Any() [2/4]
CDPL::Base::Any::Any |
( |
const Any & |
rhs | ) |
|
|
inline |
Constructs an object of type Any
with an equivalent state as rhs.
- Parameters
-
rhs | The 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
-
rhs | The 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
-
◆ ~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
-
◆ 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
-
rhs | The 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
-
rhs | The 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
-
◆ 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
-
- Returns
- A reference to itself.
◆ clear()
void CDPL::Base::Any::clear |
( |
| ) |
|
|
inlinenoexcept |
If not empty, destroys the contained object.
- Exceptions
-
◆ 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
-
◆ 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
-
◆ swap()
void CDPL::Base::Any::swap |
( |
Any & |
rhs | ) |
|
|
inlinenoexcept |
Exchange the states of *this
and rhs.
- Parameters
-
rhs | The other Any instance. |
- Exceptions
-
◆ 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::BadCast | if 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
-
◆ getData() [2/2]
template<>
const Any& CDPL::Base::Any::getData |
( |
| ) |
const |
|
inline |
The documentation for this class was generated from the following file: