## Xalan-C++ API Documentation

### The Xalan C++ XSLT Processor Version 1.10

Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members File Members

# XalanObjectStackCache.hpp

Go to the documentation of this file.

    00001 /*
    00002  * Copyright 1999-2004 The Apache Software Foundation.
    00003  *
    00004  * Licensed under the Apache License, Version 2.0 (the "License");
    00005  * you may not use this file except in compliance with the License.
    00006  * You may obtain a copy of the License at
    00007  *
    00008  *     http://www.apache.org/licenses/LICENSE-2.0
    00009  *
    00010  * Unless required by applicable law or agreed to in writing, software
    00011  * distributed under the License is distributed on an "AS IS" BASIS,
    00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    00013  * See the License for the specific language governing permissions and
    00014  * limitations under the License.
    00015  */
    00016 #if !defined(XALAN_OBJECTSTACKCACHE_HEADER_GUARD)
    00017 #define XALAN_OBJECTSTACKCACHE_HEADER_GUARD
    00018
    00019
    00020
    00021 #include <algorithm>
    00022
    00023
    00024
    00025 #include <xalanc/Include/XalanVector.hpp>
    00026 #include <xalanc/Include/STLHelper.hpp>
    00027 #include <xalanc/Include/XalanAutoPtr.hpp>
    00028 #include <xalanc/Include/XalanObjectCache.hpp>
    00029
    00030
    00031
    00032 XALAN_CPP_NAMESPACE_BEGIN
    00033
    00034
    00035 template<
    00036 class ObjectType,
    00037 #if defined(XALAN_NO_DEFAULT_TEMPLATE_ARGUMENTS)
    00038 class CreateFunctorType,
    00039 class DeleteFunctorType,
    00040 class ResetFunctorType>
    00041 #else
    00042 class CreateFunctorType = DefaultCacheCreateFunctor<ObjectType>,
    00043 class DeleteFunctorType = DeleteFunctor<ObjectType>,
    00044 class ResetFunctorType = DefaultCacheResetFunctor<ObjectType> >
    00045 #endif
    00046 class XalanObjectStackCache
    00047 {
    00048 public:
    00049
    00050     typedef XalanVector<ObjectType*>            VectorType;
    00051
    00052     typedef ObjectType  CacheObjectType;
    00053
    00054     explicit
    00055     XalanObjectStackCache(MemoryManagerType& theManager,
    00056                           unsigned int  initialListSize = 0) :
    00057         m_createFunctor(),
    00058         m_deleteFunctor(theManager),
    00059     m_stack(theManager),
    00060         m_numObjectsOnStack(0)
    00061     {
    00062         m_stack.reserve(initialListSize);
    00063
    00064     }
    00065
    00066     ~XalanObjectStackCache()
    00067     {
    00068 #if !defined(XALAN_NO_STD_NAMESPACE)
    00069         using std::for_each;
    00070 #endif
    00071         for_each(
    00072                 m_stack.begin(),
    00073                 m_stack.end(),
    00074                 m_deleteFunctor);
    00075     }
    00076
    00077     ObjectType*
    00078     get()
    00079     {
    00080
    00081         if (m_stack.size() == m_numObjectsOnStack)
    00082         {
    00083             ObjectType* const   theNewObject = m_createFunctor(m_stack.getMemoryManager());
    00084             m_stack.push_back(theNewObject);
    00085             ++m_numObjectsOnStack;
    00086             return theNewObject;
    00087         }
    00088         else
    00089         {
    00090             return m_stack[m_numObjectsOnStack++];
    00091         }
    00092     }
    00093
    00094     ObjectType*
    00095     top()
    00096     {
    00097         assert (m_numObjectsOnStack > 0);
    00098
    00099         return m_stack[m_numObjectsOnStack-1];
    00100     }
    00101
    00102     ObjectType*
    00103     release()
    00104     {
    00105         assert(m_numObjectsOnStack > 0);
    00106
    00107         return m_stack[--m_numObjectsOnStack];
    00108     }
    00109
    00110     void
    00111     reset()
    00112     {
    00113         typename VectorType::iterator iterator;
    00114
    00115         for (iterator = m_stack.begin(); iterator < m_stack.end(); iterator++)
    00116         {
    00117             m_resetFunctor(*iterator);
    00118         }
    00119     }
    00120
    00121     // Functors for various operations...
    00122     CreateFunctorType   m_createFunctor;
    00123
    00124     DeleteFunctorType   m_deleteFunctor;
    00125
    00126     ResetFunctorType    m_resetFunctor;
    00127
    00128 private:
    00129
    00130     // There are not defined...
    00131     XalanObjectStackCache(const XalanObjectCache<ObjectType, CreateFunctorType, DeleteFunctorType, ResetFunctorType>&   theRHS);
    00132
    00133     XalanObjectStackCache<ObjectType, CreateFunctorType, DeleteFunctorType, ResetFunctorType>&
    00134     operator=(const XalanObjectCache<ObjectType, CreateFunctorType, DeleteFunctorType, ResetFunctorType>&   theRHS);
    00135
    00136
    00137     // Data members...
    00138     VectorType          m_stack;
    00139
    00140     typename VectorType::size_type m_numObjectsOnStack;
    00141
    00142 };
    00143
    00144
    00145
    00146
    00147 template<class ObjectType>
    00148 class XalanObjectStackCacheDefault : public XalanObjectStackCache<ObjectType, DefaultCacheCreateFunctor<ObjectType>, DeleteFunctor<ObjectType>, DefaultCacheResetFunctor<ObjectType> >
    00149 {
    00150 public:
    00151
    00152     typedef XalanObjectStackCache<ObjectType, DefaultCacheCreateFunctor<ObjectType>, DeleteFunctor<ObjectType>, DefaultCacheResetFunctor<ObjectType> >      BaseClassType;
    00153
    00154     explicit
    00155     XalanObjectStackCacheDefault(unsigned int   initialListSize = 0) :
    00156         BaseClassType(initialListSize)
    00157     {
    00158     }
    00159 };
    00160
    00161
    00162
    00163 XALAN_CPP_NAMESPACE_END
    00164
    00165
    00166
    00167 #endif

Interpreting class diagrams

Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.

Xalan-C++ XSLT Processor Version 1.10 Copyright © 1999-2004 The Apache Software Foundation. All Rights Reserved.