00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _SALHELPER_SIMPLEREFERENCEOBJECT_HXX_
00021 #define _SALHELPER_SIMPLEREFERENCEOBJECT_HXX_
00022
00023 #include "osl/interlck.h"
00024 #include "sal/types.h"
00025 #include "salhelperdllapi.h"
00026
00027 #include <cstddef>
00028 #include <new>
00029
00030 namespace salhelper {
00031
00058 class SALHELPER_DLLPUBLIC SimpleReferenceObject
00059 {
00060 public:
00061 inline SimpleReferenceObject() SAL_THROW(()): m_nCount(0) {}
00062
00069 inline void acquire() SAL_THROW(())
00070 { osl_atomic_increment(&m_nCount); }
00071
00072 inline void release() SAL_THROW(())
00073 { if (osl_atomic_decrement(&m_nCount) == 0) delete this; }
00074
00077 static void * operator new(std::size_t nSize) SAL_THROW((std::bad_alloc));
00078
00081 static void * operator new(std::size_t nSize,
00082 std::nothrow_t const & rNothrow)
00083 SAL_THROW(());
00084
00087 static void operator delete(void * pPtr) SAL_THROW(());
00088
00091 static void operator delete(void * pPtr, std::nothrow_t const & rNothrow)
00092 SAL_THROW(());
00093
00094 protected:
00095 virtual ~SimpleReferenceObject() SAL_THROW(());
00096
00097 private:
00098 oslInterlockedCount m_nCount;
00099
00102 SALHELPER_DLLPRIVATE SimpleReferenceObject(SimpleReferenceObject &);
00103
00106 SALHELPER_DLLPRIVATE void operator =(SimpleReferenceObject);
00107
00109
00110 #ifdef _MSC_VER
00111
00112
00113
00114 protected:
00115 #endif
00116
00118 static void * operator new[](std::size_t);
00119
00122 static void operator delete[](void * pPtr);
00123
00125 };
00126
00127 }
00128
00129 #endif // _SALHELPER_SIMPLEREFERENCEOBJECT_HXX_
00130
00131