XII Release 0.1.0
Loading...
Searching...
No Matches
xiiPointerWithFlags< PtrType, NumFlagBits > Class Template Reference

A wrapper around a raw pointer that allows to use the lower N bits for flags. More...

#include <PointerWithFlags.h>

Public Member Functions

 xiiPointerWithFlags ()=default
 Initializes the pointer and flags with zero.
 
 xiiPointerWithFlags (PtrType *pPtr, xiiUInt8 uiFlags=0)
 Initializes the pointer and flags.
 
void SetPtrAndFlags (PtrType *pPtr, xiiUInt8 uiFlags)
 Changes the pointer and flags.
 
const PtrType * GetPtr () const
 Returns the masked off pointer value.
 
PtrType * GetPtr ()
 Returns the masked off pointer value.
 
void SetPtr (PtrType *pPtr)
 Changes the pointer value only. Flags stay unchanged.
 
xiiUInt8 GetFlags () const
 Returns the flags value only.
 
void SetFlags (xiiUInt8 uiFlags)
 Changes only the flags value. The given value must fit into the reserved bits.
 
 operator PtrType * ()
 Returns the masked off pointer value.
 
 operator const PtrType * () const
 Returns the masked off pointer value.
 
void operator= (PtrType *pPtr)
 Changes the pointer value only. Flags stay unchanged.
 
template<typename = typename std::enable_if<std::is_const<PtrType>::value == false>>
bool operator== (const PtrType *pPtr) const
 Compares the pointer part for equality (flags are ignored).
 
bool operator== (const xiiPointerWithFlags< PtrType, NumFlagBits > &rhs) const
 
bool operator== (PtrType *pPtr) const
 Compares the pointer part for equality (flags are ignored)
 
bool operator== (std::nullptr_t) const
 Compares the pointer part for equality (flags are ignored)
 
 operator bool () const
 Checks whether the pointer part is not nullptr (flags are ignored)
 
const PtrType * operator-> () const
 Dereferences the pointer.
 
PtrType * operator-> ()
 Dereferences the pointer.
 
const PtrType & operator* () const
 Dereferences the pointer.
 
PtrType & operator* ()
 Dereferences the pointer.
 

Detailed Description

template<typename PtrType, xiiUInt8 NumFlagBits = 2>
class xiiPointerWithFlags< PtrType, NumFlagBits >

A wrapper around a raw pointer that allows to use the lower N bits for flags.

When accessing the pointer, the lower N bits are masked off. Typically one can safely store 3 bits in the lower bits of a pointer as most data is 8 byte aligned, especially when it was heap allocated.


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