Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.11


ArenaBlockBase.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 
19 #if !defined(ARENABLOCKBASE_INCLUDE_GUARD_1357924680)
20 #define ARENABLOCKBASE_INCLUDE_GUARD_1357924680
21 
22 
23 #include <cassert>
24 #include <functional>
25 //#include <memory>
26 
28 
29 
30 #if !defined(XALAN_NO_SELECTIVE_TEMPLATE_INSTANTIATION)
32 #endif
33 
34 
35 XALAN_CPP_NAMESPACE_BEGIN
36 
37 
38 #if defined(XALAN_NO_SELECTIVE_TEMPLATE_INSTANTIATION)
39 
40 template <class Type>
41 class ArenaBlockAllocator
42 {
43 public:
44 
45  typedef typename T size_type;
46  typedef ptrdiff_t difference_type;
47  typedef Type* pointer;
48  typedef const Type* const_pointer;
49  typedef Type& reference;
50  typedef const Type& const_reference;
51  typedef Type value_type;
52 
53  ArenaBlockAllocator(MemoryManager& theManager) :
54  m_memoryManager(theManager)
55  {
56  }
57 
58  ~ArenaBlockAllocator()
59  {
60  }
61 
62  MemoryManager&
63  getMemoryManager()
64  {
65  return m_memoryManager;
66  }
67 
68  pointer
69  allocate(
70  size_type size,
71  const void* /* hint */ = 0)
72  {
73  return (pointer)m_memoryManager.allocate(size * sizeof(Type));
74  }
75 
76  void
77  deallocate(
78  pointer p,
79  size_type /* n */)
80  {
81  if(p != 0)
82  {
83  m_memoryManager.deallocate(p);
84  }
85  }
86 
87 private:
88 
89  // not defined
90  ArenaBlockAllocator(const ArenaBlockAllocator<Type>&);
91 
92  ArenaBlockAllocator<Type>&
93  operator=(const ArenaBlockAllocator<Type>&);
94 
95  MemoryManager& m_memoryManager;
96 };
97 #endif
98 
99 
100 
101 template<class ObjectType,
102 #if defined(XALAN_NO_DEFAULT_TEMPLATE_ARGUMENTS)
103  class SizeType>
104 #else
105  class SizeType = size_t>
106 #endif
108 {
109 public:
110 
112 
113 #if defined(XALAN_NO_SELECTIVE_TEMPLATE_INSTANTIATION)
114  typedef ArenaBlockAllocator<ObjectType> AllocatorType;
115 #else
117 #endif
118 
119  typedef SizeType size_type;
120 
121  MemoryManager&
123  {
124  return m_allocator.getMemoryManager();
125  }
126 
127  /*
128  * Find out if there is a block available.
129  *
130  * @return true if one is available, false if not.
131  */
132  bool
134  {
135  return m_objectCount < m_blockSize ? true : false;
136  }
137 
138  /*
139  * Find out if there are any block is allocated
140  *
141  * @return true if one is available, false if not.
142  */
143  bool
144  isEmpty() const
145  {
146  return m_objectCount == 0 ? true : false;
147  }
148 
149  /*
150  * Get the number of objects currently allocated in the
151  * block.
152  *
153  * @return The number of objects allocated.
154  */
155  size_type
157  {
158  return m_objectCount;
159  }
160 
161  /*
162  * Get the block size, that is, the number
163  * of objects in each block.
164  *
165  * @return The size of the block
166  */
167  size_type
168  getBlockSize() const
169  {
170  return m_blockSize;
171  }
172 
173  /*
174  * Determine if this block owns the specified object block.
175  * Note that, unlike ownsObject(), there does not need to
176  * be an object at the address.
177  *
178  * @param theObject the address of the object
179  * @return true if we own the object block, false if not.
180  */
181  bool
182  ownsBlock(const ObjectType* theObject) const
183  {
184  return isInBorders(theObject, m_blockSize);
185  }
186 
187 protected:
188 
190  MemoryManager& theManager,
191  size_type theBlockSize) :
192  m_allocator(theManager),
193  m_objectCount(0),
194  m_blockSize(theBlockSize),
195 #if defined(XALAN_NEW_STD_ALLOCATOR)
196  m_objectBlock(m_allocator.allocate(m_blockSize))
197 #else
198  m_objectBlock(m_allocator.allocate(m_blockSize, 0))
199 #endif
200  {
201  assert(theBlockSize > 0);
202 
203  assert(m_objectBlock != 0);
204  }
205 
207  {
208  // Release the memory...
209  m_allocator.deallocate(m_objectBlock, m_blockSize);
210 
211  }
212 
213  /*
214  * Determine if this block is located between beginning of the array
215  * and the "rightBorder" array member (not included)
216  * @param theObject the address of the object
217  * rightBorder the right
218  * @return true if we own the object block, false if not.
219  */
220  bool
222  const ObjectType* theObject,
223  size_type rightBoundary) const
224  {
225  if ( rightBoundary > m_blockSize )
226  {
227  rightBoundary = m_blockSize;
228  }
229 
230  // Use less<>, since it's guaranteed to do pointer
231  // comparisons correctly...
232  XALAN_STD_QUALIFIER less<const ObjectType*> functor;
233 
234  if (functor(theObject, m_objectBlock) == false &&
235  functor(theObject, m_objectBlock + rightBoundary) == true)
236  {
237  return true;
238  }
239  else
240  {
241  return false;
242  }
243  }
244 
245  /*
246  * Determine the offset into the block for the given address.
247  * Behavior is undefined if the address is not within our
248  * block
249  *
250  * @param theObject the address of the object
251  * @return the offset
252  */
253  size_type
254  getBlockOffset(const ObjectType* theObject) const
255  {
256  assert(size_type( (theObject - m_objectBlock) / sizeof(ObjectType) ) < m_blockSize);
257 
258  return theObject - m_objectBlock;
259  }
260 
261  /*
262  * Determine the address within our block of the object
263  * at the specified offset.
264  * Behavior is undefined if the offset is greater than the
265  * block size.
266  *
267  * @param theObject the address of the object
268  * @return the offset
269  */
270  ObjectType*
271  getBlockAddress(size_type theOffset) const
272  {
273  assert(theOffset < m_blockSize);
274 
275  return m_objectBlock + theOffset;
276  }
277 
278  // data members...
279  AllocatorType m_allocator;
280 
281  size_type m_objectCount;
282 
283  const size_type m_blockSize;
284 
285  ObjectType* m_objectBlock;
286 
287 private:
288 
289  // Not implemented...
290  ArenaBlockBase(const ThisType&);
291 
292  ThisType&
293  operator=(const ThisType&);
294 
295  bool
296  operator==(const ThisType&) const;
297 };
298 
299 XALAN_CPP_NAMESPACE_END
300 
301 
302 
303 #endif // !defined(ARENABLOCKBASE_INCLUDE_GUARD_1357924680)
bool isInBorders(const ObjectType *theObject, size_type rightBoundary) const
ArenaBlockBase(MemoryManager &theManager, size_type theBlockSize)
ArenaBlockBase< ObjectType, SizeType > ThisType
XalanAllocator< ObjectType > AllocatorType
ObjectType * m_objectBlock
ObjectType * getBlockAddress(size_type theOffset) const
bool isEmpty() const
XALAN_CPP_NAMESPACE_BEGIN typedef size_t size_type
Definition: XalanMap.hpp:46
MemoryManager & getMemoryManager()
size_type m_objectCount
AllocatorType m_allocator
bool blockAvailable() const
bool operator==(const ElemAttributeSet &theLHS, const ElemAttributeSet &theRHS)
size_type getBlockOffset(const ObjectType *theObject) const
size_type getBlockSize() const
const size_type m_blockSize
bool ownsBlock(const ObjectType *theObject) const
size_type getCountAllocated() const
#define XALAN_NEW_STD_ALLOCATOR

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