00001 /* 00002 * Copyright 1999-2004 The Apache Software Foundation. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #if !defined(XOBJECT_HEADER_GUARD_1357924680) 00017 #define XOBJECT_HEADER_GUARD_1357924680 00018 00019 00020 00021 // Base include file. Must be first. 00022 #include <xalanc/XPath/XPathDefinitions.hpp> 00023 00024 00025 00026 #include <xalanc/XalanDOM/XalanDOMString.hpp> 00027 00028 00029 00030 #include <xalanc/PlatformSupport/DoubleSupport.hpp> 00031 #include <xalanc/PlatformSupport/FormatterListener.hpp> 00032 #include <xalanc/PlatformSupport/XalanReferenceCountedObject.hpp> 00033 00034 00035 00036 #include <xalanc/DOMSupport/DOMServices.hpp> 00037 00038 00039 00040 #include <xalanc/XPath/NodeRefListBase.hpp> 00041 #include <xalanc/XPath/XalanXPathException.hpp> 00042 00043 00044 00045 XALAN_CPP_NAMESPACE_BEGIN 00046 00047 00048 00049 class MutableNodeRefList; 00050 class NodeRefListBase; 00051 class XalanDocumentFragment; 00052 class XObjectFactory; 00053 class XObjectTypeCallback; 00054 class XPathExecutionContext; 00055 00056 00057 00061 class XALAN_XPATH_EXPORT XObject : protected XalanReferenceCountedObject 00062 { 00063 public: 00064 00065 friend class XObjectPtr; 00066 00070 enum eObjectType { eTypeNull = 0, 00071 eTypeUnknown = 1, 00072 eTypeBoolean = 2, 00073 eTypeNumber = 3, 00074 eTypeString = 4, 00075 eTypeNodeSet = 5, 00076 eTypeResultTreeFrag = 6, 00077 eTypeUserDefined = 7, 00078 // These next types are implementation-specific, and 00079 // are never returned by getType(). 00080 eTypeStringReference = 8, 00081 eTypeStringAdapter = 9, 00082 eTypeStringCached = 10, 00083 eTypeXTokenNumberAdapter = 11, 00084 eTypeXTokenStringAdapter = 12, 00085 eTypeNodeSetNodeProxy = 13, 00086 eUnknown 00087 }; 00088 00092 static void 00093 initialize(); 00094 00098 static void 00099 terminate(); 00100 00106 XObject(eObjectType theObjectType); 00107 00108 XObject(const XObject& source); 00109 00116 virtual XObject* 00117 clone(void* theAddress = 0) const = 0; 00118 00125 virtual XalanDOMString 00126 getTypeString() const = 0; 00127 00133 virtual double 00134 num() const; 00135 00141 virtual bool 00142 boolean() const; 00143 00149 virtual const XalanDOMString& 00150 str() const; 00151 00152 typedef void (FormatterListener::*MemberFunctionPtr)(const XMLCh* const, const unsigned int); 00153 00161 virtual void 00162 str( 00163 FormatterListener& formatterListener, 00164 MemberFunctionPtr function) const = 0; 00165 00171 virtual double 00172 stringLength() const = 0; 00173 00179 virtual void 00180 str(XalanDOMString& theBuffer) const; 00181 00187 virtual const XalanDocumentFragment& 00188 rtree() const; 00189 00195 virtual const NodeRefListBase& 00196 nodeset() const; 00197 00203 virtual void 00204 ProcessXObjectTypeCallback(XObjectTypeCallback& theCallbackObject) = 0; 00205 00211 virtual void 00212 ProcessXObjectTypeCallback(XObjectTypeCallback& theCallbackObject) const = 0; 00213 00221 bool 00222 equals( 00223 const XObject& theRHS, 00224 XPathExecutionContext& executionContext) const; 00225 00233 bool 00234 notEquals( 00235 const XObject& theRHS, 00236 XPathExecutionContext& executionContext) const; 00237 00244 bool 00245 lessThan( 00246 const XObject& theRHS, 00247 XPathExecutionContext& executionContext) const; 00248 00256 bool 00257 lessThanOrEquals( 00258 const XObject& theRHS, 00259 XPathExecutionContext& executionContext) const; 00260 00267 bool 00268 greaterThan( 00269 const XObject& theRHS, 00270 XPathExecutionContext& executionContext) const; 00271 00279 bool 00280 greaterThanOrEquals( 00281 const XObject& theRHS, 00282 XPathExecutionContext& executionContext) const; 00283 00289 eObjectType 00290 getType() const 00291 { 00292 return m_objectType; 00293 } 00294 00300 static bool 00301 boolean(double theNumber) 00302 { 00303 return !DoubleSupport::isNaN(theNumber) && !DoubleSupport::equal(theNumber, 0.0); 00304 } 00305 00311 static bool 00312 boolean(const XalanDOMString& theString) 00313 { 00314 return theString.length() == 0 ? false : true; 00315 } 00316 00322 static bool 00323 boolean(const NodeRefListBase& theNodeList) 00324 { 00325 return theNodeList.getLength() == 0 ? false : true; 00326 } 00327 00333 static const XalanDOMString& 00334 string(bool theBool) 00335 { 00336 return theBool == true ? s_trueString : s_falseString; 00337 } 00338 00339 static void 00340 string( 00341 bool theBool, 00342 FormatterListener& formatterListener, 00343 MemberFunctionPtr function) 00344 { 00345 if(theBool == true) 00346 { 00347 (formatterListener.*function)(s_trueString.c_str(), s_trueString.length()); 00348 } 00349 else 00350 { 00351 (formatterListener.*function)(s_falseString.c_str(), s_falseString.length()); 00352 } 00353 } 00354 00360 static void 00361 string( 00362 double theNumber, 00363 XalanDOMString& theString) 00364 { 00365 DoubleToDOMString(theNumber, theString); 00366 } 00367 00368 static void 00369 string( 00370 double theNumber, 00371 FormatterListener& formatterListener, 00372 MemberFunctionPtr function) 00373 { 00374 DOMStringHelper::DoubleToCharacters(theNumber, formatterListener, function); 00375 } 00376 00382 static void 00383 string( 00384 const XalanNode& theNode, 00385 XalanDOMString& theString) 00386 { 00387 DOMServices::getNodeData(theNode, theString); 00388 } 00389 00390 static void 00391 string( 00392 const XalanNode& theNode, 00393 FormatterListener& formatterListener, 00394 MemberFunctionPtr function) 00395 { 00396 DOMServices::getNodeData(theNode, formatterListener, function); 00397 } 00398 00404 static void 00405 string( 00406 const NodeRefListBase& theNodeList, 00407 XalanDOMString& theString) 00408 { 00409 if (theNodeList.getLength() > 0) 00410 { 00411 assert(theNodeList.item(0) != 0); 00412 00413 string(*theNodeList.item(0), theString); 00414 } 00415 } 00416 00417 static void 00418 string( 00419 const NodeRefListBase& theNodeList, 00420 FormatterListener& formatterListener, 00421 MemberFunctionPtr function) 00422 { 00423 if (theNodeList.getLength() > 0) 00424 { 00425 assert(theNodeList.item(0) != 0); 00426 00427 DOMServices::getNodeData(*theNodeList.item(0), formatterListener, function); 00428 } 00429 } 00430 00436 static double 00437 number(bool theBoolean) 00438 { 00439 return theBoolean == true ? 1.0 : 0.0; 00440 } 00441 00442 static double 00443 number(const XalanDOMString& theString) 00444 { 00445 return DoubleSupport::toDouble(theString); 00446 } 00447 00453 static double 00454 number( 00455 XPathExecutionContext& executionContext, 00456 const NodeRefListBase& theNodeList); 00457 00463 static double 00464 number( 00465 XPathExecutionContext& executionContext, 00466 const XalanNode& theNode); 00467 00468 00469 // All XObject instances are controlled by an instance of an XObjectFactory. 00470 friend class XObjectFactory; 00471 00472 void 00473 setFactory(XObjectFactory* theFactory) 00474 { 00475 m_factory = theFactory; 00476 } 00477 00478 // Base class for all XObject exceptions... 00479 class XObjectException : public XalanXPathException 00480 { 00481 public: 00482 00483 explicit 00484 XObjectException( 00485 const XalanDOMString& message = XalanDOMString(), 00486 const XalanDOMString& theType = XalanDOMString(XALAN_STATIC_UCODE_STRING("XObjectException"))); 00487 00488 virtual 00489 ~XObjectException(); 00490 }; 00491 00492 class XObjectInvalidConversionException : public XObjectException 00493 { 00494 public: 00495 00496 XObjectInvalidConversionException( 00497 const XalanDOMString& fromType, 00498 const XalanDOMString& toType); 00499 00500 virtual 00501 ~XObjectInvalidConversionException(); 00502 00503 const XalanDOMString& 00504 getFromType() const 00505 { 00506 return m_fromType; 00507 } 00508 00509 const XalanDOMString& 00510 getToType() const 00511 { 00512 return m_toType; 00513 } 00514 00515 private: 00516 00517 static const XalanDOMString 00518 formatErrorString( 00519 const XalanDOMString& fromType, 00520 const XalanDOMString& toType); 00521 00522 const XalanDOMString m_fromType; 00523 00524 const XalanDOMString m_toType; 00525 }; 00526 00527 protected: 00528 00534 virtual eObjectType 00535 getRealType() const; 00536 00537 virtual void 00538 referenced(); 00539 00540 virtual void 00541 dereferenced(); 00542 00543 virtual 00544 ~XObject(); 00545 00546 static const XalanDOMString s_nullString; 00547 00548 protected: 00549 00550 static XalanDOMString s_falseString; 00551 00552 static XalanDOMString s_trueString; 00553 00554 private: 00555 00556 // Not implemented... 00557 XObject& 00558 operator=(const XObject&); 00559 00560 const eObjectType m_objectType; 00561 00562 XObjectFactory* m_factory; 00563 }; 00564 00565 00566 00570 class XALAN_XPATH_EXPORT XObjectPtr 00571 { 00572 public: 00573 00574 friend bool operator==(const XObjectPtr&, const XObjectPtr&); 00575 friend bool operator<(const XObjectPtr&, const XObjectPtr&); 00576 00580 explicit 00581 XObjectPtr(XObject* theXObject = 0) : 00582 m_xobjectPtr(theXObject) 00583 { 00584 XalanReferenceCountedObject::addReference(theXObject); 00585 } 00586 00587 XObjectPtr(const XObjectPtr& theSource) : 00588 m_xobjectPtr(theSource.m_xobjectPtr) 00589 { 00590 XalanReferenceCountedObject::addReference(m_xobjectPtr); 00591 }; 00592 00593 XObjectPtr& 00594 operator=(const XObjectPtr& theRHS) 00595 { 00596 if (m_xobjectPtr != theRHS.m_xobjectPtr) 00597 { 00598 XalanReferenceCountedObject::removeReference(m_xobjectPtr); 00599 00600 m_xobjectPtr = theRHS.m_xobjectPtr; 00601 00602 XalanReferenceCountedObject::addReference(m_xobjectPtr); 00603 } 00604 00605 return *this; 00606 } 00607 00608 ~XObjectPtr() 00609 { 00610 XalanReferenceCountedObject::removeReference(m_xobjectPtr); 00611 }; 00612 00613 void 00614 release() 00615 { 00616 XObject* const xobjectPtr = m_xobjectPtr; 00617 00618 m_xobjectPtr = 0; 00619 00620 XalanReferenceCountedObject::removeReference(xobjectPtr); 00621 } 00622 00623 bool 00624 null() const 00625 { 00626 return m_xobjectPtr == 0 ? true : false; 00627 } 00628 00629 const XObject& 00630 operator*() const 00631 { 00632 return *m_xobjectPtr; 00633 }; 00634 00635 XObject& 00636 operator*() 00637 { 00638 return *m_xobjectPtr; 00639 }; 00640 00641 const XObject* 00642 operator->() const 00643 { 00644 return m_xobjectPtr; 00645 }; 00646 00647 XObject* 00648 operator->() 00649 { 00650 return m_xobjectPtr; 00651 }; 00652 00653 const XObject* 00654 get() const 00655 { 00656 return m_xobjectPtr; 00657 }; 00658 00659 XObject* 00660 get() 00661 { 00662 return m_xobjectPtr; 00663 }; 00664 00665 private: 00666 00667 XObject* m_xobjectPtr; 00668 }; 00669 00670 00671 00672 inline bool 00673 operator==( 00674 const XObjectPtr& theLHS, 00675 const XObjectPtr& theRHS) 00676 { 00677 return theLHS.m_xobjectPtr == theRHS.m_xobjectPtr; 00678 } 00679 00680 00681 00682 inline bool 00683 operator!=( 00684 const XObjectPtr& theLHS, 00685 const XObjectPtr& theRHS) 00686 { 00687 return !(theLHS == theRHS); 00688 } 00689 00690 00691 00692 inline bool 00693 operator<( 00694 const XObjectPtr& theLHS, 00695 const XObjectPtr& theRHS) 00696 { 00697 return theLHS.m_xobjectPtr < theRHS.m_xobjectPtr; 00698 } 00699 00700 00701 00702 XALAN_CPP_NAMESPACE_END 00703 00704 00705 00706 #endif // XOBJECT_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.8 |
|