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(XALANDOMSTRINGREUSABLEALLOCATOR_INCLUDE_GUARD_12455133) 00020 #define XALANDOMSTRINGREUSABLEALLOCATOR_INCLUDE_GUARD_12455133 00021 00022 00023 00024 // Base include file. Must be first. 00025 #include <xalanc/PlatformSupport/PlatformSupportDefinitions.hpp> 00026 00027 00028 00029 #include <xalanc/PlatformSupport/ReusableArenaAllocator.hpp> 00030 00031 00032 00033 #include <xalanc/XalanDOM/XalanDOMString.hpp> 00034 00035 00036 00037 XALAN_CPP_NAMESPACE_BEGIN 00038 00039 00040 00041 class XALAN_PLATFORMSUPPORT_EXPORT XalanDOMStringReusableAllocator 00042 { 00043 public: 00044 00045 typedef XalanDOMString data_type; 00046 typedef data_type::size_type data_type_size_type; 00047 00048 #if defined(XALAN_NO_DEFAULT_TEMPLATE_ARGUMENTS) 00049 typedef ReusableArenaBlock<data_type> ArenaBlockType; 00050 00051 typedef ReusableArenaBlock<data_type, 00052 ArenaBlockType> ArenaAllocatorType; 00053 #else 00054 typedef ReusableArenaAllocator<data_type> ArenaAllocatorType; 00055 #endif 00056 00057 typedef ArenaAllocatorType::size_type size_type; 00058 00059 enum { eDefaultBlockSize = 32 }; 00060 00061 00062 /** 00063 * Construct an instance that will allocate in blocks of the specified size. 00064 * 00065 * @param theBlockSize The block size. 00066 */ 00067 XalanDOMStringReusableAllocator(MemoryManager& theManager, size_type theBlockCount); 00068 00069 ~XalanDOMStringReusableAllocator(); 00070 00071 /** 00072 * Create a XalanDOMString object. 00073 * 00074 * @return reference to the new instance 00075 */ 00076 data_type& 00077 create(); 00078 00079 /** 00080 * Create a XalanDOMString object. 00081 * 00082 * @param theString A pointer to a character string 00083 * @param theCount The number of characters in the string, or npos if the string is null-terminated. 00084 * 00085 * @return reference to the new instance 00086 */ 00087 data_type& 00088 create( 00089 const char* theString, 00090 #if defined(_MSC_VER) && (_MSC_VER <= 1300) 00091 // $$$ ToDo: Some strange bug in MSVC++ complains when using data_type::npos here. 00092 data_type_size_type theCount = data_type_size_type(-1)); 00093 #else 00094 data_type_size_type theCount = data_type_size_type(data_type::npos)); 00095 #endif 00096 00097 /** 00098 * Copy constructor 00099 * 00100 * @param theSource The source string for the copy 00101 * @param theStartPosition The position to start in the source string. 00102 * @param theCount The number of characters to copy from the source string. 00103 * 00104 * @return reference to the new instance 00105 */ 00106 data_type& 00107 create( 00108 const data_type& theSource, 00109 data_type_size_type theStartPosition = 0, 00110 data_type_size_type theCount = data_type_size_type(data_type::npos)); 00111 00112 /** 00113 * Create a XalanDOMString object. 00114 * 00115 * @param theString A pointer to a wide character string 00116 * @param theCount The number of characters in the string, or npos if the string is null-terminated. 00117 * 00118 * @return reference to the new instance 00119 */ 00120 data_type& 00121 create( 00122 const XalanDOMChar* theString, 00123 data_type_size_type theCount = data_type_size_type(data_type::npos)); 00124 00125 /** 00126 * Create a XalanDOMString object. 00127 * 00128 * @param theCount the size of the string 00129 * @param theChar the character used to initialize the string 00130 * 00131 * @return reference to the new instance 00132 */ 00133 data_type& 00134 create( 00135 data_type_size_type theCount, 00136 XalanDOMChar theChar); 00137 00138 /* 00139 * Destroy a XalanDOMString object. 00140 * 00141 */ 00142 bool 00143 destroy(XalanDOMString& theDOMString) 00144 { 00145 return m_allocator.destroyObject(&theDOMString); 00146 } 00147 00148 /** 00149 * Determine if an object is owned by the allocator... 00150 */ 00151 bool 00152 ownsObject(const data_type* theObject) 00153 { 00154 return m_allocator.ownsObject(theObject); 00155 } 00156 00157 /** 00158 * Delete all instance objects from allocator. 00159 */ 00160 void 00161 reset() 00162 { 00163 m_allocator.reset(); 00164 } 00165 00166 /** 00167 * Get the number of ArenaBlocks currently allocated. 00168 * 00169 * @return The number of blocks. 00170 */ 00171 size_type 00172 getBlockCount() const 00173 { 00174 return m_allocator.getBlockCount(); 00175 } 00176 00177 /** 00178 * Get size of an ArenaBlock, that is, the number 00179 * of objects in each block. 00180 * 00181 * @return The size of the block 00182 */ 00183 size_type 00184 getBlockSize() const 00185 { 00186 return m_allocator.getBlockSize(); 00187 } 00188 00189 /** 00190 * Get a reference to the MemoryManager instance 00191 * for this instance. 00192 * 00193 * @return A reference to the MemoryManager instance. 00194 */ 00195 MemoryManager& 00196 getMemoryManager() 00197 { 00198 return m_allocator.getMemoryManager(); 00199 } 00200 00201 /** 00202 * Get a reference to the MemoryManager instance 00203 * for this instance. 00204 * 00205 * @return A reference to the MemoryManager instance. 00206 */ 00207 const MemoryManager& 00208 getMemoryManager() const 00209 { 00210 return m_allocator.getMemoryManager(); 00211 } 00212 00213 private: 00214 00215 // Not implemented... 00216 XalanDOMStringReusableAllocator(const XalanDOMStringReusableAllocator&); 00217 00218 XalanDOMStringReusableAllocator& 00219 operator=(const XalanDOMStringReusableAllocator&); 00220 00221 // Data members... 00222 ArenaAllocatorType m_allocator; 00223 }; 00224 00225 00226 00227 XALAN_CPP_NAMESPACE_END 00228 00229 00230 00231 #endif // XALANDOMSTRINGREUSABLEALLOCATOR_INCLUDE_GUARD_12455133
Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.
Xalan-C++ XSLT Processor Version 1.11 |
|