The Vish Visualization Shell 0.3
Vish
Public Types | Public Member Functions | Public Attributes | Protected Member Functions | List of all members
MemCore::DynPtr< ObjectBase, ObjectBase > Class Template Reference

Base class for pointers to base classes. More...

#include <elementary/memcore/DynPtr.hpp>

Public Types

template<typename Object >
using DerivedDynPtr = DynPtr< Object, ObjectBase >
 Template member referring to derived DynPtrs.
 
typedef DynPtr< ObjectBase, ObjectBase > DynPtr_t
 Base class pointer.
 
using ObjectBase_t = ObjectBase
 Base class from which pointer hierarchy starts.
 

Public Member Functions

void deleteReferer ()
 Explicitely delete the intermediate referer and invalidate the internal pointer.
 
 DynPtr (const DynPtr &D)
 Copy constructor.
 
 DynPtr (const std::nullptr_t &)
 Construct from NullPtr.
 
 DynPtr (ObjectBase *Obj, const NotNullPtr &)
 Non=null constructor.
 
 DynPtr (ObjectBase *Obj, const SelfInitialize &)
 Internal constructor.
 
 DynPtr (Referer_t *SomeReferer)
 Construct from referer object.
 
bool expired () const noexcept
 check whether the current pointer is valid
 
bool force_destroy () const
 Delete the associated object unconditionally and mark this pointer as invalid.
 
const auto & getPointerID () const
 To be used as substitute for the address in memory as this one provides a more deterministic value to enhance reproducibility.
 
const type_info & getType () const noexcept
 Return type info of associated object,.
 
DynPtroperator= (const DynPtr &P) noexcept
 Assignment operator, just copies the Referer pointer.
 
ObjectBase * rawptr () const
 return pointer to referenced object, if valid pointer, otherwise NULL.
 
void ref () const
 Increment the reference count.
 
void unref () const
 Decrement the reference count.
 
bool valid () const noexcept
 check whether the current pointer is valid
 
void wref () const noexcept
 increment the weak reference count
 
void wunref () noexcept
 Decrement the weak reference count and remove the referer if it reaches zero.
 
 ~DynPtr ()
 Destructor of the dynamic pointer.
 
Validity Operators
 operator void * () const noexcept
 Check if the pointer is valid.
 
bool operator! () const noexcept
 Check if the pointer is null.
 
Analyse functions for debugging
refcount_t strong_refs () const noexcept
 Return the strong reference count, ie.
 
refcount_t weak_refs () const noexcept
 Return the weak reference count, ie.
 
Pointer arithmetic
size_t hash_value () const noexcept
 Return an integer value which is suitable for hashing.
 
const void * value () const noexcept
 Return an void* value for debug output. Must not be used otherwise!
 
std::string addrstr () const noexcept
 make a string containing hex numbers from the object's adress.
 
std::string to_string () const
 Convert information about this pointer to a human-readable form.
 
void speak (const char *s, const char *prefix="") const noexcept
 Print some debug messages to the console via printf()
 
void Speak (const char *s, const char *prefix="") const
 Print some debug messages to the console via printf(); this is a higher-level version of speak() which demangles the type names.
 
bool operator!= (const std::nullptr_t &) const noexcept
 inequality operator
 
bool operator!= (const DynPtr &other) const noexcept
 inequality operator
 
bool operator== (const DynPtr &other) const noexcept
 Equality operator.
 
bool operator< (const DynPtr &other) const noexcept
 lesser than operator
 
bool operator<= (const DynPtr &other) const noexcept
 lesser equal than operator
 
bool operator> (const DynPtr &other) const noexcept
 greater than operator
 
bool operator>= (const DynPtr &other) const noexcept
 greater than operator
 

Public Attributes

Memcore_DynPtr_pointer_ID_class_access : PointerID_t myPointerID = -1
 The intermediate referer object for indirect referencing.
 

Protected Member Functions

void assignReferer (const DynPtr &P) noexcept
 Assignment, copies the Referer pointer, used within derived classes.
 

Detailed Description

template<class ObjectBase>
class MemCore::DynPtr< ObjectBase, ObjectBase >

Base class for pointers to base classes.

Implements basic operations on pointers.

Constructor & Destructor Documentation

◆ ~DynPtr()

template<class ObjectBase >
MemCore::DynPtr< ObjectBase, ObjectBase >::~DynPtr ( )
inline

Destructor of the dynamic pointer.

It does neither touch the reference counting nor eventually delete the associated object, although it can detect a possible memory leak.

Note that even if the strong reference count is zero, the object is not destroyed.

        Data*Dptr = new Data(10);
        {
                WeakPtrImpl<Data> d = Dptr;
        }
        delete Dptr;

Member Function Documentation

◆ getType()

template<class ObjectBase >
const type_info & MemCore::DynPtr< ObjectBase, ObjectBase >::getType ( ) const
inlinenoexcept

Return type info of associated object,.

  • typeid(void) is returned if the pointer is NULL

◆ operator==()

template<class ObjectBase >
bool MemCore::DynPtr< ObjectBase, ObjectBase >::operator== ( const DynPtr< ObjectBase, ObjectBase > &  other) const
inlinenoexcept

Equality operator.

It compares the adresses of the intermediate reference object, not of the true data object. This enables comparisions with actually deleted objects when the WeakPtrImpl already is invalid: Two invalid WeakPtrImpl<>'s are ONLY equal if they both referred to the same deleted object, otherwise they are UNEQUAL, even if both are invalid and compare true to a NullPtr() !

◆ ref()

template<class ObjectBase >
void MemCore::DynPtr< ObjectBase, ObjectBase >::ref ( ) const
inline

Increment the reference count.

Note that only semi-positive refcounts are increased. A negative refcount indicates a static or automatic object, i.e. one which does not require any refcounting at all.

Note
The first referencing to a strong pointer will call deferred_initialize() . This function might possibly throw an exception.

◆ strong_refs()

template<class ObjectBase >
refcount_t MemCore::DynPtr< ObjectBase, ObjectBase >::strong_refs ( ) const
inlinenoexcept

Return the strong reference count, ie.

how many pointers keep the object alive. Note that an negative value indicates a dead object. If the returned value is null_referencer , then there is not even a referer object, ie. no more weak references exist. Actually, this cannot happen and indicates a bug, like intermediate usage of native pointers. Only somewhere in intermediate constuctor code such things are thinkable.

References MemCore::ReferenceCount::null_referencer.

◆ unref()

template<class ObjectBase >
void MemCore::DynPtr< ObjectBase, ObjectBase >::unref ( ) const
inline

Decrement the reference count.

Once it reaches zero value, the object is inevitably destroyed and the reference count is set to -1 to indicate invalidity. There is no way to reset the reference count from a negative value to a positive one. Any further ref() calls will be ignored, the object is lost forever, but its referer object may still be alive as a zombie placeholder.

References MemCore::PreDestructionTrait< Object >::predestruct().

◆ weak_refs()

template<class ObjectBase >
refcount_t MemCore::DynPtr< ObjectBase, ObjectBase >::weak_refs ( ) const
inlinenoexcept

Return the weak reference count, ie.

how many references exist to the object. Note that if only weak references exist to an object, it is likely to be a zombie.

References MemCore::ReferenceCount::null_referencer.