Xalan-C++ API Reference  1.12.0
ArenaBlock.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(ARENABLOCK_INCLUDE_GUARD_1357924680)
20 #define ARENABLOCK_INCLUDE_GUARD_1357924680
21 
22 
23 
25 
26 
27 
28 
29 namespace XALAN_CPP_NAMESPACE {
30 
31 
32 template<class ObjectType,
33 #if defined(XALAN_NO_DEFAULT_TEMPLATE_ARGUMENTS)
34  class SizeType>
35 #else
36  class SizeType = size_t>
37 #endif
38 class ArenaBlock : public ArenaBlockBase<ObjectType, SizeType>
39 {
40 public:
41 
43 
45 
47 
48  /*
49  * Construct an ArenaBlock of the specified size
50  * of objects.
51  *
52  * @param theManager The memory manager instance for the block.
53  * @param theBlockSize The size of the block (the number of objects it can contain).
54  */
56  MemoryManager& theManager,
57  size_type theBlockSize) :
58  BaseClassType(theManager, theBlockSize)
59  {
60  }
61 
63  {
64  assert( this->m_objectCount <= this->m_blockSize );
65 
66  for ( size_type i = 0; i < this->m_objectCount ; ++i )
67  {
68  XalanDestroy(this->m_objectBlock[i]);
69  }
70  }
71 
72  static ThisType*
74  MemoryManager& theManager,
75  size_type theBlockSize)
76  {
77  ThisType* theInstance;
78 
79  return XalanConstruct(
80  theManager,
81  theInstance,
82  theManager,
83  theBlockSize);
84  }
85 
86  /*
87  * Allocate a block. Once the object is constructed, you must call
88  * commitAllocation().
89  *
90  * @return a pointer to the new block.
91  */
92  ObjectType*
94  {
95  // Any space left?
96  if (this->m_objectCount == this->m_blockSize)
97  {
98  return 0;
99  }
100  else
101  {
102  assert(this->m_objectBlock != 0);
103 
104  return this->m_objectBlock + this->m_objectCount;
105  }
106  }
107 
108  /*
109  * Commit the previous allocation.
110  *
111  * @param theBlock the address that was returned by allocateBlock()
112  */
113  void
114 #if defined (NDEBUG)
115  commitAllocation(ObjectType* /* theBlock */)
116 #else
117  commitAllocation(ObjectType* theBlock)
118 #endif
119  {
120  assert(theBlock == this->m_objectBlock + this->m_objectCount);
121  assert(this->m_objectCount < this->m_blockSize);
122 
123  ++this->m_objectCount;
124  }
125 
126  /*
127  * Determine if this block owns the specified object. Note
128  * that even if the object address is within our block, this
129  * call will return false if no object currently occupies the
130  * block. See also ownsBlock().
131  *
132  * @param theObject the address of the object.
133  * @return true if we own the object, false if not.
134  */
135  bool
136  ownsObject(const ObjectType* theObject) const
137  {
138  return this->isInBorders(theObject, this->m_objectCount);
139  }
140 
141 private:
142 
143  // Not implemented...
145 
147  operator=(const ArenaBlock<ObjectType, SizeType>&);
148 
149  bool
151 };
152 
153 
154 
155 }
156 
157 
158 
159 #endif // !defined(ARENABLOCK_INCLUDE_GUARD_1357924680)
xalanc::ArenaBlock::ownsObject
bool ownsObject(const ObjectType *theObject) const
Definition: ArenaBlock.hpp:136
xalanc::ArenaBlock::size_type
BaseClassType::size_type size_type
Definition: ArenaBlock.hpp:46
XALAN_CPP_NAMESPACE
#define XALAN_CPP_NAMESPACE
Xalan-C++ namespace, including major and minor version.
Definition: XalanVersion.hpp:76
xalanc::ArenaBlock::BaseClassType
ArenaBlockBase< ObjectType, SizeType > BaseClassType
Definition: ArenaBlock.hpp:42
xalanc::XalanConstruct
Type * XalanConstruct(MemoryManager &theMemoryManager, Type *&theInstance)
Definition: XalanMemoryManagement.hpp:200
xalanc::ArenaBlock::ArenaBlock
ArenaBlock(MemoryManager &theManager, size_type theBlockSize)
Definition: ArenaBlock.hpp:55
xalanc::operator==
bool operator==(const XalanVector< Type > &theLHS, const XalanVector< Type > &theRHS)
Definition: XalanVector.hpp:1118
xalanc::ArenaBlock
Definition: ArenaBlock.hpp:38
xalanc::ArenaBlock::~ArenaBlock
~ArenaBlock()
Definition: ArenaBlock.hpp:62
xalanc::ArenaBlockBase
Definition: ArenaBlockBase.hpp:107
ArenaBlockBase.hpp
xalanc::ArenaBlock::create
static ThisType * create(MemoryManager &theManager, size_type theBlockSize)
Definition: ArenaBlock.hpp:73
xalanc::XalanDestroy
void XalanDestroy(Type &theArg)
Definition: XalanMemoryManagement.hpp:150
xalanc::ArenaBlockBase< data_type, size_t >::size_type
size_t size_type
Definition: ArenaBlockBase.hpp:119
xalanc::ArenaBlock::commitAllocation
void commitAllocation(ObjectType *theBlock)
Definition: ArenaBlock.hpp:117
xalanc::ArenaBlock::ThisType
ArenaBlock< ObjectType, SizeType > ThisType
Definition: ArenaBlock.hpp:44
xalanc::ArenaBlock::allocateBlock
ObjectType * allocateBlock()
Definition: ArenaBlock.hpp:93