ADTF
3.18.2
|
A smart pointer allocating its memory only on the stack. More...
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) | |
Initializes the storage by calling the copy constructor of type T . More... | |
StackPtr (T &&data) | |
Initializes the storage by moving data to internal memory representation. More... | |
~StackPtr () | |
Destructor. | |
StackPtr (const StackPtr &other) | |
Copy constructor. More... | |
StackPtr & | operator= (StackPtr other) |
Assignment operator. More... | |
StackPtr (StackPtr &&other) | |
Move constructor. More... | |
T * | operator-> () |
Operator overload to use this class like a raw pointer. More... | |
const T * | operator-> () const |
Operator overload to use this class like a raw pointer - for const correctness. More... | |
T & | operator* () |
Operator overload to use this class like a raw pointer. More... | |
const T & | operator* () const |
Operator overload to use this class like a raw pointer - for const correctness. More... | |
operator bool () const noexcept | |
Check whether *this owns an object. More... | |
void | reset () |
Unitializes the storage and, if constructed, destructs the storaged object. | |
template<typename... Args> | |
void | reset (Args &&... args) |
Resets the managed object of type T by forwarding args to its ctor. More... | |
void | swap (StackPtr &other) |
Swap storage of *this with storage of other stack pointer. More... | |
Private Types | |
enum | StackPtrIntrospection { NumFlagBytes = 1 , OverheadSize = (Alignment - (StackSize % Alignment)) , StorageSize = StackSize + OverheadSize , FirstFlagPosition = StackSize } |
Calculate entire size of the _storage - adds padding bytes to comply to the alignment. More... | |
enum | StackPtrFlagPositions { InitializeStatus = FirstFlagPosition } |
Absolute bit positions of the flags inside the overhead area of the storage. More... | |
enum class | StackPtrFlags : char { IsDestroyed = 0x00 , IsConstructed = 0x01 } |
Flags for StackPtrFlagPositions . More... | |
Private Member Functions | |
void * | address () |
Get pointer to beginning of the storage. More... | |
const void * | address () const |
Get pointer to beginning of the storage provided for const correctness. More... | |
void | setFlag (StackPtrFlagPositions position, StackPtrFlags flag) |
Sets a flag to the appropriate position in the overhead section of the storage. More... | |
bool | isConstructed () const noexcept |
Check whether the object hidden by the storage got constructed. More... | |
Private Attributes | |
std::array< char, StorageSize > | _storage |
Aligned storage large enough to contain one object of type T and some overhead for flags. | |
A smart pointer allocating its memory only on the stack.
T | The storaged type - must be default and move constructible |
StackSize | Size of the stack to allocate - must at least be the sizeof the object of type T . |
Alignment | Alignment of the storage |
Definition at line 32 of file stack_ptr_decl.h.
|
private |
Absolute bit positions of the flags inside the overhead area of the storage.
Enumerator | |
---|---|
InitializeStatus | Flag position for the initialize status. |
Definition at line 143 of file stack_ptr_decl.h.
|
strongprivate |
Flags for StackPtrFlagPositions
.
Enumerator | |
---|---|
IsDestroyed | for InitializeStatus --> contained object not constructed |
IsConstructed | for InitializeStatus --> contained object constructed |
Definition at line 148 of file stack_ptr_decl.h.
|
private |
Calculate entire size of the _storage - adds padding bytes to comply to the alignment.
Enumerator | |
---|---|
NumFlagBytes | Number of bytes required to store control flags. |
OverheadSize | Size of the overhead containing the flags (complying to alignment) |
StorageSize | Entire size of the _storage, including aligned overhead for necessary flags. |
FirstFlagPosition | First byte of the StackPtr flag area. |
Definition at line 131 of file stack_ptr_decl.h.
|
inline |
Initializes the storage by calling the copy constructor of type T
.
[in] | data | Object of type T whose content gets copy constructed into the storage |
Definition at line 37 of file stack_ptr_impl.h.
|
inline |
Initializes the storage by moving data
to internal memory representation.
[in] | data | Object of type T that gets moved into the storage |
Definition at line 43 of file stack_ptr_impl.h.
Copy constructor.
[in] | other | Object of type StackPtr whose content gets copy constructed into the storage only if the object inside its storage was constructed |
Definition at line 57 of file stack_ptr_impl.h.
References StackPtr< T, StackSize, Alignment >::isConstructed().
Move constructor.
[in,out] | other | Move-from object, left in a valid but unspecified state |
Definition at line 73 of file stack_ptr_impl.h.
|
inlineprivate |
Get pointer to beginning of the storage.
Definition at line 164 of file stack_ptr_impl.h.
Referenced by StackPtr< T, StackSize, Alignment >::StackPtr().
|
inlineprivate |
Get pointer to beginning of the storage provided for const correctness.
Definition at line 170 of file stack_ptr_impl.h.
|
inlineprivatenoexcept |
Check whether the object hidden by the storage got constructed.
true
if the object was constructed, false
otherwise. Definition at line 183 of file stack_ptr_impl.h.
Referenced by StackPtr< T, StackSize, Alignment >::StackPtr(), StackPtr< Implementation, 64 >::StackPtr(), and StackPtr< T, StackSize, Alignment >::swap().
|
inlineexplicitnoexcept |
Check whether *this owns an object.
true
if *this owns an object, false
otherwise Definition at line 105 of file stack_ptr_impl.h.
|
inline |
Operator overload to use this class like a raw pointer.
T
Definition at line 93 of file stack_ptr_impl.h.
|
inline |
Operator overload to use this class like a raw pointer - for const correctness.
T
Definition at line 99 of file stack_ptr_impl.h.
|
inline |
Operator overload to use this class like a raw pointer.
T
Definition at line 81 of file stack_ptr_impl.h.
|
inline |
Operator overload to use this class like a raw pointer - for const correctness.
T
Definition at line 87 of file stack_ptr_impl.h.
Assignment operator.
[in] | other | Object of type StackPtr whose content gets copy constructed into the storage only if the object inside its storage was constructed |
Definition at line 65 of file stack_ptr_impl.h.
|
inline |
Resets the managed object of type T
by forwarding args
to its ctor.
Args | Argument types of type T ctor |
[in] | args | Arguments passed to the ctor of type T for its construction |
Definition at line 121 of file stack_ptr_impl.h.
References adtf_ddl::access_element::reset().
|
inlineprivate |
Sets a flag
to the appropriate position
in the overhead section of the storage.
[in] | position | Position of the flag in the overhead area |
[in] | flag | The flag to set |
Definition at line 176 of file stack_ptr_impl.h.
Referenced by StackPtr< T, StackSize, Alignment >::StackPtr().
|
inline |
Swap storage of *this with storage of other
stack pointer.
[in] | other | Object of type StackPtr whose content gets swapped with *this |
Definition at line 129 of file stack_ptr_impl.h.
References StackPtr< T, StackSize, Alignment >::_storage, StackPtr< T, StackSize, Alignment >::isConstructed(), StackPtr< T, StackSize, Alignment >::reset(), adtf_ddl::access_element::reset(), and a_util::memory::swap().
Referenced by a_util::memory::swap().