dbertoni    01/10/29 20:11:22

  Modified:    c/src/XSLT StylesheetExecutionContext.hpp
                        StylesheetExecutionContextDefault.cpp
                        StylesheetExecutionContextDefault.hpp
  Log:
  Changes for new result tree fragment implementation.  Changes to store indent 
amount and prefer that to the XMLParserLiaison instance.
  
  Revision  Changes    Path
  1.67      +8 -0      xml-xalan/c/src/XSLT/StylesheetExecutionContext.hpp
  
  Index: StylesheetExecutionContext.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/StylesheetExecutionContext.hpp,v
  retrieving revision 1.66
  retrieving revision 1.67
  diff -u -r1.66 -r1.67
  --- StylesheetExecutionContext.hpp    2001/10/19 18:42:23     1.66
  +++ StylesheetExecutionContext.hpp    2001/10/30 04:11:22     1.67
  @@ -400,6 +400,14 @@
        virtual int
        getIndent() const = 0;
   
  +     /**
  +      * Set the current number of spaces to indent.
  +      * 
  +      * @param indentAmount The number of spaces to indent.  Use -1 for the 
default amount.
  +      */
  +     virtual void
  +     setIndent(int   indentAmount) = 0;
  +
        // $$$ ToDo: Remove this one!!!!
        /**
         * Execute an XPath and return the resulting XObject. The lifetime of 
this
  
  
  
  1.78      +95 -12    
xml-xalan/c/src/XSLT/StylesheetExecutionContextDefault.cpp
  
  Index: StylesheetExecutionContextDefault.cpp
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/c/src/XSLT/StylesheetExecutionContextDefault.cpp,v
  retrieving revision 1.77
  retrieving revision 1.78
  diff -u -r1.77 -r1.78
  --- StylesheetExecutionContextDefault.cpp     2001/10/19 18:42:23     1.77
  +++ StylesheetExecutionContextDefault.cpp     2001/10/30 04:11:22     1.78
  @@ -97,6 +97,7 @@
   
   #include <XalanSourceTree/FormatterToSourceTree.hpp>
   #include <XalanSourceTree/XalanSourceTreeDocument.hpp>
  +#include <XalanSourceTree/XalanSourceTreeDocumentFragment.hpp>
   
   
   
  @@ -153,7 +154,8 @@
        m_formatterToTextCache(),
        m_formatterToSourceTreeCache(),
        m_nodeSorterCache(),
  -     m_resultTreeFragCache(eResultTreeFragCacheListSize)
  +     m_resultTreeFragCache(*this, eResultTreeFragCacheListSize),
  +     m_indentAmount(-1)
   {
   }
   
  @@ -187,7 +189,8 @@
        m_formatterToTextCache(),
        m_formatterToSourceTreeCache(),
        m_nodeSorterCache(),
  -     m_resultTreeFragCache(eResultTreeFragCacheListSize)
  +     m_resultTreeFragCache(*this, eResultTreeFragCacheListSize),
  +     m_indentAmount(-1)
   {
   }
   
  @@ -456,13 +459,28 @@
   int
   StylesheetExecutionContextDefault::getIndent() const
   {
  -     assert(m_xsltProcessor != 0);
  +     if (m_indentAmount != -1)
  +     {
  +             return m_indentAmount;
  +     }
  +     else
  +     {
  +             assert(m_xsltProcessor != 0);
   
  -     return m_xsltProcessor->getXMLParserLiaison().getIndent();
  +             return m_xsltProcessor->getXMLParserLiaison().getIndent();
  +     }
   }
   
   
   
  +void
  +StylesheetExecutionContextDefault::setIndent(int     indentAmount)
  +{
  +     m_indentAmount = indentAmount;
  +}
  +
  +
  +
   const XObjectPtr
   StylesheetExecutionContextDefault::executeXPath(
                        const XalanDOMString&   str,
  @@ -911,7 +929,7 @@
   
        BorrowReturnResultTreeFrag      theResultTreeFrag(*this);
   
  -     GetReleaseCachedObject<FormatterToSourceTreeCacheType>  
theGuard(m_formatterToSourceTreeCache);
  +     GuardCachedObject<FormatterToSourceTreeCacheType>       
theGuard(m_formatterToSourceTreeCache);
   
        FormatterToSourceTree* const    theFormatter = theGuard.get();
        assert(theFormatter != 0);
  @@ -919,7 +937,16 @@
        XalanSourceTreeDocument* const  theDocument = getSourceTreeFactory();
   
        theFormatter->setDocument(theDocument);
  -     theFormatter->setDocumentFragment(theResultTreeFrag.get());
  +
  +     XalanSourceTreeDocumentFragment* const  theDocumentFragment =
  +#if defined(XALAN_OLD_STYLE_CASTS)
  +             ((const 
ResultTreeFrag*)theResultTreeFrag.get())->getDocumentFragment();
  +#else
  +             static_cast<const 
ResultTreeFrag*>(theResultTreeFrag.get())->getDocumentFragment();
  +#endif
  +     assert(theDocumentFragment != 0);
  +
  +     theFormatter->setDocumentFragment(theDocumentFragment);
   
        theFormatter->setPrefixResolver(m_xsltProcessor);
   
  @@ -1428,12 +1455,17 @@
        m_formatterToTextCache.reset();
        m_formatterToSourceTreeCache.reset();
        m_nodeSorterCache.reset();
  -     m_resultTreeFragCache.reset(),
  +     m_resultTreeFragCache.reset();
   
        // Just in case endDocument() was not called,
        // clean things up...
        cleanUpTransients();
   
  +     // Destroy the source tree factory, which
  +     // will destroy all result tree fragment nodes
  +     // that were generated...
  +     m_sourceTreeResultTreeFactory.reset();
  +
        // Reset the default execution context...
        m_xpathExecutionContextDefault.reset();
   }
  @@ -2149,6 +2181,8 @@
   XalanSourceTreeDocument*
   StylesheetExecutionContextDefault::getSourceTreeFactory() const
   {
  +     assert(m_xsltProcessor != 0);
  +
        if(m_sourceTreeResultTreeFactory.get() == 0)
        {
   #if defined(XALAN_NO_MUTABLE)
  @@ -2309,15 +2343,64 @@
   
        m_keyTables.clear();
   
  -     // Destroy the source tree factory, which
  -     // will destroy all result tree fragment nodes
  -     // that were generated...
  -     m_sourceTreeResultTreeFactory.reset();
  -
        m_countersTable.reset();
   
        // Clear any cached XPaths...
        clearXPathCache();
   
        assert(m_matchPatternCache.size() == 0);
  +}
  +
  +
  +
  +StylesheetExecutionContextDefault::ResultTreeFragCache::ResultTreeFragCache(
  +                     StylesheetExecutionContextDefault&      
theExecutionContext,
  +                     unsigned int                                            
initialSize) :
  +     m_resultTreeFragCache(initialSize),
  +     m_documentFragmentCache(initialSize)
  +{
  +     
m_documentFragmentCache.m_createFunctor.setExecutionContext(&theExecutionContext);
  +}
  +
  +
  +
  
+StylesheetExecutionContextDefault::ResultTreeFragCache::~ResultTreeFragCache()
  +{
  +}
  +
  +
  +
  +ResultTreeFragBase*
  +StylesheetExecutionContextDefault::ResultTreeFragCache::get()
  +{
  +     GuardCachedObject<ResultTreeFragCacheType>              
theResultTreeFrag(m_resultTreeFragCache);
  +     assert(theResultTreeFrag.get() != 0);
  +
  +     
theResultTreeFrag.get()->setDocumentFragment(m_documentFragmentCache.get());
  +     assert(theResultTreeFrag.get()->getDocumentFragment() != 0);
  +
  +     return theResultTreeFrag.release();
  +}
  +
  +
  +
  +bool
  
+StylesheetExecutionContextDefault::ResultTreeFragCache::release(ResultTreeFragBase*
          theResultTreeFragBase)
  +{
  +     assert(theResultTreeFragBase != 0);
  +
  +     ResultTreeFrag* const   theResultTreeFrag =
  +#if defined(XALAN_OLD_STYLE_CASTS)
  +             (ResultTreeFrag*)theResultTreeFragBase;
  +#else
  +             static_cast<ResultTreeFrag*>(theResultTreeFragBase);
  +#endif
  +
  +     XalanSourceTreeDocumentFragment* const  theDocumentFragment =
  +                     theResultTreeFrag->getDocumentFragment();
  +     assert(theDocumentFragment != 0);
  +
  +     m_documentFragmentCache.release(theDocumentFragment);
  +
  +     return m_resultTreeFragCache.release(theResultTreeFrag);
   }
  
  
  
  1.70      +114 -10   
xml-xalan/c/src/XSLT/StylesheetExecutionContextDefault.hpp
  
  Index: StylesheetExecutionContextDefault.hpp
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/c/src/XSLT/StylesheetExecutionContextDefault.hpp,v
  retrieving revision 1.69
  retrieving revision 1.70
  diff -u -r1.69 -r1.70
  --- StylesheetExecutionContextDefault.hpp     2001/10/19 18:42:23     1.69
  +++ StylesheetExecutionContextDefault.hpp     2001/10/30 04:11:22     1.70
  @@ -78,7 +78,6 @@
   
   
   
  -#include <XPath/ResultTreeFrag.hpp>
   #include <XPath/XPathExecutionContextDefault.hpp>
   
   
  @@ -91,11 +90,13 @@
   #include <XalanSourceTree/XalanSourceTreeDocument.hpp>
   #endif
   #include <XalanSourceTree/FormatterToSourceTree.hpp>
  +#include <XalanSourceTree/XalanSourceTreeDocumentFragment.hpp>
   
   
   
   #include <XSLT/CountersTable.hpp>
   #include <XSLT/NodeSorter.hpp>
  +#include <XSLT/ResultTreeFrag.hpp>
   #include <XSLT/Stylesheet.hpp>
   #include <XSLT/VariablesStack.hpp>
   
  @@ -338,6 +339,9 @@
        virtual int
        getIndent() const;
   
  +     virtual void
  +     setIndent(int   indentAmount);
  +
        // $$$ ToDo: Get rid of this!!!!
        virtual const XObjectPtr
        executeXPath(
  @@ -950,6 +954,13 @@
                XSLTEngineImpl&         m_xsltProcessor;
        };
   
  +     /**
  +      * Get a XalanSourceTreeDocument, primarily for creating result 
  +      * tree fragments.
  +      */
  +     XalanSourceTreeDocument*
  +     getSourceTreeFactory() const;
  +
   private:
   
        /**
  @@ -967,13 +978,6 @@
                        ParamsVectorType&                       params);
   
        /**
  -      * Get a XalanSourceTreeDocument, primarily for creating result 
  -      * tree fragments.
  -      */
  -     XalanSourceTreeDocument*
  -     getSourceTreeFactory() const;
  -
  -     /**
         * Determine if the XPath is one that we have cached.
         *
         * @param theXPath the XPath instance to check
  @@ -1007,6 +1011,105 @@
        void
        cleanUpTransients();
   
  +     /**
  +      *
  +      * A simple class to cache ResultTreeFrag and
  +      * XalanSourceTreeDocumentFragment instances.
  +      *
  +      */
  +     class XALAN_XSLT_EXPORT ResultTreeFragCache
  +     {
  +     public:
  +
  +             ResultTreeFragCache(
  +                             StylesheetExecutionContextDefault&      
theExecutionContext,
  +                             unsigned int                                    
        initialSize);
  +
  +             ~ResultTreeFragCache();
  +
  +             ResultTreeFragBase*
  +             get();
  +
  +             bool
  +             release(ResultTreeFragBase*             theResultTreeFragBase);
  +
  +             void
  +             reset()
  +             {
  +                     m_resultTreeFragCache.reset();
  +
  +                     m_documentFragmentCache.reset();
  +             }
  +
  +     private:
  +
  +             /**
  +              *
  +              * A simple functor class to create 
XalanSourceTreeDocumentFragment
  +              * instances.  This is necessary because the constructor 
requires
  +              * a XalanSourceTreeDocument instance.
  +              *
  +              */
  +             class XALAN_XSLT_EXPORT LocalCreateFunctor
  +             {
  +             public:
  +
  +                     LocalCreateFunctor() :
  +                             m_executionContext(0)
  +                     {
  +                     }
  +
  +                     void
  +                     setExecutionContext(StylesheetExecutionContextDefault*  
theExecutionContext)
  +                     {
  +                             m_executionContext = theExecutionContext;
  +                     }
  +
  +                     XalanSourceTreeDocumentFragment*
  +                     operator()() const
  +                     {
  +                             assert(m_executionContext != 0);
  +
  +                             return new 
XalanSourceTreeDocumentFragment(*m_executionContext->getSourceTreeFactory());
  +                     }
  +
  +                     StylesheetExecutionContextDefault*              
m_executionContext;
  +             };
  +
  +             /**
  +              *
  +              * A simple functor class to clear the children from a 
  +              * XalanSourceTreeDocumentFragment so it can be re-used.
  +              *
  +              */
  +             class XALAN_XSLT_EXPORT LocalResetFunctor
  +             {
  +             public:
  +
  +                     void
  +                     operator()(XalanSourceTreeDocumentFragment*             
theInstance) const
  +                     {
  +                             theInstance->clearChildren();
  +                     }
  +             };
  +
  +             typedef XalanObjectCache<
  +                                     ResultTreeFrag,
  +                                     
DefaultCacheCreateFunctor<ResultTreeFrag>,
  +                                     DeleteFunctor<ResultTreeFrag>,
  +                                     ClearCacheResetFunctor<ResultTreeFrag> 
>                ResultTreeFragCacheType;
  +
  +             typedef XalanObjectCache<
  +                                     XalanSourceTreeDocumentFragment,
  +                                     LocalCreateFunctor,
  +                                     
DeleteFunctor<XalanSourceTreeDocumentFragment>,
  +                                     LocalResetFunctor>                      
                                                                
DocumentFragmentCacheType;
  +
  +             ResultTreeFragCacheType                 m_resultTreeFragCache;
  +
  +             DocumentFragmentCacheType               m_documentFragmentCache;
  +     };
  +
        XPathExecutionContextDefault    m_xpathExecutionContextDefault;
   
        // $$ ToDo: Try to remove this dependency, and rely only on 
XSLTProcessor...
  @@ -1064,15 +1167,16 @@
        typedef XalanObjectCacheDefault<FormatterToText>                
FormatterToTextCacheType;
        typedef XalanObjectCacheDefault<FormatterToSourceTree>  
FormatterToSourceTreeCacheType;
        typedef XalanObjectCacheDefault<NodeSorter>                             
NodeSorterCacheType;
  -     typedef XalanObjectCache<ResultTreeFragBase, 
DefaultCacheCreateFunctor<ResultTreeFrag>, DeleteFunctor<ResultTreeFragBase>, 
ClearCacheResetFunctor<ResultTreeFragBase> >         ResultTreeFragCacheType;
   
        FormatterToTextCacheType                        m_formatterToTextCache;
   
        FormatterToSourceTreeCacheType          m_formatterToSourceTreeCache;
   
        NodeSorterCacheType                                     
m_nodeSorterCache;
  +
  +     ResultTreeFragCache                                     
m_resultTreeFragCache;
   
  -     ResultTreeFragCacheType                         m_resultTreeFragCache;
  +     int                                                                     
m_indentAmount;
   
        static XalanNumberFormatFactory         
s_defaultXalanNumberFormatFactory;
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to