Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.10

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

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