Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.10

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

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