![]() |
IAIRef.hGo to the documentation of this file.00001 #ifndef _IAIREF_H_ 00002 #define _IAIREF_H_ 00003 00004 /* 00005 * Name: IAIRef.h 00006 * $Revision: 1 $ 00007 * Author: 00008 * Date: 00009 * Purpose: Reference counted objects. 00010 * 00011 * ADOBE SYSTEMS INCORPORATED 00012 * Copyright 1986-2007 Adobe Systems Incorporated. 00013 * All rights reserved. 00014 * 00015 * NOTICE: Adobe permits you to use, modify, and distribute this file 00016 * in accordance with the terms of the Adobe license agreement 00017 * accompanying it. If you have received this file from a source other 00018 * than Adobe, then your use, modification, or distribution of it 00019 * requires the prior written permission of Adobe. 00020 * 00021 */ 00022 00025 #include "AICountedObject.h" 00026 00027 namespace ai { 00028 // start of namespace ai 00029 00030 00033 class RefReplaceParam; 00034 00035 enum IncrementPolicy 00036 { 00037 DoIncrement, 00038 DoNotIncrement 00039 }; 00040 00058 extern AICountedObjectSuite *GetAICountedObjectSuitePtr(); 00059 00100 template <class X> class Ref { 00101 public: 00103 Ref () : x(0) {} 00104 00107 Ref (const X& x, IncrementPolicy policy = DoIncrement); 00108 00111 Ref (const Ref<X>& ref); 00112 00114 ~Ref (); 00115 00118 operator X () const 00119 {return x;} 00120 00124 void Assign(const X& x, IncrementPolicy policy = DoIncrement); 00125 00128 Ref<X>& operator= (const Ref<X>& ref); 00129 00132 bool operator== (const Ref<X>& ref) const 00133 {return x == ref.x;} 00134 00137 bool operator!= (const Ref<X>& ref) const 00138 {return x != ref.x;} 00139 00146 X* operator<< (void (*f)(const RefReplaceParam& p)); 00147 00153 Ref<X>& to(); 00154 00155 protected: 00156 X x; 00157 }; 00158 00159 00160 inline void Replace (const RefReplaceParam&) 00161 { 00162 } 00163 00164 template <class X> Ref<X>::Ref (const X& _x, IncrementPolicy policy) : x(_x) 00165 { 00166 AICountedObjectSuite* theSuite = GetAICountedObjectSuitePtr(); 00167 if (policy == DoIncrement) 00168 theSuite->AddRef(x); 00169 } 00170 00171 template <class X> Ref<X>::Ref (const Ref<X>& ref) : x(ref.x) 00172 { 00173 AICountedObjectSuite* theSuite = GetAICountedObjectSuitePtr(); 00174 theSuite->AddRef(x); 00175 } 00176 00177 template <class X> Ref<X>::~Ref () 00178 { 00179 AICountedObjectSuite* theSuite = GetAICountedObjectSuitePtr(); 00180 theSuite->Release(x); 00181 } 00182 00183 template <class X> void Ref<X>::Assign(const X& _x, IncrementPolicy policy) 00184 { 00185 if (x != _x) 00186 { 00187 AICountedObjectSuite* theSuite = GetAICountedObjectSuitePtr(); 00188 theSuite->Release(x); 00189 x = _x; 00190 if (policy == DoIncrement) 00191 theSuite->AddRef(x); 00192 } 00193 } 00194 00195 template <class X> Ref<X>& Ref<X>::operator= (const Ref<X>& ref) 00196 { 00197 if (x != ref.x) 00198 { 00199 AICountedObjectSuite* theSuite = GetAICountedObjectSuitePtr(); 00200 theSuite->Release(x); 00201 x = ref.x; 00202 theSuite->AddRef(x); 00203 } 00204 return *this; 00205 } 00206 00207 template <class X> X* Ref<X>::operator<< (void (*)(const RefReplaceParam &p)) 00208 { 00209 AICountedObjectSuite* theSuite = GetAICountedObjectSuitePtr(); 00210 theSuite->Release(x); 00211 x = 0; 00212 return &x; 00213 } 00214 00215 template <class X> Ref<X>& Ref<X>::to() 00216 { 00217 AICountedObjectSuite* theSuite = GetAICountedObjectSuitePtr(); 00218 theSuite->AddRef(x); 00219 00220 return *this; 00221 } 00222 00223 // end of namespace ai 00224 } 00225 00226 #if !AICOUNTEDOBJECTSUITE_DEFINED 00227 00228 extern "C" 00229 { 00230 extern AICountedObjectSuite *sAICountedObject; 00231 } 00232 00237 inline AICountedObjectSuite *ai::GetAICountedObjectSuitePtr() 00238 { 00239 return sAICountedObject; 00240 } 00241 00242 #endif //AICOUNTEDOBJECTSUITE_DEFINED 00243 00244 #endif |
||||||
|
![]() |
|