Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.10

XalanObjectStackCache.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #if !defined(XALAN_OBJECTSTACKCACHE_HEADER_GUARD)
17 #define XALAN_OBJECTSTACKCACHE_HEADER_GUARD
18 
19 
20 
21 #include <algorithm>
22 
23 
24 
29 
30 
31 
32 XALAN_CPP_NAMESPACE_BEGIN
33 
34 
35 template<
36 class ObjectType,
37 #if defined(XALAN_NO_DEFAULT_TEMPLATE_ARGUMENTS)
38 class CreateFunctorType,
39 class DeleteFunctorType,
40 class ResetFunctorType>
41 #else
42 class CreateFunctorType = DefaultCacheCreateFunctor<ObjectType>,
43 class DeleteFunctorType = DeleteFunctor<ObjectType>,
44 class ResetFunctorType = DefaultCacheResetFunctor<ObjectType> >
45 #endif
47 {
48 public:
49 
51 
52  typedef ObjectType CacheObjectType;
53 
54  explicit
56  unsigned int initialListSize = 0) :
58  m_deleteFunctor(theManager),
59  m_stack(theManager),
60  m_numObjectsOnStack(0)
61  {
62  m_stack.reserve(initialListSize);
63 
64  }
65 
67  {
68 #if !defined(XALAN_NO_STD_NAMESPACE)
69  using std::for_each;
70 #endif
71  for_each(
72  m_stack.begin(),
73  m_stack.end(),
75  }
76 
77  ObjectType*
78  get()
79  {
80 
81  if (m_stack.size() == m_numObjectsOnStack)
82  {
83  ObjectType* const theNewObject = m_createFunctor(m_stack.getMemoryManager());
84  m_stack.push_back(theNewObject);
85  ++m_numObjectsOnStack;
86  return theNewObject;
87  }
88  else
89  {
90  return m_stack[m_numObjectsOnStack++];
91  }
92  }
93 
94  ObjectType*
95  top()
96  {
97  assert (m_numObjectsOnStack > 0);
98 
99  return m_stack[m_numObjectsOnStack-1];
100  }
101 
102  ObjectType*
104  {
105  assert(m_numObjectsOnStack > 0);
106 
107  return m_stack[--m_numObjectsOnStack];
108  }
109 
110  void
112  {
113  typename VectorType::iterator iterator;
114 
115  for (iterator = m_stack.begin(); iterator < m_stack.end(); iterator++)
116  {
117  m_resetFunctor(*iterator);
118  }
119  }
120 
121  // Functors for various operations...
122  CreateFunctorType m_createFunctor;
123 
124  DeleteFunctorType m_deleteFunctor;
125 
126  ResetFunctorType m_resetFunctor;
127 
128 private:
129 
130  // There are not defined...
132 
135 
136 
137  // Data members...
138  VectorType m_stack;
139 
140  typename VectorType::size_type m_numObjectsOnStack;
141 
142 };
143 
144 
145 
146 
147 template<class ObjectType>
148 class XalanObjectStackCacheDefault : public XalanObjectStackCache<ObjectType, DefaultCacheCreateFunctor<ObjectType>, DeleteFunctor<ObjectType>, DefaultCacheResetFunctor<ObjectType> >
149 {
150 public:
151 
153 
154  explicit
155  XalanObjectStackCacheDefault(unsigned int initialListSize = 0) :
156  BaseClassType(initialListSize)
157  {
158  }
159 };
160 
161 
162 
163 XALAN_CPP_NAMESPACE_END
164 
165 
166 
167 #endif

Interpreting class diagrams

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

dot

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

Apache Logo