ML Reference
ml::RefCountedBase Class Reference

#include <mlRefCountedBase.h>

Inheritance diagram for ml::RefCountedBase:
ml::EventSource ml::Base

Public Member Functions

 RefCountedBase ()
 Constructor.
 RefCountedBase (const RefCountedBase &)
 Explicit copy constructor.
virtual void incRefCount () const
 Increases the reference count.
virtual void decRefCount () const
 Decreases the reference count (object will be deleted if the reference count is decremented to 0).
bool isRefCountedBase () const override
 Returns whether the instance is derived from RefCountedBase.
Public Member Functions inherited from ml::EventSource
 EventSource ()
 EventSource (const EventSource &evSource)
 ~EventSource () override
void addEventListener (BaseEventCallback *cb, void *userData)
void removeEventListener (BaseEventCallback *cb, void *userData)
bool hasEventListeners () const
Public Member Functions inherited from ml::Base
 Base ()
 Constructor.
virtual ~Base ()
 Destructor.
virtual BasedeepCopy () const
bool isOfAllowedType (const std::vector< const RuntimeType * > &types) const
virtual std::string detailString () const
virtual bool implementsPersistence (PersistenceInterface) const
virtual std::string persistentState () const
 Returns a string describing the object's internal state.
virtual void setPersistentState (const std::string &state)
virtual void addStateToTree (TreeNode *) const
 Attaches the object state as children of the given parent node.
virtual void readStateFromTree (TreeNode *)
 Reads the object state from the children of the given parent node.
virtual void writeTo (AbstractPersistenceOutputStream *) const
virtual void readFrom (AbstractPersistenceInputStream *, int)

Static Public Member Functions

static void updateReferenceCountingIfSupported (Base *oldValue, Base *newValue, bool &isRefCountedBase)

Protected Member Functions

 ~RefCountedBase () override
 Destructor.
Protected Member Functions inherited from ml::EventSource
void sendEvent (BaseEvent *event, void *skipListener=nullptr)

Protected Attributes

std::atomic_int_least32_t _refCount
 Reference count.

Additional Inherited Members

Public Types inherited from ml::Base
enum  PersistenceInterface { PersistenceByString , PersistenceByTreeNode , PersistenceByStream }
 This enum describes the different persistence interfaces available. More...

Detailed Description

RefCountedBase class adds intrusive reference counting support to the Base class. It should be used together with boost::intrusive_ptr and the ML_REFCOUNTED_PTR macro.

Definition at line 30 of file mlRefCountedBase.h.

Constructor & Destructor Documentation

◆ RefCountedBase() [1/2]

ml::RefCountedBase::RefCountedBase ( )

Constructor.

Referenced by RefCountedBase(), and updateReferenceCountingIfSupported().

◆ RefCountedBase() [2/2]

ml::RefCountedBase::RefCountedBase ( const RefCountedBase & )

Explicit copy constructor.

References RefCountedBase().

◆ ~RefCountedBase()

ml::RefCountedBase::~RefCountedBase ( )
overrideprotected

Destructor.

Macro for the declaration of the runtime type system methods, defined in mlRuntimeSubClass.h.

Member Function Documentation

◆ decRefCount()

virtual void ml::RefCountedBase::decRefCount ( ) const
virtual

Decreases the reference count (object will be deleted if the reference count is decremented to 0).

◆ incRefCount()

virtual void ml::RefCountedBase::incRefCount ( ) const
virtual

Increases the reference count.

◆ isRefCountedBase()

bool ml::RefCountedBase::isRefCountedBase ( ) const
inlineoverridevirtual

Returns whether the instance is derived from RefCountedBase.

Reimplemented from ml::Base.

Definition at line 46 of file mlRefCountedBase.h.

Referenced by updateReferenceCountingIfSupported().

◆ updateReferenceCountingIfSupported()

void ml::RefCountedBase::updateReferenceCountingIfSupported ( Base * oldValue,
Base * newValue,
bool & isRefCountedBase )
static

Helper method that handles incrementing/decrementing of the reference count if base instances support it. It decrements the reference count of oldValue if supported and not NULL. It increments the reference count of newValue if supported and not NULL. isRefCountedBase must indicate whether oldValue supported reference counting. isRefCountedBase will be set to true if the newValue supports reference counting.

References isRefCountedBase(), and RefCountedBase().

Member Data Documentation

◆ _refCount

std::atomic_int_least32_t ml::RefCountedBase::_refCount
mutableprotected

Reference count.

Definition at line 64 of file mlRefCountedBase.h.


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