MeVisLab Toolbox Reference
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 boost::intrusive_ptr.
33
34// Forward declaration of our templated (see below) base class.
35template<typename Derived>
37
38// Forward declaration of the functions used by boost::intrusive_ptr
39template<typename Derived>
41template<typename Derived>
43
47template<typename Derived>
49protected:
50 IntrusivePtrBase(): _referenceCount(0) {};
51
52private:
56
57 mutable long _referenceCount;
58 mutable boost::mutex _referenceCountMutex;
59};
60
62template<typename Derived>
63inline void intrusive_ptr_add_ref(const IntrusivePtrBase<Derived>* ptr) { ptr->_referenceCountMutex.lock(); ptr->_referenceCount++; ptr->_referenceCountMutex.unlock(); }
64template<typename Derived>
65inline void intrusive_ptr_release(const IntrusivePtrBase<Derived>* ptr) { ptr->_referenceCountMutex.lock(); ptr->_referenceCount--; ptr->_referenceCountMutex.unlock(); if (ptr->_referenceCount==0) delete static_cast<const Derived*>(ptr); }
66
68
69#ifdef WIN32
70#pragma warning( pop )
71#endif
72
73#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