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 #if !defined(XALAN_OBJECTSTACKCACHE_HEADER_GUARD) 00019 #define XALAN_OBJECTSTACKCACHE_HEADER_GUARD 00020 00021 00022 00023 #include <algorithm> 00024 00025 00026 00027 #include <xalanc/Include/XalanVector.hpp> 00028 #include <xalanc/Include/STLHelper.hpp> 00029 #include <xalanc/Include/XalanAutoPtr.hpp> 00030 #include <xalanc/Include/XalanObjectCache.hpp> 00031 00032 00033 00034 XALAN_CPP_NAMESPACE_BEGIN 00035 00036 00037 template< 00038 class ObjectType, 00039 #if defined(XALAN_NO_DEFAULT_TEMPLATE_ARGUMENTS) 00040 class CreateFunctorType, 00041 class DeleteFunctorType, 00042 class ResetFunctorType> 00043 #else 00044 class CreateFunctorType = DefaultCacheCreateFunctor<ObjectType>, 00045 class DeleteFunctorType = DeleteFunctor<ObjectType>, 00046 class ResetFunctorType = DefaultCacheResetFunctor<ObjectType> > 00047 #endif 00048 class XalanObjectStackCache 00049 { 00050 public: 00051 00052 typedef XalanVector<ObjectType*> VectorType; 00053 00054 typedef ObjectType CacheObjectType; 00055 00056 explicit 00057 XalanObjectStackCache( 00058 MemoryManager& theManager, 00059 XalanSize_t initialListSize = 0) : 00060 m_createFunctor(), 00061 m_deleteFunctor(theManager), 00062 m_stack(theManager), 00063 m_numObjectsOnStack(0) 00064 { 00065 m_stack.reserve(initialListSize); 00066 } 00067 00068 ~XalanObjectStackCache() 00069 { 00070 #if !defined(XALAN_NO_STD_NAMESPACE) 00071 using std::for_each; 00072 #endif 00073 for_each( 00074 m_stack.begin(), 00075 m_stack.end(), 00076 m_deleteFunctor); 00077 } 00078 00079 ObjectType* 00080 get() 00081 { 00082 00083 if (m_stack.size() == m_numObjectsOnStack) 00084 { 00085 ObjectType* const theNewObject = m_createFunctor(m_stack.getMemoryManager()); 00086 m_stack.push_back(theNewObject); 00087 ++m_numObjectsOnStack; 00088 return theNewObject; 00089 } 00090 else 00091 { 00092 return m_stack[m_numObjectsOnStack++]; 00093 } 00094 } 00095 00096 ObjectType* 00097 top() 00098 { 00099 assert (m_numObjectsOnStack > 0); 00100 00101 return m_stack[m_numObjectsOnStack-1]; 00102 } 00103 00104 ObjectType* 00105 release() 00106 { 00107 assert(m_numObjectsOnStack > 0); 00108 00109 return m_stack[--m_numObjectsOnStack]; 00110 } 00111 00112 void 00113 reset() 00114 { 00115 typename VectorType::iterator iterator; 00116 00117 for (iterator = m_stack.begin(); iterator < m_stack.end(); iterator++) 00118 { 00119 m_resetFunctor(*iterator); 00120 } 00121 } 00122 00123 // Functors for various operations... 00124 CreateFunctorType m_createFunctor; 00125 00126 DeleteFunctorType m_deleteFunctor; 00127 00128 ResetFunctorType m_resetFunctor; 00129 00130 private: 00131 00132 // There are not defined... 00133 XalanObjectStackCache(const XalanObjectCache<ObjectType, CreateFunctorType, DeleteFunctorType, ResetFunctorType>& theRHS); 00134 00135 XalanObjectStackCache<ObjectType, CreateFunctorType, DeleteFunctorType, ResetFunctorType>& 00136 operator=(const XalanObjectCache<ObjectType, CreateFunctorType, DeleteFunctorType, ResetFunctorType>& theRHS); 00137 00138 00139 // Data members... 00140 VectorType m_stack; 00141 00142 typename VectorType::size_type m_numObjectsOnStack; 00143 00144 }; 00145 00146 00147 00148 00149 template<class ObjectType> 00150 class XalanObjectStackCacheDefault : public XalanObjectStackCache<ObjectType, DefaultCacheCreateFunctor<ObjectType>, DeleteFunctor<ObjectType>, DefaultCacheResetFunctor<ObjectType> > 00151 { 00152 public: 00153 00154 typedef XalanObjectStackCache<ObjectType, DefaultCacheCreateFunctor<ObjectType>, DeleteFunctor<ObjectType>, DefaultCacheResetFunctor<ObjectType> > BaseClassType; 00155 00156 explicit 00157 XalanObjectStackCacheDefault(XalanSize_t initialListSize = 0) : 00158 BaseClassType(initialListSize) 00159 { 00160 } 00161 }; 00162 00163 00164 00165 XALAN_CPP_NAMESPACE_END 00166 00167 00168 00169 #endif
Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.
Xalan-C++ XSLT Processor Version 1.11 |
|