00001 /* 00002 * Licensed to the Apache Software Foundation (ASF) under one 00003 * or more contributor license agreements. See the NOTICE file 00004 * distributed with this work for additional information 00005 * regarding copyright ownership. The ASF licenses this file 00006 * to you under the Apache License, Version 2.0 (the "License"); 00007 * you may not use this file except in compliance with the License. 00008 * You may obtain a copy of the License at 00009 * 00010 * http://www.apache.org/licenses/LICENSE-2.0 00011 * 00012 * Unless required by applicable law or agreed to in writing, software 00013 * distributed under the License is distributed on an "AS IS" BASIS, 00014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 * See the License for the specific language governing permissions and 00016 * limitations under the License. 00017 */ 00018 #if !defined(XPATHFACTORY_HEADER_GUARD_1357924680) 00019 #define XPATHFACTORY_HEADER_GUARD_1357924680 00020 00021 00022 00023 // Base include file. Must be first. 00024 #include <xalanc/XPath/XPathDefinitions.hpp> 00025 00026 #include <xalanc/Include/XalanMemoryManagement.hpp> 00027 00028 #include <cassert> 00029 #include <functional> 00030 00031 00032 00033 XALAN_CPP_NAMESPACE_BEGIN 00034 00035 00036 00037 class XPath; 00038 00039 00040 00041 class XALAN_XPATH_EXPORT XPathFactory 00042 { 00043 public: 00044 00045 explicit 00046 XPathFactory(); 00047 00048 virtual 00049 ~XPathFactory(); 00050 00051 /** 00052 * Return an XPath to the factory. 00053 * 00054 * @param theXPath The XPath to be returned 00055 * @return true if the object belongs to the factory, false if not. 00056 */ 00057 bool 00058 returnObject(const XPath* theXPath) 00059 { 00060 return doReturnObject(theXPath); 00061 } 00062 00063 /** 00064 * Reset the instance. This invalidates all existing instances created 00065 * with this XPathFactory. 00066 */ 00067 virtual void 00068 reset() = 0; 00069 00070 /** 00071 * Create an XPath. The XPath instance is owned by the factory, and should 00072 * not be deleted. The factory will manage the lifetime. 00073 * 00074 */ 00075 virtual XPath* 00076 create() = 0; 00077 00078 /** 00079 * 00080 * A functor for use with stl algorithms. 00081 * 00082 */ 00083 #if defined(XALAN_NO_STD_NAMESPACE) 00084 struct DeleteXPathFunctor : public unary_function<const XPath*, void> 00085 #else 00086 struct DeleteXPathFunctor : public std::unary_function<const XPath*, bool> 00087 #endif 00088 { 00089 public: 00090 00091 DeleteXPathFunctor( 00092 XPathFactory& theFactoryInstance, 00093 bool fInReset = false) : 00094 m_factoryInstance(theFactoryInstance), 00095 m_fInReset(fInReset) 00096 { 00097 } 00098 00099 result_type 00100 operator()(argument_type theXPath) const 00101 { 00102 if (m_fInReset == true) 00103 { 00104 return m_factoryInstance.doReturnObject(theXPath, 00105 true); 00106 } 00107 else 00108 { 00109 return m_factoryInstance.returnObject(theXPath); 00110 } 00111 } 00112 00113 private: 00114 00115 XPathFactory& m_factoryInstance; 00116 00117 const bool m_fInReset; 00118 }; 00119 00120 friend struct DeleteXPathFunctor; 00121 00122 protected: 00123 00124 virtual bool 00125 doReturnObject( 00126 const XPath* theXPath, 00127 bool fInReset = false) = 0; 00128 }; 00129 00130 00131 00132 /** 00133 * Manages the lifetime of an XPath instance. 00134 */ 00135 class XPathGuard 00136 { 00137 public: 00138 00139 /** 00140 * Construct an XPathGuard instance from a factory object and an XPath. 00141 * 00142 * @param theFactory object that manages lifetime of XPaths 00143 * @param theXPath pointer to XPath managed 00144 */ 00145 XPathGuard( 00146 XPathFactory& theFactory, 00147 const XPath* theXPath) : 00148 m_factory(&theFactory), 00149 m_object(theXPath) 00150 { 00151 } 00152 00153 // Note that copy construction transfers ownership, just 00154 // as std::auto_ptr. 00155 XPathGuard(XPathGuard& theRHS) 00156 { 00157 // Release the current object... 00158 release(); 00159 00160 // Copy the factory and object pointers... 00161 m_factory = theRHS.m_factory; 00162 m_object = theRHS.m_object; 00163 00164 // The source object no longer points to 00165 // the object... 00166 theRHS.m_factory = 0; 00167 theRHS.m_object = 0; 00168 } 00169 00170 ~XPathGuard() 00171 { 00172 reset(); 00173 } 00174 00175 /** 00176 * Retrieve the object pointer (must not be null) 00177 * 00178 * @return pointer to XPath 00179 */ 00180 const XPath* 00181 operator->() const 00182 { 00183 assert(m_object != 0); 00184 00185 return m_object; 00186 } 00187 00188 /** 00189 * Retrieve the object pointer (may be null) 00190 * 00191 * @return pointer to XPath 00192 */ 00193 const XPath* 00194 get() const 00195 { 00196 return m_object; 00197 } 00198 00199 /** 00200 * Return the referenced object to the factory and set pointers to null. 00201 */ 00202 void 00203 reset() 00204 { 00205 if (m_object != 0) 00206 { 00207 assert(m_factory != 0); 00208 00209 m_factory->returnObject(m_object); 00210 00211 m_object = 0; 00212 } 00213 00214 m_factory = 0; 00215 } 00216 00217 /** 00218 * Transfers ownership of XPath to caller 00219 * 00220 * @return pointer to XPath 00221 */ 00222 const XPath* 00223 release() 00224 { 00225 const XPath* const theTemp = m_object; 00226 00227 m_object = 0; 00228 00229 return theTemp; 00230 } 00231 00232 private: 00233 00234 XPathGuard& 00235 operator=(const XPathGuard&); 00236 00237 bool 00238 operator==(const XPathGuard&) const; 00239 00240 00241 // Data members... 00242 XPathFactory* m_factory; 00243 const XPath* m_object; 00244 }; 00245 00246 00247 00248 XALAN_CPP_NAMESPACE_END 00249 00250 00251 00252 #endif // XPATHFACTORY_HEADER_GUARD_1357924680
Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.
Xalan-C++ XSLT Processor Version 1.11 |
|