Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.11


XalanMemMgrAutoPtr.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(XALANMEMMGRAUTOPTR_HEADER_GUARD_1357924680)
19 #define XALANMEMMGRAUTOPTR_HEADER_GUARD_1357924680
20 
21 
22 
23 // Base include file. Must be first.
25 
26 
27 
29 
30 #include <cstddef>
31 
32 #include <cassert>
33 
34 #include <utility>
35 
36 
37 
38 XALAN_CPP_NAMESPACE_BEGIN
39 
40 
41 
42 XALAN_USING_XERCES(MemoryManager)
43 
44 // An auto_ptr-like class that supports the MemoryManager class.
45 template<class Type>
47 {
48 public:
49 
50  typedef XALAN_STD_QUALIFIER pair<MemoryManager*, Type*> AutoPtrPairType;
51 
52  class MemMgrAutoPtrData : public AutoPtrPairType
53  {
54  public:
55 
57  AutoPtrPairType()
58  {
59  }
60 
62  MemoryManager* memoryManager,
63  Type* dataPointer):
64  AutoPtrPairType(memoryManager, dataPointer)
65  {
66  invariants();
67  }
68 
69  bool
71  {
72  return this->first != 0 && this->second != 0;
73  }
74 
75  void
77  {
78  invariants();
79 
80  if (isInitialized())
81  {
82  this->second->~Type();
83 
84  this->first->deallocate(this->second);
85  }
86  }
87 
88  void
90  MemoryManager* memoryManager,
91  Type* dataPointer)
92  {
93  invariants();
94 
95  this->first = memoryManager;
96 
97  this->second = dataPointer;
98 
99  invariants();
100  }
101 
102  private:
103 
104  void
105  invariants() const
106  {
107  assert(
108  isInitialized() ||
109  (this->first == 0 && this->second == 0));
110  }
111  };
112 
113 
115  MemoryManager& theManager,
116  Type* ptr) :
117  m_pointerInfo(&theManager, ptr)
118  {
119  }
120 
122  m_pointerInfo()
123  {
124  }
125 
127  m_pointerInfo(const_cast<XalanMemMgrAutoPtr<Type>&>(theSource).release())
128  {
129  }
130 
133  {
134  if (this != &theRHS)
135  {
136  m_pointerInfo.deallocate();
137 
138  m_pointerInfo = theRHS.release();
139  }
140 
141  return *this;
142  }
143 
145  {
146  m_pointerInfo.deallocate();
147  }
148 
149  Type&
150  operator*() const
151  {
152  return *m_pointerInfo.second;
153  }
154 
155  Type*
156  operator->() const
157  {
158  return m_pointerInfo.second;
159  }
160 
161  Type*
162  get() const
163  {
164  return m_pointerInfo.second;
165  }
166 
167  MemoryManager*
169  {
170  return m_pointerInfo.first;
171  }
172 
173  const MemoryManager*
175  {
176  return m_pointerInfo.first;
177  }
178 
181  {
182  MemMgrAutoPtrData tmp = m_pointerInfo;
183 
184  m_pointerInfo.reset(0, 0);
185 
186  return MemMgrAutoPtrData(tmp);
187  }
188 
189  Type*
191  {
192  MemMgrAutoPtrData tmp = release();
193 
194  return tmp.second;
195  }
196 
197  void
199  MemoryManager* theManager = 0,
200  Type* thePointer = 0)
201  {
202  m_pointerInfo.deallocate();
203 
204  m_pointerInfo.reset(theManager, thePointer);
205  }
206 
207 private:
208 
209  // data member
210  MemMgrAutoPtrData m_pointerInfo;
211 };
212 
213 
214 
215 
216 template<class Type>
218 {
219 public:
220 
221 #if defined(XALAN_STRICT_ANSI_HEADERS)
222  typedef std::size_t size_type;
223 #else
224  typedef size_t size_type;
225 #endif
226 
228  {
229  public:
230 
232  m_memoryManager(0),
233  m_dataArray(0),
234  m_size(0)
235  {
236  }
237 
239  MemoryManager* memoryManager,
240  Type* dataPointer,
241  size_type size):
242  m_memoryManager(memoryManager),
243  m_dataArray(dataPointer),
244  m_size(size)
245  {
246  invariants();
247  }
248 
249  bool
251  {
252  return m_memoryManager != 0 && m_dataArray != 0 && m_size != 0;
253  }
254 
255  void
257  {
258  invariants();
259 
260  if ( isInitilized() )
261  {
262  assert ( m_dataArray != 0 );
263 
264  for ( size_type i = 0; i < m_size ; ++i )
265  {
266  m_dataArray[i].~Type();
267  }
268 
269  m_memoryManager->deallocate(m_dataArray);
270  }
271  }
272 
273  void
275  MemoryManager* theMemoryManager,
276  Type* thePointer,
277  size_type size)
278  {
279  invariants();
280 
281  m_memoryManager = theMemoryManager;
282 
283  m_dataArray = thePointer;
284 
285  m_size = size;
286 
287  invariants();
288  }
289 
290  MemoryManager* m_memoryManager;
291 
292  Type* m_dataArray;
293 
294  size_type m_size;
295 
296  private:
297 
298  void
299  invariants()const
300  {
301  assert(
302  isInitilized() ||
303  (m_memoryManager == 0 && m_dataArray == 0 && m_size == 0));
304  }
305  };
306 
308  MemoryManager& theManager,
309  Type* ptr,
310  size_type size) :
311  m_pointerInfo(
312  &theManager,
313  ptr,
314  size)
315  {
316  }
317 
319  m_pointerInfo()
320  {
321  }
322 
324  m_pointerInfo(((XalanMemMgrAutoPtr<Type>&)theSource).release())
325  {
326  }
327 
330  {
331  if (this != &theRHS)
332  {
333  m_pointerInfo.deallocate();
334 
335  m_pointerInfo = theRHS.release();
336  }
337 
338  return *this;
339  }
340 
342  {
343  m_pointerInfo.deallocate();
344  }
345 
346  Type&
347  operator*() const
348  {
349  return *m_pointerInfo.m_dataArray;
350  }
351 
352  Type*
353  operator->() const
354  {
355  return m_pointerInfo.m_dataArray;
356  }
357 
358  Type*
359  get() const
360  {
361  return m_pointerInfo.m_dataArray;
362  }
363 
364  size_type
365  getSize()const
366  {
367  return m_pointerInfo.m_size;
368  }
369 
370  MemoryManager*
372  {
373  return m_pointerInfo.m_memoryManager;
374  }
375 
376  const MemoryManager*
378  {
379  return m_pointerInfo.m_memoryManager;
380  }
381 
383  operator++ ()
384  {
385  ++m_pointerInfo.m_size;
386 
387  return *this;
388  }
389 
390  /* Since this class is not reference-counted, I don't see how this
391  could work, since the destruction of the temporary will free
392  the controlled pointer.
393  XalanMemMgrAutoPtrArray<Type>
394  operator++ (int)
395  {
396  XalanMemMgrAutoPtrArray<Type> temp = *this;
397  ++*this;
398 
399  return temp;
400  }
401  */
402 
405  {
406  MemMgrAutoPtrArrayData tmp = m_pointerInfo;
407 
408  m_pointerInfo.reset(0, 0, 0);
409 
410  return MemMgrAutoPtrArrayData(tmp);
411  }
412 
413  Type*
415  {
417 
418  return tmp.m_dataArray;
419  }
420 
421  void
423  MemoryManager* theManager = 0,
424  Type* thePointer = 0 ,
425  size_type size = 0)
426  {
427  m_pointerInfo.deallocate();
428 
429  m_pointerInfo.reset(theManager, thePointer, size);
430  }
431 
432  Type&
433  operator[](size_type index) const
434  {
435  return m_pointerInfo.m_dataArray[index];
436  }
437 
438 private:
439 
440  // data member
441  MemMgrAutoPtrArrayData m_pointerInfo;
442 };
443 
444 
445 
446 
447 XALAN_CPP_NAMESPACE_END
448 
449 
450 
451 #endif // if !defined(XALANMEMMGRAUTOPTR_HEADER_GUARD_1357924680)
XALAN_STD_QUALIFIER pair< MemoryManager *, Type * > AutoPtrPairType
const MemoryManager * getMemoryManager() const
void reset(MemoryManager *theManager=0, Type *thePointer=0, size_type size=0)
Type & operator[](size_type index) const
XalanMemMgrAutoPtrArray< Type > & operator=(XalanMemMgrAutoPtrArray< Type > &theRHS)
MemMgrAutoPtrArrayData(MemoryManager *memoryManager, Type *dataPointer, size_type size)
void reset(MemoryManager *theManager=0, Type *thePointer=0)
void reset(MemoryManager *theMemoryManager, Type *thePointer, size_type size)
MemoryManager * getMemoryManager()
XalanMemMgrAutoPtr< Type > & operator=(XalanMemMgrAutoPtr< Type > &theRHS)
MemMgrAutoPtrArrayData release()
XALAN_CPP_NAMESPACE_BEGIN typedef size_t size_type
Definition: XalanMap.hpp:46
MemMgrAutoPtrData(MemoryManager *memoryManager, Type *dataPointer)
XalanMemMgrAutoPtr(MemoryManager &theManager, Type *ptr)
void reset(MemoryManager *memoryManager, Type *dataPointer)
XalanMemMgrAutoPtrArray(MemoryManager &theManager, Type *ptr, size_type size)
const MemoryManager * getMemoryManager() const
MemoryManager * getMemoryManager()
XALAN_CPP_NAMESPACE_BEGIN XALAN_USING_XERCES(Locator)
MemMgrAutoPtrData release()
XalanMemMgrAutoPtr(const XalanMemMgrAutoPtr< Type > &theSource)
XalanMemMgrAutoPtrArray(const XalanMemMgrAutoPtrArray< Type > &theSource)

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