MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
mlIntrusivePtrBase.h
Go to the documentation of this file.
1/*************************************************************************************
2**
3** Copyright 2010, 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_INTRUSIVE_PTR_BASE_H
14#define ML_INTRUSIVE_PTR_BASE_H
15
16
18
19#include "mlVesselGraphSystem.h"
20#include "VesselGraphTypes.h"
22#include <boost/thread/mutex.hpp>
24
25#ifdef WIN32
26#pragma warning(push)
27#pragma warning(disable : 4396)
28#endif
29
31
32// Some forward declarations, which are required to be able to declare the required friend functions for
33// boost::intrusive_ptr.
34
35// Forward declaration of our templated (see below) base class.
36template <typename Derived> class IntrusivePtrBase;
37
38// Forward declaration of the functions used by boost::intrusive_ptr
39template <typename Derived> void intrusive_ptr_add_ref(const IntrusivePtrBase<Derived>* ptr);
40template <typename Derived> void intrusive_ptr_release(const IntrusivePtrBase<Derived>* ptr);
41
45template <typename Derived> class IntrusivePtrBase
46{
47protected:
49 : _referenceCount(0) {};
50
51private:
55
56 mutable long _referenceCount;
57 mutable boost::mutex _referenceCountMutex;
58};
59
61template <typename Derived> inline void intrusive_ptr_add_ref(const IntrusivePtrBase<Derived>* ptr)
62{
63 ptr->_referenceCountMutex.lock();
64 ptr->_referenceCount++;
65 ptr->_referenceCountMutex.unlock();
66}
67template <typename Derived> inline void intrusive_ptr_release(const IntrusivePtrBase<Derived>* ptr)
68{
69 ptr->_referenceCountMutex.lock();
70 ptr->_referenceCount--;
71 ptr->_referenceCountMutex.unlock();
72 if (ptr->_referenceCount == 0)
73 delete static_cast<const Derived*>(ptr);
74}
75
77
78#ifdef WIN32
79#pragma warning(pop)
80#endif
81
82#endif // __mlIntrusivePtrBase_H_
A base-class enabling the use of boost::intrusive_ptr in derived classes.
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 VESSELGRAPH_END_NAMESPACE
#define VESSELGRAPH_BEGIN_NAMESPACE