Xalan-C++ API Reference 1.12.0
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
33namespace XALAN_CPP_NAMESPACE {
34
35
36
37class XPath;
38
39
40
42{
43public:
44
45 explicit
47
48 virtual
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
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 */
84 {
85 public:
86
89 bool fInReset = false) :
90 m_factoryInstance(theFactoryInstance),
91 m_fInReset(fInReset)
92 {
93 }
94
95 bool
97 {
98 if (m_fInReset == true)
99 {
100 return m_factoryInstance.doReturnObject(theXPath,
101 true);
102 }
103 else
104 {
105 return m_factoryInstance.returnObject(theXPath);
106 }
107 }
108
109 private:
110
111 XPathFactory& m_factoryInstance;
112
113 const bool m_fInReset;
114 };
115
116 friend struct DeleteXPathFunctor;
117
118protected:
119
120 virtual bool
122 const XPath* theXPath,
123 bool fInReset = false) = 0;
124};
125
126
127
128/**
129 * Manages the lifetime of an XPath instance.
130 */
132{
133public:
134
135 /**
136 * Construct an XPathGuard instance from a factory object and an XPath.
137 *
138 * @param theFactory object that manages lifetime of XPaths
139 * @param theXPath pointer to XPath managed
140 */
143 const XPath* theXPath) :
144 m_factory(&theFactory),
145 m_object(theXPath)
146 {
147 }
148
149 // Note that copy construction transfers ownership, just
150 // as std::auto_ptr.
152 {
153 // Release the current object...
154 release();
155
156 // Copy the factory and object pointers...
157 m_factory = theRHS.m_factory;
158 m_object = theRHS.m_object;
159
160 // The source object no longer points to
161 // the object...
162 theRHS.m_factory = 0;
163 theRHS.m_object = 0;
164 }
165
167 {
168 reset();
169 }
170
171 /**
172 * Retrieve the object pointer (must not be null)
173 *
174 * @return pointer to XPath
175 */
176 const XPath*
178 {
179 assert(m_object != 0);
180
181 return m_object;
182 }
183
184 /**
185 * Retrieve the object pointer (may be null)
186 *
187 * @return pointer to XPath
188 */
189 const XPath*
190 get() const
191 {
192 return m_object;
193 }
194
195 /**
196 * Return the referenced object to the factory and set pointers to null.
197 */
198 void
200 {
201 if (m_object != 0)
202 {
203 assert(m_factory != 0);
204
205 m_factory->returnObject(m_object);
206
207 m_object = 0;
208 }
209
210 m_factory = 0;
211 }
212
213 /**
214 * Transfers ownership of XPath to caller
215 *
216 * @return pointer to XPath
217 */
218 const XPath*
220 {
221 const XPath* const theTemp = m_object;
222
223 m_object = 0;
224
225 return theTemp;
226 }
227
228private:
229
231 operator=(const XPathGuard&);
232
233 bool
234 operator==(const XPathGuard&) const;
235
236
237 // Data members...
238 XPathFactory* m_factory;
239 const XPath* m_object;
240};
241
242
243
244}
245
246
247
248#endif // XPATHFACTORY_HEADER_GUARD_1357924680
#define XALAN_XPATH_EXPORT
#define XALAN_CPP_NAMESPACE
Xalan-C++ namespace, including major and minor version.
virtual bool doReturnObject(const XPath *theXPath, bool fInReset=false)=0
bool returnObject(const XPath *theXPath)
Return an XPath to the factory.
virtual void reset()=0
Reset the instance.
virtual XPath * create()=0
Create an XPath.
Manages the lifetime of an XPath instance.
const XPath * release()
Transfers ownership of XPath to caller.
XPathGuard(XPathGuard &theRHS)
XPathGuard(XPathFactory &theFactory, const XPath *theXPath)
Construct an XPathGuard instance from a factory object and an XPath.
void reset()
Return the referenced object to the factory and set pointers to null.
const XPath * operator->() const
Retrieve the object pointer (must not be null)
const XPath * get() const
Retrieve the object pointer (may be null)
bool operator==(const XalanVector< Type > &theLHS, const XalanVector< Type > &theRHS)
A functor for use with stl algorithms.
DeleteXPathFunctor(XPathFactory &theFactoryInstance, bool fInReset=false)
bool operator()(const XPath *theXPath) const