# class RefObject | A reference counted object. More...
Full name | `TelEngine::RefObject`
Definition | `#include <yateclass.h>`
Inherits | TelEngine::GenObject [public ]
Inherited by | AnalogLine, AnalogLineGroup, Array, CallEndpoint, ChanAssist, Channel, ClientAccount, ClientChannel, ClientContact, ClientResource, DataConsumer, DataEndpoint, DataNode, DataSource, DataTranslator, DurationUpdate, GTT, IAXFrame, IAXFrameOut, IAXFullFrame, IAXInfoElement, IAXInfoElementBinary, IAXInfoElementNumeric, IAXInfoElementString, IAXMetaTrunkFrame, IAXTransaction, IAXTrunkInfo, ISDNFrame, ISDNIUA, ISDNIUAClient, ISDNLayer2, ISDNLayer3, ISDNQ921, ISDNQ921, ISDNQ921Management, ISDNQ921Management, ISDNQ921Management, ISDNQ921Passive, ISDNQ921Passive, ISDNQ931, ISDNQ931Call, ISDNQ931CallMonitor, ISDNQ931Message, ISDNQ931Monitor, JBClientStream, JBClusterStream, JBEvent, JBServerStream, JBStream, JBStreamSetList, JGSession, JGSession0, JGSession1, JGSessionContent, JsArray, JsFunction, JsObject, JsRegExp, MGCPEndpoint, MGCPMessage, MGCPTransaction, MessageHook, MessagePostHook, MessageQueue, MucRoom, MucRoomMember, SCCP, SCCPManagement, SCCPUser, SIGAdaptClient, SIGAdaptServer, SIGAdaptation, SIGTransport, SIPMessage, SIPParty, SIPTransaction, SS7AnsiSccpManagement, SS7BICC, SS7ISUP, SS7ISUPCall, SS7ItuSccpManagement, SS7L2User, SS7L3User, SS7Layer2, SS7Layer3, SS7Layer4, SS7M2PA, SS7M2UA, SS7M2UAClient, SS7M3UA, SS7MTP2, SS7MTP2, SS7MTP3, SS7MTP3, SS7Management, SS7MsgISUP, SS7MsgSCCP, SS7MsgSNM, SS7MsgSccpReassemble, SS7Route, SS7Router, SS7Router, SS7SCCP, SS7SCCP, SS7SUA, SS7TCAP, SS7TCAPANSI, SS7TCAPITU, SS7TCAPTransaction, SS7TCAPTransactionANSI, SS7TCAPTransactionITU, SS7TUP, SS7Testing, SccpLocalSubsystem, SccpRemote, SccpSubsystem, ScriptCode, ScriptContext, SignallingCall, SignallingCircuit, SignallingCircuitGroup, SignallingCircuitSpan, SignallingComponent, SignallingInterface, SignallingMessage, SignallingReceiver, SubsystemStatusTest, TCAPUser, ThreadedSource, XmlElementOut
List of all Methods
Annotated List
Files
Globals
Hierarchy
Index

#### Public Methods

- RefObject ()
- virtual ~RefObject ()
- virtual void* getObject (const String& name) const
- virtual bool alive () const
- bool ref ()
- bool deref ()
- inline int refcount () const
- virtual void destruct ()

#### Public Static Methods

- static bool efficientIncDec ()

#### Protected Methods

- virtual void zeroRefs ()
- bool resurrect ()
- virtual void destroyed ()

## Detailed Description

A reference counted object. Whenever using multiple inheritance you should inherit this class virtually.

RefObject () | ### RefObject

The constructor initializes the reference counter to 1! Use deref() to destruct the object when safe

~RefObject () | ### ~RefObject

[virtual]

Destructor.

void* getObject (const String& name) | ### getObject

[const virtual]

Get a pointer to a derived class given that class name

Parameters:

name | Name of the class we are asking for

Returns: Pointer to the requested class or NULL if this object doesn't implement it

Reimplemented from GenObject.

bool alive () | ### alive

[const virtual]

Check if the object is still referenced and safe to access. Note that you should not trust this result unless the object is locked by other means.

Returns: True if the object is referenced and safe to access

Reimplemented from GenObject.

bool ref () | ### ref

Increments the reference counter if not already zero

Returns: True if the object was successfully referenced and is safe to access

bool deref () | ### deref

Decrements the reference counter, destroys the object if it reaches zero

     // Deref this object, return quickly if the object was deleted
     if (deref()) return;

Returns: True if the object may have been deleted, false if it still exists and is safe to access

inline int refcount () | ### refcount

[const]

Get the current value of the reference counter

Returns: The value of the reference counter

void destruct () | ### destruct

[virtual]

Refcounted objects should just have the counter decremented. That will destroy them only when the refcount reaches zero.

Reimplemented from GenObject.

bool efficientIncDec () | ### efficientIncDec

[static]

Check if reference counter manipulations are efficient on this platform. If platform does not support atomic operations a mutex pool is used.

Returns: True if refcount uses atomic integer operations

void zeroRefs () | ### zeroRefs

[protected virtual]

This method is called when the reference count reaches zero after unlocking the mutex if the call to zeroRefsTest() returned true. The default behaviour is to delete the object.

bool resurrect () | ### resurrect

[protected]

Bring the object back alive by setting the reference counter to one. Note that it works only if the counter was zero previously

Returns: True if the object was resurrected - its name may be Lazarus ;-)

void destroyed () | ### destroyed

[protected virtual]

Pre-destruction notification, called just before the object is deleted. Unlike in the destructor it is safe to call virtual methods here. Reimplementing this method allows to perform any object cleanups.

Generated by: paulc on bussard on Mon Feb 10 13:15:47 2014, using kdoc 2.0a54.