Back to index

lightning-sunbird  0.9+nobinonly
txXPathResultComparator.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is TransforMiiX XSLT processor code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Jonas Sicking.
00019  * Portions created by the Initial Developer are Copyright (C) 2001
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Jonas Sicking <sicking@bigfoot.com>
00024  *   Peter Van der Beken <peterv@propagandism.org>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either the GNU General Public License Version 2 or later (the "GPL"), or
00028  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #ifndef TRANSFRMX_XPATHRESULTCOMPARATOR_H
00041 #define TRANSFRMX_XPATHRESULTCOMPARATOR_H
00042 
00043 #include "txCore.h"
00044 #ifndef TX_EXE
00045 #include "nsCOMPtr.h"
00046 #include "nsICollation.h"
00047 #endif
00048 #include "nsString.h"
00049 
00050 class txAExprResult;
00051 
00052 /*
00053  * Result comparators
00054  */
00055 class txXPathResultComparator
00056 {
00057 public:
00058     virtual ~txXPathResultComparator()
00059     {
00060     }
00061 
00062     /*
00063      * Compares two XPath results. Returns -1 if val1 < val2,
00064      * 1 if val1 > val2 and 0 if val1 == val2.
00065      */
00066     virtual int compareValues(TxObject* val1, TxObject* val2) = 0;
00067     
00068     /*
00069      * Create a sortable value.
00070      */
00071     virtual TxObject* createSortableValue(txAExprResult* exprRes) = 0;
00072 };
00073 
00074 /*
00075  * Compare results as stings (data-type="text")
00076  */
00077 class txResultStringComparator : public txXPathResultComparator
00078 {
00079 public:
00080     txResultStringComparator(MBool aAscending, MBool aUpperFirst,
00081                              const nsAFlatString& aLanguage);
00082     virtual ~txResultStringComparator();
00083 
00084     int compareValues(TxObject* aVal1, TxObject* aVal2);
00085     TxObject* createSortableValue(txAExprResult* aExprRes);
00086 private:
00087 #ifndef TX_EXE
00088     nsCOMPtr<nsICollation> mCollation;
00089     nsresult init(const nsAFlatString& aLanguage);
00090     nsresult createRawSortKey(const PRInt32 aStrength,
00091                               const nsString& aString,
00092                               PRUint8** aKey,
00093                               PRUint32* aLength);
00094 #endif
00095     int mSorting;
00096 
00097     class StringValue : public TxObject
00098     {
00099     public:
00100 #ifdef TX_EXE
00101         nsString mStr;
00102 #else
00103         StringValue();
00104         ~StringValue();
00105 
00106         PRUint8* mKey;
00107         void* mCaseKey;
00108         PRUint32 mLength, mCaseLength;
00109 #endif
00110     };
00111 };
00112 
00113 /*
00114  * Compare results as numbers (data-type="number")
00115  */
00116 class txResultNumberComparator : public txXPathResultComparator
00117 {
00118 public:
00119     txResultNumberComparator(MBool aAscending);
00120     virtual ~txResultNumberComparator();
00121 
00122     int compareValues(TxObject* aVal1, TxObject* aVal2);
00123     TxObject* createSortableValue(txAExprResult* aExprRes);
00124 
00125 private:
00126     int mAscending;
00127 
00128     class NumberValue : public TxObject
00129     {
00130     public:
00131         double mVal;
00132     };
00133 };
00134 
00135 #endif