TaggedBaseRef< T, HANDLER, TAG, TAG_BITS, DEFAULT_VALUE, ENABLE_POINTER_CONVERSION > Class Template Reference

#include <taggedbaseref.h>

Detailed Description

template<typename T, typename HANDLER, typename TAG, Int TAG_BITS, TAG DEFAULT_VALUE = TAG(0), Bool ENABLE_POINTER_CONVERSION = true>
class maxon::TaggedBaseRef< T, HANDLER, TAG, TAG_BITS, DEFAULT_VALUE, ENABLE_POINTER_CONVERSION >

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.

Template Parameters
TType of the referenced object.
HANDLERThe reference handler implements the specific behaviour whenever a reference is changed to point to another object.
TAGType of the tag. This has to be Bool, an integral or an enumeration type.
TAG_BITSThe 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_VALUEThe default value of the tag.
ENABLE_POINTER_CONVERSIONUse 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 >::typeoperator* () 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 >::typeMakeWritable (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
 

Member Typedef Documentation

◆ ReferencedType

using ReferencedType = T

A type alias for the type the TaggedBaseRef points to.

Constructor & Destructor Documentation

◆ TaggedBaseRef() [1/4]

TaggedBaseRef ( )
default

◆ TaggedBaseRef() [2/4]

TaggedBaseRef ( T *  ptr,
TAG  tag 
)

Constructs a TaggedBaseRef, initializing pointer and tag with the given arguments.

Parameters
[in]ptrPointer with which the TaggedBaseRef is initialized, may be nullptr.
[in]tagTag value with which the TaggedBaseRef is initialized, may be nullptr.

◆ TaggedBaseRef() [3/4]

TaggedBaseRef ( const TaggedBaseRef< T, HANDLER, TAG, TAG_BITS, DEFAULT_VALUE, ENABLE_POINTER_CONVERSION > &  src)

◆ TaggedBaseRef() [4/4]

TaggedBaseRef ( TaggedBaseRef< T, HANDLER, TAG, TAG_BITS, DEFAULT_VALUE, ENABLE_POINTER_CONVERSION > &&  src)

◆ ~TaggedBaseRef()

Member Function Documentation

◆ MAXON_OPERATOR_COPY_ASSIGNMENT()

MAXON_OPERATOR_COPY_ASSIGNMENT ( TaggedBaseRef< T, HANDLER, TAG, TAG_BITS, DEFAULT_VALUE, ENABLE_POINTER_CONVERSION >  )

◆ MAXON_OPERATOR_MOVE_ASSIGNMENT()

MAXON_OPERATOR_MOVE_ASSIGNMENT ( TaggedBaseRef< T, HANDLER, TAG, TAG_BITS, DEFAULT_VALUE, ENABLE_POINTER_CONVERSION >  )

◆ Reset()

void Reset ( )

Resets pointer to nullptr and tag value to DEFAULT_VALUE. This includes the proper release of the reference.

◆ operator T*()

operator T* ( ) const

User-defined conversion to T*, unpacking the internal pointer.

Returns
Internal pointer.

◆ operator Bool()

operator Bool ( ) const
explicit

Checks if the pointer is valid (i.e., not a nullptr).

Returns
True if the internal pointer is not a nullptr.

◆ operator->()

T* operator-> ( ) const

Allows direct access to the members of the pointee. You have to check for a nullptr before.

Returns
Internal pointer.

◆ operator*()

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.

Note
Not available for T = void.
Returns
Pointee as a reference.

◆ GetPointer()

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.

Returns
Internal pointer.

◆ SetPointer()

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.

Parameters
[in]ptrNew pointer for the TaggedBaseRef.

◆ GetTag()

TAG GetTag ( ) const

Returns tag value of the TaggedBaseRef.

Returns
Current tag value.

◆ SetTag()

void SetTag ( TAG  t)

Sets tag value of this TaggedBaseRef to t. The pointer won't be changed.

Parameters
[in]tNew tag value for the TaggedBaseRef.

◆ MAXON_OPERATOR_EQUALITY_HASHCODE()

MAXON_OPERATOR_EQUALITY_HASHCODE ( TaggedBaseRef< T, HANDLER, TAG, TAG_BITS, DEFAULT_VALUE, ENABLE_POINTER_CONVERSION >  ,
_ptr   
)

◆ MakeWritable()

ResultRef<typename std::remove_const<T>::type> MakeWritable ( Bool  resetOnError = true)

◆ ToString()

SFINAEHelper<String, T>::type ToString ( const FormatStatement format = nullptr) const

Returns a String representation of this @CLASS.

Parameters
[in]formatStatementNullptr or additional formatting instruction.
Returns
String representation of this @CLASS.

◆ PrivateSetTarget()

void PrivateSetTarget ( ResultPtr< T >  src)

Member Data Documentation

◆ TAG_MASK

const UInt TAG_MASK
static

The bit mask for tag values.

◆ _ptr

UInt _ptr
private