00001 /* 00002 * PROPRIETARY INFORMATION. This software is proprietary to 00003 * Side Effects Software Inc., and is not to be reproduced, 00004 * transmitted, or disclosed in any way without written permission. 00005 * 00006 * Produced by: 00007 * Mark Elendt 00008 * Side Effects Software Inc 00009 * 477 Richmond Street West 00010 * Toronto, Ontario 00011 * Canada M5V 3E7 00012 * 416-504-9876 00013 * 00014 * NAME: UT_PtrProxy.h ( UT Library, C++) 00015 * 00016 * COMMENTS: Template interface to the UT_ProxyPointer methods 00017 */ 00018 00019 #ifndef __UT_PtrProxy__ 00020 #define __UT_PtrProxy__ 00021 00022 #include "UT_ProxyPointer.h" 00023 00024 00025 // 00026 // First half of the proxy pointer interface. The UT_PtrProxy maintains a 00027 // pointer to the source object. 00028 // 00029 template <typename utObj> 00030 class UT_PtrProxy { 00031 public: 00032 explicit UT_PtrProxy(utObj *me) 00033 { 00034 myId = UT_ProxyPointer::allocProxy(me); 00035 } 00036 ~UT_PtrProxy() 00037 { 00038 UT_ProxyPointer::freeProxy(myId); 00039 } 00040 00041 int getId() const { return myId; } 00042 00043 operator const utObj *() const 00044 { 00045 const void *v = UT_ProxyPointer::lookupProxy(myId); 00046 return (const utObj *)v; 00047 } 00048 operator utObj *() 00049 { 00050 void *v = UT_ProxyPointer::lookupProxy(myId); 00051 return (utObj *)v; 00052 } 00053 operator int() const 00054 { 00055 return myId; 00056 } 00057 void swizzle(utObj *me) 00058 { 00059 UT_ProxyPointer::swizzlePointer(me); 00060 } 00061 unsigned int getReferences() const 00062 { 00063 return UT_ProxyPointer::getReferenceCount(myId)-1; 00064 } 00065 00066 private: 00067 int myId; 00068 }; 00069 00070 template <typename utObj> 00071 class UT_RefProxy { 00072 public: 00073 explicit UT_RefProxy(int id) 00074 { 00075 init(id); 00076 } 00077 explicit UT_RefProxy(const UT_PtrProxy<utObj>&ptr) 00078 { 00079 init(ptr.getId()); 00080 } 00081 ~UT_RefProxy() { UT_ProxyPointer::deReferenceProxy(myId); } 00082 00083 operator const utObj *() const 00084 { 00085 const void *v = UT_ProxyPointer::lookupProxy(myId); 00086 return (const utObj *)v; 00087 } 00088 operator utObj *() 00089 { 00090 void *v = UT_ProxyPointer::lookupProxy(myId); 00091 return (utObj *)v; 00092 } 00093 operator int() const 00094 { 00095 return myId; 00096 } 00097 00098 private: 00099 void init(int id) 00100 { 00101 myId = id; 00102 UT_ProxyPointer::referenceProxy(myId); 00103 } 00104 int myId; 00105 }; 00106 00107 00108 #endif 00109
1.5.9