Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.10

XalanMemoryManagement.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #if !defined(XALANMEMORYMANAGEMENT_HEADER_GUARD_1357924680)
17 #define XALANMEMORYMANAGEMENT_HEADER_GUARD_1357924680
18 
19 
20 // Base include file. Must be first.
22 
23 
24 
25 #include <cstddef>
26 #include <new>
27 
28 
29 
30 #include <xercesc/framework/MemoryManager.hpp>
31 
32 
33 
34 
35 XALAN_CPP_NAMESPACE_BEGIN
36 
37 
38 
39 typedef XERCES_CPP_NAMESPACE_QUALIFIER MemoryManager MemoryManagerType;
40 XALAN_USING_XERCES(MemoryManager)
41 
42 
43 
45 {
46 public:
47 
48 #if defined(XALAN_STRICT_ANSI_HEADERS)
49  typedef std::size_t size_type;
50 #else
51  typedef size_t size_type;
52 #endif
53 
54  XalanAllocationGuard(
55  MemoryManager& theMemoryManager,
56  void* thePointer) :
57  m_memoryManager(theMemoryManager),
58  m_pointer(thePointer)
59  {
60  }
61 
62  XalanAllocationGuard(
63  MemoryManager& theMemoryManager,
64  size_type theSize) :
65  m_memoryManager(theMemoryManager),
66  m_pointer(theMemoryManager.allocate(theSize))
67  {
68  }
69 
70  ~XalanAllocationGuard()
71  {
72  if (m_pointer != 0)
73  {
74  m_memoryManager.deallocate(m_pointer);
75  }
76  }
77 
78  void*
79  get() const
80  {
81  return m_pointer;
82  }
83 
84  void
85  release()
86  {
87  m_pointer = 0;
88  }
89 
90 private:
91 
92  // Data members...
93  MemoryManager& m_memoryManager;
94 
95  void* m_pointer;
96 };
97 
98 
99 
100 template<class Type>
101 void
102 XalanDestroy(Type& theArg)
103 {
104  theArg.~Type();
105 }
106 
107 
108 
109 template<class Type>
110 void
111 XalanDestroy(Type* theArg)
112 {
113  if (theArg != 0)
114  {
115  theArg->~Type();
116  }
117 }
118 
119 
120 
121 template<class Type>
122 void
124  MemoryManager& theMemoryManager,
125  Type* theArg)
126 {
127  if (theArg != 0)
128  {
129  XalanDestroy(*theArg);
130 
131  theMemoryManager.deallocate(theArg);
132  }
133 }
134 
135 
136 
137 template<class Type>
138 void
140  MemoryManager& theMemoryManager,
141  Type& theArg)
142 {
143  XalanDestroy(theArg);
144 
145  theMemoryManager.deallocate(&theArg);
146 }
147 
148 
149 
150 template<class Type>
151 Type*
153  MemoryManager& theMemoryManager,
154  Type*& theInstance)
155 {
156  XalanAllocationGuard theGuard(
157  theMemoryManager,
158  sizeof(Type));
159 
160  theInstance =
161  new (theGuard.get()) Type;
162 
163  theGuard.release();
164 
165  return theInstance;
166 }
167 
168 
169 
170 template<
171  class Type,
172  class Param1Type>
173 Type*
175  MemoryManager& theMemoryManager,
176  Type*& theInstance,
177  const Param1Type& theParam1)
178 {
179  XalanAllocationGuard theGuard(
180  theMemoryManager,
181  sizeof(Type));
182 
183  theInstance =
184  new (theGuard.get()) Type(theParam1);
185 
186  theGuard.release();
187 
188  return theInstance;
189 }
190 
191 
192 
193 template<
194  class Type,
195  class Param1Type>
196 Type*
198  MemoryManager& theMemoryManager,
199  Type*& theInstance,
200  Param1Type& theParam1)
201 {
202  XalanAllocationGuard theGuard(
203  theMemoryManager,
204  sizeof(Type));
205 
206  theInstance =
207  new (theGuard.get()) Type(theParam1);
208 
209  theGuard.release();
210 
211  return theInstance;
212 }
213 
214 
215 
216 template<
217  class Type,
218  class Param1Type,
219  class Param2Type>
220 Type*
222  MemoryManager& theMemoryManager,
223  Type*& theInstance,
224  Param1Type& theParam1,
225  const Param2Type& theParam2)
226 {
227  XalanAllocationGuard theGuard(
228  theMemoryManager,
229  sizeof(Type));
230 
231  theInstance =
232  new (theGuard.get()) Type(theParam1, theParam2);
233 
234  theGuard.release();
235 
236  return theInstance;
237 }
238 
239 
240 
241 template<
242  class Type,
243  class Param1Type,
244  class Param2Type,
245  class Param3Type>
246 Type*
248  MemoryManager& theMemoryManager,
249  Type*& theInstance,
250  Param1Type& theParam1,
251  const Param2Type& theParam2,
252  Param3Type& theParam3)
253 {
254  XalanAllocationGuard theGuard(
255  theMemoryManager,
256  sizeof(Type));
257 
258  theInstance =
259  new (theGuard.get()) Type(theParam1, theParam2, theParam3);
260 
261  theGuard.release();
262 
263  return theInstance;
264 }
265 
266 
267 
268 template<
269  class Type,
270  class Param1Type,
271  class Param2Type,
272  class Param3Type,
273  class Param4Type,
274  class Param5Type>
275 Type*
277  MemoryManager& theMemoryManager,
278  Type*& theInstance,
279  Param1Type& theParam1,
280  Param2Type& theParam2,
281  const Param3Type& theParam3,
282  const Param4Type& theParam4,
283  const Param5Type& theParam5)
284 {
285  XalanAllocationGuard theGuard(
286  theMemoryManager,
287  sizeof(Type));
288 
289  theInstance =
290  new (theGuard.get()) Type(theParam1, theParam2, theParam3, theParam4, theParam5);
291 
292  theGuard.release();
293 
294  return theInstance;
295 }
296 
297 
298 
299 template<
300  class Type,
301  class Param1Type,
302  class Param2Type,
303  class Param3Type,
304  class Param4Type,
305  class Param5Type,
306  class Param6Type>
307 Type*
309  MemoryManager& theMemoryManager,
310  Type*& theInstance,
311  Param1Type& theParam1,
312  Param2Type& theParam2,
313  const Param3Type& theParam3,
314  const Param4Type& theParam4,
315  const Param5Type& theParam5,
316  const Param6Type& theParam6)
317 {
318  XalanAllocationGuard theGuard(
319  theMemoryManager,
320  sizeof(Type));
321 
322  theInstance =
323  new (theGuard.get()) Type(theParam1, theParam2, theParam3, theParam4, theParam5, theParam6);
324 
325  theGuard.release();
326 
327  return theInstance;
328 }
329 
330 
331 
332 template<class Type>
333 Type*
335  MemoryManager& theMemoryManager,
336  const Type& theSource)
337 {
338  XalanAllocationGuard theGuard(
339  theMemoryManager,
340  sizeof(Type));
341 
342  Type* const theInstance =
343  new (theGuard.get()) Type(theSource);
344 
345  theGuard.release();
346 
347  return theInstance;
348 }
349 
350 
351 
352 template<
353  class Type,
354  class Param1Type>
355 Type*
357  MemoryManager& theMemoryManager,
358  const Type& theSource,
359  Param1Type& theParam1)
360 {
361  XalanAllocationGuard theGuard(
362  theMemoryManager,
363  sizeof(Type));
364 
365  Type* const theInstance =
366  new (theGuard.get()) Type(theSource, theParam1);
367 
368  theGuard.release();
369 
370  return theInstance;
371 }
372 
373 
374 
376 {
377 public:
378 
379  static MemoryManager&
380  getDummyMemMgr();
381 
382  static MemoryManager&
383  getDefaultXercesMemMgr();
384 
385  static MemoryManager&
386  getDefault()
387  {
388  return getDefaultXercesMemMgr();
389  }
390 };
391 
392 
393 
394 
395 #if defined (XALAN_DEVELOPMENT)
396 #define XALAN_DEFAULT_CONSTRUCTOR_MEMORY_MGR
397 #define XALAN_DEFAULT_CONSTRACTOR_MEMORY_MGR
398 #define XALAN_DEFAULT_MEMMGR = XalanMemMgrs::getDummyMemMgr()
399 #else
400 #define XALAN_DEFAULT_CONSTRUCTOR_MEMORY_MGR = XalanMemMgrs::getDefaultXercesMemMgr()
401 #define XALAN_DEFAULT_CONSTRACTOR_MEMORY_MGR XALAN_DEFAULT_CONSTRUCTOR_MEMORY_MGR
402 #define XALAN_DEFAULT_MEMMGR = XalanMemMgrs::getDefaultXercesMemMgr()
403 #endif
404 
405 
406 
407 template <class C>
409 {
410  ConstructValueWithNoMemoryManager(MemoryManager& /*mgr*/) :
411  value()
412  {
413  }
414 
415  C value;
416 };
417 
418 template <class C>
420 {
421  ConstructValueWithMemoryManager(MemoryManager& mgr) :
422  value(mgr)
423  {
424  }
425 
426  C value;
427 };
428 
429 template <class C>
431 {
433 
434  static C* construct(C* address, MemoryManager& /* mgr */)
435  {
436  return (C*) new (address) C;
437  }
438 
439  static C* construct(C* address, const C& theRhs, MemoryManager& /* mgr */)
440  {
441  return (C*) new (address) C(theRhs);
442  }
443 };
444 
445 template <class C>
447 {
449 
450  static C* construct(C* address, MemoryManager& mgr)
451  {
452  return (C*) new (address) C(mgr);
453  }
454 
455  static C* construct(C* address, const C& theRhs, MemoryManager& mgr)
456  {
457  return (C*) new (address) C(theRhs, mgr);
458  }
459 };
460 
461 template <class C>
463 {
465 
466 };
467 
468 #define XALAN_USES_MEMORY_MANAGER(Type) \
469 template<> \
470 struct MemoryManagedConstructionTraits<Type> \
471  { \
472  typedef ConstructWithMemoryManager<Type> Constructor; \
473  };
474 
475 template <class C>
477 {
479 };
480 
481 template <class C>
483 {
485 };
486 
487 
488 
489 
490 XALAN_CPP_NAMESPACE_END
491 
492 
493 
494 #endif // XALANMEMORYMANAGEMENT_HEADER_GUARD_1357924680
495 
496 

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