ML Reference
mlRefCountedBase.h
Go to the documentation of this file.
1/*************************************************************************************
2**
3** Copyright 2011, MeVis Medical Solutions AG
4**
5** The user may use this file in accordance with the license agreement provided with
6** the Software or, alternatively, in accordance with the terms contained in a
7** written agreement between the user and MeVis Medical Solutions AG.
8**
9** For further information use the contact form at https://www.mevislab.de/contact
10**
11**************************************************************************************/
12
13#ifndef ML_REF_COUNTED_BASE_H
14#define ML_REF_COUNTED_BASE_H
15
17
18#include "mlEventSource.h"
19
20#include <ThirdPartyWarningsDisable.h>
21#include <boost/intrusive_ptr.hpp>
22#include <ThirdPartyWarningsRestore.h>
23#include <atomic>
24
25ML_START_NAMESPACE
26
27//----------------------------------------------------------------------
31{
32public:
35
38
40 virtual void incRefCount() const;
41
43 virtual void decRefCount() const;
44
46 bool isRefCountedBase() const override { return true; }
47
53 static void updateReferenceCountingIfSupported(Base* oldValue, Base* newValue, bool& isRefCountedBase);
54
58
59protected:
61 ~RefCountedBase() override;
62
64 mutable std::atomic_int_least32_t _refCount;
65};
66
67inline void intrusive_ptr_add_ref(const ML_UTILS_NAMESPACE::RefCountedBase* p)
68{
69 p->incRefCount();
70}
71
72inline void intrusive_ptr_release(const ML_UTILS_NAMESPACE::RefCountedBase* p)
73{
74 p->decRefCount();
75}
76
77ML_UTILS_END_NAMESPACE
78
80#define ML_REFCOUNTED_PTR(CLASSNAME) \
81 class CLASSNAME; \
82 typedef ::boost::intrusive_ptr<CLASSNAME> CLASSNAME##Ptr; \
83 typedef ::boost::intrusive_ptr<const CLASSNAME> CLASSNAME##ConstPtr;
84
85ML_START_NAMESPACE
86 ML_REFCOUNTED_PTR(RefCountedBase)
87ML_END_NAMESPACE
88
89#endif // __mlRefCountedBase_H
90
91
virtual void incRefCount() const
Increases the reference count.
~RefCountedBase() override
Destructor.
static void updateReferenceCountingIfSupported(Base *oldValue, Base *newValue, bool &isRefCountedBase)
virtual void decRefCount() const
Decreases the reference count (object will be deleted if the reference count is decremented to 0).
RefCountedBase(const RefCountedBase &)
Explicit copy constructor.
bool isRefCountedBase() const override
Returns whether the instance is derived from RefCountedBase.
RefCountedBase()
Constructor.
std::atomic_int_least32_t _refCount
Reference count.
#define ML_ABSTRACT_CLASS_HEADER(className)
#define ML_REFCOUNTED_PTR(CLASSNAME)
Macro that defines convenience Ptr/ConstPtr typedefs to be used instead of intrusive_ptr templates.
#define ML_UTILS_EXPORT
Definition mlUtilities.h:18
void intrusive_ptr_release(const ml::RefCountedBase *p)
void intrusive_ptr_add_ref(const ml::RefCountedBase *p)