Loading...
Searching...
No Matches
TfPointerAndBits< T > Class Template Reference

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

#include <pointerAndBits.h>

Public Member Functions

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

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 ( )
inlineconstexprnoexcept

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 
)
inlineexplicitconstexprnoexcept

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
inlineconstexprnoexcept

Retrieve the stored bits as the integral type Integral.

Definition at line 120 of file pointerAndBits.h.

◆ Get()

constexpr T * Get ( ) const
inlineconstexprnoexcept

Retrieve the pointer.

Definition at line 147 of file pointerAndBits.h.

◆ GetLiteral()

constexpr uintptr_t GetLiteral ( ) const
inlineconstexprnoexcept

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 156 of file pointerAndBits.h.

◆ GetMaxValue()

constexpr uintptr_t GetMaxValue ( ) const
inlineconstexpr

Definition at line 94 of file pointerAndBits.h.

◆ GetNumBitsValues()

constexpr uintptr_t GetNumBitsValues ( ) const
inlineconstexpr

Definition at line 98 of file pointerAndBits.h.

◆ operator*()

constexpr T & operator* ( ) const
inlineconstexprnoexcept

Dereference.

Definition at line 114 of file pointerAndBits.h.

◆ operator->()

constexpr T * operator-> ( ) const
inlineconstexprnoexcept

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 136 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 142 of file pointerAndBits.h.

◆ SetBits()

void SetBits ( Integral  val)
inlinenoexcept

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

Definition at line 131 of file pointerAndBits.h.

◆ Swap()

void Swap ( TfPointerAndBits< T > &  other)
inlinenoexcept

Swap this PointerAndBits with other.

Definition at line 161 of file pointerAndBits.h.


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