TfPointerAndBits< T > Class Template Reference

This class stores a T * and a small integer in the space of a T *. More...

Public Member Functions

constexpr TfPointerAndBits () noexcept
 Constructor. More...
 
constexpr TfPointerAndBits (T *p, uintptr_t bits=0) noexcept
 Constructor. Set the pointer to p, and the bits to bits. More...
 
constexpr uintptr_t GetMaxValue () const
 
constexpr uintptr_t GetNumBitsValues () const
 
TfPointerAndBitsoperator= (T *ptr) noexcept
 Assignment. Leaves bits unmodified. More...
 
constexpr T * operator-> () const noexcept
 Indirection. More...
 
constexpr T & operator * () const noexcept
 Dereference. More...
 
template<class Integral >
constexpr Integral BitsAs () const noexcept
 Retrieve the stored bits as the integral type Integral. More...
 
template<class Integral >
void SetBits (Integral val) noexcept
 Set the stored bits. No static range checking is performed. More...
 
void Set (T *ptr) noexcept
 Set the pointer value to ptr. More...
 
template<class Integral >
void Set (T *ptr, Integral val) noexcept
 Set the pointer value to ptr and the bits to val. More...
 
constexpr T * Get () const noexcept
 Retrieve the pointer. More...
 
constexpr uintptr_t GetLiteral () const noexcept
 Retrieve the raw underlying value. More...
 
void Swap (TfPointerAndBits &other) noexcept
 Swap this PointerAndBits with other. More...
 

Detailed Description

template<class T>
class TfPointerAndBits< T >

This class stores a T * and a small integer in the space of a T *.

The number of bits possible to store depends on the alignment of T. The number of distinct values representable by the bits and the maximal value are exposed via the compile time constants NumBitsValues and MaxValue, respectively.

The bits may be set and retrieved as any integral type. The pointer value and the bits value may be set and retrieved independently.

Definition at line 53 of file pointerAndBits.h.

Constructor & Destructor Documentation

◆ TfPointerAndBits() [1/2]

constexpr TfPointerAndBits ( )
inlinenoexcept

Constructor.

Pointer is initialized to null, bits are initialized to zero.

Definition at line 81 of file pointerAndBits.h.

◆ TfPointerAndBits() [2/2]

constexpr TfPointerAndBits ( T *  p,
uintptr_t  bits = 0 
)
inlineexplicitnoexcept

Constructor. Set the pointer to p, and the bits to bits.

Definition at line 87 of file pointerAndBits.h.

Member Function Documentation

◆ BitsAs()

constexpr Integral BitsAs ( ) const
inlinenoexcept

Retrieve the stored bits as the integral type Integral.

Definition at line 120 of file pointerAndBits.h.

◆ Get()

constexpr T* Get ( ) const
inlinenoexcept

Retrieve the pointer.

Definition at line 145 of file pointerAndBits.h.

◆ GetLiteral()

constexpr uintptr_t GetLiteral ( ) const
inlinenoexcept

Retrieve the raw underlying value.

This can be useful for doing literal equality checks between two instances. The only guarantees are that this has the same bit pattern as the pointer value if the bits are 0, and will compare equal to another instance when both have identical pointer and bits values.

Definition at line 154 of file pointerAndBits.h.

◆ operator *()

constexpr T& operator * ( ) const
inlinenoexcept

Dereference.

Definition at line 114 of file pointerAndBits.h.

◆ operator->()

constexpr T* operator-> ( ) const
inlinenoexcept

Indirection.

Definition at line 109 of file pointerAndBits.h.

◆ operator=()

TfPointerAndBits& operator= ( T *  ptr)
inlinenoexcept

Assignment. Leaves bits unmodified.

Definition at line 103 of file pointerAndBits.h.

◆ Set() [1/2]

void Set ( T *  ptr)
inlinenoexcept

Set the pointer value to ptr.

Definition at line 134 of file pointerAndBits.h.

◆ Set() [2/2]

void Set ( T *  ptr,
Integral  val 
)
inlinenoexcept

Set the pointer value to ptr and the bits to val.

Definition at line 140 of file pointerAndBits.h.

◆ SetBits()

void SetBits ( Integral  val)
inlinenoexcept

Set the stored bits. No static range checking is performed.

Definition at line 129 of file pointerAndBits.h.

◆ Swap()

void Swap ( TfPointerAndBits< T > &  other)
inlinenoexcept

Swap this PointerAndBits with other.

Definition at line 159 of file pointerAndBits.h.


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