Plasma Engine  2.0
Loading...
Searching...
No Matches
plPointerWithFlags< 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

 plPointerWithFlags ()=default
 Initializes the pointer and flags with zero.
 
 plPointerWithFlags (PtrType *pPtr, plUInt8 uiFlags=0)
 Initializes the pointer and flags.
 
void SetPtrAndFlags (PtrType *pPtr, plUInt8 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.
 
plUInt8 GetFlags () const
 Returns the flags value only.
 
void SetFlags (plUInt8 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 plPointerWithFlags< PtrType, NumFlagBits > &rhs) const
 
 PL_ADD_DEFAULT_OPERATOR_NOTEQUAL (const plPointerWithFlags< PtrType, NumFlagBits > &)
 
bool operator== (PtrType *pPtr) const
 Compares the pointer part for equality (flags are ignored)
 
 PL_ADD_DEFAULT_OPERATOR_NOTEQUAL (PtrType *)
 
bool operator== (std::nullptr_t) const
 Compares the pointer part for equality (flags are ignored)
 
 PL_ADD_DEFAULT_OPERATOR_NOTEQUAL (std::nullptr_t)
 
 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, plUInt8 NumFlagBits = 2>
class plPointerWithFlags< 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: