dbertoni    2002/10/11 00:10:04

  Modified:    c/src/DOMSupport XalanNamespacesStack.cpp
                        XalanNamespacesStack.hpp
  Log:
  Clean-up.
  
  Revision  Changes    Path
  1.2       +37 -111   xml-xalan/c/src/DOMSupport/XalanNamespacesStack.cpp
  
  Index: XalanNamespacesStack.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/DOMSupport/XalanNamespacesStack.cpp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XalanNamespacesStack.cpp  11 Oct 2002 01:55:47 -0000      1.1
  +++ XalanNamespacesStack.cpp  11 Oct 2002 07:10:03 -0000      1.2
  @@ -121,6 +121,8 @@
                                const XalanDOMChar*                     theURI,
                                XalanDOMString::size_type       theLength)
   {
  +     // If we're at the end, we need to allocate something
  +     // new, then update m_position.
        if (m_position == m_namespaces.end())
        {
                m_namespaces.resize(m_namespaces.size() + 1);
  @@ -128,8 +130,9 @@
                m_position = m_namespaces.end() - 1;
        }
   
  -     XalanNamespace&         theNamespace = *m_position;
  +     value_type&             theNamespace = *m_position;
   
  +     // Set the appropriate values...
        theNamespace.setPrefix(thePrefix);
   
        theNamespace.setURI(theURI, theLength);
  @@ -140,7 +143,10 @@
   
   
   const XalanDOMString*
  -XalanNamespacesStack::XalanNamespacesStackEntry::getNamespaceForPrefix(const 
XalanDOMString& thePrefix) const
  +XalanNamespacesStack::XalanNamespacesStackEntry::findEntry(
  +                     const XalanDOMString&   theKey,
  +                     MemberFunctionType              theKeyFunction,
  +                     MemberFunctionType              theValueFunction) const
   {
        if (m_namespaces.empty() == false)
        {
  @@ -148,51 +154,23 @@
   
                do
                {
  +                     // m_position is always pointed past the end, so
  +                     // decrement first.
                        --i;
   
  -                     const XalanNamespace&   ns = (*i);
  +                     const value_type&       ns = (*i);
   
  -                     const XalanDOMString&   thisPrefix = ns.getPrefix();
  +                     const XalanDOMString&   thisKey = 
(ns.*theKeyFunction)();
   
  -                     if(equals(thePrefix, thisPrefix))
  +                     if(equals(theKey, thisKey))
                        {
  -                             return &ns.getURI();
  +                             return &(ns.*theValueFunction)();
                        }
                } while (i != m_namespaces.begin());
        }
   
        return 0;
   }
  -
  -
  -
  -const XalanDOMString*
  -XalanNamespacesStack::XalanNamespacesStackEntry::getPrefixForNamespace(const 
XalanDOMString& theURI) const
  -{
  -     if (m_namespaces.empty() == false)
  -     {
  -             const_iterator  i(m_position);
  -
  -             do
  -             {
  -                     --i;
  -
  -                     const XalanNamespace&   ns = (*i);
  -
  -                     const XalanDOMString&   thisURI = ns.getURI();
  -
  -                     if(equals(theURI, thisURI))
  -                     {
  -                             return &ns.getPrefix();
  -                     }
  -             } while (i != m_namespaces.begin());
  -     }
  -
  -     return 0;
  -}
  -
  -
  -
   void
   XalanNamespacesStack::XalanNamespacesStackEntry::clear()
   {
  @@ -248,7 +226,7 @@
                m_createNewContextStack.back() = false;
        }
   
  -     XalanNamespacesStackEntry&      theCurrentEntry = *m_stackPosition;
  +     value_type&     theCurrentEntry = *m_stackPosition;
   
        // Add a new namespace declaration...
        theCurrentEntry.addDeclaration(thePrefix, theURI, theLength);
  @@ -290,17 +268,11 @@
   
   
   const XalanDOMString*
  -XalanNamespacesStack::getNamespaceForPrefix(const XalanDOMString&    
thePrefix) const
  +XalanNamespacesStack::findEntry(
  +                     const XalanDOMString&   theKey,
  +                     MemberFunctionType              theFunction) const
   {
  -     if(::equals(thePrefix, DOMServices::s_XMLString))
  -     {
  -             return &DOMServices::s_XMLNamespaceURI;
  -     }
  -     else if (::equals(thePrefix, DOMServices::s_XMLNamespace))
  -     {
  -             return &DOMServices::s_XMLNamespacePrefixURI;
  -     }
  -     else if (m_stackPosition == m_stackBegin)
  +     if (m_stackPosition == m_stackBegin)
        {
                return 0;
        }
  @@ -309,55 +281,38 @@
                NamespacesStackType::const_iterator             
theBegin(m_stackBegin);
                NamespacesStackType::const_iterator             
theEnd(m_stackPosition + 1);
   
  -             const XalanDOMString*   nsURI = 0;
  +             const XalanDOMString*   theValue = 0;
   
  -             if (theBegin != theEnd)
  +             do
                {
  -                     do
  -                     {
  -                             nsURI = 
(*(--theEnd)).getNamespaceForPrefix(thePrefix);
  +                     theValue = ((*(--theEnd)).*theFunction)(theKey);
   
  -                             if (nsURI != 0)
  -                             {
  -                                     break;
  -                             }
  -                     } while(theBegin != theEnd);
  -             }
  +                     if (theValue != 0)
  +                     {
  +                             break;
  +                     }
  +             } while(theBegin != theEnd);
   
  -             return nsURI;
  +             return theValue;
        }
   }
   
   
   
   const XalanDOMString*
  -XalanNamespacesStack::getPrefixForNamespace(const XalanDOMString&    theURI) 
const
  +XalanNamespacesStack::getNamespaceForPrefix(const XalanDOMString&    
thePrefix) const
   {
  -     if (m_stackPosition == m_stackBegin)
  +     if(::equals(thePrefix, DOMServices::s_XMLString))
        {
  -             return 0;
  +             return &DOMServices::s_XMLNamespaceURI;
  +     }
  +     else if (::equals(thePrefix, DOMServices::s_XMLNamespace))
  +     {
  +             return &DOMServices::s_XMLNamespacePrefixURI;
        }
        else
        {
  -             NamespacesStackType::const_iterator             
theBegin(m_stackBegin);
  -             NamespacesStackType::const_iterator             
theEnd(m_stackPosition + 1);
  -
  -             const XalanDOMString*   prefix = 0;
  -
  -             if (theBegin != theEnd)
  -             {
  -                     do
  -                     {
  -                             prefix = 
(*(--theEnd)).getPrefixForNamespace(theURI);
  -
  -                             if (prefix != 0)
  -                             {
  -                                     break;
  -                             }
  -                     } while(theBegin != theEnd);
  -             }
  -
  -             return prefix;
  +             return findEntry(thePrefix, &value_type::getNamespaceForPrefix);
        }
   }
   
  @@ -374,10 +329,7 @@
        }
        else
        {
  -             const XalanNamespacesStackEntry&        theNamespaces =
  -                     *m_stackPosition;
  -
  -             return theNamespaces.isPrefixPresent(thePrefix);
  +             return (*m_stackPosition).isPrefixPresent(thePrefix);
        }
   }
   
  @@ -395,30 +347,4 @@
        m_stackPosition = m_stackBegin;
   
        m_createNewContextStack.clear();
  -}
  -
  -
  -
  -const XalanDOMString*
  -XalanNamespacesStack::getNamespaceForPrefix(
  -                     NamespacesStackType::const_iterator             
theBegin,
  -                     NamespacesStackType::const_iterator             theEnd,
  -                     const XalanDOMString&                                   
prefix)
  -{
  -     const XalanDOMString*   nsURI = 0;
  -
  -     if (theBegin != theEnd)
  -     {
  -             do
  -             {
  -                     nsURI = (*(--theEnd)).getNamespaceForPrefix(prefix);
  -
  -                     if (nsURI != 0)
  -                     {
  -                             break;
  -                     }
  -             } while(theBegin != theEnd);
  -     }
  -
  -     return nsURI;
   }
  
  
  
  1.3       +39 -42    xml-xalan/c/src/DOMSupport/XalanNamespacesStack.hpp
  
  Index: XalanNamespacesStack.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/DOMSupport/XalanNamespacesStack.hpp,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- XalanNamespacesStack.hpp  11 Oct 2002 02:13:08 -0000      1.2
  +++ XalanNamespacesStack.hpp  11 Oct 2002 07:10:03 -0000      1.3
  @@ -85,12 +85,16 @@
        {
        public:
   
  +             typedef XalanNamespace  value_type;
  +
   #if defined(XALAN_NO_NAMESPACES)
  -             typedef deque<XalanNamespace>           NamespaceCollectionType;
  +             typedef deque<value_type>               NamespaceCollectionType;
   #else
  -             typedef std::deque<XalanNamespace>      NamespaceCollectionType;
  +             typedef std::deque<value_type>  NamespaceCollectionType;
   #endif
   
  +             typedef const XalanDOMString& 
(value_type::*MemberFunctionType)() const;
  +
                typedef NamespaceCollectionType::iterator                       
                iterator;
                typedef NamespaceCollectionType::reverse_iterator               
        reverse_iterator;
                typedef NamespaceCollectionType::const_iterator                 
        const_iterator;
  @@ -118,7 +122,10 @@
                 * @return pointer to the string value if found, otherwise 0.
                 */
                const XalanDOMString*
  -             getNamespaceForPrefix(const XalanDOMString&             
thePrefix) const;
  +             getNamespaceForPrefix(const XalanDOMString&             
thePrefix) const
  +             {
  +                     return findEntry(thePrefix, &XalanNamespace::getPrefix, 
&XalanNamespace::getURI);
  +             }
   
                /**
                 * Get the prefix for a namespace.
  @@ -127,7 +134,10 @@
                 * @return pointer to the string value if found, otherwise 0.
                 */
                const XalanDOMString*
  -             getPrefixForNamespace(const XalanDOMString&             theURI) 
const;
  +             getPrefixForNamespace(const XalanDOMString&             theURI) 
const
  +             {
  +                     return findEntry(theURI, XalanNamespace::getURI, 
XalanNamespace::getPrefix);
  +             }
   
                bool
                isPrefixPresent(const XalanDOMString&   thePrefix) const
  @@ -197,17 +207,26 @@
   
        private:
   
  +             const XalanDOMString*
  +             findEntry(
  +                     const XalanDOMString&   theKey,
  +                     MemberFunctionType              theKeyFunction,
  +                     MemberFunctionType              theValueFunction) const;
  +
                NamespaceCollectionType         m_namespaces;
   
                iterator                                        m_position;
        };
   
  +
  +     typedef XalanNamespacesStackEntry       value_type;
  +
   #if defined(XALAN_NO_NAMESPACES)
  -     typedef deque<XalanNamespacesStackEntry>        NamespacesStackType;
  -     typedef vector<bool>                                            
BoolVectorType;
  +     typedef deque<value_type>               NamespacesStackType;
  +     typedef vector<bool>                    BoolVectorType;
   #else
  -     typedef std::deque<XalanNamespacesStackEntry>   NamespacesStackType;
  -     typedef std::vector<bool>                                               
BoolVectorType;
  +     typedef std::deque<value_type>  NamespacesStackType;
  +     typedef std::vector<bool>               BoolVectorType;
   #endif
   
        typedef NamespacesStackType::iterator                                   
iterator;
  @@ -215,7 +234,9 @@
        typedef NamespacesStackType::const_iterator                             
const_iterator;
        typedef NamespacesStackType::const_reverse_iterator             
const_reverse_iterator;
   
  -     typedef NamespacesStackType::size_type          size_type;
  +     typedef NamespacesStackType::size_type  size_type;
  +
  +     typedef const XalanDOMString* (value_type::*MemberFunctionType)(const 
XalanDOMString&) const;
   
   
        explicit
  @@ -261,7 +282,10 @@
        getNamespaceForPrefix(const XalanDOMString&             thePrefix) 
const;
   
        const XalanDOMString*
  -     getPrefixForNamespace(const XalanDOMString&             theURI) const;
  +     getPrefixForNamespace(const XalanDOMString&             theURI) const
  +     {
  +             return findEntry(theURI, &value_type::getPrefixForNamespace);
  +     }
   
        /**
         * See if the prefix has been mapped to a namespace in the current
  @@ -335,38 +359,6 @@
   
   private:
   
  -     /**
  -      * Get the namespace for a prefix by searching a range of iterators.
  -      * The search is done in reverse, from the end of the range to the
  -      * beginning.
  -      *
  -      * @param theBegin The beginning iterator for the range
  -      * @param theBegin The ending iterator for the range
  -      * @param prefix  namespace prefix to find
  -      * @return pointer to the string value if found, otherwise null.
  -      */
  -     static const XalanDOMString*
  -     getNamespaceForPrefix(
  -                     NamespacesStackType::const_iterator             
theBegin,
  -                     NamespacesStackType::const_iterator             theEnd,
  -                     const XalanDOMString&                                   
prefix);
  -
  -     /**
  -      * Get the prefix for a namespace by searching a range of iterators.
  -      * The search is done in reverse, from the end of the range to the
  -      * beginning.
  -      *
  -      * @param theBegin The beginning iterator for the range to search
  -      * @param theBegin The ending iterator for the range to search
  -      * @param uri     URI string for namespace to find
  -      * @return pointer to the string value if found, otherwise null.
  -      */
  -     static const XalanDOMString*
  -     getPrefixForNamespace(
  -                     NamespacesStackType::const_iterator             
theBegin,
  -                     NamespacesStackType::const_iterator             theEnd,
  -                     const XalanDOMString&                                   
uri);
  -
        // not implemented
        XalanNamespacesStack(const XalanNamespacesStack&);
   
  @@ -377,6 +369,11 @@
        operator=(const XalanNamespacesStack&);
   
        enum { eDefaultCreateNewContextStackSize = 25 };
  +
  +     const XalanDOMString*
  +     findEntry(
  +                     const XalanDOMString&   theKey,
  +                     MemberFunctionType              theFunction) const;
   
        /**
         * A stack to keep track of the result tree namespaces.
  
  
  

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

Reply via email to