MeVisLab Toolbox 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
25
26//----------------------------------------------------------------------
30{
31public:
34
37
39 virtual void incRefCount() const;
40
42 virtual void decRefCount() const;
43
45 bool isRefCountedBase() const override { return true; }
46
52 static void updateReferenceCountingIfSupported(Base* oldValue, Base* newValue, bool& isRefCountedBase);
53
57
58protected:
60 ~RefCountedBase() override;
61
64};
65
66inline void intrusive_ptr_add_ref(const ML_UTILS_NAMESPACE::RefCountedBase* p)
67{
68 p->incRefCount();
69}
70
71inline void intrusive_ptr_release(const ML_UTILS_NAMESPACE::RefCountedBase* p)
72{
73 p->decRefCount();
74}
75
77
79#define ML_REFCOUNTED_PTR(CLASSNAME) \
80 class CLASSNAME; \
81 typedef ::boost::intrusive_ptr<CLASSNAME> CLASSNAME##Ptr; \
82 typedef ::boost::intrusive_ptr<const CLASSNAME> CLASSNAME##ConstPtr;
83
85 ML_REFCOUNTED_PTR(RefCountedBase)
87
88#endif // __mlRefCountedBase_H
89
90
Class representing general ML objects that support import/export via strings (setPersistentState() an...
Definition mlBase.h:59
EventSourceBase class adds event listener handling to Base.
RefCountedBase class adds intrusive reference counting support to the Base class.
virtual void incRefCount() const
Increase reference count.
~RefCountedBase() override
Macro for the declaration of the runtime type system methods, defined in mlRuntimeSubClass....
static void updateReferenceCountingIfSupported(Base *oldValue, Base *newValue, bool &isRefCountedBase)
Helper method that handles inc/dec of ref count if base instances support it.
virtual void decRefCount() const
Decrease ref count (object will be deleted if ref count is decremented to 0)
RefCountedBase(const RefCountedBase &)
Explicit copy constructor.
bool isRefCountedBase() const override
Returns if the instance is derived from RefCountedBase.
MLint32 _refCount
Reference count.
RefCountedBase()
Constructor.
#define ML_ABSTRACT_CLASS_HEADER(className)
Same like ML_ABSTRACT_CLASS_HEADER_EXPORTED with a non existing export symbol.
void intrusive_ptr_add_ref(const IntrusivePtrBase< Derived > *ptr)
Provide overloads for reference counting functions used by boost::intrusive_ptr.
void intrusive_ptr_release(const IntrusivePtrBase< Derived > *ptr)
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
#define ML_REFCOUNTED_PTR(CLASSNAME)
Macro that defines convenience Ptr/ConstPtr typedefs to be used instead of intrusive_ptr templates.
signed int MLint32
Definition mlTypeDefs.h:161
#define ML_UTILS_EXPORT
Defines platform dependent DLL export macro for mlUtils.
Definition mlUtilities.h:20