Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.10

Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

XObject.hpp

Go to the documentation of this file.
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(MemoryManagerType& theManager);
00094 
00098     static void
00099     terminate();
00100 
00106     XObject(eObjectType     theObjectType);
00107 
00108     XObject(const XObject&  source);
00109 
00110 
00117     virtual const XalanDOMString&
00118     getTypeString() const = 0;
00119 
00125     virtual double
00126     num() const;
00127 
00133     virtual bool
00134     boolean() const;
00135 
00141     virtual const XalanDOMString&
00142     str() const;
00143 
00144     typedef void (FormatterListener::*MemberFunctionPtr)(const XMLCh* const, const unsigned int);
00145 
00153     virtual void
00154     str(
00155             FormatterListener&  formatterListener,
00156             MemberFunctionPtr   function) const = 0;
00157 
00163     virtual double
00164     stringLength() const = 0;
00165 
00171     virtual void
00172     str(XalanDOMString& theBuffer) const;
00173 
00179     virtual const XalanDocumentFragment&
00180     rtree() const;
00181 
00187     virtual const NodeRefListBase&
00188     nodeset() const;
00189 
00195     virtual void
00196     ProcessXObjectTypeCallback(XObjectTypeCallback&     theCallbackObject) = 0;
00197 
00203     virtual void
00204     ProcessXObjectTypeCallback(XObjectTypeCallback&     theCallbackObject) const = 0;
00205 
00213     bool
00214     equals(
00215             const XObject&          theRHS,
00216             XPathExecutionContext&  executionContext) const;
00217 
00225     bool
00226     notEquals(
00227             const XObject&          theRHS,
00228             XPathExecutionContext&  executionContext) const;
00229 
00236     bool
00237     lessThan(
00238             const XObject&          theRHS,
00239             XPathExecutionContext&  executionContext) const;
00240 
00248     bool
00249     lessThanOrEquals(
00250             const XObject&          theRHS,
00251             XPathExecutionContext&  executionContext) const;
00252 
00259     bool
00260     greaterThan(
00261             const XObject&          theRHS,
00262             XPathExecutionContext&  executionContext) const;
00263 
00271     bool
00272     greaterThanOrEquals(
00273             const XObject&          theRHS,
00274             XPathExecutionContext&  executionContext) const;
00275 
00281     eObjectType
00282     getType() const
00283     {
00284         return m_objectType;
00285     }
00286 
00292     static bool
00293     boolean(double  theNumber)
00294     {
00295         return !DoubleSupport::isNaN(theNumber) && !DoubleSupport::equal(theNumber, 0.0);
00296     }
00297 
00303     static bool
00304     boolean(const XalanDOMString&   theString)
00305     {
00306         return theString.length() == 0 ? false : true;
00307     }
00308 
00314     static bool
00315     boolean(const NodeRefListBase&  theNodeList)
00316     {
00317         return theNodeList.getLength() == 0 ? false : true;
00318     }
00319 
00325     static const XalanDOMString&
00326     string(bool     theBool)
00327     {
00328         return theBool == true ? s_trueString : s_falseString;
00329     }
00330 
00331     static void
00332     string(
00333             bool                theBool,
00334             FormatterListener&  formatterListener,
00335             MemberFunctionPtr   function)
00336     {
00337         if(theBool == true)
00338         {
00339             (formatterListener.*function)(s_trueString.c_str(), s_trueString.length());
00340         }
00341         else
00342         {
00343             (formatterListener.*function)(s_falseString.c_str(), s_falseString.length());
00344         }
00345     }
00346 
00352     static void
00353     string(
00354             double              theNumber,
00355             XalanDOMString&     theString)
00356     {
00357         DoubleToDOMString(theNumber, theString);
00358     }
00359 
00360     static void
00361     string(
00362             double              theNumber,
00363             FormatterListener&  formatterListener,
00364             MemberFunctionPtr   function)
00365     {
00366         DOMStringHelper::DoubleToCharacters(theNumber, formatterListener, function);
00367     }
00368 
00374     static void
00375     string(
00376             const XalanNode&    theNode,
00377             XalanDOMString&     theString)
00378     {
00379         DOMServices::getNodeData(theNode, theString);
00380     }
00381 
00382     static void
00383     string(
00384             const XalanNode&    theNode,
00385             FormatterListener&  formatterListener,
00386             MemberFunctionPtr   function)
00387     {
00388         DOMServices::getNodeData(theNode, formatterListener, function);
00389     }
00390 
00396     static void
00397     string(
00398             const NodeRefListBase&  theNodeList,
00399             XalanDOMString&         theString)
00400     {
00401         if (theNodeList.getLength() > 0)
00402         {
00403             assert(theNodeList.item(0) != 0);
00404 
00405             string(*theNodeList.item(0), theString);
00406         }
00407     }
00408 
00409     static void
00410     string(
00411             const NodeRefListBase&  theNodeList,
00412             FormatterListener&      formatterListener,
00413             MemberFunctionPtr       function)
00414     {
00415         if (theNodeList.getLength() > 0)
00416         {
00417             assert(theNodeList.item(0) != 0);
00418 
00419             DOMServices::getNodeData(*theNodeList.item(0), formatterListener, function);
00420         }
00421     }
00422 
00428     static double
00429     number(bool     theBoolean)
00430     {
00431         return theBoolean == true ? 1.0 : 0.0;
00432     }
00433 
00434     static double
00435     number(const XalanDOMString&    theString,
00436             MemoryManagerType&      theManager)
00437     {
00438         return DoubleSupport::toDouble(theString, theManager);
00439     }
00440 
00446     static double
00447     number(
00448             XPathExecutionContext&  executionContext,
00449             const NodeRefListBase&  theNodeList);
00450 
00456     static double
00457     number(
00458             XPathExecutionContext&  executionContext,
00459             const XalanNode&        theNode);
00460 
00461 
00462     // All XObject instances are controlled by an instance of an XObjectFactory.
00463     friend class XObjectFactory;
00464 
00465     void
00466     setFactory(XObjectFactory*  theFactory)
00467     {
00468         m_factory = theFactory;
00469     }
00470 
00471     // Base class for all XObject exceptions...
00472     class XObjectException : public XalanXPathException
00473     {
00474     public:
00475 
00476         explicit
00477         XObjectException(
00478                 const XalanDOMString&   message = XalanDOMString(XalanMemMgrs::getDummyMemMgr()),
00479                 MemoryManagerType& theManager = XalanMemMgrs::getDummyMemMgr());
00480 
00481         XObjectException( const XObjectException& other) ;
00482 
00483         virtual
00484         ~XObjectException();
00485 
00486         virtual const XalanDOMChar*
00487         getType() const
00488         {
00489             return m_type;
00490         }
00491     private:
00492 
00493         static const XalanDOMChar   m_type[];
00494     };
00495 
00496     class XObjectInvalidConversionException : public XObjectException
00497     {
00498     public:
00499 
00500         XObjectInvalidConversionException(
00501                                 eObjectType fromType,
00502                                 eObjectType toType);
00503 
00504 
00505         XObjectInvalidConversionException( const XObjectInvalidConversionException& other);
00506 
00507         virtual
00508         ~XObjectInvalidConversionException();
00509 
00510         virtual const XalanDOMChar*
00511         getType() const
00512         {
00513             return m_type;
00514         }
00515 
00516 
00517     private:
00518 
00519         static const XalanDOMChar   m_type[];
00520 
00521         static const XalanDOMString&
00522         formatErrorString(
00523                 const XalanDOMString&   fromType,
00524                 const XalanDOMString&   toType,
00525                 XalanDOMString&         theResult);
00526 
00527 
00528         const eObjectType       m_from;
00529 
00530         const eObjectType       m_to;
00531     };
00532 
00533 protected:
00534 
00540     virtual eObjectType
00541     getRealType() const;
00542 
00543     virtual void 
00544     referenced();
00545 
00546     virtual void 
00547     dereferenced();
00548 
00549     virtual
00550     ~XObject();
00551 
00552     static const XalanDOMString     s_emptyString;
00553 
00554     static const XalanDOMString&    s_booleanString;
00555 
00556     static const XalanDOMString&    s_falseString;
00557 
00558     static const XalanDOMString&    s_nodesetString;
00559 
00560     static const XalanDOMString&    s_numberString;
00561 
00562     static const XalanDOMString&    s_resultTreeFragmentString;
00563 
00564     static const XalanDOMString&    s_stringString;
00565 
00566     static const XalanDOMString&    s_trueString;
00567 
00568 private:
00569 
00570     // Not implemented...
00571     XObject&
00572     operator=(const XObject&);
00573 
00574     const eObjectType   m_objectType;
00575 
00576     XObjectFactory*     m_factory;
00577 };
00578 
00579 
00580 
00584 class XALAN_XPATH_EXPORT XObjectPtr
00585 {
00586 public:
00587 
00588     friend bool operator==(const XObjectPtr&, const XObjectPtr&);
00589     friend bool operator<(const XObjectPtr&, const XObjectPtr&);
00590 
00594     explicit
00595     XObjectPtr(XObject*     theXObject = 0) :
00596         m_xobjectPtr(theXObject)
00597     {
00598         XalanReferenceCountedObject::addReference(theXObject);
00599     }
00600     
00601     XObjectPtr(const XObjectPtr&    theSource) :
00602         m_xobjectPtr(theSource.m_xobjectPtr)
00603     { 
00604         XalanReferenceCountedObject::addReference(m_xobjectPtr);
00605     };
00606 
00607     XObjectPtr&
00608     operator=(const XObjectPtr&     theRHS)
00609     { 
00610         if (m_xobjectPtr != theRHS.m_xobjectPtr)
00611         {
00612             XalanReferenceCountedObject::removeReference(m_xobjectPtr);
00613 
00614             m_xobjectPtr = theRHS.m_xobjectPtr;
00615 
00616             XalanReferenceCountedObject::addReference(m_xobjectPtr);
00617         }
00618 
00619         return *this;
00620     }
00621 
00622     ~XObjectPtr()
00623     {
00624         XalanReferenceCountedObject::removeReference(m_xobjectPtr);
00625     };  
00626 
00627     void
00628     release()
00629     {
00630         XObject* const  xobjectPtr = m_xobjectPtr;
00631 
00632         m_xobjectPtr = 0;
00633 
00634         XalanReferenceCountedObject::removeReference(xobjectPtr);
00635     }
00636 
00637     bool
00638     null() const
00639     {
00640         return m_xobjectPtr == 0 ? true : false;
00641     }
00642 
00643     const XObject&
00644     operator*() const
00645     {
00646         return *m_xobjectPtr;
00647     };
00648 
00649     XObject&
00650     operator*() 
00651     {
00652         return *m_xobjectPtr;
00653     };
00654 
00655     const XObject*
00656     operator->() const
00657     {
00658         return m_xobjectPtr;
00659     };
00660 
00661     XObject*
00662     operator->()
00663     {
00664         return m_xobjectPtr;
00665     };
00666 
00667     const XObject*
00668     get() const
00669     {
00670         return m_xobjectPtr;
00671     };
00672 
00673     XObject*
00674     get()
00675     {
00676         return m_xobjectPtr;
00677     };
00678 
00679 private:
00680 
00681     XObject*    m_xobjectPtr;
00682 };
00683 
00684 
00685 
00686 inline bool
00687 operator==(
00688             const XObjectPtr&   theLHS,
00689             const XObjectPtr&   theRHS)
00690 {
00691     return theLHS.m_xobjectPtr == theRHS.m_xobjectPtr;
00692 }
00693 
00694 
00695 
00696 inline bool
00697 operator!=(
00698             const XObjectPtr&   theLHS,
00699             const XObjectPtr&   theRHS)
00700 {
00701     return !(theLHS == theRHS);
00702 }
00703 
00704 
00705 
00706 inline bool
00707 operator<(
00708             const XObjectPtr&   theLHS,
00709             const XObjectPtr&   theRHS)
00710 {
00711     return theLHS.m_xobjectPtr < theRHS.m_xobjectPtr;
00712 }
00713 
00714 
00715 
00716 XALAN_CPP_NAMESPACE_END
00717 
00718 
00719 
00720 #endif  // XOBJECT_HEADER_GUARD_1357924680

Interpreting class diagrams

Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.

dot

Xalan-C++ XSLT Processor Version 1.10
Copyright © 1999-2004 The Apache Software Foundation. All Rights Reserved.

Apache Logo