Xalan-C++ API Reference 1.12.0
XalanMemoryManagement.hpp
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18#if !defined(XALANMEMORYMANAGEMENT_HEADER_GUARD_1357924680)
19#define XALANMEMORYMANAGEMENT_HEADER_GUARD_1357924680
20
21
22// Base include file. Must be first.
24
25
26
27#include <cassert>
28#include <cstddef>
29#include <new>
30
31
32
33#include <xercesc/framework/MemoryManager.hpp>
34
35
36
37
38namespace XALAN_CPP_NAMESPACE {
39
40
41
42using xercesc::MemoryManager;
43typedef MemoryManager MemoryManagerType;
44
45
46class XALAN_PLATFORM_EXPORT XalanMemoryManager : public MemoryManager
47{
48public:
49
50#if XERCES_VERSION_MAJOR < 3
51 typedef std::size_t size_type;
52#else
53 typedef XalanSize_t size_type;
54#endif
55
56
58
59 virtual
61
62 virtual void*
64
65 virtual void
66 deallocate(void* pointer) = 0;
67
68 virtual MemoryManager*
70
71 static MemoryManager&
73 {
74#if XERCES_VERSION_MAJOR < 3
75 return theMemoryManager;
76#else
77 assert(theMemoryManager.getExceptionMemoryManager() != 0);
78
79 return *theMemoryManager.getExceptionMemoryManager();
80#endif
81 }
82
83protected:
84
86
88 operator=(const XalanMemoryManager& /* theRHS */)
89 {
90 return *this;
91 }
92};
93
94
95
97{
98public:
99
100 typedef std::size_t size_type;
101
103 MemoryManager& theMemoryManager,
104 void* thePointer) :
105 m_memoryManager(theMemoryManager),
106 m_pointer(thePointer)
107 {
108 }
109
111 MemoryManager& theMemoryManager,
113 m_memoryManager(theMemoryManager),
114 m_pointer(theMemoryManager.allocate(theSize))
115 {
116 }
117
119 {
120 if (m_pointer != 0)
121 {
122 m_memoryManager.deallocate(m_pointer);
123 }
124 }
125
126 void*
127 get() const
128 {
129 return m_pointer;
130 }
131
132 void
134 {
135 m_pointer = 0;
136 }
137
138private:
139
140 // Data members...
141 MemoryManager& m_memoryManager;
142
143 void* m_pointer;
144};
145
146
147
148template<class Type>
149void
151{
152 theArg.~Type();
153}
154
155
156
157template<class Type>
158void
160{
161 if (theArg != 0)
162 {
163 theArg->~Type();
164 }
165}
166
167
168
169template<class Type>
170void
172 MemoryManager& theMemoryManager,
173 Type* theArg)
174{
175 if (theArg != 0)
176 {
178
179 theMemoryManager.deallocate(theArg);
180 }
181}
182
183
184
185template<class Type>
186void
188 MemoryManager& theMemoryManager,
189 Type& theArg)
190{
192
193 theMemoryManager.deallocate(&theArg);
194}
195
196
197
198template<class Type>
199Type*
201 MemoryManager& theMemoryManager,
203{
206 sizeof(Type));
207
209 new (theGuard.get()) Type;
210
212
213 return theInstance;
214}
215
216
217
218template<
219 class Type,
220 class Param1Type>
221Type*
223 MemoryManager& theMemoryManager,
225 const Param1Type& theParam1)
226{
229 sizeof(Type));
230
232 new (theGuard.get()) Type(theParam1);
233
235
236 return theInstance;
237}
238
239
240
241template<
242 class Type,
243 class Param1Type>
244Type*
246 MemoryManager& theMemoryManager,
249{
252 sizeof(Type));
253
255 new (theGuard.get()) Type(theParam1);
256
258
259 return theInstance;
260}
261
262
263
264template<
265 class Type,
266 class Param1Type,
267 class Param2Type>
268Type*
270 MemoryManager& theMemoryManager,
273 const Param2Type& theParam2)
274{
277 sizeof(Type));
278
281
283
284 return theInstance;
285}
286
287
288
289template<
290 class Type,
291 class Param1Type,
292 class Param2Type,
293 class Param3Type,
294 class Param4Type>
295Type*
297 MemoryManager& theMemoryManager,
299 const Param1Type* theParam1,
300 const Param2Type* theParam2,
301 const Param3Type* theParam3,
303{
306 sizeof(Type));
307
310
312
313 return theInstance;
314}
315
316
317
318template<
319 class Type,
320 class Param1Type,
321 class Param2Type,
322 class Param3Type,
323 class Param4Type,
324 class Param5Type,
325 class Param6Type>
326Type*
328 MemoryManager& theMemoryManager,
330 const Param1Type* theParam1,
331 const Param2Type* theParam2,
332 const Param3Type* theParam3,
333 const Param4Type* theParam4,
334 const Param5Type* theParam5,
336{
339 sizeof(Type));
340
342 new (theGuard.get()) Type(
343 theParam1,
344 theParam2,
345 theParam3,
346 theParam4,
347 theParam5,
348 theParam6);
349
351
352 return theInstance;
353}
354
355
356
357template<
358 class Type,
359 class Param1Type,
360 class Param2Type,
361 class Param3Type>
362Type*
364 MemoryManager& theMemoryManager,
367 const Param2Type& theParam2,
369{
372 sizeof(Type));
373
376
378
379 return theInstance;
380}
381
382
383
384template<
385 class Type,
386 class Param1Type,
387 class Param2Type,
388 class Param3Type,
389 class Param4Type,
390 class Param5Type>
391Type*
393 MemoryManager& theMemoryManager,
397 const Param3Type& theParam3,
398 const Param4Type& theParam4,
399 const Param5Type& theParam5)
400{
403 sizeof(Type));
404
407
409
410 return theInstance;
411}
412
413
414
415template<
416 class Type,
417 class Param1Type,
418 class Param2Type,
419 class Param3Type,
420 class Param4Type,
421 class Param5Type,
422 class Param6Type>
423Type*
445
446
447
448template<class Type>
449Type*
451 MemoryManager& theMemoryManager,
452 const Type& theSource)
453{
456 sizeof(Type));
457
458 Type* const theInstance =
459 new (theGuard.get()) Type(theSource);
460
462
463 return theInstance;
464}
465
466
467
468template<
469 class Type,
470 class Param1Type>
471Type*
473 MemoryManager& theMemoryManager,
474 const Type& theSource,
476{
479 sizeof(Type));
480
481 Type* const theInstance =
483
485
486 return theInstance;
487}
488
489
490
492{
493public:
494
495 static MemoryManager&
497
498 static MemoryManager&
500
501 static MemoryManager&
503 {
504 return getDefaultXercesMemMgr();
505 }
506};
507
508
509
510
511#if defined (XALAN_DEVELOPMENT)
512#define XALAN_DEFAULT_CONSTRUCTOR_MEMMGR
513#define XALAN_DEFAULT_MEMMGR = XalanMemMgrs::getDummyMemMgr()
514#else
515#define XALAN_DEFAULT_CONSTRUCTOR_MEMMGR = XalanMemMgrs::getDefaultXercesMemMgr()
516#define XALAN_DEFAULT_MEMMGR = XalanMemMgrs::getDefaultXercesMemMgr()
517#endif
518
519
520
521template <class C>
523{
524 ConstructValueWithNoMemoryManager(MemoryManager& /*mgr*/) :
525 value()
526 {
527 }
528
530};
531
532template <class C>
534{
536 value(mgr)
537 {
538 }
539
541};
542
543template <class C>
545{
547
548 static C* construct(C* address, MemoryManager& /* mgr */)
549 {
550 return (C*) new (address) C();
551 }
552
553 static C* construct(C* address, const C& theRhs, MemoryManager& /* mgr */)
554 {
555 return (C*) new (address) C(theRhs);
556 }
557};
558
559template <class C>
561{
563
564 static C* construct(C* address, MemoryManager& mgr)
565 {
566 return (C*) new (address) C(mgr);
567 }
568
569 static C* construct(C* address, const C& theRhs, MemoryManager& mgr)
570 {
571 return (C*) new (address) C(theRhs, mgr);
572 }
573};
574
575template <class C>
581
582template <class C>
588
589#define XALAN_USES_MEMORY_MANAGER(Type) \
590template<> \
591struct MemoryManagedConstructionTraits<Type> \
592 { \
593 typedef ConstructWithMemoryManager<Type> Constructor; \
594 };
595
596template <class C>
601
602template <class C>
607
608
609
610}
611
612
613
614#endif // XALANMEMORYMANAGEMENT_HEADER_GUARD_1357924680
#define XALAN_PLATFORM_EXPORT
#define XALAN_CPP_NAMESPACE
Xalan-C++ namespace, including major and minor version.
XalanAllocationGuard(MemoryManager &theMemoryManager, void *thePointer)
XalanAllocationGuard(MemoryManager &theMemoryManager, size_type theSize)
static MemoryManager & getDefaultXercesMemMgr()
static MemoryManager & getDefault()
static MemoryManager & getDummyMemMgr()
XalanMemoryManager(const XalanMemoryManager &theSource)
virtual void * allocate(size_type size)=0
XalanMemoryManager & operator=(const XalanMemoryManager &)
static MemoryManager & getExceptionMemoryManager(MemoryManager &theMemoryManager)
virtual MemoryManager * getExceptionMemoryManager()=0
virtual void deallocate(void *pointer)=0
MemoryManager MemoryManagerType
Type * XalanConstruct(MemoryManager &theMemoryManager, Type *&theInstance)
Type * XalanCopyConstruct(MemoryManager &theMemoryManager, const Type &theSource)
void XalanDestroy(Type &theArg)
ConstructValueWithMemoryManager< C > ConstructableType
static C * construct(C *address, const C &theRhs, MemoryManager &mgr)
static C * construct(C *address, MemoryManager &mgr)
ConstructWithNoMemoryManager< C > Constructor
static C * construct(C *address, MemoryManager &)
static C * construct(C *address, const C &theRhs, MemoryManager &)
ConstructValueWithNoMemoryManager< C > ConstructableType
ConstructWithNoMemoryManager< C > Constructor