00001 /* 00002 * Licensed to the Apache Software Foundation (ASF) under one 00003 * or more contributor license agreements. See the NOTICE file 00004 * distributed with this work for additional information 00005 * regarding copyright ownership. The ASF licenses this file 00006 * to you under the Apache License, Version 2.0 (the "License"); 00007 * you may not use this file except in compliance with the License. 00008 * You may obtain a copy of the License at 00009 * 00010 * http://www.apache.org/licenses/LICENSE-2.0 00011 * 00012 * Unless required by applicable law or agreed to in writing, software 00013 * distributed under the License is distributed on an "AS IS" BASIS, 00014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 * See the License for the specific language governing permissions and 00016 * limitations under the License. 00017 */ 00018 00019 #if !defined(ARENABLOCK_INCLUDE_GUARD_1357924680) 00020 #define ARENABLOCK_INCLUDE_GUARD_1357924680 00021 00022 00023 00024 #include <xalanc/PlatformSupport/ArenaBlockBase.hpp> 00025 00026 00027 00028 00029 XALAN_CPP_NAMESPACE_BEGIN 00030 00031 00032 template<class ObjectType, 00033 #if defined(XALAN_NO_DEFAULT_TEMPLATE_ARGUMENTS) 00034 class SizeType> 00035 #else 00036 class SizeType = size_t> 00037 #endif 00038 class ArenaBlock : public ArenaBlockBase<ObjectType, SizeType> 00039 { 00040 public: 00041 00042 typedef ArenaBlockBase<ObjectType, SizeType> BaseClassType; 00043 00044 typedef ArenaBlock<ObjectType, SizeType> ThisType; 00045 00046 typedef typename BaseClassType::size_type size_type; 00047 00048 /* 00049 * Construct an ArenaBlock of the specified size 00050 * of objects. 00051 * 00052 * @param theManager The memory manager instance for the block. 00053 * @param theBlockSize The size of the block (the number of objects it can contain). 00054 */ 00055 ArenaBlock( 00056 MemoryManager& theManager, 00057 size_type theBlockSize) : 00058 BaseClassType(theManager, theBlockSize) 00059 { 00060 } 00061 00062 ~ArenaBlock() 00063 { 00064 assert( this->m_objectCount <= this->m_blockSize ); 00065 00066 for ( size_type i = 0; i < this->m_objectCount ; ++i ) 00067 { 00068 XalanDestroy(this->m_objectBlock[i]); 00069 } 00070 } 00071 00072 static ThisType* 00073 create( 00074 MemoryManager& theManager, 00075 size_type theBlockSize) 00076 { 00077 ThisType* theInstance; 00078 00079 return XalanConstruct( 00080 theManager, 00081 theInstance, 00082 theManager, 00083 theBlockSize); 00084 } 00085 00086 /* 00087 * Allocate a block. Once the object is constructed, you must call 00088 * commitAllocation(). 00089 * 00090 * @return a pointer to the new block. 00091 */ 00092 ObjectType* 00093 allocateBlock() 00094 { 00095 // Any space left? 00096 if (this->m_objectCount == this->m_blockSize) 00097 { 00098 return 0; 00099 } 00100 else 00101 { 00102 assert(this->m_objectBlock != 0); 00103 00104 return this->m_objectBlock + this->m_objectCount; 00105 } 00106 } 00107 00108 /* 00109 * Commit the previous allocation. 00110 * 00111 * @param theBlock the address that was returned by allocateBlock() 00112 */ 00113 void 00114 #if defined (NDEBUG) 00115 commitAllocation(ObjectType* /* theBlock */) 00116 #else 00117 commitAllocation(ObjectType* theBlock) 00118 #endif 00119 { 00120 assert(theBlock == this->m_objectBlock + this->m_objectCount); 00121 assert(this->m_objectCount < this->m_blockSize); 00122 00123 ++this->m_objectCount; 00124 } 00125 00126 /* 00127 * Determine if this block owns the specified object. Note 00128 * that even if the object address is within our block, this 00129 * call will return false if no object currently occupies the 00130 * block. See also ownsBlock(). 00131 * 00132 * @param theObject the address of the object. 00133 * @return true if we own the object, false if not. 00134 */ 00135 bool 00136 ownsObject(const ObjectType* theObject) const 00137 { 00138 return this->isInBorders(theObject, this->m_objectCount); 00139 } 00140 00141 private: 00142 00143 // Not implemented... 00144 ArenaBlock(const ArenaBlock<ObjectType, SizeType>&); 00145 00146 ArenaBlock<ObjectType, SizeType>& 00147 operator=(const ArenaBlock<ObjectType, SizeType>&); 00148 00149 bool 00150 operator==(const ArenaBlock<ObjectType, SizeType>&) const; 00151 }; 00152 00153 00154 00155 XALAN_CPP_NAMESPACE_END 00156 00157 00158 00159 #endif // !defined(ARENABLOCK_INCLUDE_GUARD_1357924680)
Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.
Xalan-C++ XSLT Processor Version 1.11 |
|