Panda3D
|
00001 // Filename: copyOnWriteObject.I 00002 // Created by: drose (09Apr07) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 00016 template<class Base> 00017 TypeHandle CopyOnWriteObj<Base>::_type_handle; 00018 00019 template<class Base, class Param1> 00020 TypeHandle CopyOnWriteObj1<Base, Param1>::_type_handle; 00021 00022 //////////////////////////////////////////////////////////////////// 00023 // Function: CopyOnWriteObject::Constructor 00024 // Access: Public 00025 // Description: 00026 //////////////////////////////////////////////////////////////////// 00027 INLINE CopyOnWriteObject:: 00028 CopyOnWriteObject() 00029 #ifdef COW_THREADED 00030 : _lock_mutex("CopyOnWriteObject::_lock"), 00031 _lock_cvar(_lock_mutex) 00032 #endif 00033 { 00034 #ifdef DO_MEMORY_USAGE 00035 MemoryUsage::update_type(this, this); 00036 #endif 00037 #ifdef COW_THREADED 00038 _lock_status = LS_unlocked; 00039 _locking_thread = NULL; 00040 #endif // COW_THREADED 00041 } 00042 00043 //////////////////////////////////////////////////////////////////// 00044 // Function: CopyOnWriteObject::Copy Constructor 00045 // Access: Public 00046 // Description: 00047 //////////////////////////////////////////////////////////////////// 00048 INLINE CopyOnWriteObject:: 00049 CopyOnWriteObject(const CopyOnWriteObject ©) : 00050 CachedTypedWritableReferenceCount(copy) 00051 #ifdef COW_THREADED 00052 , _lock_mutex("CopyOnWriteObject::_lock"), 00053 _lock_cvar(_lock_mutex) 00054 #endif 00055 { 00056 #ifdef DO_MEMORY_USAGE 00057 MemoryUsage::update_type(this, this); 00058 #endif 00059 #ifdef COW_THREADED 00060 _lock_status = LS_unlocked; 00061 _locking_thread = NULL; 00062 #endif // COW_THREADED 00063 } 00064 00065 //////////////////////////////////////////////////////////////////// 00066 // Function: CopyOnWriteObject::Copy Assignment Operator 00067 // Access: Public 00068 // Description: 00069 //////////////////////////////////////////////////////////////////// 00070 INLINE void CopyOnWriteObject:: 00071 operator = (const CopyOnWriteObject ©) { 00072 CachedTypedWritableReferenceCount::operator = (copy); 00073 } 00074 00075 #ifdef COW_THREADED 00076 //////////////////////////////////////////////////////////////////// 00077 // Function: CopyOnWriteObject::cache_ref 00078 // Access: Published 00079 // Description: See CachedTypedWritableReferenceCount::cache_ref(). 00080 //////////////////////////////////////////////////////////////////// 00081 INLINE void CopyOnWriteObject:: 00082 cache_ref() const { 00083 MutexHolder holder(_lock_mutex); 00084 CachedTypedWritableReferenceCount::cache_ref(); 00085 } 00086 #endif // COW_THREADED 00087 00088 //////////////////////////////////////////////////////////////////// 00089 // Function: CopyOnWriteObj::Constructor 00090 // Access: Public 00091 // Description: 00092 //////////////////////////////////////////////////////////////////// 00093 template<class Base> 00094 INLINE CopyOnWriteObj<Base>:: 00095 CopyOnWriteObj() { 00096 } 00097 00098 //////////////////////////////////////////////////////////////////// 00099 // Function: CopyOnWriteObj::Copy Constructor 00100 // Access: Public 00101 // Description: 00102 //////////////////////////////////////////////////////////////////// 00103 template<class Base> 00104 INLINE CopyOnWriteObj<Base>:: 00105 CopyOnWriteObj(const Base ©) : 00106 Base(copy) 00107 { 00108 } 00109 00110 //////////////////////////////////////////////////////////////////// 00111 // Function: CopyOnWriteObj::Copy Constructor 00112 // Access: Public 00113 // Description: 00114 //////////////////////////////////////////////////////////////////// 00115 template<class Base> 00116 INLINE CopyOnWriteObj<Base>:: 00117 CopyOnWriteObj(const CopyOnWriteObj<Base> ©) : 00118 CopyOnWriteObject(copy), 00119 Base(copy) 00120 { 00121 } 00122 00123 //////////////////////////////////////////////////////////////////// 00124 // Function: CopyOnWriteObj::make_cow_copy 00125 // Access: Protected, Virtual 00126 // Description: 00127 //////////////////////////////////////////////////////////////////// 00128 template<class Base> 00129 PT(CopyOnWriteObject) CopyOnWriteObj<Base>:: 00130 make_cow_copy() { 00131 return new CopyOnWriteObj<Base>(*this); 00132 } 00133 00134 //////////////////////////////////////////////////////////////////// 00135 // Function: CopyOnWriteObj::init_type 00136 // Access: Public 00137 // Description: 00138 //////////////////////////////////////////////////////////////////// 00139 template<class Base> 00140 void CopyOnWriteObj<Base>:: 00141 init_type() { 00142 #if defined(HAVE_RTTI) && !defined(__EDG__) 00143 // If we have RTTI, we can determine the name of the base type. 00144 string base_name = typeid(Base).name(); 00145 #else 00146 string base_name = "unknown"; 00147 #endif 00148 00149 TypeHandle base_type = register_dynamic_type(base_name); 00150 00151 CopyOnWriteObject::init_type(); 00152 _type_handle = 00153 register_dynamic_type("CopyOnWriteObj<" + base_name + ">", 00154 base_type, 00155 CopyOnWriteObject::get_class_type()); 00156 } 00157 00158 //////////////////////////////////////////////////////////////////// 00159 // Function: CopyOnWriteObj1::Constructor 00160 // Access: Public 00161 // Description: 00162 //////////////////////////////////////////////////////////////////// 00163 template<class Base, class Param1> 00164 INLINE CopyOnWriteObj1<Base, Param1>:: 00165 CopyOnWriteObj1(Param1 p1) : Base(p1) { 00166 } 00167 00168 //////////////////////////////////////////////////////////////////// 00169 // Function: CopyOnWriteObj1::Copy Constructor 00170 // Access: Public 00171 // Description: 00172 //////////////////////////////////////////////////////////////////// 00173 template<class Base, class Param1> 00174 INLINE CopyOnWriteObj1<Base, Param1>:: 00175 CopyOnWriteObj1(const Base ©) : 00176 Base(copy) 00177 { 00178 } 00179 00180 //////////////////////////////////////////////////////////////////// 00181 // Function: CopyOnWriteObj1::Copy Constructor 00182 // Access: Public 00183 // Description: 00184 //////////////////////////////////////////////////////////////////// 00185 template<class Base, class Param1> 00186 INLINE CopyOnWriteObj1<Base, Param1>:: 00187 CopyOnWriteObj1(const CopyOnWriteObj1<Base, Param1> ©) : 00188 CopyOnWriteObject(copy), 00189 Base(copy) 00190 { 00191 } 00192 00193 //////////////////////////////////////////////////////////////////// 00194 // Function: CopyOnWriteObj1::make_cow_copy 00195 // Access: Protected, Virtual 00196 // Description: 00197 //////////////////////////////////////////////////////////////////// 00198 template<class Base, class Param1> 00199 PT(CopyOnWriteObject) CopyOnWriteObj1<Base, Param1>:: 00200 make_cow_copy() { 00201 return new CopyOnWriteObj1<Base, Param1>(*this); 00202 } 00203 00204 //////////////////////////////////////////////////////////////////// 00205 // Function: CopyOnWriteObj1::init_type 00206 // Access: Public 00207 // Description: 00208 //////////////////////////////////////////////////////////////////// 00209 template<class Base, class Param1> 00210 void CopyOnWriteObj1<Base, Param1>:: 00211 init_type() { 00212 #if defined(HAVE_RTTI) && !defined(__EDG__) 00213 // If we have RTTI, we can determine the name of the base type. 00214 string base_name = typeid(Base).name(); 00215 #else 00216 string base_name = "unknown"; 00217 #endif 00218 00219 TypeHandle base_type = register_dynamic_type(base_name); 00220 00221 CopyOnWriteObject::init_type(); 00222 _type_handle = 00223 register_dynamic_type("CopyOnWriteObj1<" + base_name + ">", 00224 base_type, 00225 CopyOnWriteObject::get_class_type()); 00226 }