Template Class pointer#
Defined in File pointer.h
Class Documentation#
-
template<typename T, size_t nFixedSize = 0>
class pointer# Managed pointer class.
Buffer management class. There are two versions of buffer management, fixed buffer management (nFixedSize template parameter larger than 0) and dynamic buffer management (nFixedSize template parameter is 0). The fixed buffer management contains a fixed memory allocation of the amount of elements (capacity) and manages the size within this buffer. Copies of this pointer class will copy the buffer as well. The dynamic buffer behaves like a shared pointer. Copies of the pointer class will copy the pointer, but not the content. The lifetime of the content is managed through reference counter. The functions of this class are similar to the functions of the std::shared_ptr class.
- Template Parameters:
T – Type to use for the buffer allocation.
nFixedSize – Size of the fixed size buffer or 0 for a dynamic sized buffer.
Public Functions
-
pointer() noexcept#
Default constructor.
-
pointer(const pointer &rptr)#
Copy constructor of same pointer type.
- Parameters:
rptr – [in] Reference to the pointer to copy.
-
template<size_t nFixedSize2>
pointer(const pointer<T, nFixedSize2> &rptr)# Copy constructor of other pointer types.
- Template Parameters:
nFixedSize2 – The fixed size of the provided pointer.
- Parameters:
rptr – [in] Reference to the pointer to copy.
-
pointer(pointer &&rptr)#
Move constructor of same pointer type.
- Parameters:
rptr – [in] Reference to the pointer to copy.
-
template<size_t nFixedSize2>
pointer(pointer<T, nFixedSize2> &&rptr)# Move constructor of other pointer types.
- Template Parameters:
nFixedSize2 – The fixed size of the provided pointer.
- Parameters:
rptr – [in] Reference to the pointer to copy.
-
~pointer()#
Destructor.
-
pointer &operator=(const pointer &rptr)#
Assignment operator of same pointer type.
- Parameters:
rptr – [in] Reference to the pointer to assign.
- Returns:
Reference to this pointer.
-
template<size_t nFixedSize2>
pointer &operator=(const pointer<T, nFixedSize2> &rptr)# Assignment operator of other pointer types.
- Template Parameters:
nFixedSize2 – The fixed size of the provided pointer.
- Parameters:
rptr – [in] Reference to the pointer to assign.
- Returns:
Reference to this pointer.
-
pointer &operator=(pointer &&rptr)#
Move operator of same pointer type.
- Parameters:
rptr – [in] Reference to the pointer to assign.
- Returns:
Reference to this pointer.
-
template<size_t nFixedSize2>
pointer &operator=(pointer<T, nFixedSize2> &&rptr)# Move operator of other pointer types.
- Template Parameters:
nFixedSize2 – The fixed size of the provided pointer.
- Parameters:
rptr – [in] Reference to the pointer to assign.
- Returns:
Reference to this pointer.
-
void reset()#
Reduces the reference count and if zero deletes the allocation. Clears the pointer.
-
template<size_t nFixedSizeRight>
void swap(pointer<T, nFixedSizeRight> &rptr)# Swaps this pointer with the provided pointer. tparam nFixedSizeRight The fixed size of the provided pointer.
- Parameters:
rptr – [in] Reference to the provided pointer to swap with.
-
element_type *get() const noexcept#
Get access to the underlying buffer.
- Returns:
Pointer to the buffer.
-
element_type &operator[](size_t nIndex) const#
Get the indexed value of the pointer.
- Parameters:
nIndex – [in] Index to request the value of.
- Returns:
Reference to the indexed value.
-
operator bool() const noexcept#
Return whether a pointer is assigned.
- Returns:
Returns ‘true’ when a pointer is assigned; ‘false’ otherwise.
-
size_t size() const noexcept#
Return the amount of elements allocated for this pointer.
- Returns:
The size of the pointer.
-
void resize(size_t nSize)#
Resize the pointer.
- Parameters:
nSize – [in] Size of the new pointer.
-
size_t capacity() const noexcept#
Return the capacity (in amount of elements) this buffer can hold.
- Returns:
The capacity of the buffer pointed to by this pointer.
Public Members
-
T m_rgtData[nFixedSize] = {}#
The size of the buffer.
-
uint8_t m_rguiBuffer[aligned_size_bytes]#
The buffer aligned to 64 bits.
Public Static Attributes
-
static const size_t size_bytes = nFixedSize * sizeof(T)#
The size of this pointer allocation element in bytes.
-
static const size_t aligned_size_bytes = nFixedSize * sizeof(T) + ((nFixedSize * sizeof(T) % 8) ? (8 - nFixedSize * sizeof(T) % 8) : 0)#
The size of this pointer allocation in bytes aligned to 64-bits.