00001 /* 00002 * The Apache Software License, Version 1.1 00003 * 00004 * 00005 * Copyright (c) 1999 The Apache Software Foundation. All rights 00006 * reserved. 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions 00010 * are met: 00011 * 00012 * 1. Redistributions of source code must retain the above copyright 00013 * notice, this list of conditions and the following disclaimer. 00014 * 00015 * 2. Redistributions in binary form must reproduce the above copyright 00016 * notice, this list of conditions and the following disclaimer in 00017 * the documentation and/or other materials provided with the 00018 * distribution. 00019 * 00020 * 3. The end-user documentation included with the redistribution, 00021 * if any, must include the following acknowledgment: 00022 * "This product includes software developed by the 00023 * Apache Software Foundation (http://www.apache.org/)." 00024 * Alternately, this acknowledgment may appear in the software itself, 00025 * if and wherever such third-party acknowledgments normally appear. 00026 * 00027 * 4. The names "Xalan" and "Apache Software Foundation" must 00028 * not be used to endorse or promote products derived from this 00029 * software without prior written permission. For written 00030 * permission, please contact apache@apache.org. 00031 * 00032 * 5. Products derived from this software may not be called "Apache", 00033 * nor may "Apache" appear in their name, without prior written 00034 * permission of the Apache Software Foundation. 00035 * 00036 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 00037 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00038 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00039 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 00040 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00041 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00042 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 00043 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00044 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00045 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 00046 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00047 * SUCH DAMAGE. 00048 * ==================================================================== 00049 * 00050 * This software consists of voluntary contributions made by many 00051 * individuals on behalf of the Apache Software Foundation and was 00052 * originally based on software copyright (c) 1999, International 00053 * Business Machines, Inc., http://www.ibm.com. For more 00054 * information on the Apache Software Foundation, please see 00055 * <http://www.apache.org/>. 00056 */ 00057 #if !defined(XOBJECTFACTORY_HEADER_GUARD_1357924680) 00058 #define XOBJECTFACTORY_HEADER_GUARD_1357924680 00059 00060 00061 00062 // Base include file. Must be first. 00063 #include <XPath/XPathDefinitions.hpp> 00064 00065 00066 00067 #include <algorithm> 00068 #include <cassert> 00069 #include <set> 00070 00071 00072 00073 #include <XPath/XObject.hpp> 00074 #include <XPath/XPathExecutionContext.hpp> 00075 00076 00077 00078 class XalanNode; 00079 class MutableNodeRefList; 00080 class NodeRefListBase; 00081 class ResultTreeFragBase; 00082 class XObject; 00083 00084 00085 00089 class XALAN_XPATH_EXPORT XObjectFactory 00090 { 00091 public: 00092 00093 typedef XPathExecutionContext::BorrowReturnMutableNodeRefList BorrowReturnMutableNodeRefList; 00094 00095 XObjectFactory(); 00096 00097 virtual 00098 ~XObjectFactory(); 00099 00100 00107 bool 00108 returnObject(const XObject* theXObject) 00109 { 00110 return doReturnObject(theXObject); 00111 } 00112 00117 virtual void 00118 reset() = 0; 00119 00126 virtual XObject* 00127 clone(const XObject& theXObject) = 0; 00128 00137 virtual XObject* 00138 createBoolean( 00139 bool theValue, 00140 bool fOptimize = true) = 0; 00141 00149 virtual XObject* 00150 createNodeSet( 00151 BorrowReturnMutableNodeRefList& theValue, 00152 bool fOptimize = true) = 0; 00153 00162 virtual XObject* 00163 createNull(bool fOptimize = true) = 0; 00164 00172 virtual XObject* 00173 createNumber( 00174 double theValue, 00175 bool fOptimize = true) = 0; 00176 00184 virtual XObject* 00185 createString( 00186 const XalanDOMString& theValue, 00187 bool fOptimize = true) = 0; 00188 00196 virtual XObject* 00197 createUnknown( 00198 const XalanDOMString& theValue, 00199 bool fOptimize = true) = 0; 00200 00208 virtual XObject* 00209 createResultTreeFrag( 00210 ResultTreeFragBase* theValue, 00211 bool fOptimize = true) = 0; 00212 00220 virtual XObject* 00221 createSpan( 00222 BorrowReturnMutableNodeRefList& theValue, 00223 bool fOptimize = true) = 0; 00224 00230 #if defined(XALAN_NO_NAMESPACES) 00231 struct DeleteXObjectFunctor : public unary_function<const XObject*, void> 00232 #else 00233 struct DeleteXObjectFunctor : public std::unary_function<const XObject*, void> 00234 #endif 00235 { 00236 public: 00237 00238 DeleteXObjectFunctor( 00239 XObjectFactory& theFactoryInstance, 00240 bool fInReset = false) : 00241 m_factoryInstance(theFactoryInstance), 00242 m_fInReset(fInReset) 00243 { 00244 } 00245 00246 result_type 00247 operator()(argument_type theXObject) const 00248 { 00249 if (m_fInReset == true) 00250 { 00251 m_factoryInstance.doReturnObject( 00252 theXObject, 00253 true); 00254 } 00255 else 00256 { 00257 m_factoryInstance.returnObject(theXObject); 00258 } 00259 } 00260 00261 private: 00262 00263 XObjectFactory& m_factoryInstance; 00264 00265 const bool m_fInReset; 00266 }; 00267 00268 friend struct DeleteXObjectFunctor; 00269 00270 protected: 00271 00277 void 00278 deleteObject(const XObject* theXObject) const 00279 { 00280 #if defined(XALAN_CANNOT_DELETE_CONST) 00281 delete (XObject*)theXObject; 00282 #else 00283 delete theXObject; 00284 #endif 00285 } 00286 00293 00294 virtual bool 00295 doReturnObject( 00296 const XObject* theXObject, 00297 bool fInReset = false) = 0; 00298 00299 private: 00300 00301 // Not implemented... 00302 XObjectFactory(const XObjectFactory&); 00303 00304 XObjectFactory& 00305 operator=(const XObjectFactory&); 00306 00307 bool 00308 operator==(const XObjectFactory&) const; 00309 }; 00310 00311 00312 00316 class XObjectGuard 00317 { 00318 public: 00319 00326 XObjectGuard( 00327 XObjectFactory& theFactory, 00328 const XObject* theXObject) : 00329 m_factory(&theFactory), 00330 m_object(theXObject) 00331 { 00332 } 00333 00334 explicit 00335 XObjectGuard() : 00336 m_factory(0), 00337 m_object(0) 00338 { 00339 } 00340 00341 // Note that copy construction transfers ownership, just 00342 // as std::auto_ptr. 00343 XObjectGuard(XObjectGuard& theRHS) 00344 { 00345 // Release the current object... 00346 release(); 00347 00348 // Copy the factory and object pointers... 00349 m_factory = theRHS.m_factory; 00350 m_object = theRHS.m_object; 00351 00352 // The source object no longer points to 00353 // the object... 00354 theRHS.m_factory = 0; 00355 theRHS.m_object = 0; 00356 } 00357 00358 ~XObjectGuard() 00359 { 00360 reset(); 00361 } 00362 00363 // Note that assignment transfers ownership, just 00364 // as std::auto_ptr. 00365 XObjectGuard& 00366 operator=(XObjectGuard& theRHS) 00367 { 00368 if (&theRHS != this) 00369 { 00370 // Release the current object... 00371 release(); 00372 00373 // Copy the factory and object pointers... 00374 m_factory = theRHS.m_factory; 00375 m_object = theRHS.m_object; 00376 00377 // The source object no longer points to 00378 // the object... 00379 theRHS.m_factory = 0; 00380 theRHS.m_object = 0; 00381 } 00382 00383 return *this; 00384 } 00385 00391 const XObject* 00392 operator->() const 00393 { 00394 assert(m_object != 0); 00395 00396 return m_object; 00397 } 00398 00404 const XObject* 00405 get() const 00406 { 00407 return m_object; 00408 } 00409 00413 void 00414 reset() 00415 { 00416 if (m_object != 0) 00417 { 00418 assert(m_factory != 0); 00419 00420 m_factory->returnObject(m_object); 00421 00422 m_object = 0; 00423 } 00424 00425 m_factory = 0; 00426 } 00427 00432 void 00433 reset( 00434 XObjectFactory& theFactory, 00435 const XObject* theXObject) 00436 { 00437 if (m_object != 0) 00438 { 00439 assert(m_factory != 0); 00440 00441 m_factory->returnObject(m_object); 00442 } 00443 00444 m_object = theXObject; 00445 m_factory = &theFactory; 00446 } 00447 00453 const XObject* 00454 release() 00455 { 00456 const XObject* const theTemp = m_object; 00457 00458 m_object = 0; 00459 00460 return theTemp; 00461 } 00462 00463 private: 00464 00465 bool 00466 operator==(const XObjectGuard&) const; 00467 00468 00469 // Data members... 00470 XObjectFactory* m_factory; 00471 const XObject* m_object; 00472 }; 00473 00474 00475 00476 #endif // XOBJECTFACTORY_HEADER_GUARD_1357924680
Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.
![]() |
Xalan-C++ XSL Transformer Version 1.0 |
|