ezEngine  Release 25.03
ezPointerWithFlags< 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

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