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
29namespace XALAN_CPP_NAMESPACE {
30
31
32template<class ObjectType,
33#if defined(XALAN_NO_DEFAULT_TEMPLATE_ARGUMENTS)
34 class SizeType>
35#else
36 class SizeType = size_t>
37#endif
38class ArenaBlock : public ArenaBlockBase<ObjectType, SizeType>
39{
40public:
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 */
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,
76 {
78
79 return XalanConstruct(
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
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
141private:
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)
#define XALAN_CPP_NAMESPACE
Xalan-C++ namespace, including major and minor version.
ObjectType * allocateBlock()
ArenaBlock< ObjectType, SizeType > ThisType
void commitAllocation(ObjectType *theBlock)
bool ownsObject(const ObjectType *theObject) const
static ThisType * create(MemoryManager &theManager, size_type theBlockSize)
ArenaBlock(MemoryManager &theManager, size_type theBlockSize)
BaseClassType::size_type size_type
ArenaBlockBase< ObjectType, SizeType > BaseClassType
Type * XalanConstruct(MemoryManager &theMemoryManager, Type *&theInstance)
bool operator==(const XalanVector< Type > &theLHS, const XalanVector< Type > &theRHS)
void XalanDestroy(Type &theArg)