Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.10

Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

XalanMemoryManagement.hpp

Go to the documentation of this file.
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 XALAN_USING_XERCES(MemoryManager)
00041 
00042 
00043 
00044 class XalanAllocationGuard
00045 {
00046 public:
00047 
00048 #if defined(XALAN_STRICT_ANSI_HEADERS)
00049     typedef std::size_t     size_type;
00050 #else
00051     typedef size_t          size_type;
00052 #endif
00053 
00054     XalanAllocationGuard(
00055                 MemoryManager&  theMemoryManager,
00056                 void*           thePointer) :
00057         m_memoryManager(theMemoryManager),
00058         m_pointer(thePointer)
00059     {
00060     }
00061 
00062     XalanAllocationGuard(
00063                 MemoryManager&  theMemoryManager,
00064                 size_type       theSize) :
00065         m_memoryManager(theMemoryManager),
00066         m_pointer(theMemoryManager.allocate(theSize))
00067     {
00068     }
00069 
00070     ~XalanAllocationGuard()
00071     {
00072         if (m_pointer != 0)
00073         {
00074             m_memoryManager.deallocate(m_pointer);
00075         }
00076     }
00077 
00078     void*
00079     get() const
00080     {
00081         return m_pointer;
00082     }
00083 
00084     void
00085     release()
00086     {
00087         m_pointer = 0;
00088     }
00089 
00090 private:
00091 
00092     // Data members...
00093     MemoryManager&  m_memoryManager;
00094 
00095     void*               m_pointer;
00096 };
00097 
00098 
00099 
00100 template<class Type>
00101 void
00102 XalanDestroy(Type&  theArg)
00103 {
00104     theArg.~Type();
00105 }
00106 
00107 
00108 
00109 template<class Type>
00110 void
00111 XalanDestroy(Type*  theArg)
00112 {
00113     if (theArg != 0)
00114     {
00115         theArg->~Type();
00116     }
00117 }
00118 
00119 
00120 
00121 template<class Type>
00122 void
00123 XalanDestroy(
00124             MemoryManager&  theMemoryManager,
00125             Type*           theArg)
00126 {
00127     if (theArg != 0)
00128     {
00129         XalanDestroy(*theArg);
00130 
00131         theMemoryManager.deallocate(theArg);
00132     }
00133 }
00134 
00135 
00136 
00137 template<class Type>
00138 void
00139 XalanDestroy(
00140             MemoryManager&  theMemoryManager,
00141             Type&           theArg)
00142 {
00143     XalanDestroy(theArg);
00144 
00145     theMemoryManager.deallocate(&theArg);
00146 }
00147 
00148 
00149 
00150 template<class Type>
00151 Type*
00152 XalanConstruct(
00153             MemoryManager&  theMemoryManager,
00154             Type*&          theInstance)
00155 {
00156     XalanAllocationGuard    theGuard(
00157                                 theMemoryManager,
00158                                 sizeof(Type));
00159 
00160     theInstance =
00161         new (theGuard.get()) Type;
00162 
00163     theGuard.release();
00164 
00165     return theInstance;
00166 }
00167 
00168 
00169 
00170 template<
00171     class Type,
00172     class Param1Type>
00173 Type*
00174 XalanConstruct(
00175             MemoryManager&      theMemoryManager,
00176             Type*&              theInstance,
00177             const Param1Type&   theParam1)
00178 {
00179     XalanAllocationGuard    theGuard(
00180                                 theMemoryManager,
00181                                 sizeof(Type));
00182 
00183     theInstance =
00184         new (theGuard.get()) Type(theParam1);
00185 
00186     theGuard.release();
00187 
00188     return theInstance;
00189 }
00190 
00191 
00192 
00193 template<
00194     class Type,
00195     class Param1Type>
00196 Type*
00197 XalanConstruct(
00198             MemoryManager&  theMemoryManager,
00199             Type*&          theInstance,
00200             Param1Type&     theParam1)
00201 {
00202     XalanAllocationGuard    theGuard(
00203                                 theMemoryManager,
00204                                 sizeof(Type));
00205 
00206     theInstance =
00207         new (theGuard.get()) Type(theParam1);
00208 
00209     theGuard.release();
00210 
00211     return theInstance;
00212 }
00213 
00214 
00215 
00216 template<
00217     class Type,
00218     class Param1Type,
00219     class Param2Type>
00220 Type*
00221 XalanConstruct(
00222             MemoryManager&      theMemoryManager,
00223             Type*&              theInstance,
00224             Param1Type&         theParam1,
00225             const Param2Type&   theParam2)
00226 {
00227     XalanAllocationGuard    theGuard(
00228                                 theMemoryManager,
00229                                 sizeof(Type));
00230 
00231     theInstance =
00232         new (theGuard.get()) Type(theParam1, theParam2);
00233 
00234     theGuard.release();
00235 
00236     return theInstance;
00237 }
00238 
00239 
00240 
00241 template<
00242     class Type,
00243     class Param1Type,
00244     class Param2Type,
00245     class Param3Type>
00246 Type*
00247 XalanConstruct(
00248             MemoryManager&      theMemoryManager,
00249             Type*&              theInstance,
00250             Param1Type&         theParam1,
00251             const Param2Type&   theParam2,
00252             Param3Type&         theParam3)
00253 {
00254     XalanAllocationGuard    theGuard(
00255                                 theMemoryManager,
00256                                 sizeof(Type));
00257 
00258     theInstance =
00259         new (theGuard.get()) Type(theParam1, theParam2, theParam3);
00260 
00261     theGuard.release();
00262 
00263     return theInstance;
00264 }
00265 
00266 
00267 
00268 template<
00269     class Type,
00270     class Param1Type,
00271     class Param2Type,
00272     class Param3Type,
00273     class Param4Type,
00274     class Param5Type>
00275 Type*
00276 XalanConstruct(
00277             MemoryManager&      theMemoryManager,
00278             Type*&              theInstance,
00279             Param1Type&         theParam1,
00280             Param2Type&         theParam2,
00281             const Param3Type&   theParam3,
00282             const Param4Type&   theParam4,
00283             const Param5Type&   theParam5)
00284 {
00285     XalanAllocationGuard    theGuard(
00286                                 theMemoryManager,
00287                                 sizeof(Type));
00288 
00289     theInstance =
00290         new (theGuard.get()) Type(theParam1, theParam2, theParam3, theParam4, theParam5);
00291 
00292     theGuard.release();
00293 
00294     return theInstance;
00295 }
00296 
00297 
00298 
00299 template<
00300     class Type,
00301     class Param1Type,
00302     class Param2Type,
00303     class Param3Type,
00304     class Param4Type,
00305     class Param5Type,
00306     class Param6Type>
00307 Type*
00308 XalanConstruct(
00309             MemoryManager&      theMemoryManager,
00310             Type*&              theInstance,
00311             Param1Type&         theParam1,
00312             Param2Type&         theParam2,
00313             const Param3Type&   theParam3,
00314             const Param4Type&   theParam4,
00315             const Param5Type&   theParam5,
00316             const Param6Type&   theParam6)
00317 {
00318     XalanAllocationGuard    theGuard(
00319                                 theMemoryManager,
00320                                 sizeof(Type));
00321 
00322     theInstance =
00323         new (theGuard.get()) Type(theParam1, theParam2, theParam3, theParam4, theParam5, theParam6);
00324 
00325     theGuard.release();
00326 
00327     return theInstance;
00328 }
00329 
00330 
00331 
00332 template<class Type>
00333 Type*
00334 XalanCopyConstruct(
00335             MemoryManager&  theMemoryManager,
00336             const Type&     theSource)
00337 {
00338     XalanAllocationGuard    theGuard(
00339                                 theMemoryManager,
00340                                 sizeof(Type));
00341 
00342     Type* const     theInstance =
00343         new (theGuard.get()) Type(theSource);
00344 
00345     theGuard.release();
00346 
00347     return theInstance;
00348 }
00349 
00350 
00351 
00352 template<
00353     class Type,
00354     class Param1Type>
00355 Type*
00356 XalanCopyConstruct(
00357             MemoryManager&  theMemoryManager,
00358             const Type&     theSource,
00359             Param1Type&     theParam1)
00360 {
00361     XalanAllocationGuard    theGuard(
00362                                 theMemoryManager,
00363                                 sizeof(Type));
00364 
00365     Type* const     theInstance =
00366         new (theGuard.get()) Type(theSource, theParam1);
00367 
00368     theGuard.release();
00369 
00370     return theInstance;
00371 }
00372 
00373 
00374 
00375 class XALAN_PLATFORM_EXPORT XalanMemMgrs
00376 {
00377 public:
00378 
00379     static MemoryManager&
00380     getDummyMemMgr();
00381 
00382     static MemoryManager&
00383     getDefaultXercesMemMgr();
00384 
00385     static MemoryManager&
00386     getDefault()
00387     {
00388         return getDefaultXercesMemMgr();
00389     }
00390 };
00391 
00392 
00393 
00394 
00395 #if defined (XALAN_DEVELOPMENT)
00396 #define XALAN_DEFAULT_CONSTRUCTOR_MEMORY_MGR
00397 #define XALAN_DEFAULT_CONSTRACTOR_MEMORY_MGR
00398 #define XALAN_DEFAULT_MEMMGR = XalanMemMgrs::getDummyMemMgr()
00399 #else
00400 #define XALAN_DEFAULT_CONSTRUCTOR_MEMORY_MGR = XalanMemMgrs::getDefaultXercesMemMgr()
00401 #define XALAN_DEFAULT_CONSTRACTOR_MEMORY_MGR XALAN_DEFAULT_CONSTRUCTOR_MEMORY_MGR
00402 #define XALAN_DEFAULT_MEMMGR = XalanMemMgrs::getDefaultXercesMemMgr()
00403 #endif
00404 
00405 
00406 
00407 template <class C>
00408 struct ConstructValueWithNoMemoryManager 
00409 { 
00410     ConstructValueWithNoMemoryManager(MemoryManager& /*mgr*/) :
00411         value()
00412     {
00413     }
00414 
00415     C value;
00416 };
00417 
00418 template <class C>
00419 struct ConstructValueWithMemoryManager
00420 {   
00421     ConstructValueWithMemoryManager(MemoryManager& mgr) :
00422         value(mgr)
00423     {
00424     }
00425 
00426     C value;
00427 };
00428 
00429 template <class C>
00430 struct ConstructWithNoMemoryManager
00431 {
00432     typedef ConstructValueWithNoMemoryManager<C>   ConstructableType;
00433 
00434     static C* construct(C* address, MemoryManager& /* mgr */)
00435     {
00436         return (C*) new (address) C;
00437     }
00438 
00439     static C* construct(C* address, const C& theRhs, MemoryManager& /* mgr */)
00440     {
00441         return (C*) new (address) C(theRhs);
00442     }
00443 };
00444 
00445 template <class C>
00446 struct ConstructWithMemoryManager
00447 {
00448     typedef ConstructValueWithMemoryManager<C>    ConstructableType;
00449 
00450     static C* construct(C* address, MemoryManager& mgr)
00451     {
00452         return (C*) new (address) C(mgr);
00453     }
00454 
00455     static C* construct(C* address, const C& theRhs, MemoryManager& mgr)
00456     {
00457         return (C*) new (address) C(theRhs, mgr);
00458     }
00459 };
00460 
00461 template <class C>
00462 struct MemoryManagedConstructionTraits
00463 {
00464     typedef ConstructWithNoMemoryManager<C> Constructor;
00465 
00466 };
00467 
00468 #define  XALAN_USES_MEMORY_MANAGER(Type)  \
00469 template<> \
00470 struct MemoryManagedConstructionTraits<Type> \
00471     { \
00472         typedef ConstructWithMemoryManager<Type> Constructor; \
00473     };
00474 
00475 template <class C>
00476 struct ConstructWithMemoryManagerTraits 
00477 {
00478     typedef ConstructWithMemoryManager<C>       Constructor;
00479 };
00480 
00481 template <class C>
00482 struct ConstructWithNoMemoryManagerTraits
00483 {
00484     typedef ConstructWithNoMemoryManager<C> Constructor;
00485 };
00486 
00487 
00488 
00489 
00490 XALAN_CPP_NAMESPACE_END
00491 
00492 
00493 
00494 #endif  // XALANMEMORYMANAGEMENT_HEADER_GUARD_1357924680
00495 
00496 

Interpreting class diagrams

Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.

dot

Xalan-C++ XSLT Processor Version 1.10
Copyright © 1999-2004 The Apache Software Foundation. All Rights Reserved.

Apache Logo