32 #include "AddonString.h" 35 #ifdef XBMC_ADDON_DEBUG_MEMORY 36 #include "utils/log.h" 38 #include "AddonUtils.h" 60 mutable std::atomic<long> refs;
61 bool m_isDeallocating =
false;
66 #ifdef XBMC_ADDON_DEBUG_MEMORY 84 std::unique_lock<CCriticalSection> lock(*
this);
85 m_isDeallocating =
true;
98 inline const char* GetClassname()
const {
return typeid(*this).name(); }
99 inline LanguageHook* GetLanguageHook() {
return languageHook; }
108 static short getNumAddonClasses();
110 #ifdef XBMC_ADDON_DEBUG_MEMORY 116 #ifndef XBMC_ADDON_DEBUG_MEMORY 119 #ifdef LOG_LIFECYCLE_EVENTS 120 CLog::Log(LOGDEBUG,
"NEWADDON REFCNT decrementing to {} on {} 0x{:x}", ct, GetClassname(),
121 (
long)(((
void*)
this)));
131 #ifdef XBMC_ADDON_DEBUG_MEMORY 137 #ifndef XBMC_ADDON_DEBUG_MEMORY 139 #ifdef LOG_LIFECYCLE_EVENTS 140 CLog::Log(LOGDEBUG,
"NEWADDON REFCNT incrementing to {} on {} 0x{:x}", ++refs, GetClassname(),
141 (
long)(((
void*)
this)));
154 template <
class T>
class Ref 158 inline Ref() : ac(NULL) {}
159 inline Ref(
const T* _ac) : ac(const_cast<T*>(_ac)) {
if (ac) ac->Acquire(); refcheck; }
162 inline Ref(
Ref<T> const & oref) : ac(const_cast<T*>(oref.get())) {
if (ac) ac->Acquire(); refcheck; }
163 template<
class O>
inline Ref(
Ref<O> const & oref) : ac(static_cast<T*>(oref.get())) {
if (ac) ac->Acquire(); refcheck; }
183 { T* tmp = ac; ac =
const_cast<T*
>(oref.get());
if (ac) ac->Acquire();
if (tmp) tmp->Release(); refcheck;
return *
this; }
185 inline T* operator->()
const { refcheck;
return ac; }
190 inline operator T*()
const { refcheck;
return ac; }
191 inline T*
get()
const { refcheck;
return ac; }
192 inline T& getRef()
const { refcheck;
return *ac; }
194 inline ~
Ref() { refcheck;
if (ac) ac->Release(); }
195 inline bool isNull()
const { refcheck;
return ac == NULL; }
196 inline bool isNotNull()
const { refcheck;
return ac != NULL; }
197 inline bool isSet()
const { refcheck;
return ac != NULL; }
198 inline bool operator!()
const { refcheck;
return ac == NULL; }
199 inline bool operator==(
const AddonClass::Ref<T>& oref)
const { refcheck;
return ac == oref.ac; }
200 inline bool operator<(const AddonClass::Ref<T>& oref)
const { refcheck;
return ac < oref.ac; }
203 template<
class O>
inline void reset(
Ref<O> const & oref) { refcheck; (*this) =
static_cast<T*
>(oref.get()); refcheck; }
204 template<
class O>
inline void reset(O * oref) { refcheck; (*this) =
static_cast<T*
>(oref); refcheck; }
205 inline void reset() { refcheck;
if (ac) ac->Release(); ac = NULL; }
This class is a smart pointer for a Referenced class.
Definition: AddonClass.h:154
Ref< T > & operator=(Ref< T > const &oref)
operator= should work with either another smart pointer or a pointer since it will be able to convert...
Definition: AddonClass.h:182
Defining LOG_LIFECYCLE_EVENTS will log all instantiations, deletions and also reference countings (in...
Definition: Addon.cpp:25
virtual void deallocating()
This method is meant to be called from the destructor of the lowest level class.
Definition: AddonClass.h:82
static short getNextClassIndex()
This is meant to be called during static initialization and so isn't synchronized.
Definition: LanguageHook.h:29
bool isDeallocating()
This method should be called while holding a Synchronize on the object.
Definition: AddonClass.h:106
This class is the superclass for all reference counted classes in the api.
Definition: AddonClass.h:57