wxMaxima
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions
CellPtrBase Class Reference

An implementation detail for the type-specific templated cell pointers. More...

#include <CellPtr.h>

Inheritance diagram for CellPtrBase:
[legend]

Public Member Functions

 operator bool () const noexcept
 
void reset () noexcept
 
auto cmpPointers (const CellPtrBase &o) const noexcept
 This is exactly like the spaceship operator in C++20.
 
auto cmpObjects (const CellPtrBase &o) const noexcept
 This is the spaceship operator acting on pointed-to objects.
 
auto cmpObjects (const Observed *o) const noexcept
 This is the spaceship operator acting on pointed-to objects.
 
bool IsNull () const
 
bool HasOneObserved () const
 
bool HasControlBlock () const
 

Static Public Member Functions

template<typename U >
static bool constexpr is_pointer ()
 
static size_t GetLiveInstanceCount () noexcept
 

Protected Member Functions

 CellPtrBase (Observed *obj=nullptr) noexcept
 
 CellPtrBase (const CellPtrBase &o) noexcept
 
 CellPtrBase (CellPtrBase &&o) noexcept
 
CellPtrBaseoperator= (const CellPtrBase &o) noexcept
 
CellPtrBaseoperator= (CellPtrBase &&o) noexcept
 
Observedbase_get () const noexcept
 
void base_reset (Observed *obj=nullptr) noexcept
 

Static Protected Member Functions

static int CmpAddresses (const void *a, const void *b) noexcept
 A total order over two (possibly unrelated) addresses, usable with < 0 / == 0 / > 0. Compares them as unsigned integers rather than via pointer subtraction: see the GH #2208 comment on cmpObjects() below.
 

Detailed Description

An implementation detail for the type-specific templated cell pointers.

A CellPtrBase (and thus the derived CellPtr) can be in one of 3 states:

  1. Pointing to no object: its m_ptr is null.
  2. A sole pointer to an object: its m_ptr points to the Observed, and observed's m_ptr points back at this pointer.
  3. One of many pointers to the object: its m_ptr points to the Observed::ControlBlock, and the observed's m_ptr also points to the control block.

Member Function Documentation

◆ base_reset()

void CellPtrBase::base_reset ( Observed obj = nullptr)
protectednoexcept

Different objects must have control blocks that are either null or non-null but different.

◆ cmpObjects()

auto CellPtrBase::cmpObjects ( const CellPtrBase o) const
inlinenoexcept

This is the spaceship operator acting on pointed-to objects.

GH #2208: this used to be a plain base_get() - o.base_get() pointer subtraction. That is undefined behavior for two pointers into unrelated objects, and in practice, on 32-bit architectures, it can silently produce the wrong sign: a signed ptrdiff_t subtraction of two addresses spread widely across the (much smaller) 32-bit address space can overflow and wrap around, which a 64-bit build's much sparser address space essentially never triggers. Comparing the two addresses as unsigned integers instead is well-defined on any architecture and gives the total order operator< (used via cmpObjects() < 0) actually needs.


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