Zserio C++17 runtime library  1.1.0
Built for Zserio 2.18.1
zserio::BasicAny< ALLOC > Class Template Reference

#include <Any.h>

Inheritance diagram for zserio::BasicAny< ALLOC >:
Collaboration diagram for zserio::BasicAny< ALLOC >:

Public Types

using allocator_type = ALLOC
 
- Public Types inherited from zserio::AllocatorHolder< std::allocator< uint8_t > >
using allocator_type = std::allocator< uint8_t >
 

Public Member Functions

 BasicAny ()
 
 BasicAny (const ALLOC &allocator)
 
template<typename T , typename std::enable_if<!std::is_same< typename std::decay< T >::type, BasicAny >::value &&!std::is_same< typename std::decay< T >::type, ALLOC >::value, int >::type = 0>
 BasicAny (T &&value, const ALLOC &allocator=ALLOC())
 
 ~BasicAny ()
 
 BasicAny (const BasicAny &other)
 
 BasicAny (const BasicAny &other, const ALLOC &allocator)
 
BasicAnyoperator= (const BasicAny &other)
 
 BasicAny (BasicAny &&other) noexcept
 
 BasicAny (BasicAny &&other, const ALLOC &allocator)
 
BasicAnyoperator= (BasicAny &&other)
 
template<typename T , typename std::enable_if<!std::is_same< typename std::decay< T >::type, BasicAny >::value, int >::type = 0>
BasicAnyoperator= (T &&value)
 
void swap (BasicAny &other)
 
void reset ()
 
template<typename T >
void set (T &&value)
 
template<typename T , typename... ARGS>
T & emplace (ARGS &&... args)
 
template<typename T >
T * get_if () noexcept
 
template<typename T >
const T * get_if () const noexcept
 
template<typename T >
T & get ()
 
template<typename T >
const T & get () const
 
template<typename T >
bool isType () const noexcept
 
bool hasValue () const noexcept
 
- Public Member Functions inherited from zserio::AllocatorHolder< std::allocator< uint8_t > >
 AllocatorHolder ()
 
 AllocatorHolder (const allocator_type &allocator)
 
 AllocatorHolder (allocator_type &&allocator)
 
allocator_type get_allocator () const
 
 AllocatorHolder (const AllocatorHolder &other)=default
 
 AllocatorHolder (AllocatorHolder &&other)=default
 
 ~AllocatorHolder ()=default
 
AllocatorHolderoperator= (const AllocatorHolder &other)=default
 
AllocatorHolderoperator= (AllocatorHolder &&other)=default
 

Additional Inherited Members

- Protected Member Functions inherited from zserio::AllocatorHolder< std::allocator< uint8_t > >
void set_allocator (const allocator_type &allocator)
 
void set_allocator (allocator_type &&allocator)
 
allocator_typeget_allocator_ref ()
 
const allocator_typeget_allocator_ref () const
 

Detailed Description

template<typename ALLOC = std::allocator<uint8_t>>
class zserio::BasicAny< ALLOC >

Type safe container for single values of any type which doesn't need RTTI.

Definition at line 288 of file Any.h.

Member Typedef Documentation

◆ allocator_type

template<typename ALLOC = std::allocator<uint8_t>>
using zserio::BasicAny< ALLOC >::allocator_type = ALLOC

Definition at line 296 of file Any.h.

Constructor & Destructor Documentation

◆ BasicAny() [1/7]

template<typename ALLOC = std::allocator<uint8_t>>
zserio::BasicAny< ALLOC >::BasicAny ( )
inline

Empty constructor.

Definition at line 301 of file Any.h.

◆ BasicAny() [2/7]

template<typename ALLOC = std::allocator<uint8_t>>
zserio::BasicAny< ALLOC >::BasicAny ( const ALLOC &  allocator)
inlineexplicit

Constructor from given allocator

Definition at line 308 of file Any.h.

◆ BasicAny() [3/7]

template<typename ALLOC = std::allocator<uint8_t>>
template<typename T , typename std::enable_if<!std::is_same< typename std::decay< T >::type, BasicAny >::value &&!std::is_same< typename std::decay< T >::type, ALLOC >::value, int >::type = 0>
zserio::BasicAny< ALLOC >::BasicAny ( T &&  value,
const ALLOC &  allocator = ALLOC() 
)
inlineexplicit

Constructor from any value.

Parameters
valueValue of any type to hold. Supports move semantic.

Definition at line 323 of file Any.h.

◆ ~BasicAny()

template<typename ALLOC = std::allocator<uint8_t>>
zserio::BasicAny< ALLOC >::~BasicAny ( )
inline

Destructor.

Definition at line 333 of file Any.h.

◆ BasicAny() [4/7]

template<typename ALLOC = std::allocator<uint8_t>>
zserio::BasicAny< ALLOC >::BasicAny ( const BasicAny< ALLOC > &  other)
inline

Copy constructor.

Parameters
otherAny holder to copy.

Definition at line 343 of file Any.h.

◆ BasicAny() [5/7]

template<typename ALLOC = std::allocator<uint8_t>>
zserio::BasicAny< ALLOC >::BasicAny ( const BasicAny< ALLOC > &  other,
const ALLOC &  allocator 
)
inline

Allocator-extended copy constructor.

Parameters
otherAny holder to copy.
allocatorAllocator to be used for dynamic memory allocations.

Definition at line 356 of file Any.h.

◆ BasicAny() [6/7]

template<typename ALLOC = std::allocator<uint8_t>>
zserio::BasicAny< ALLOC >::BasicAny ( BasicAny< ALLOC > &&  other)
inlinenoexcept

Move constructor.

Parameters
otherAny holder to move from.

Definition at line 390 of file Any.h.

◆ BasicAny() [7/7]

template<typename ALLOC = std::allocator<uint8_t>>
zserio::BasicAny< ALLOC >::BasicAny ( BasicAny< ALLOC > &&  other,
const ALLOC &  allocator 
)
inline

Allocator-extended move constructor.

Parameters
otherAny holder to move from.
allocatorAllocator to be used for dynamic memory allocations.

Definition at line 402 of file Any.h.

Member Function Documentation

◆ emplace()

template<typename ALLOC = std::allocator<uint8_t>>
template<typename T , typename... ARGS>
T& zserio::BasicAny< ALLOC >::emplace ( ARGS &&...  args)
inline

Constructs a value of type T with given arguments

Parameters
argsArguments for value construction

Definition at line 498 of file Any.h.

◆ get() [1/2]

template<typename ALLOC = std::allocator<uint8_t>>
template<typename T >
T& zserio::BasicAny< ALLOC >::get ( )
inline

Gets value of the given type.

Returns
Value of the requested type if the type matches the stored value.
Exceptions
CppRuntimeExceptionif the requested type doesn't match the stored value.

Definition at line 558 of file Any.h.

◆ get() [2/2]

template<typename ALLOC = std::allocator<uint8_t>>
template<typename T >
const T& zserio::BasicAny< ALLOC >::get ( ) const
inline

Gets value of the given type.

Returns
Value of the requested type if the type matches the stored value.
Exceptions
CppRuntimeExceptionif the requested type doesn't match the stored value.

Definition at line 572 of file Any.h.

◆ get_if() [1/2]

template<typename ALLOC = std::allocator<uint8_t>>
template<typename T >
const T* zserio::BasicAny< ALLOC >::get_if ( ) const
inlinenoexcept

Gets the pointer of the given type or nullptr if such value is not present.

Returns
Pointer to the value of the requested type if the type matches the stored value.

Definition at line 533 of file Any.h.

◆ get_if() [2/2]

template<typename ALLOC = std::allocator<uint8_t>>
template<typename T >
T* zserio::BasicAny< ALLOC >::get_if ( )
inlinenoexcept

Gets the pointer of the given type or nullptr if such value is not present.

Returns
Pointer to the value of the requested type if the type matches the stored value.

Definition at line 510 of file Any.h.

◆ hasValue()

template<typename ALLOC = std::allocator<uint8_t>>
bool zserio::BasicAny< ALLOC >::hasValue ( ) const
inlinenoexcept

Checks whether the holder has any value.

Returns
True if the holder has assigned any value, false otherwise.

Definition at line 594 of file Any.h.

◆ isType()

template<typename ALLOC = std::allocator<uint8_t>>
template<typename T >
bool zserio::BasicAny< ALLOC >::isType ( ) const
inlinenoexcept

Check whether the holder holds the given type.

Returns
True if the stored value is of the given type, false otherwise.

Definition at line 584 of file Any.h.

◆ operator=() [1/3]

template<typename ALLOC = std::allocator<uint8_t>>
BasicAny& zserio::BasicAny< ALLOC >::operator= ( BasicAny< ALLOC > &&  other)
inline

Move assignment operator.

Parameters
otherAny holder to move from.
Returns
Reference to this.

Definition at line 415 of file Any.h.

◆ operator=() [2/3]

template<typename ALLOC = std::allocator<uint8_t>>
BasicAny& zserio::BasicAny< ALLOC >::operator= ( const BasicAny< ALLOC > &  other)
inline

Copy assignment operator.

Parameters
otherAny holder to copy.
Returns
Reference to this.

Definition at line 369 of file Any.h.

◆ operator=() [3/3]

template<typename ALLOC = std::allocator<uint8_t>>
template<typename T , typename std::enable_if<!std::is_same< typename std::decay< T >::type, BasicAny >::value, int >::type = 0>
BasicAny& zserio::BasicAny< ALLOC >::operator= ( T &&  value)
inline

Value assignment operator.

Parameters
valueAny value to assign. Supports move semantic.
Returns
Reference to this.

Definition at line 440 of file Any.h.

◆ reset()

template<typename ALLOC = std::allocator<uint8_t>>
void zserio::BasicAny< ALLOC >::reset ( )
inline

Resets the holder.

Definition at line 476 of file Any.h.

◆ set()

template<typename ALLOC = std::allocator<uint8_t>>
template<typename T >
void zserio::BasicAny< ALLOC >::set ( T &&  value)
inline

Sets any value to the holder.

Parameters
valueAny value to set. Supports move semantic.

Definition at line 487 of file Any.h.

◆ swap()

template<typename ALLOC = std::allocator<uint8_t>>
void zserio::BasicAny< ALLOC >::swap ( BasicAny< ALLOC > &  other)
inline

Swaps the holder with another.

Parameters
otherOther BasicAny to swap content with.

Definition at line 452 of file Any.h.


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