Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.11


ArenaAllocator.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(ARENAALLOCATOR_INCLUDE_GUARD_1357924680)
20 #define ARENAALLOCATOR_INCLUDE_GUARD_1357924680
21 
22 
23 
24 #include <algorithm>
25 
26 
27 
30 
31 
32 
33 #include "ArenaBlock.hpp"
34 
35 
36 
37 XALAN_CPP_NAMESPACE_BEGIN
38 
39 
40 
41 template<class ObjectType,
42 #if defined(XALAN_NO_DEFAULT_TEMPLATE_ARGUMENTS)
43  class ArenaBlockType>
44 #else
45  class ArenaBlockType = ArenaBlock<ObjectType> >
46 #endif
48 {
49 public:
50 
52 
54 
56 
57  /*
58  * Construct an instance that will allocate blocks of the specified size.
59  *
60  * @param theBlockSize The block size.
61  */
63  MemoryManager& theManager,
64  size_type theBlockSize) :
65  m_blockSize(theBlockSize),
66  m_blocks(theManager)
67  {
68  }
69 
70  virtual
72  {
73  reset();
74  }
75 
76  MemoryManager&
78  {
79  return m_blocks.getMemoryManager();
80  }
81 
82  const MemoryManager&
84  {
85  return m_blocks.getMemoryManager();
86  }
87 
88  /*
89  * Get size of an ArenaBlock, that is, the number
90  * of objects in each block.
91  *
92  * @return The size of the block
93  */
94  size_type
95  getBlockSize() const
96  {
97  return m_blockSize;
98  }
99 
100  /*
101  * Set size of an ArenaBlock, that is, the number
102  * of objects in each block. Only affects blocks
103  * allocated after the call.
104  *
105  * @param theSize The size of the block
106  */
107  void
108  setBlockSize(size_type theSize)
109  {
110  m_blockSize = theSize;
111  }
112 
113  /*
114  * Get the number of ArenaBlocks currently allocated.
115  *
116  * @return The number of blocks.
117  */
118  size_type
120  {
121  return (size_type)m_blocks.size();
122  }
123 
124  /*
125  * Allocate a block of the appropriate size for an
126  * object. Call commitAllocation() when after
127  * the object is successfully constructed.
128  *
129  * @return A pointer to a block of memory
130  */
131  virtual ObjectType*
133  {
134  if (m_blocks.empty() == true ||
135  m_blocks.back()->blockAvailable() == false)
136  {
138  ArenaBlockType::create(
140  m_blockSize));
141  }
142  assert(
143  m_blocks.empty() == false &&
144  m_blocks.back() != 0 &&
145  m_blocks.back()->blockAvailable() == true);
146 
147  return m_blocks.back()->allocateBlock();
148  }
149 
150  /*
151  * Commits the allocation of the previous
152  * allocateBlock() call.
153  *
154  * @param theObject A pointer to a block of memory
155  */
156  virtual void
157  commitAllocation(ObjectType* theObject)
158  {
159  assert(
160  m_blocks.empty() == false &&
161  m_blocks.back()->ownsBlock(theObject) == true);
162 
163  m_blocks.back()->commitAllocation(theObject);
164 
165  assert(m_blocks.back()->ownsObject(theObject) == true);
166  }
167 
168  virtual bool
169  ownsObject(const ObjectType* theObject) const
170  {
171  bool fResult = false;
172 
173  typedef typename ArenaBlockListType::const_reverse_iterator const_reverse_iterator;
174 
175  // Search back for a block that may have allocated the object...
176  const const_reverse_iterator theEnd = this->m_blocks.rend();
177 
178  const_reverse_iterator i = this->m_blocks.rbegin();
179 
180  while(i != theEnd)
181  {
182  assert(*i != 0);
183 
184  if ((*i)->ownsObject(theObject) == true)
185  {
186  fResult = true;
187 
188  break;
189  }
190  else
191  {
192  ++i;
193  }
194  }
195 
196  return fResult;
197  }
198 
199  virtual void
201  {
202  XALAN_STD_QUALIFIER for_each(
203  m_blocks.begin(),
204  m_blocks.end(),
206 
207  m_blocks.clear();
208  }
209 
210 protected:
211 
212  // data members...
213  size_type m_blockSize;
214 
215  ArenaBlockListType m_blocks;
216 
217 private:
218 
219  // Not defined...
221 
224 
225  bool
226  operator==(const ArenaAllocator<ObjectType, ArenaBlockType>&) const;
227 };
228 
229 
230 
231 XALAN_CPP_NAMESPACE_END
232 
233 
234 
235 #endif // !defined(ARENAALLOCATOR_INCLUDE_GUARD_1357924680)
ArenaAllocator(MemoryManager &theManager, size_type theBlockSize)
MemoryManager & getMemoryManager()
bool empty() const
Definition: XalanList.hpp:341
virtual void reset()
const MemoryManager & getMemoryManager() const
iterator end()
Definition: XalanList.hpp:280
size_type size() const
Definition: XalanList.hpp:328
reverse_iterator rend()
Definition: XalanList.hpp:304
iterator begin()
Definition: XalanList.hpp:268
void clear()
Definition: XalanList.hpp:442
size_type getBlockSize() const
ArenaBlockListType m_blocks
Functor to delete objects, used in STL iteration algorithms.
Definition: STLHelper.hpp:103
XALAN_CPP_NAMESPACE_BEGIN typedef size_t size_type
Definition: XalanMap.hpp:46
XalanList< ArenaBlockType * > ArenaBlockListType
void push_back(const value_type &data)
Definition: XalanList.hpp:347
virtual ~ArenaAllocator()
virtual bool ownsObject(const ObjectType *theObject) const
reference back()
Definition: XalanList.hpp:322
ArenaAllocator< ObjectType, ArenaBlockType > ThisType
MemoryManager & getMemoryManager()
Definition: XalanList.hpp:252
virtual void commitAllocation(ObjectType *theObject)
virtual ObjectType * allocateBlock()
reverse_iterator rbegin()
Definition: XalanList.hpp:292
size_type getBlockCount() const
void setBlockSize(size_type theSize)
ArenaBlockType::size_type size_type
size_type m_blockSize

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