ADTF
Loading...
Searching...
No Matches
a_util::memory::StackPtr< T, StackSize, Alignment > Class Template Reference

#include <stack_ptr_decl.h>

Public Member Functions

 StackPtr ()
 Initializes the storage and constructs object ot type T by calling its default ctor.
 
 StackPtr (std::nullptr_t)
 Constructor overload t zero-initialize the storage - no object of type T is constructed!
 
 StackPtr (const T &data)
 
 StackPtr (T &&data)
 
 ~StackPtr ()
 Destructor.
 
 StackPtr (const StackPtr &other)
 
StackPtroperator= (StackPtr other)
 
 StackPtr (StackPtr &&other)
 
T * operator-> ()
 
const T * operator-> () const
 
T & operator* ()
 
const T & operator* () const
 
 operator bool () const noexcept
 
void reset ()
 Unitializes the storage and, if constructed, destructs the storaged object.
 
template<typename... Args>
void reset (Args &&... args)
 
void swap (StackPtr &other)
 

Friends

template<typename U, std::size_t SSize, std::size_t A>
bool operator== (const StackPtr< U, SSize, A > &lhs, const StackPtr< U, SSize, A > &rhs)
 

Detailed Description

template<typename T, std::size_t StackSize = sizeof(T), std::size_t Alignment = alignof(std::size_t)>
class a_util::memory::StackPtr< T, StackSize, Alignment >

A smart pointer allocating its memory only on the stack

Template Parameters
TThe storaged type - must be default and move constructible
StackSizeSize of the stack to allocate - must at least be the sizeof the object of type T.
AlignmentAlignment of the storage

Constructor & Destructor Documentation

◆ StackPtr() [1/4]

template<typename T, std::size_t StackSize, std::size_t Alignment>
a_util::memory::StackPtr< T, StackSize, Alignment >::StackPtr ( const T & data)
inline

Initializes the storage by calling the copy constructor of type T

Parameters
[in]dataObject of type T whose content gets copy constructed into the storage

◆ StackPtr() [2/4]

template<typename T, std::size_t StackSize, std::size_t Alignment>
a_util::memory::StackPtr< T, StackSize, Alignment >::StackPtr ( T && data)
inline

Initializes the storage by moving data to internal memory representation.

Parameters
[in]dataObject of type T that gets moved into the storage

◆ StackPtr() [3/4]

template<typename T, std::size_t StackSize, std::size_t Alignment>
a_util::memory::StackPtr< T, StackSize, Alignment >::StackPtr ( const StackPtr< T, StackSize, Alignment > & other)
inline

Copy constructor

Parameters
[in]otherObject of type StackPtr whose content gets copy constructed into the storage only if the object inside its storage was constructed

◆ StackPtr() [4/4]

template<typename T, std::size_t StackSize, std::size_t Alignment>
a_util::memory::StackPtr< T, StackSize, Alignment >::StackPtr ( StackPtr< T, StackSize, Alignment > && other)
inline

Move constructor

Parameters
[in,out]otherMove-from object, left in a valid but unspecified state

Member Function Documentation

◆ operator bool()

template<typename T, std::size_t StackSize, std::size_t Alignment>
a_util::memory::StackPtr< T, StackSize, Alignment >::operator bool ( ) const
inlineexplicitnoexcept

Check whether *this owns an object

Returns
true if *this owns an object, false otherwise

◆ operator*() [1/2]

template<typename T, std::size_t StackSize, std::size_t Alignment>
T & a_util::memory::StackPtr< T, StackSize, Alignment >::operator* ( )
inline

Operator overload to use this class like a raw pointer

Returns
Reference to the storaged object of type T
Warning
No check is performed whether the object was really constructed

◆ operator*() [2/2]

template<typename T, std::size_t StackSize, std::size_t Alignment>
const T & a_util::memory::StackPtr< T, StackSize, Alignment >::operator* ( ) const
inline

Operator overload to use this class like a raw pointer - for const correctness

Returns
Reference to the storaged object of type T
Warning
No check is performed whether the object was really constructed

◆ operator->() [1/2]

template<typename T, std::size_t StackSize, std::size_t Alignment>
T * a_util::memory::StackPtr< T, StackSize, Alignment >::operator-> ( )
inline

Operator overload to use this class like a raw pointer

Returns
Pointer to the storaged object of type T
Warning
No check is performed whether the object was really constructed

◆ operator->() [2/2]

template<typename T, std::size_t StackSize, std::size_t Alignment>
const T * a_util::memory::StackPtr< T, StackSize, Alignment >::operator-> ( ) const
inline

Operator overload to use this class like a raw pointer - for const correctness

Returns
Pointer to the storaged object of type T
Warning
No check is performed whether the object was really constructed

◆ operator=()

template<typename T, std::size_t StackSize, std::size_t Alignment>
StackPtr< T, StackSize, Alignment > & a_util::memory::StackPtr< T, StackSize, Alignment >::operator= ( StackPtr< T, StackSize, Alignment > other)
inline

Assignment operator

Parameters
[in]otherObject of type StackPtr whose content gets copy constructed into the storage only if the object inside its storage was constructed
Returns
*this

◆ reset()

template<typename T, std::size_t StackSize, std::size_t Alignment>
template<typename... Args>
void a_util::memory::StackPtr< T, StackSize, Alignment >::reset ( Args &&... args)
inline

Resets the managed object of type T by forwarding args to its ctor

Template Parameters
ArgsArgument types of type T ctor
Parameters
[in]argsArguments passed to the ctor of type T for its construction

◆ swap()

template<typename T, std::size_t StackSize, std::size_t Alignment>
void a_util::memory::StackPtr< T, StackSize, Alignment >::swap ( StackPtr< T, StackSize, Alignment > & other)
inline

Swap storage of *this with storage of other stack pointer

Parameters
[in]otherObject of type StackPtr whose content gets swapped with *this
Note
The storage is swapped byte-by-byte, so depending on the size this operation might be very time consuming.

Friends And Related Symbol Documentation

◆ operator==

template<typename T, std::size_t StackSize = sizeof(T), std::size_t Alignment = alignof(std::size_t)>
template<typename U, std::size_t SSize, std::size_t A>
bool operator== ( const StackPtr< U, SSize, A > & lhs,
const StackPtr< U, SSize, A > & rhs )
friend

Compare for equality

Template Parameters
UManaged type
SSizeSize the managed type occupies
AByte alignment of the storage
Parameters
[in]lhsLeft hand side object
[in]rhsRight hand side object
Returns
true if both objects are equal, false otherwise

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