00001 /* 00002 * Licensed to the Apache Software Foundation (ASF) under one 00003 * or more contributor license agreements. See the NOTICE file 00004 * distributed with this work for additional information 00005 * regarding copyright ownership. The ASF licenses this file 00006 * to you under the Apache License, Version 2.0 (the "License"); 00007 * you may not use this file except in compliance with the License. 00008 * You may obtain a copy of the License at 00009 * 00010 * http://www.apache.org/licenses/LICENSE-2.0 00011 * 00012 * Unless required by applicable law or agreed to in writing, software 00013 * distributed under the License is distributed on an "AS IS" BASIS, 00014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 * See the License for the specific language governing permissions and 00016 * limitations under the License. 00017 */ 00018 #if !defined(XALANMEMORYMANAGEMENT_HEADER_GUARD_1357924680) 00019 #define XALANMEMORYMANAGEMENT_HEADER_GUARD_1357924680 00020 00021 00022 // Base include file. Must be first. 00023 #include <xalanc/Include/PlatformDefinitions.hpp> 00024 00025 00026 00027 #include <cassert> 00028 #include <cstddef> 00029 #include <new> 00030 00031 00032 00033 #include <xercesc/framework/MemoryManager.hpp> 00034 00035 00036 00037 00038 XALAN_CPP_NAMESPACE_BEGIN 00039 00040 00041 00042 XALAN_USING_XERCES(MemoryManager) 00043 typedef MemoryManager MemoryManagerType; 00044 00045 00046 class XALAN_PLATFORM_EXPORT XalanMemoryManager : public MemoryManager 00047 { 00048 public: 00049 00050 #if XERCES_VERSION_MAJOR < 3 00051 #if defined(XALAN_STRICT_ANSI_HEADERS) 00052 typedef std::size_t size_type; 00053 #else 00054 typedef size_t size_type; 00055 #endif 00056 #else 00057 typedef XalanSize_t size_type; 00058 #endif 00059 00060 00061 XalanMemoryManager(); 00062 00063 virtual 00064 ~XalanMemoryManager(); 00065 00066 virtual void* 00067 allocate(size_type size) = 0; 00068 00069 virtual void 00070 deallocate(void* pointer) = 0; 00071 00072 virtual MemoryManager* 00073 getExceptionMemoryManager() = 0; 00074 00075 static MemoryManager& 00076 getExceptionMemoryManager(MemoryManager& theMemoryManager) 00077 { 00078 #if XERCES_VERSION_MAJOR < 3 00079 return theMemoryManager; 00080 #else 00081 assert(theMemoryManager.getExceptionMemoryManager() != 0); 00082 00083 return *theMemoryManager.getExceptionMemoryManager(); 00084 #endif 00085 } 00086 00087 protected: 00088 00089 XalanMemoryManager(const XalanMemoryManager& theSource); 00090 00091 XalanMemoryManager& 00092 operator=(const XalanMemoryManager& /* theRHS */) 00093 { 00094 return *this; 00095 } 00096 }; 00097 00098 00099 00100 class XalanAllocationGuard 00101 { 00102 public: 00103 00104 #if defined(XALAN_STRICT_ANSI_HEADERS) 00105 typedef std::size_t size_type; 00106 #else 00107 typedef size_t size_type; 00108 #endif 00109 00110 XalanAllocationGuard( 00111 MemoryManager& theMemoryManager, 00112 void* thePointer) : 00113 m_memoryManager(theMemoryManager), 00114 m_pointer(thePointer) 00115 { 00116 } 00117 00118 XalanAllocationGuard( 00119 MemoryManager& theMemoryManager, 00120 size_type theSize) : 00121 m_memoryManager(theMemoryManager), 00122 m_pointer(theMemoryManager.allocate(theSize)) 00123 { 00124 } 00125 00126 ~XalanAllocationGuard() 00127 { 00128 if (m_pointer != 0) 00129 { 00130 m_memoryManager.deallocate(m_pointer); 00131 } 00132 } 00133 00134 void* 00135 get() const 00136 { 00137 return m_pointer; 00138 } 00139 00140 void 00141 release() 00142 { 00143 m_pointer = 0; 00144 } 00145 00146 private: 00147 00148 // Data members... 00149 MemoryManager& m_memoryManager; 00150 00151 void* m_pointer; 00152 }; 00153 00154 00155 00156 template<class Type> 00157 void 00158 XalanDestroy(Type& theArg) 00159 { 00160 theArg.~Type(); 00161 } 00162 00163 00164 00165 template<class Type> 00166 void 00167 XalanDestroy(Type* theArg) 00168 { 00169 if (theArg != 0) 00170 { 00171 theArg->~Type(); 00172 } 00173 } 00174 00175 00176 00177 template<class Type> 00178 void 00179 XalanDestroy( 00180 MemoryManager& theMemoryManager, 00181 Type* theArg) 00182 { 00183 if (theArg != 0) 00184 { 00185 XalanDestroy(*theArg); 00186 00187 theMemoryManager.deallocate(theArg); 00188 } 00189 } 00190 00191 00192 00193 template<class Type> 00194 void 00195 XalanDestroy( 00196 MemoryManager& theMemoryManager, 00197 Type& theArg) 00198 { 00199 XalanDestroy(theArg); 00200 00201 theMemoryManager.deallocate(&theArg); 00202 } 00203 00204 00205 00206 template<class Type> 00207 Type* 00208 XalanConstruct( 00209 MemoryManager& theMemoryManager, 00210 Type*& theInstance) 00211 { 00212 XalanAllocationGuard theGuard( 00213 theMemoryManager, 00214 sizeof(Type)); 00215 00216 theInstance = 00217 new (theGuard.get()) Type; 00218 00219 theGuard.release(); 00220 00221 return theInstance; 00222 } 00223 00224 00225 00226 template< 00227 class Type, 00228 class Param1Type> 00229 Type* 00230 XalanConstruct( 00231 MemoryManager& theMemoryManager, 00232 Type*& theInstance, 00233 const Param1Type& theParam1) 00234 { 00235 XalanAllocationGuard theGuard( 00236 theMemoryManager, 00237 sizeof(Type)); 00238 00239 theInstance = 00240 new (theGuard.get()) Type(theParam1); 00241 00242 theGuard.release(); 00243 00244 return theInstance; 00245 } 00246 00247 00248 00249 template< 00250 class Type, 00251 class Param1Type> 00252 Type* 00253 XalanConstruct( 00254 MemoryManager& theMemoryManager, 00255 Type*& theInstance, 00256 Param1Type& theParam1) 00257 { 00258 XalanAllocationGuard theGuard( 00259 theMemoryManager, 00260 sizeof(Type)); 00261 00262 theInstance = 00263 new (theGuard.get()) Type(theParam1); 00264 00265 theGuard.release(); 00266 00267 return theInstance; 00268 } 00269 00270 00271 00272 template< 00273 class Type, 00274 class Param1Type, 00275 class Param2Type> 00276 Type* 00277 XalanConstruct( 00278 MemoryManager& theMemoryManager, 00279 Type*& theInstance, 00280 Param1Type& theParam1, 00281 const Param2Type& theParam2) 00282 { 00283 XalanAllocationGuard theGuard( 00284 theMemoryManager, 00285 sizeof(Type)); 00286 00287 theInstance = 00288 new (theGuard.get()) Type(theParam1, theParam2); 00289 00290 theGuard.release(); 00291 00292 return theInstance; 00293 } 00294 00295 00296 00297 template< 00298 class Type, 00299 class Param1Type, 00300 class Param2Type, 00301 class Param3Type, 00302 class Param4Type> 00303 Type* 00304 XalanConstruct( 00305 MemoryManager& theMemoryManager, 00306 Type*& theInstance, 00307 const Param1Type* theParam1, 00308 const Param2Type* theParam2, 00309 const Param3Type* theParam3, 00310 Param4Type& theParam4) 00311 { 00312 XalanAllocationGuard theGuard( 00313 theMemoryManager, 00314 sizeof(Type)); 00315 00316 theInstance = 00317 new (theGuard.get()) Type(theParam1, theParam2, theParam3, theParam4); 00318 00319 theGuard.release(); 00320 00321 return theInstance; 00322 } 00323 00324 00325 00326 template< 00327 class Type, 00328 class Param1Type, 00329 class Param2Type, 00330 class Param3Type, 00331 class Param4Type, 00332 class Param5Type, 00333 class Param6Type> 00334 Type* 00335 XalanConstruct( 00336 MemoryManager& theMemoryManager, 00337 Type*& theInstance, 00338 const Param1Type* theParam1, 00339 const Param2Type* theParam2, 00340 const Param3Type* theParam3, 00341 const Param4Type* theParam4, 00342 const Param5Type* theParam5, 00343 Param6Type& theParam6) 00344 { 00345 XalanAllocationGuard theGuard( 00346 theMemoryManager, 00347 sizeof(Type)); 00348 00349 theInstance = 00350 new (theGuard.get()) Type( 00351 theParam1, 00352 theParam2, 00353 theParam3, 00354 theParam4, 00355 theParam5, 00356 theParam6); 00357 00358 theGuard.release(); 00359 00360 return theInstance; 00361 } 00362 00363 00364 00365 template< 00366 class Type, 00367 class Param1Type, 00368 class Param2Type, 00369 class Param3Type> 00370 Type* 00371 XalanConstruct( 00372 MemoryManager& theMemoryManager, 00373 Type*& theInstance, 00374 Param1Type& theParam1, 00375 const Param2Type& theParam2, 00376 Param3Type& theParam3) 00377 { 00378 XalanAllocationGuard theGuard( 00379 theMemoryManager, 00380 sizeof(Type)); 00381 00382 theInstance = 00383 new (theGuard.get()) Type(theParam1, theParam2, theParam3); 00384 00385 theGuard.release(); 00386 00387 return theInstance; 00388 } 00389 00390 00391 00392 template< 00393 class Type, 00394 class Param1Type, 00395 class Param2Type, 00396 class Param3Type, 00397 class Param4Type, 00398 class Param5Type> 00399 Type* 00400 XalanConstruct( 00401 MemoryManager& theMemoryManager, 00402 Type*& theInstance, 00403 Param1Type& theParam1, 00404 Param2Type& theParam2, 00405 const Param3Type& theParam3, 00406 const Param4Type& theParam4, 00407 const Param5Type& theParam5) 00408 { 00409 XalanAllocationGuard theGuard( 00410 theMemoryManager, 00411 sizeof(Type)); 00412 00413 theInstance = 00414 new (theGuard.get()) Type(theParam1, theParam2, theParam3, theParam4, theParam5); 00415 00416 theGuard.release(); 00417 00418 return theInstance; 00419 } 00420 00421 00422 00423 template< 00424 class Type, 00425 class Param1Type, 00426 class Param2Type, 00427 class Param3Type, 00428 class Param4Type, 00429 class Param5Type, 00430 class Param6Type> 00431 Type* 00432 XalanConstruct( 00433 MemoryManager& theMemoryManager, 00434 Type*& theInstance, 00435 Param1Type& theParam1, 00436 Param2Type& theParam2, 00437 const Param3Type& theParam3, 00438 const Param4Type& theParam4, 00439 const Param5Type& theParam5, 00440 const Param6Type& theParam6) 00441 { 00442 XalanAllocationGuard theGuard( 00443 theMemoryManager, 00444 sizeof(Type)); 00445 00446 theInstance = 00447 new (theGuard.get()) Type(theParam1, theParam2, theParam3, theParam4, theParam5, theParam6); 00448 00449 theGuard.release(); 00450 00451 return theInstance; 00452 } 00453 00454 00455 00456 template<class Type> 00457 Type* 00458 XalanCopyConstruct( 00459 MemoryManager& theMemoryManager, 00460 const Type& theSource) 00461 { 00462 XalanAllocationGuard theGuard( 00463 theMemoryManager, 00464 sizeof(Type)); 00465 00466 Type* const theInstance = 00467 new (theGuard.get()) Type(theSource); 00468 00469 theGuard.release(); 00470 00471 return theInstance; 00472 } 00473 00474 00475 00476 template< 00477 class Type, 00478 class Param1Type> 00479 Type* 00480 XalanCopyConstruct( 00481 MemoryManager& theMemoryManager, 00482 const Type& theSource, 00483 Param1Type& theParam1) 00484 { 00485 XalanAllocationGuard theGuard( 00486 theMemoryManager, 00487 sizeof(Type)); 00488 00489 Type* const theInstance = 00490 new (theGuard.get()) Type(theSource, theParam1); 00491 00492 theGuard.release(); 00493 00494 return theInstance; 00495 } 00496 00497 00498 00499 class XALAN_PLATFORM_EXPORT XalanMemMgrs 00500 { 00501 public: 00502 00503 static MemoryManager& 00504 getDummyMemMgr(); 00505 00506 static MemoryManager& 00507 getDefaultXercesMemMgr(); 00508 00509 static MemoryManager& 00510 getDefault() 00511 { 00512 return getDefaultXercesMemMgr(); 00513 } 00514 }; 00515 00516 00517 00518 00519 #if defined (XALAN_DEVELOPMENT) 00520 #define XALAN_DEFAULT_CONSTRUCTOR_MEMMGR 00521 #define XALAN_DEFAULT_MEMMGR = XalanMemMgrs::getDummyMemMgr() 00522 #else 00523 #define XALAN_DEFAULT_CONSTRUCTOR_MEMMGR = XalanMemMgrs::getDefaultXercesMemMgr() 00524 #define XALAN_DEFAULT_MEMMGR = XalanMemMgrs::getDefaultXercesMemMgr() 00525 #endif 00526 00527 00528 00529 template <class C> 00530 struct ConstructValueWithNoMemoryManager 00531 { 00532 ConstructValueWithNoMemoryManager(MemoryManager& /*mgr*/) : 00533 value() 00534 { 00535 } 00536 00537 C value; 00538 }; 00539 00540 template <class C> 00541 struct ConstructValueWithMemoryManager 00542 { 00543 ConstructValueWithMemoryManager(MemoryManager& mgr) : 00544 value(mgr) 00545 { 00546 } 00547 00548 C value; 00549 }; 00550 00551 template <class C> 00552 struct ConstructWithNoMemoryManager 00553 { 00554 typedef ConstructValueWithNoMemoryManager<C> ConstructableType; 00555 00556 static C* construct(C* address, MemoryManager& /* mgr */) 00557 { 00558 return (C*) new (address) C(); 00559 } 00560 00561 static C* construct(C* address, const C& theRhs, MemoryManager& /* mgr */) 00562 { 00563 return (C*) new (address) C(theRhs); 00564 } 00565 }; 00566 00567 template <class C> 00568 struct ConstructWithMemoryManager 00569 { 00570 typedef ConstructValueWithMemoryManager<C> ConstructableType; 00571 00572 static C* construct(C* address, MemoryManager& mgr) 00573 { 00574 return (C*) new (address) C(mgr); 00575 } 00576 00577 static C* construct(C* address, const C& theRhs, MemoryManager& mgr) 00578 { 00579 return (C*) new (address) C(theRhs, mgr); 00580 } 00581 }; 00582 00583 template <class C> 00584 struct MemoryManagedConstructionTraits 00585 { 00586 typedef ConstructWithNoMemoryManager<C> Constructor; 00587 00588 }; 00589 00590 template <class C> 00591 struct ExplicitMemoryManagedConstructionTraits 00592 { 00593 typedef ConstructWithMemoryManager<C> Constructor; 00594 00595 }; 00596 00597 #define XALAN_USES_MEMORY_MANAGER(Type) \ 00598 template<> \ 00599 struct MemoryManagedConstructionTraits<Type> \ 00600 { \ 00601 typedef ConstructWithMemoryManager<Type> Constructor; \ 00602 }; 00603 00604 template <class C> 00605 struct ConstructWithMemoryManagerTraits 00606 { 00607 typedef ConstructWithMemoryManager<C> Constructor; 00608 }; 00609 00610 template <class C> 00611 struct ConstructWithNoMemoryManagerTraits 00612 { 00613 typedef ConstructWithNoMemoryManager<C> Constructor; 00614 }; 00615 00616 00617 00618 XALAN_CPP_NAMESPACE_END 00619 00620 00621 00622 #endif // XALANMEMORYMANAGEMENT_HEADER_GUARD_1357924680
Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.
Xalan-C++ XSLT Processor Version 1.11 |
|