#include <taggedbaseref.h>
A TaggedBaseRef is similar to a BaseRef, but it allows to save some extra information (the tag) in the lowest bits of the internal pointer while still having the size of a pointer.
Pointers obtained through the DefaultAllocator have a guaranteed minimal alignment of DefaultAllocator::MIN_ALIGNMENT_MASK. The mask is 15 which means that the lowest 4 bits are guaranteed to be zero. With a TaggedBaseRef you can use those 4 bits for extra information. For other allocators the number of usable bits will be different.
T | Type of the referenced object. |
HANDLER | The reference handler implements the specific behaviour whenever a reference is changed to point to another object. |
TAG | Type of the tag. This has to be Bool, an integral or an enumeration type. |
TAG_BITS | The number of bits to use for the tag. In debug configuration it is checked that pointers have sufficient alignment, and that tag values don't make use of exceeding bits. |
DEFAULT_VALUE | The default value of the tag. |
ENABLE_POINTER_CONVERSION | Use true (the default) to allow the conversion operator to T*. |
Public Types | |
using | ReferencedType = T |
Public Member Functions | |
TaggedBaseRef ()=default | |
TaggedBaseRef (T *ptr, TAG tag) | |
TaggedBaseRef (const TaggedBaseRef &src) | |
MAXON_OPERATOR_COPY_ASSIGNMENT (TaggedBaseRef) | |
TaggedBaseRef (TaggedBaseRef &&src) | |
MAXON_OPERATOR_MOVE_ASSIGNMENT (TaggedBaseRef) | |
~TaggedBaseRef () | |
void | Reset () |
operator T* () const | |
operator Bool () const | |
T * | operator-> () const |
std::conditional< STD_IS_REPLACEMENT(same, const T, const void), DeleteReturnType01, T >::type & | operator* () const |
T * | GetPointer () const |
void | SetPointer (T *ptr) |
TAG | GetTag () const |
void | SetTag (TAG t) |
MAXON_OPERATOR_EQUALITY_HASHCODE (TaggedBaseRef, _ptr) | |
ResultRef< typename std::remove_const< T >::type > | MakeWritable (Bool resetOnError=true) |
SFINAEHelper< String, T >::type | ToString (const FormatStatement *format=nullptr) const |
void | PrivateSetTarget (ResultPtr< T > src) |
Static Public Attributes | |
static const UInt | TAG_MASK |
Private Attributes | |
UInt | _ptr |
using ReferencedType = T |
A type alias for the type the TaggedBaseRef points to.
|
default |
TaggedBaseRef | ( | T * | ptr, |
TAG | tag | ||
) |
Constructs a TaggedBaseRef, initializing pointer and tag with the given arguments.
[in] | ptr | Pointer with which the TaggedBaseRef is initialized, may be nullptr. |
[in] | tag | Tag value with which the TaggedBaseRef is initialized, may be nullptr. |
TaggedBaseRef | ( | const TaggedBaseRef< T, HANDLER, TAG, TAG_BITS, DEFAULT_VALUE, ENABLE_POINTER_CONVERSION > & | src | ) |
TaggedBaseRef | ( | TaggedBaseRef< T, HANDLER, TAG, TAG_BITS, DEFAULT_VALUE, ENABLE_POINTER_CONVERSION > && | src | ) |
~TaggedBaseRef | ( | ) |
MAXON_OPERATOR_COPY_ASSIGNMENT | ( | TaggedBaseRef< T, HANDLER, TAG, TAG_BITS, DEFAULT_VALUE, ENABLE_POINTER_CONVERSION > | ) |
MAXON_OPERATOR_MOVE_ASSIGNMENT | ( | TaggedBaseRef< T, HANDLER, TAG, TAG_BITS, DEFAULT_VALUE, ENABLE_POINTER_CONVERSION > | ) |
void Reset | ( | ) |
Resets pointer to nullptr and tag value to DEFAULT_VALUE. This includes the proper release of the reference.
operator T* | ( | ) | const |
User-defined conversion to T*, unpacking the internal pointer.
|
explicit |
Checks if the pointer is valid (i.e., not a nullptr).
T* operator-> | ( | ) | const |
Allows direct access to the members of the pointee. You have to check for a nullptr before.
std::conditional<STD_IS_REPLACEMENT(same, const T, const void), DeleteReturnType01, T>::type& operator* | ( | ) | const |
Dereferences the TaggedBaseRef. This yields the pointee as a reference. You have to check for a nullptr before.
T* GetPointer | ( | ) | const |
Returns the internal pointer of the TaggedBaseRef. You can also use operator-> to access members of the pointee directly through the TaggedBaseRef.
void SetPointer | ( | T * | ptr | ) |
Sets the pointer of this TaggedBaseRef to ptr. This includes proper reference handling according to HANDLER. The tag value won't be changed.
[in] | ptr | New pointer for the TaggedBaseRef. |
TAG GetTag | ( | ) | const |
Returns tag value of the TaggedBaseRef.
void SetTag | ( | TAG | t | ) |
Sets tag value of this TaggedBaseRef to t. The pointer won't be changed.
[in] | t | New tag value for the TaggedBaseRef. |
MAXON_OPERATOR_EQUALITY_HASHCODE | ( | TaggedBaseRef< T, HANDLER, TAG, TAG_BITS, DEFAULT_VALUE, ENABLE_POINTER_CONVERSION > | , |
_ptr | |||
) |
SFINAEHelper<String, T>::type ToString | ( | const FormatStatement * | format = nullptr | ) | const |
void PrivateSetTarget | ( | ResultPtr< T > | src | ) |
|
static |
The bit mask for tag values.
|
private |