Class CObjectLifetimeWrapper#

Inheritance Relationships#

Base Types#

Class Documentation#

class CObjectLifetimeWrapper : public sdv::IInterfaceAccess, public sdv::IObjectLifetime, public sdv::IObjectDestroy#

Helper class to implement the IObjectLifetime interface for objects not supporting this.

Public Functions

CObjectLifetimeWrapper() = default#

Default constructor.

inline ~CObjectLifetimeWrapper()#

Destructor automatically destroying the object.

inline virtual void Increment() override#

Increment the lifetime. Needs to be balanced by a call to Decrement. Overload of IObjectLifetime::Increment.

inline virtual bool Decrement() override#

Decrement the lifetime. If the lifetime reaches zero, the object will be destroyed (through the exposed IObjectDestroy interface). Overload of IObjectLifetime::Decrement.

Returns:

Returns ‘true’ if the object was destroyed, false if not.

inline virtual uint32_t GetCount() const override#

Get the current lifetime count. Overload of IObjectLifetime::GetCount.

Remark

The GetCount function returns a momentary value, which can be changed at any moment.

Returns:

Returns the current counter value.

inline virtual void DestroyObject() override#

Destroy the object. Overload of IObjectDestroy::DestroyObject.

Attention

After a call of this function, all exposed interfaces render invalid and should not be used any more.

Public Members

IInterfaceAccess *m_pObject = nullptr#

The interface pointer.

std::atomic<int32_t> m_iCounter = 0#

The lifetime counter.

std::unique_ptr<CObjectLifetimeWrapper> m_ptrKeepAlive#

The one instance of this wrapper class.

Public Static Functions

static inline IInterfaceAccess *CreateWrapper(IInterfaceAccess *pObject)#

Create a object lifetime wrapper object.

Create an object lifetime wrapper object and assign the provided interface to the wrapper. The wrapper object blocks calls to IObjectDestroy since it will take ober the management of object lifetime.

Parameters:

pObject[in] Interface of the object to wrap. This object needs to expose IObjectDestroy and could expose IObjectLifetime.

Returns:

Returns an interface giving access to a IObjectLifetime interface, forwarding all other interface calls.