00001 /* 00002 * Copyright 1999-2004 The Apache Software Foundation. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #if !defined(XALANMEMORYMANAGEMENT_HEADER_GUARD_1357924680) 00017 #define XALANMEMORYMANAGEMENT_HEADER_GUARD_1357924680 00018 00019 00020 // Base include file. Must be first. 00021 #include <xalanc/Include/PlatformDefinitions.hpp> 00022 00023 00024 00025 #include <cstddef> 00026 #include <new> 00027 00028 00029 00030 #include <xercesc/framework/MemoryManager.hpp> 00031 00032 00033 00034 00035 XALAN_CPP_NAMESPACE_BEGIN 00036 00037 00038 00039 typedef XERCES_CPP_NAMESPACE_QUALIFIER MemoryManager MemoryManagerType; 00040 00041 00042 00043 class XalanAllocationGuard 00044 { 00045 public: 00046 00047 #if defined(XALAN_STRICT_ANSI_HEADERS) 00048 typedef std::size_t size_type; 00049 #else 00050 typedef size_t size_type; 00051 #endif 00052 00053 XalanAllocationGuard( 00054 MemoryManagerType& theMemoryManager, 00055 void* thePointer) : 00056 m_memoryManager(theMemoryManager), 00057 m_pointer(thePointer) 00058 { 00059 } 00060 00061 XalanAllocationGuard( 00062 MemoryManagerType& theMemoryManager, 00063 size_type theSize) : 00064 m_memoryManager(theMemoryManager), 00065 m_pointer(theMemoryManager.allocate(theSize)) 00066 { 00067 } 00068 00069 ~XalanAllocationGuard() 00070 { 00071 if (m_pointer != 0) 00072 { 00073 m_memoryManager.deallocate(m_pointer); 00074 } 00075 } 00076 00077 void* 00078 get() const 00079 { 00080 return m_pointer; 00081 } 00082 00083 void 00084 release() 00085 { 00086 m_pointer = 0; 00087 } 00088 00089 private: 00090 00091 // Data members... 00092 MemoryManagerType& m_memoryManager; 00093 00094 void* m_pointer; 00095 }; 00096 00097 00098 00099 template<class Type> 00100 void 00101 XalanDestroy(Type& theArg) 00102 { 00103 theArg.~Type(); 00104 } 00105 00106 00107 00108 template<class Type> 00109 void 00110 XalanDestroy(Type* theArg) 00111 { 00112 if (theArg != 0) 00113 { 00114 theArg->~Type(); 00115 } 00116 } 00117 00118 00119 00120 template<class Type> 00121 void 00122 XalanDestroy( 00123 MemoryManagerType& theMemoryManager, 00124 Type* theArg) 00125 { 00126 if (theArg != 0) 00127 { 00128 XalanDestroy(*theArg); 00129 00130 theMemoryManager.deallocate(theArg); 00131 } 00132 } 00133 00134 00135 00136 template<class Type> 00137 void 00138 XalanDestroy( 00139 MemoryManagerType& theMemoryManager, 00140 Type& theArg) 00141 { 00142 XalanDestroy(theArg); 00143 00144 theMemoryManager.deallocate(&theArg); 00145 } 00146 00147 00148 00149 template<class Type> 00150 Type* 00151 XalanConstruct( 00152 MemoryManagerType& theMemoryManager, 00153 Type*& theInstance) 00154 { 00155 XalanAllocationGuard theGuard( 00156 theMemoryManager, 00157 sizeof(Type)); 00158 00159 theInstance = 00160 new (theGuard.get()) Type; 00161 00162 theGuard.release(); 00163 00164 return theInstance; 00165 } 00166 00167 00168 00169 template< 00170 class Type, 00171 class Param1Type> 00172 Type* 00173 XalanConstruct( 00174 MemoryManagerType& theMemoryManager, 00175 Type*& theInstance, 00176 const Param1Type& theParam1) 00177 { 00178 XalanAllocationGuard theGuard( 00179 theMemoryManager, 00180 sizeof(Type)); 00181 00182 theInstance = 00183 new (theGuard.get()) Type(theParam1); 00184 00185 theGuard.release(); 00186 00187 return theInstance; 00188 } 00189 00190 00191 00192 template< 00193 class Type, 00194 class Param1Type> 00195 Type* 00196 XalanConstruct( 00197 MemoryManagerType& theMemoryManager, 00198 Type*& theInstance, 00199 Param1Type& theParam1) 00200 { 00201 XalanAllocationGuard theGuard( 00202 theMemoryManager, 00203 sizeof(Type)); 00204 00205 theInstance = 00206 new (theGuard.get()) Type(theParam1); 00207 00208 theGuard.release(); 00209 00210 return theInstance; 00211 } 00212 00213 00214 00215 template< 00216 class Type, 00217 class Param1Type, 00218 class Param2Type> 00219 Type* 00220 XalanConstruct( 00221 MemoryManagerType& theMemoryManager, 00222 Type*& theInstance, 00223 Param1Type& theParam1, 00224 const Param2Type& theParam2) 00225 { 00226 XalanAllocationGuard theGuard( 00227 theMemoryManager, 00228 sizeof(Type)); 00229 00230 theInstance = 00231 new (theGuard.get()) Type(theParam1, theParam2); 00232 00233 theGuard.release(); 00234 00235 return theInstance; 00236 } 00237 00238 00239 00240 template< 00241 class Type, 00242 class Param1Type, 00243 class Param2Type, 00244 class Param3Type> 00245 Type* 00246 XalanConstruct( 00247 MemoryManagerType& theMemoryManager, 00248 Type*& theInstance, 00249 Param1Type& theParam1, 00250 const Param2Type& theParam2, 00251 Param3Type& theParam3) 00252 { 00253 XalanAllocationGuard theGuard( 00254 theMemoryManager, 00255 sizeof(Type)); 00256 00257 theInstance = 00258 new (theGuard.get()) Type(theParam1, theParam2, theParam3); 00259 00260 theGuard.release(); 00261 00262 return theInstance; 00263 } 00264 00265 00266 00267 template< 00268 class Type, 00269 class Param1Type, 00270 class Param2Type, 00271 class Param3Type, 00272 class Param4Type, 00273 class Param5Type> 00274 Type* 00275 XalanConstruct( 00276 MemoryManagerType& theMemoryManager, 00277 Type*& theInstance, 00278 Param1Type& theParam1, 00279 Param2Type& theParam2, 00280 const Param3Type& theParam3, 00281 const Param4Type& theParam4, 00282 const Param5Type& theParam5) 00283 { 00284 XalanAllocationGuard theGuard( 00285 theMemoryManager, 00286 sizeof(Type)); 00287 00288 theInstance = 00289 new (theGuard.get()) Type(theParam1, theParam2, theParam3, theParam4, theParam5); 00290 00291 theGuard.release(); 00292 00293 return theInstance; 00294 } 00295 00296 00297 00298 template<class Type> 00299 Type* 00300 XalanCopyConstruct( 00301 MemoryManagerType& theMemoryManager, 00302 const Type& theSource) 00303 { 00304 XalanAllocationGuard theGuard( 00305 theMemoryManager, 00306 sizeof(Type)); 00307 00308 Type* const theInstance = 00309 new (theGuard.get()) Type(theSource); 00310 00311 theGuard.release(); 00312 00313 return theInstance; 00314 } 00315 00316 00317 00318 template< 00319 class Type, 00320 class Param1Type> 00321 Type* 00322 XalanCopyConstruct( 00323 MemoryManagerType& theMemoryManager, 00324 const Type& theSource, 00325 Param1Type& theParam1) 00326 { 00327 XalanAllocationGuard theGuard( 00328 theMemoryManager, 00329 sizeof(Type)); 00330 00331 Type* const theInstance = 00332 new (theGuard.get()) Type(theSource, theParam1); 00333 00334 theGuard.release(); 00335 00336 return theInstance; 00337 } 00338 00339 00340 00341 class XALAN_PLATFORM_EXPORT XalanMemMgrs 00342 { 00343 public: 00344 00345 static MemoryManagerType& 00346 getDummyMemMgr(); 00347 00348 00349 static MemoryManagerType& 00350 getDefaultXercesMemMgr(); 00351 }; 00352 00353 00354 00355 00356 #if defined (XALAN_DEVELOPMENT) 00357 #define XALAN_DEFAULT_CONSTRACTOR_MEMORY_MGR 00358 #define XALAN_DEFAULT_MEMMGR = XalanMemMgrs::getDummyMemMgr() 00359 #else 00360 #define XALAN_DEFAULT_CONSTRACTOR_MEMORY_MGR = XalanMemMgrs::getDefaultXercesMemMgr() 00361 #define XALAN_DEFAULT_MEMMGR = XalanMemMgrs::getDefaultXercesMemMgr() 00362 #endif 00363 00364 00365 00366 template <class C> 00367 class ConstructValueWithNoMemoryManager 00368 { 00369 public: 00370 ConstructValueWithNoMemoryManager(MemoryManagerType& /*mgr*/) 00371 { 00372 } 00373 00374 C value; 00375 00376 }; 00377 00378 template <class C> 00379 struct ConstructValueWithMemoryManager 00380 { 00381 ConstructValueWithMemoryManager(MemoryManagerType& mgr) : 00382 value(mgr) 00383 { 00384 } 00385 00386 C value; 00387 }; 00388 00389 template <class C> 00390 struct ConstructWithNoMemoryManager 00391 { 00392 typedef ConstructValueWithNoMemoryManager<C> ConstructableType; 00393 00394 static C* construct(C* address, MemoryManagerType& /* mgr */) 00395 { 00396 return (C*) new (address) C; 00397 } 00398 00399 static C* construct(C* address, const C& theRhs, MemoryManagerType& /* mgr */) 00400 { 00401 return (C*) new (address) C(theRhs); 00402 } 00403 }; 00404 00405 template <class C> 00406 struct ConstructWithMemoryManager 00407 { 00408 typedef ConstructValueWithMemoryManager<C> ConstructableType; 00409 00410 static C* construct(C* address, MemoryManagerType& mgr) 00411 { 00412 return (C*) new (address) C(mgr); 00413 } 00414 00415 static C* construct(C* address, const C& theRhs, MemoryManagerType& mgr) 00416 { 00417 return (C*) new (address) C(theRhs, mgr); 00418 } 00419 }; 00420 00421 template <class C> 00422 struct MemoryManagedConstructionTraits 00423 { 00424 typedef ConstructWithNoMemoryManager<C> Constructor; 00425 00426 }; 00427 00428 #define XALAN_USES_MEMORY_MANAGER(Type) \ 00429 template<> \ 00430 struct MemoryManagedConstructionTraits<Type> \ 00431 { \ 00432 typedef ConstructWithMemoryManager<Type> Constructor; \ 00433 }; 00434 00435 template <class C> 00436 struct ConstructWithMemoryManagerTraits 00437 { 00438 typedef ConstructWithMemoryManager<C> Constructor; 00439 }; 00440 00441 template <class C> 00442 struct ConstructWithNoMemoryManagerTraits 00443 { 00444 typedef ConstructWithNoMemoryManager<C> Constructor; 00445 }; 00446 00447 00448 00449 00450 XALAN_CPP_NAMESPACE_END 00451 00452 00453 00454 #endif // XALANMEMORYMANAGEMENT_HEADER_GUARD_1357924680 00455 00456
Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.
![]() |
Xalan-C++ XSLT Processor Version 1.9 |
|