Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.11


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 
38 XALAN_CPP_NAMESPACE_BEGIN
39 
40 
41 
42 XALAN_USING_XERCES(MemoryManager)
43 typedef MemoryManager MemoryManagerType;
44 
45 
46 class XALAN_PLATFORM_EXPORT XalanMemoryManager : public MemoryManager
47 {
48 public:
49 
50 #if XERCES_VERSION_MAJOR < 3
51  #if defined(XALAN_STRICT_ANSI_HEADERS)
52  typedef std::size_t size_type;
53  #else
54  typedef size_t size_type;
55  #endif
56 #else
57  typedef XalanSize_t size_type;
58 #endif
59 
60 
62 
63  virtual
65 
66  virtual void*
67  allocate(size_type size) = 0;
68 
69  virtual void
70  deallocate(void* pointer) = 0;
71 
72  virtual MemoryManager*
73  getExceptionMemoryManager() = 0;
74 
75  static MemoryManager&
76  getExceptionMemoryManager(MemoryManager& theMemoryManager)
77  {
78 #if XERCES_VERSION_MAJOR < 3
79  return theMemoryManager;
80 #else
81  assert(theMemoryManager.getExceptionMemoryManager() != 0);
82 
83  return *theMemoryManager.getExceptionMemoryManager();
84 #endif
85  }
86 
87 protected:
88 
89  XalanMemoryManager(const XalanMemoryManager& theSource);
90 
92  operator=(const XalanMemoryManager& /* theRHS */)
93  {
94  return *this;
95  }
96 };
97 
98 
99 
101 {
102 public:
103 
104 #if defined(XALAN_STRICT_ANSI_HEADERS)
105  typedef std::size_t size_type;
106 #else
107  typedef size_t size_type;
108 #endif
109 
111  MemoryManager& theMemoryManager,
112  void* thePointer) :
113  m_memoryManager(theMemoryManager),
114  m_pointer(thePointer)
115  {
116  }
117 
119  MemoryManager& theMemoryManager,
120  size_type theSize) :
121  m_memoryManager(theMemoryManager),
122  m_pointer(theMemoryManager.allocate(theSize))
123  {
124  }
125 
127  {
128  if (m_pointer != 0)
129  {
130  m_memoryManager.deallocate(m_pointer);
131  }
132  }
133 
134  void*
135  get() const
136  {
137  return m_pointer;
138  }
139 
140  void
142  {
143  m_pointer = 0;
144  }
145 
146 private:
147 
148  // Data members...
149  MemoryManager& m_memoryManager;
150 
151  void* m_pointer;
152 };
153 
154 
155 
156 template<class Type>
157 void
158 XalanDestroy(Type& theArg)
159 {
160  theArg.~Type();
161 }
162 
163 
164 
165 template<class Type>
166 void
167 XalanDestroy(Type* theArg)
168 {
169  if (theArg != 0)
170  {
171  theArg->~Type();
172  }
173 }
174 
175 
176 
177 template<class Type>
178 void
180  MemoryManager& theMemoryManager,
181  Type* theArg)
182 {
183  if (theArg != 0)
184  {
185  XalanDestroy(*theArg);
186 
187  theMemoryManager.deallocate(theArg);
188  }
189 }
190 
191 
192 
193 template<class Type>
194 void
196  MemoryManager& theMemoryManager,
197  Type& theArg)
198 {
199  XalanDestroy(theArg);
200 
201  theMemoryManager.deallocate(&theArg);
202 }
203 
204 
205 
206 template<class Type>
207 Type*
209  MemoryManager& theMemoryManager,
210  Type*& theInstance)
211 {
212  XalanAllocationGuard theGuard(
213  theMemoryManager,
214  sizeof(Type));
215 
216  theInstance =
217  new (theGuard.get()) Type;
218 
219  theGuard.release();
220 
221  return theInstance;
222 }
223 
224 
225 
226 template<
227  class Type,
228  class Param1Type>
229 Type*
231  MemoryManager& theMemoryManager,
232  Type*& theInstance,
233  const Param1Type& theParam1)
234 {
235  XalanAllocationGuard theGuard(
236  theMemoryManager,
237  sizeof(Type));
238 
239  theInstance =
240  new (theGuard.get()) Type(theParam1);
241 
242  theGuard.release();
243 
244  return theInstance;
245 }
246 
247 
248 
249 template<
250  class Type,
251  class Param1Type>
252 Type*
254  MemoryManager& theMemoryManager,
255  Type*& theInstance,
256  Param1Type& theParam1)
257 {
258  XalanAllocationGuard theGuard(
259  theMemoryManager,
260  sizeof(Type));
261 
262  theInstance =
263  new (theGuard.get()) Type(theParam1);
264 
265  theGuard.release();
266 
267  return theInstance;
268 }
269 
270 
271 
272 template<
273  class Type,
274  class Param1Type,
275  class Param2Type>
276 Type*
278  MemoryManager& theMemoryManager,
279  Type*& theInstance,
280  Param1Type& theParam1,
281  const Param2Type& theParam2)
282 {
283  XalanAllocationGuard theGuard(
284  theMemoryManager,
285  sizeof(Type));
286 
287  theInstance =
288  new (theGuard.get()) Type(theParam1, theParam2);
289 
290  theGuard.release();
291 
292  return theInstance;
293 }
294 
295 
296 
297 template<
298  class Type,
299  class Param1Type,
300  class Param2Type,
301  class Param3Type,
302  class Param4Type>
303 Type*
305  MemoryManager& theMemoryManager,
306  Type*& theInstance,
307  const Param1Type* theParam1,
308  const Param2Type* theParam2,
309  const Param3Type* theParam3,
310  Param4Type& theParam4)
311 {
312  XalanAllocationGuard theGuard(
313  theMemoryManager,
314  sizeof(Type));
315 
316  theInstance =
317  new (theGuard.get()) Type(theParam1, theParam2, theParam3, theParam4);
318 
319  theGuard.release();
320 
321  return theInstance;
322 }
323 
324 
325 
326 template<
327  class Type,
328  class Param1Type,
329  class Param2Type,
330  class Param3Type,
331  class Param4Type,
332  class Param5Type,
333  class Param6Type>
334 Type*
336  MemoryManager& theMemoryManager,
337  Type*& theInstance,
338  const Param1Type* theParam1,
339  const Param2Type* theParam2,
340  const Param3Type* theParam3,
341  const Param4Type* theParam4,
342  const Param5Type* theParam5,
343  Param6Type& theParam6)
344 {
345  XalanAllocationGuard theGuard(
346  theMemoryManager,
347  sizeof(Type));
348 
349  theInstance =
350  new (theGuard.get()) Type(
351  theParam1,
352  theParam2,
353  theParam3,
354  theParam4,
355  theParam5,
356  theParam6);
357 
358  theGuard.release();
359 
360  return theInstance;
361 }
362 
363 
364 
365 template<
366  class Type,
367  class Param1Type,
368  class Param2Type,
369  class Param3Type>
370 Type*
372  MemoryManager& theMemoryManager,
373  Type*& theInstance,
374  Param1Type& theParam1,
375  const Param2Type& theParam2,
376  Param3Type& theParam3)
377 {
378  XalanAllocationGuard theGuard(
379  theMemoryManager,
380  sizeof(Type));
381 
382  theInstance =
383  new (theGuard.get()) Type(theParam1, theParam2, theParam3);
384 
385  theGuard.release();
386 
387  return theInstance;
388 }
389 
390 
391 
392 template<
393  class Type,
394  class Param1Type,
395  class Param2Type,
396  class Param3Type,
397  class Param4Type,
398  class Param5Type>
399 Type*
401  MemoryManager& theMemoryManager,
402  Type*& theInstance,
403  Param1Type& theParam1,
404  Param2Type& theParam2,
405  const Param3Type& theParam3,
406  const Param4Type& theParam4,
407  const Param5Type& theParam5)
408 {
409  XalanAllocationGuard theGuard(
410  theMemoryManager,
411  sizeof(Type));
412 
413  theInstance =
414  new (theGuard.get()) Type(theParam1, theParam2, theParam3, theParam4, theParam5);
415 
416  theGuard.release();
417 
418  return theInstance;
419 }
420 
421 
422 
423 template<
424  class Type,
425  class Param1Type,
426  class Param2Type,
427  class Param3Type,
428  class Param4Type,
429  class Param5Type,
430  class Param6Type>
431 Type*
433  MemoryManager& theMemoryManager,
434  Type*& theInstance,
435  Param1Type& theParam1,
436  Param2Type& theParam2,
437  const Param3Type& theParam3,
438  const Param4Type& theParam4,
439  const Param5Type& theParam5,
440  const Param6Type& theParam6)
441 {
442  XalanAllocationGuard theGuard(
443  theMemoryManager,
444  sizeof(Type));
445 
446  theInstance =
447  new (theGuard.get()) Type(theParam1, theParam2, theParam3, theParam4, theParam5, theParam6);
448 
449  theGuard.release();
450 
451  return theInstance;
452 }
453 
454 
455 
456 template<class Type>
457 Type*
459  MemoryManager& theMemoryManager,
460  const Type& theSource)
461 {
462  XalanAllocationGuard theGuard(
463  theMemoryManager,
464  sizeof(Type));
465 
466  Type* const theInstance =
467  new (theGuard.get()) Type(theSource);
468 
469  theGuard.release();
470 
471  return theInstance;
472 }
473 
474 
475 
476 template<
477  class Type,
478  class Param1Type>
479 Type*
481  MemoryManager& theMemoryManager,
482  const Type& theSource,
483  Param1Type& theParam1)
484 {
485  XalanAllocationGuard theGuard(
486  theMemoryManager,
487  sizeof(Type));
488 
489  Type* const theInstance =
490  new (theGuard.get()) Type(theSource, theParam1);
491 
492  theGuard.release();
493 
494  return theInstance;
495 }
496 
497 
498 
500 {
501 public:
502 
503  static MemoryManager&
504  getDummyMemMgr();
505 
506  static MemoryManager&
507  getDefaultXercesMemMgr();
508 
509  static MemoryManager&
511  {
512  return getDefaultXercesMemMgr();
513  }
514 };
515 
516 
517 
518 
519 #if defined (XALAN_DEVELOPMENT)
520 #define XALAN_DEFAULT_CONSTRUCTOR_MEMMGR
521 #define XALAN_DEFAULT_MEMMGR = XalanMemMgrs::getDummyMemMgr()
522 #else
523 #define XALAN_DEFAULT_CONSTRUCTOR_MEMMGR = XalanMemMgrs::getDefaultXercesMemMgr()
524 #define XALAN_DEFAULT_MEMMGR = XalanMemMgrs::getDefaultXercesMemMgr()
525 #endif
526 
527 
528 
529 template <class C>
531 {
532  ConstructValueWithNoMemoryManager(MemoryManager& /*mgr*/) :
533  value()
534  {
535  }
536 
537  C value;
538 };
539 
540 template <class C>
542 {
543  ConstructValueWithMemoryManager(MemoryManager& mgr) :
544  value(mgr)
545  {
546  }
547 
548  C value;
549 };
550 
551 template <class C>
553 {
555 
556  static C* construct(C* address, MemoryManager& /* mgr */)
557  {
558  return (C*) new (address) C();
559  }
560 
561  static C* construct(C* address, const C& theRhs, MemoryManager& /* mgr */)
562  {
563  return (C*) new (address) C(theRhs);
564  }
565 };
566 
567 template <class C>
569 {
571 
572  static C* construct(C* address, MemoryManager& mgr)
573  {
574  return (C*) new (address) C(mgr);
575  }
576 
577  static C* construct(C* address, const C& theRhs, MemoryManager& mgr)
578  {
579  return (C*) new (address) C(theRhs, mgr);
580  }
581 };
582 
583 template <class C>
585 {
587 
588 };
589 
590 template <class C>
592 {
594 
595 };
596 
597 #define XALAN_USES_MEMORY_MANAGER(Type) \
598 template<> \
599 struct MemoryManagedConstructionTraits<Type> \
600  { \
601  typedef ConstructWithMemoryManager<Type> Constructor; \
602  };
603 
604 template <class C>
606 {
608 };
609 
610 template <class C>
612 {
614 };
615 
616 
617 
618 XALAN_CPP_NAMESPACE_END
619 
620 
621 
622 #endif // XALANMEMORYMANAGEMENT_HEADER_GUARD_1357924680
ConstructValueWithNoMemoryManager< C > ConstructableType
static C * construct(C *address, const C &theRhs, MemoryManager &)
ConstructWithNoMemoryManager< C > Constructor
static C * construct(C *address, const C &theRhs, MemoryManager &mgr)
ConstructWithMemoryManager< C > Constructor
ConstructValueWithMemoryManager< C > ConstructableType
XalanAllocationGuard(MemoryManager &theMemoryManager, size_type theSize)
Type * XalanCopyConstruct(MemoryManager &theMemoryManager, const Type &theSource)
ConstructWithMemoryManager< C > Constructor
XALAN_CPP_NAMESPACE_BEGIN typedef MemoryManager MemoryManagerType
static C * construct(C *address, MemoryManager &)
XALAN_CPP_NAMESPACE_BEGIN typedef size_t size_type
Definition: XalanMap.hpp:46
static MemoryManager & getExceptionMemoryManager(MemoryManager &theMemoryManager)
static C * construct(C *address, MemoryManager &mgr)
static MemoryManager & getDefault()
void XalanDestroy(Type &theArg)
ConstructWithNoMemoryManager< C > Constructor
XalanMemoryManager & operator=(const XalanMemoryManager &)
XalanAllocationGuard(MemoryManager &theMemoryManager, void *thePointer)
#define XALAN_PLATFORM_EXPORT
XALAN_CPP_NAMESPACE_BEGIN XALAN_USING_XERCES(Locator)
ConstructValueWithMemoryManager(MemoryManager &mgr)
Type * XalanConstruct(MemoryManager &theMemoryManager, Type *&theInstance)

Interpreting class diagrams

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

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

Apache Logo