MeVisLabToolboxReference
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 <boost/intrusive_ptr.hpp>
00016 
00017 ML_START_NAMESPACE
00018 
00019 //----------------------------------------------------------------------
00022 class ML_UTILS_EXPORT RefCountedBase : public EventSource
00023 {
00024 public:
00026   RefCountedBase();
00027 
00029   virtual void incRefCount() const;
00030 
00032   virtual void decRefCount() const;
00033 
00035   virtual bool isRefCountedBase() const { return true; } 
00036 
00042   static void updateReferenceCountingIfSupported(Base* oldValue, Base* newValue, bool& isRefCountedBase);
00043 
00046   ML_ABSTRACT_CLASS_HEADER(RefCountedBase)
00047 
00048 protected:
00050   virtual ~RefCountedBase();
00051 
00053   mutable MLint32 _refCount;
00054 };
00055 
00056 inline void intrusive_ptr_add_ref(const ML_UTILS_NAMESPACE::RefCountedBase* p)
00057 {
00058   p->incRefCount();
00059 }
00060 
00061 inline void intrusive_ptr_release(const ML_UTILS_NAMESPACE::RefCountedBase* p)
00062 {
00063   p->decRefCount();
00064 }
00065 
00066 ML_UTILS_END_NAMESPACE
00067 
00069 #define ML_REFCOUNTED_PTR(CLASSNAME) \
00070   class CLASSNAME; \
00071   typedef ::boost::intrusive_ptr<CLASSNAME> CLASSNAME##Ptr; \
00072   typedef ::boost::intrusive_ptr<const CLASSNAME> CLASSNAME##ConstPtr;
00073 
00074 ML_START_NAMESPACE 
00075   ML_REFCOUNTED_PTR(RefCountedBase)
00076 ML_END_NAMESPACE
00077 
00078 #endif // __mlRefCountedBase_H
00079 
00080