Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.11


XPathFactory.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(XPATHFACTORY_HEADER_GUARD_1357924680)
19 #define XPATHFACTORY_HEADER_GUARD_1357924680
20 
21 
22 
23 // Base include file. Must be first.
25 
27 
28 #include <cassert>
29 #include <functional>
30 
31 
32 
33 XALAN_CPP_NAMESPACE_BEGIN
34 
35 
36 
37 class XPath;
38 
39 
40 
42 {
43 public:
44 
45  explicit
46  XPathFactory();
47 
48  virtual
49  ~XPathFactory();
50 
51  /**
52  * Return an XPath to the factory.
53  *
54  * @param theXPath The XPath to be returned
55  * @return true if the object belongs to the factory, false if not.
56  */
57  bool
58  returnObject(const XPath* theXPath)
59  {
60  return doReturnObject(theXPath);
61  }
62 
63  /**
64  * Reset the instance. This invalidates all existing instances created
65  * with this XPathFactory.
66  */
67  virtual void
68  reset() = 0;
69 
70  /**
71  * Create an XPath. The XPath instance is owned by the factory, and should
72  * not be deleted. The factory will manage the lifetime.
73  *
74  */
75  virtual XPath*
76  create() = 0;
77 
78  /**
79  *
80  * A functor for use with stl algorithms.
81  *
82  */
83 #if defined(XALAN_NO_STD_NAMESPACE)
84  struct DeleteXPathFunctor : public unary_function<const XPath*, void>
85 #else
86  struct DeleteXPathFunctor : public std::unary_function<const XPath*, bool>
87 #endif
88  {
89  public:
90 
92  XPathFactory& theFactoryInstance,
93  bool fInReset = false) :
94  m_factoryInstance(theFactoryInstance),
95  m_fInReset(fInReset)
96  {
97  }
98 
99  result_type
100  operator()(argument_type theXPath) const
101  {
102  if (m_fInReset == true)
103  {
104  return m_factoryInstance.doReturnObject(theXPath,
105  true);
106  }
107  else
108  {
109  return m_factoryInstance.returnObject(theXPath);
110  }
111  }
112 
113  private:
114 
115  XPathFactory& m_factoryInstance;
116 
117  const bool m_fInReset;
118  };
119 
120  friend struct DeleteXPathFunctor;
121 
122 protected:
123 
124  virtual bool
125  doReturnObject(
126  const XPath* theXPath,
127  bool fInReset = false) = 0;
128 };
129 
130 
131 
132 /**
133  * Manages the lifetime of an XPath instance.
134  */
136 {
137 public:
138 
139  /**
140  * Construct an XPathGuard instance from a factory object and an XPath.
141  *
142  * @param theFactory object that manages lifetime of XPaths
143  * @param theXPath pointer to XPath managed
144  */
146  XPathFactory& theFactory,
147  const XPath* theXPath) :
148  m_factory(&theFactory),
149  m_object(theXPath)
150  {
151  }
152 
153  // Note that copy construction transfers ownership, just
154  // as std::auto_ptr.
156  {
157  // Release the current object...
158  release();
159 
160  // Copy the factory and object pointers...
161  m_factory = theRHS.m_factory;
162  m_object = theRHS.m_object;
163 
164  // The source object no longer points to
165  // the object...
166  theRHS.m_factory = 0;
167  theRHS.m_object = 0;
168  }
169 
171  {
172  reset();
173  }
174 
175  /**
176  * Retrieve the object pointer (must not be null)
177  *
178  * @return pointer to XPath
179  */
180  const XPath*
181  operator->() const
182  {
183  assert(m_object != 0);
184 
185  return m_object;
186  }
187 
188  /**
189  * Retrieve the object pointer (may be null)
190  *
191  * @return pointer to XPath
192  */
193  const XPath*
194  get() const
195  {
196  return m_object;
197  }
198 
199  /**
200  * Return the referenced object to the factory and set pointers to null.
201  */
202  void
204  {
205  if (m_object != 0)
206  {
207  assert(m_factory != 0);
208 
209  m_factory->returnObject(m_object);
210 
211  m_object = 0;
212  }
213 
214  m_factory = 0;
215  }
216 
217  /**
218  * Transfers ownership of XPath to caller
219  *
220  * @return pointer to XPath
221  */
222  const XPath*
224  {
225  const XPath* const theTemp = m_object;
226 
227  m_object = 0;
228 
229  return theTemp;
230  }
231 
232 private:
233 
234  XPathGuard&
235  operator=(const XPathGuard&);
236 
237  bool
238  operator==(const XPathGuard&) const;
239 
240 
241  // Data members...
242  XPathFactory* m_factory;
243  const XPath* m_object;
244 };
245 
246 
247 
248 XALAN_CPP_NAMESPACE_END
249 
250 
251 
252 #endif // XPATHFACTORY_HEADER_GUARD_1357924680
const XPath * operator->() const
Retrieve the object pointer (must not be null)
Manages the lifetime of an XPath instance.
Definition: XPath.hpp:64
const XPath * release()
Transfers ownership of XPath to caller.
XPathGuard(XPathGuard &theRHS)
bool returnObject(const XPath *theXPath)
Return an XPath to the factory.
bool operator==(const ElemAttributeSet &theLHS, const ElemAttributeSet &theRHS)
DeleteXPathFunctor(XPathFactory &theFactoryInstance, bool fInReset=false)
XPathGuard(XPathFactory &theFactory, const XPath *theXPath)
Construct an XPathGuard instance from a factory object and an XPath.
#define XALAN_XPATH_EXPORT
A functor for use with stl algorithms.
result_type operator()(argument_type theXPath) const
void reset()
Return the referenced object to the factory and set pointers to null.

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