The Vish Visualization Shell 0.3
Vish
Public Types | Public Member Functions | Protected Member Functions | List of all members
MemCore::ReferenceBase< Object > Class Template Reference

Base class for objects which do reference counting. More...

#include <elementary/memcore/RefPtr.hpp>

Public Types

using reference_domain_t = Object
 The type of the base class.
 
using SelfPtr_t = WeakPtr< Object, Object >
 Type for a pointer to this object itself.
 

Public Member Functions

auto getObjectCountID () const noexcept
 Get a unique ID for this object in the given domain.
 
bool isIdentical (const WeakPtr< Object, Object > &PossibleSelf) const noexcept
 Check if this object is identical to the one used by the given pointer.
 
void mkAutoDestructive ()
 Marks this object as being automatically destructed, e.g.
 
refcount_t refcount () const noexcept
 The strong reference count.
 
 ReferenceBase (Object *that) noexcept
 Constructor, initializes reference counter to zero.
 
const auto & self () const
 Return weak pointer to the object self.
 
refcount_t wrefcount () const noexcept
 The weak reference count.
 

Protected Member Functions

virtual void extremeUnction ()
 A virtual function that will be called just before the object is destroyed.
 
ReferenceBaseoperator= (const ReferenceBase &R)
 Protected assignment operator (should not be called).
 
void suicide ()
 Delete this.
 
virtual ~ReferenceBase ()
 Virtual destructor.
 

Detailed Description

template<class Object>
class MemCore::ReferenceBase< Object >

Base class for objects which do reference counting.

Contains a reference counter, to be used with the RefPtr<> template.

See also
WeakPtr, StrongPtr
Note
When a child class is derived from multiple base classes, the ReferenceBase<> class should be the first one. This is required for memory leak debugging purposes, where the internal object tracer only stores void pointers

Member Function Documentation

◆ extremeUnction()

template<class Object >
virtual void MemCore::ReferenceBase< Object >::extremeUnction ( )
inlineprotectedvirtual

A virtual function that will be called just before the object is destroyed.

It will be called while the reference count is just zero, thus reference pointers are still (barely!) valid to this object. An implementation of this function is like a virtual destructor with yet intact reference pointers, whereas in a virtual destructor all reference pointers have already been invalidated. Consequently, the object itself is still valid when this function is called, but it will no longer be considered valid once the destructor is called.

Reimplemented in A< Object >, A< Object >, A< Object >, and A< Object >.

◆ getObjectCountID()

template<class Object >
auto MemCore::ReferenceBase< Object >::getObjectCountID ( ) const
inlinenoexcept

Get a unique ID for this object in the given domain.

Each ReferenceBase gets a unique such number. This object count ID serves like a unique pointer to each object, but moreover is unique for the object even if another one was living at the same memory address some time before.

Referenced by MemCore::CacheQueue::list_info().

◆ mkAutoDestructive()

template<class Object >
void MemCore::ReferenceBase< Object >::mkAutoDestructive ( )
inline

Marks this object as being automatically destructed, e.g.

it is a static or automatic variable, or it is deleted explicetly. This call increments the strong reference count, such that its lifetime is preserved over all strong pointers referring to this object.

This function is identical to calling self().ref(). The effect can be reversed by calling self().unref(), which might destroy the object in charge if no other strong pointer refers to this object. In general, there is no need to call the unref() function. Its only purpose where to keep the object alive temporarily with no strong pointer referring to it; usually, it should be simpler to just introduce a strong pointer. On the other hand, the ref() call makes sense for automatic or static objects, where "the system" holds a (not-strong) pointer to the object.

◆ operator=()

template<class Object >
ReferenceBase & MemCore::ReferenceBase< Object >::operator= ( const ReferenceBase< Object > &  R)
inlineprotected

Protected assignment operator (should not be called).

Leaves references untouched. We may assume that some child data are copied from the other reference object, but that the references to this object by itself are unchanged, i.e. just the data change due to the assigment operation, but not the references.

◆ self()

template<class Object >
const auto & MemCore::ReferenceBase< Object >::self ( ) const
inline