7 #include <nx/sdk/helpers/lib_context.h> 8 #include <nx/sdk/i_ref_countable.h> 47 return m_refCountHolderDelegate ? m_refCountHolderDelegate->addRef() : ++m_refCount;
55 if (m_refCountHolderDelegate)
58 const int newRefCounter = --m_refCount;
59 if (newRefCounter == 0)
60 delete m_refCountable;
66 if (m_refCountHolderDelegate)
67 return m_refCountHolderDelegate->refCount();
72 mutable std::atomic<int> m_refCount{1};
73 const IRefCountable*
const m_refCountable =
nullptr;
74 const RefCountableHolder*
const m_refCountHolderDelegate =
nullptr;
82 template<
class RefCountableInterface>
93 if (
const auto refCountableRegistry = libContext().refCountableRegistry())
94 refCountableRegistry->notifyDestroyed(
this, refCount());
97 virtual int addRef()
const override {
return m_refCountableHolder.addRef(); }
98 virtual int releaseRef()
const override {
return m_refCountableHolder.
releaseRef(); }
100 int refCount()
const {
return m_refCountableHolder.refCount(); }
103 RefCountable(): m_refCountableHolder(static_cast<const IRefCountable*>(
this))
105 if (
const auto refCountableRegistry = libContext().refCountableRegistry())
106 refCountableRegistry->notifyCreated(
this, refCount());
RefCountableHolder(const RefCountableHolder *delegate)
Definition: ref_countable.h:43
RefCountableHolder(const IRefCountable *refCountable)
Definition: ref_countable.h:38
int releaseRef() const
Definition: ref_countable.h:53
Definition: device_agent.h:12
Definition: ref_countable.h:23
Definition: i_ref_countable.h:48
Definition: ref_countable.h:83