ML Reference
MeVis/Foundation/Sources/MLUtilities/mlRefCountedBase.h
Go to the documentation of this file.
00001 // **InsertLicense** code
00002 //-------------------------------------------------------------------------
00004 
00009 //-------------------------------------------------------------------------
00010 #ifndef __mlRefCountedBase_H
00011 #define __mlRefCountedBase_H
00012 
00013 #include "mlEventSource.h"
00014 
00015 #include "mlSystemWarningsDisable.h"
00016 #include <boost/intrusive_ptr.hpp>
00017 #include "mlSystemWarningsRestore.h"
00018 
00019 ML_START_NAMESPACE
00020 
00021 //----------------------------------------------------------------------
00024 class ML_UTILS_EXPORT RefCountedBase : public EventSource
00025 {
00026 public:
00028   RefCountedBase();
00029 
00031   virtual void incRefCount() const;
00032 
00034   virtual void decRefCount() const;
00035 
00037   virtual bool isRefCountedBase() const { return true; } 
00038 
00044   static void updateReferenceCountingIfSupported(Base* oldValue, Base* newValue, bool& isRefCountedBase);
00045 
00048   ML_ABSTRACT_CLASS_HEADER(RefCountedBase)
00049 
00050 protected:
00052   virtual ~RefCountedBase();
00053 
00055   mutable MLint32 _refCount;
00056 };
00057 
00058 inline void intrusive_ptr_add_ref(const ML_UTILS_NAMESPACE::RefCountedBase* p)
00059 {
00060   p->incRefCount();
00061 }
00062 
00063 inline void intrusive_ptr_release(const ML_UTILS_NAMESPACE::RefCountedBase* p)
00064 {
00065   p->decRefCount();
00066 }
00067 
00068 ML_UTILS_END_NAMESPACE
00069 
00071 #define ML_REFCOUNTED_PTR(CLASSNAME) \
00072   class CLASSNAME; \
00073   typedef ::boost::intrusive_ptr<CLASSNAME> CLASSNAME##Ptr; \
00074   typedef ::boost::intrusive_ptr<const CLASSNAME> CLASSNAME##ConstPtr;
00075 
00076 ML_START_NAMESPACE 
00077   ML_REFCOUNTED_PTR(RefCountedBase)
00078 ML_END_NAMESPACE
00079 
00080 #endif // __mlRefCountedBase_H
00081 
00082