00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef __UT_LOCKEDRAWPTR_H__
00036 #define __UT_LOCKEDRAWPTR_H__
00037
00038 #include "UT_API.h"
00039 #include <memory>
00040 #include "UT_Algorithm.h"
00041 #include "UT_Assert.h"
00042 #include "UT_Lock.h"
00043
00044 template <typename PTR>
00045 class UT_LockedRawPtr
00046 {
00047 public:
00048 UT_LockedRawPtr()
00049 : myPtr(0)
00050 , myAutoLock(0)
00051 {
00052 }
00053 UT_LockedRawPtr(PTR &ptr, UT_Lock &lock)
00054 : myPtr(&ptr)
00055 , myAutoLock(new UT_AutoLock(lock))
00056 {
00057 }
00058 UT_LockedRawPtr(const UT_LockedRawPtr &other)
00059 : myPtr(other.myPtr)
00060 , myAutoLock(other.myAutoLock)
00061 {
00062 }
00063 UT_LockedRawPtr &operator=(const UT_LockedRawPtr &other)
00064 {
00065 if (&other != this)
00066 {
00067 myPtr = other.myPtr;
00068 myAutoLock = other.myAutoLock;
00069 }
00070 return *this;
00071 }
00072
00073 PTR & operator*() const { UT_ASSERT(myPtr); return *myPtr; }
00074 PTR * operator->() const { UT_ASSERT(myPtr); return myPtr; }
00075
00076 operator bool() const { return (myPtr != 0); }
00077 bool operator!() const { return (myPtr == 0); }
00078
00079 private:
00080 PTR * myPtr;
00081 mutable std::auto_ptr<UT_AutoLock> myAutoLock;
00082 };
00083
00084 #endif // __UT_LOCKEDRAWPTR_H__