## Xalan-C++ API Documentation

### The Xalan C++ XSLT Processor Version 1.9

Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

# NodeSorter.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(XALAN_NODESORTER_HEADER_GUARD)
    00017 #define XALAN_NODESORTER_HEADER_GUARD
    00018
    00025 // Base include file.  Must be first.
    00026 #include "XSLTDefinitions.hpp"
    00027
    00028
    00029
    00030 #include <functional>
    00031
    00032
    00033
    00034 #include <xalanc/Include/XalanVector.hpp>
    00035
    00036
    00037
    00038 #include <xalanc/XPath/XObject.hpp>
    00039
    00040
    00041
    00042 #include <xalanc/XSLT/NodeSortKey.hpp>
    00043
    00044
    00045
    00046 XALAN_CPP_NAMESPACE_BEGIN
    00047
    00048
    00049
    00050 class MutableNodeRefList;
    00051 class StylesheetExecutionContext;
    00052 class XalanNode;
    00053 class XPath;
    00054
    00055
    00056 typedef XalanVector<double>         NumberVectorTypeDecl;
    00057 XALAN_USES_MEMORY_MANAGER(NumberVectorTypeDecl)
    00058
    00059 typedef XalanVector<XalanDOMString> StringVectorTypeDecl;
    00060 XALAN_USES_MEMORY_MANAGER(StringVectorTypeDecl)
    00061
    00062
    00063
    00066 class XALAN_XSLT_EXPORT NodeSorter
    00067 {
    00068 public:
    00069
    00070     struct XALAN_XSLT_EXPORT VectorEntry
    00071     {
    00072     public:
    00073
    00074         VectorEntry(
    00075             XalanNode*      theNode = 0,
    00076             unsigned int    thePosition = 0) :
    00077             m_node(theNode),
    00078             m_position(thePosition)
    00079         {
    00080         }
    00081
    00082         XalanNode*      m_node;
    00083         unsigned int    m_position;
    00084     };
    00085
    00086     typedef XalanVector<VectorEntry>            NodeVectorType;
    00087     typedef XalanVector<NodeSortKey>            NodeSortKeyVectorType;
    00088
    00089     explicit
    00090     NodeSorter(MemoryManagerType& theManager);
    00091
    00092     ~NodeSorter();
    00093
    00094     NodeSortKeyVectorType&
    00095     getSortKeys()
    00096     {
    00097         return m_keys;
    00098     }
    00099
    00107     void
    00108     sort(
    00109             StylesheetExecutionContext&     executionContext,
    00110             MutableNodeRefList&             theList);
    00111
    00115 #if defined(XALAN_NO_STD_NAMESPACE)
    00116     struct XALAN_XSLT_EXPORT NodeSortKeyCompare : public binary_function<const NodeVectorType::value_type&, const NodeVectorType::value_type&, bool>
    00117 #else
    00118     struct XALAN_XSLT_EXPORT NodeSortKeyCompare : public std::binary_function<const NodeVectorType::value_type&, const NodeVectorType::value_type&, bool>
    00119 #endif
    00120     {
    00121     public:
    00122
    00130         NodeSortKeyCompare(
    00131                 StylesheetExecutionContext&     executionContext,
    00132                 NodeSorter&                     theSorter,
    00133                 const NodeVectorType&           theNodes,
    00134                 const NodeSortKeyVectorType&    theNodeSortKeys) :
    00135             m_executionContext(executionContext),
    00136             m_sorter(theSorter),
    00137             m_nodes(theNodes),
    00138             m_nodeSortKeys(theNodeSortKeys)
    00139         {
    00140         }
    00141
    00151         int
    00152         compare(
    00153                 first_argument_type     theLHS,
    00154                 second_argument_type    theRHS,
    00155                 unsigned int            theKeyIndex = 0) const;
    00156
    00165         result_type
    00166         operator()(
    00167                 first_argument_type     theLHS,
    00168                 second_argument_type    theRHS,
    00169                 unsigned int            theKeyIndex = 0) const
    00170         {
    00171             return compare(theLHS, theRHS, theKeyIndex) < 0 ? true : false;
    00172         }
    00173
    00174     protected:
    00175
    00176         double
    00177         getNumberResult(
    00178                 const NodeSortKey&      theKey,
    00179                 unsigned int            theKeyIndex,
    00180                 first_argument_type     theEntry) const;
    00181
    00182         const XalanDOMString&
    00183         getStringResult(
    00184                 const NodeSortKey&      theKey,
    00185                 unsigned int            theKeyIndex,
    00186                 first_argument_type     theEntry) const;
    00187
    00188     private:
    00189
    00190         StylesheetExecutionContext&     m_executionContext;
    00191         NodeSorter&                     m_sorter;
    00192         const NodeVectorType&           m_nodes;
    00193         const NodeSortKeyVectorType&    m_nodeSortKeys;
    00194     };
    00195
    00196     friend struct NodeSortKeyCompare;
    00197
    00198     typedef NumberVectorTypeDecl        NumberVectorType;
    00199     typedef XalanVector<XObjectPtr>     XObjectVectorType;
    00200     typedef StringVectorTypeDecl        StringVectorType;
    00201
    00202     typedef XalanVector<NumberVectorType>   NumberCacheType;
    00203     typedef XalanVector<XObjectVectorType>  XObjectCacheType;
    00204     typedef XalanVector<StringVectorType>   StringCacheType;
    00205
    00206     typedef NumberCacheType     NumberResultsCacheType;
    00207
    00208 #if defined(XALAN_NODESORTER_CACHE_XOBJECTS)
    00209     typedef XObjectCacheType    StringResultsCacheType;
    00210 #else
    00211     typedef StringCacheType     StringResultsCacheType;
    00212 #endif
    00213
    00214 private:
    00215
    00222     void
    00223     sort(StylesheetExecutionContext&    executionContext);
    00224
    00225     // Data members...
    00226     NumberResultsCacheType  m_numberResultsCache;
    00227
    00228     StringResultsCacheType  m_stringResultsCache;
    00229
    00230     NodeSortKeyVectorType   m_keys;
    00231
    00232     NodeVectorType          m_scratchVector;
    00233 };
    00234
    00235
    00236
    00237 XALAN_CPP_NAMESPACE_END
    00238
    00239
    00240
    00241 #endif  // XALAN_NODESORTER_HEADER_GUARD

Interpreting class diagrams

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

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