Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.11


XalanObjectStackCache.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 #if !defined(XALAN_OBJECTSTACKCACHE_HEADER_GUARD)
19 #define XALAN_OBJECTSTACKCACHE_HEADER_GUARD
20 
21 
22 
23 #include <algorithm>
24 
25 
26 
31 
32 
33 
34 XALAN_CPP_NAMESPACE_BEGIN
35 
36 
37 template<
38 class ObjectType,
39 #if defined(XALAN_NO_DEFAULT_TEMPLATE_ARGUMENTS)
40 class CreateFunctorType,
41 class DeleteFunctorType,
42 class ResetFunctorType>
43 #else
44 class CreateFunctorType = DefaultCacheCreateFunctor<ObjectType>,
45 class DeleteFunctorType = DeleteFunctor<ObjectType>,
46 class ResetFunctorType = DefaultCacheResetFunctor<ObjectType> >
47 #endif
49 {
50 public:
51 
53 
54  typedef ObjectType CacheObjectType;
55 
56  explicit
58  MemoryManager& theManager,
59  XalanSize_t initialListSize = 0) :
61  m_deleteFunctor(theManager),
62  m_stack(theManager),
63  m_numObjectsOnStack(0)
64  {
65  m_stack.reserve(initialListSize);
66  }
67 
69  {
70 #if !defined(XALAN_NO_STD_NAMESPACE)
71  using std::for_each;
72 #endif
73  for_each(
74  m_stack.begin(),
75  m_stack.end(),
77  }
78 
79  ObjectType*
80  get()
81  {
82 
83  if (m_stack.size() == m_numObjectsOnStack)
84  {
85  ObjectType* const theNewObject = m_createFunctor(m_stack.getMemoryManager());
86  m_stack.push_back(theNewObject);
87  ++m_numObjectsOnStack;
88  return theNewObject;
89  }
90  else
91  {
92  return m_stack[m_numObjectsOnStack++];
93  }
94  }
95 
96  ObjectType*
97  top()
98  {
99  assert (m_numObjectsOnStack > 0);
100 
101  return m_stack[m_numObjectsOnStack-1];
102  }
103 
104  ObjectType*
106  {
107  assert(m_numObjectsOnStack > 0);
108 
109  return m_stack[--m_numObjectsOnStack];
110  }
111 
112  void
114  {
115  typename VectorType::iterator iterator;
116 
117  for (iterator = m_stack.begin(); iterator < m_stack.end(); iterator++)
118  {
119  m_resetFunctor(*iterator);
120  }
121  }
122 
123  // Functors for various operations...
124  CreateFunctorType m_createFunctor;
125 
126  DeleteFunctorType m_deleteFunctor;
127 
128  ResetFunctorType m_resetFunctor;
129 
130 private:
131 
132  // There are not defined...
134 
137 
138 
139  // Data members...
140  VectorType m_stack;
141 
142  typename VectorType::size_type m_numObjectsOnStack;
143 
144 };
145 
146 
147 
148 
149 template<class ObjectType>
150 class XalanObjectStackCacheDefault : public XalanObjectStackCache<ObjectType, DefaultCacheCreateFunctor<ObjectType>, DeleteFunctor<ObjectType>, DefaultCacheResetFunctor<ObjectType> >
151 {
152 public:
153 
155 
156  explicit
157  XalanObjectStackCacheDefault(XalanSize_t initialListSize = 0) :
158  BaseClassType(initialListSize)
159  {
160  }
161 };
162 
163 
164 
165 XALAN_CPP_NAMESPACE_END
166 
167 
168 
169 #endif
iterator end()
CreateFunctorType m_createFunctor
void push_back(const value_type &data)
iterator begin()
void reserve(size_type theSize)
size_type size() const
XalanObjectStackCacheDefault(XalanSize_t initialListSize=0)
const MemoryManager & getMemoryManager() const
XalanVector< ObjectType * > VectorType
DeleteFunctorType m_deleteFunctor
XalanObjectStackCache< ObjectType, DefaultCacheCreateFunctor< ObjectType >, DeleteFunctor< ObjectType >, DefaultCacheResetFunctor< ObjectType > > BaseClassType
XalanObjectStackCache(MemoryManager &theManager, XalanSize_t initialListSize=0)

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.11
Copyright © 1999-2012 The Apache Software Foundation.
All Rights Reserved.

Apache Logo