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(XOBJECTFACTORY_HEADER_GUARD_1357924680) 00019 #define XOBJECTFACTORY_HEADER_GUARD_1357924680 00020 00021 00022 00023 // Base include file. Must be first. 00024 #include <xalanc/XPath/XPathDefinitions.hpp> 00025 00026 00027 00028 #include <algorithm> 00029 #include <cassert> 00030 00031 00032 #include <xalanc/XPath/XObject.hpp> 00033 #include <xalanc/XPath/XPathExecutionContext.hpp> 00034 00035 00036 00037 XALAN_CPP_NAMESPACE_BEGIN 00038 00039 00040 00041 class XalanNode; 00042 class MutableNodeRefList; 00043 class NodeRefListBase; 00044 class XObject; 00045 class XObjectPtr; 00046 class XToken; 00047 00048 00049 00050 /** 00051 * This class handles the creation of XObjects and manages their lifetime. 00052 */ 00053 class XALAN_XPATH_EXPORT XObjectFactory 00054 { 00055 public: 00056 00057 typedef XPathExecutionContext::BorrowReturnMutableNodeRefList BorrowReturnMutableNodeRefList; 00058 typedef XPathExecutionContext::GetCachedString GetCachedString; 00059 typedef XPathExecutionContext::GetCachedString GetAndReleaseCachedString; 00060 00061 00062 XObjectFactory(MemoryManager& theManager); 00063 00064 virtual 00065 ~XObjectFactory(); 00066 00067 00068 MemoryManager& 00069 getMemoryManager() 00070 { 00071 return m_memoryManager; 00072 } 00073 00074 /** 00075 * Return an XObject to the factory. 00076 * 00077 * @param theXObject The XObject to be returned 00078 * @return true if the object belongs to the factory, false if not. 00079 */ 00080 bool 00081 returnObject(XObject* theXObject) 00082 { 00083 return doReturnObject(theXObject); 00084 } 00085 00086 /** 00087 * Reset the instance. This invalidates all existing instances created 00088 * with this XObjectFactory. 00089 */ 00090 virtual void 00091 reset() = 0; 00092 00093 /** 00094 * Create a boolean XObject from a boolean value. 00095 * 00096 * @param theValue value used to create object 00097 * @return pointer to new object 00098 */ 00099 virtual const XObjectPtr 00100 createBoolean(bool theValue) = 0; 00101 00102 /** 00103 * Create a node set XObject from a node list. 00104 * 00105 * @param theValue value used to create object. theValue will be owned by the new XObject. 00106 * @return pointer to new object 00107 */ 00108 virtual const XObjectPtr 00109 createNodeSet(BorrowReturnMutableNodeRefList& theValue) = 0; 00110 00111 /** 00112 * Create a node set XObject from a node. 00113 * 00114 * @param theNOde value used to create object. 00115 * @return pointer to new object 00116 */ 00117 virtual const XObjectPtr 00118 createNodeSet(XalanNode* theValue) = 0; 00119 00120 /** 00121 * Create a numeric XObject from a number. 00122 * 00123 * @param theValue value used to create object 00124 * @return pointer to new object 00125 */ 00126 virtual const XObjectPtr 00127 createNumber(double theValue) = 0; 00128 00129 /** 00130 * Create a numeric XObject from an XToken. The XToken 00131 * instance must be inexistence for the lifetime of the 00132 * object. 00133 * 00134 * @param theValue value used to create object 00135 * @return pointer to new object 00136 */ 00137 virtual const XObjectPtr 00138 createNumber(const XToken& theValue) = 0; 00139 00140 /** 00141 * Create a string XObject from a string. 00142 * 00143 * @param theValue value used to create object 00144 * @return pointer to new object 00145 */ 00146 virtual const XObjectPtr 00147 createString(const XalanDOMString& theValue) = 0; 00148 00149 /** 00150 * Create a string XObject from a null-terminated array of characters. 00151 * 00152 * @param theValue a pointer to the array 00153 * @return pointer to new object 00154 */ 00155 virtual const XObjectPtr 00156 createString(const XalanDOMChar* theValue) = 0; 00157 00158 /** 00159 * Create a string XObject from an array of characters. 00160 * 00161 * @param theValue a pointer to the array 00162 * @paran theLength the length of the array 00163 * @return pointer to new object 00164 */ 00165 virtual const XObjectPtr 00166 createString( 00167 const XalanDOMChar* theValue, 00168 XalanSize_t theLength) = 0; 00169 00170 /** 00171 * Create a string XObject from an XToken. The XToken 00172 * instance must be inexistence for the lifetime of the 00173 * object. 00174 * 00175 * @param theValue value used to create object 00176 * @return pointer to new object 00177 */ 00178 virtual const XObjectPtr 00179 createString(const XToken& theValue) = 0; 00180 00181 /** 00182 * Create a string XObject from a string. The XObject 00183 * will hold a reference to the supplied string, so 00184 * the string must be in scope for the lifetime of 00185 * the instance 00186 * 00187 * @param theValue value used to create object 00188 * @return pointer to new object 00189 */ 00190 virtual const XObjectPtr 00191 createStringReference(const XalanDOMString& theValue) = 0; 00192 00193 /** 00194 * Create a string XObject that will adapt another XObject to 00195 * behave like a string. The XObject holds a reference to the 00196 * other XObject. 00197 * 00198 * @param theValue value used to create object 00199 * @paran theExecutionContext The current execution context 00200 * @return pointer to new object 00201 */ 00202 virtual const XObjectPtr 00203 createStringAdapter( 00204 const XObjectPtr& theValue, 00205 XPathExecutionContext& theExecutionContext) = 0; 00206 00207 /** 00208 * Create a string XObject from a cached XalanDOMString, 00209 * 00210 * @param theValue value used to create object 00211 * @return pointer to new object 00212 */ 00213 virtual const XObjectPtr 00214 createString(GetCachedString& theValue) = 0; 00215 00216 /** 00217 * Create an "unknown" XObject from a string. 00218 * 00219 * @param theValue value used to create object 00220 * @return pointer to new object 00221 */ 00222 virtual const XObjectPtr 00223 createUnknown(const XalanDOMString& theValue) = 0; 00224 00225 /** 00226 * Hold a reference to an XObject instance until the 00227 * factory is reset. This is needed in a very few cases 00228 * when the object lifetime needs to extend after the 00229 * execution of an XPath expression. 00230 * 00231 * @param theValue The XObjectPtr instance. 00232 */ 00233 virtual void 00234 holdReference(XObjectPtr theValue) = 0; 00235 00236 /** 00237 * 00238 * A public functor for use with stl algorithms. 00239 * 00240 */ 00241 #if defined(XALAN_NO_STD_NAMESPACE) 00242 struct DeleteXObjectFunctor : public unary_function<XObject*, void> 00243 #else 00244 struct DeleteXObjectFunctor : public std::unary_function<XObject*, bool> 00245 #endif 00246 { 00247 public: 00248 00249 DeleteXObjectFunctor( 00250 XObjectFactory& theFactoryInstance, 00251 bool fInReset = false) : 00252 m_factoryInstance(theFactoryInstance), 00253 m_fInReset(fInReset) 00254 { 00255 } 00256 00257 result_type 00258 operator()(argument_type theXObject) const 00259 { 00260 if (m_fInReset == true) 00261 { 00262 return m_factoryInstance.doReturnObject( 00263 theXObject, 00264 true); 00265 } 00266 else 00267 { 00268 return m_factoryInstance.returnObject(theXObject); 00269 } 00270 } 00271 00272 private: 00273 00274 XObjectFactory& m_factoryInstance; 00275 00276 const bool m_fInReset; 00277 }; 00278 00279 friend struct DeleteXObjectFunctor; 00280 00281 protected: 00282 00283 /** 00284 * Return the actual implementation type of an XObject. 00285 * 00286 * @param theXObject the XObject 00287 */ 00288 XObject::eObjectType 00289 getRealType(const XObject& theXObject) const 00290 { 00291 return theXObject.getRealType(); 00292 } 00293 00294 /** 00295 * Delete a FactoryObject instance. 00296 * 00297 * @param theXObject the XObject instance to delete. 00298 */ 00299 void 00300 deleteObject(const XObject* theXObject) const 00301 { 00302 if( theXObject!= 0) 00303 { 00304 XObject* const nonConst = 00305 const_cast<XObject*>(theXObject); 00306 00307 nonConst->~XObject(); 00308 00309 m_memoryManager.deallocate(nonConst); 00310 } 00311 } 00312 00313 /** 00314 * Return an XObject to the factory. 00315 * 00316 * @param theXObject XObject to be returned 00317 * @param fInReset true when called during reset(). 00318 */ 00319 00320 virtual bool 00321 doReturnObject( 00322 XObject* theXObject, 00323 bool fInReset = false) = 0; 00324 00325 private: 00326 00327 // Not implemented... 00328 XObjectFactory(const XObjectFactory&); 00329 00330 XObjectFactory& 00331 operator=(const XObjectFactory&); 00332 00333 bool 00334 operator==(const XObjectFactory&) const; 00335 00336 MemoryManager& m_memoryManager; 00337 }; 00338 00339 00340 00341 XALAN_CPP_NAMESPACE_END 00342 00343 00344 00345 #endif // XOBJECTFACTORY_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 |
|