Initial revision
[TestXSLT.git] / libsablot / src / engine / context.h
1 /* 
2  * The contents of this file are subject to the Mozilla Public
3  * License Version 1.1 (the "License"); you may not use this file
4  * except in compliance with the License. You may obtain a copy of
5  * the License at http://www.mozilla.org/MPL/
6  * 
7  * Software distributed under the License is distributed on an "AS
8  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9  * implied. See the License for the specific language governing
10  * rights and limitations under the License.
11  * 
12  * The Original Code is the Sablotron XSLT Processor.
13  * 
14  * The Initial Developer of the Original Code is Ginger Alliance Ltd.
15  * Portions created by Ginger Alliance are Copyright (C) 2000-2002
16  * Ginger Alliance Ltd. All Rights Reserved.
17  * 
18  * Contributor(s):
19  * 
20  * Alternatively, the contents of this file may be used under the
21  * terms of the GNU General Public License Version 2 or later (the
22  * "GPL"), in which case the provisions of the GPL are applicable 
23  * instead of those above.  If you wish to allow use of your 
24  * version of this file only under the terms of the GPL and not to
25  * allow others to use your version of this file under the MPL,
26  * indicate your decision by deleting the provisions above and
27  * replace them with the notice and other provisions required by
28  * the GPL.  If you do not delete the provisions above, a recipient
29  * may use your version of this file under either the MPL or the
30  * GPL.
31  */
32
33 #ifndef ContextHIncl
34 #define ContextHIncl
35
36 // GP: clean
37
38 /*****************************************************************
39
40     c   o   n   t   e   x   t   .   h
41
42 *****************************************************************/
43
44 #include "expr.h"
45 #include "verts.h"
46
47 class SortDefList;
48
49 class CList : public SList<NodeHandle>
50 {
51 public:
52     friend class Key;
53     CList();
54     ~CList();
55     virtual int compare(int i, int j, void *data);
56     virtual void swap(int i, int j);
57     void incRefCount();
58     int decRefCount();
59     eFlag sort(Sit S, XSLElement *caller, Context*, SortDefList* sortDefs_ = NULL);
60 protected:
61     Bool wcsValues; //says whether values are wcsxfrm'ed
62     PList<char*> values;
63     List<int> tags; //used for the nested sort
64 private:
65     int refCount;
66     SortDefList *sortDefs;
67     eFlag makeValues(Sit S, int from, int to, int level, 
68         XSLElement *caller, Context *ctxt);
69     int currLevel;
70     int compareWithoutDocOrd(int i, int j);
71     Bool tagChanged(int i, int j);
72     void report(Sit S, MsgType type, MsgCode code, const Str& arg1, const Str& arg2);    
73 };
74
75
76 /*****************************************************************
77
78     C   o   n   t   e   x   t
79
80   expression evaluation context
81
82 *****************************************************************/
83
84 class KList;
85
86 class Context 
87 {
88     friend class CList;
89 public:
90     Context(NodeHandle current, Bool isForKey_ = FALSE);
91     ~Context();
92     int 
93         getPosition() const;
94     int 
95         getSize() const;
96     NodeHandle 
97         current() const;
98     NodeHandle
99         getCurrentNode() const;
100     void
101         setCurrentNode(NodeHandle);
102     void    
103         reset();
104     Bool 
105         isFinished() const;
106     Bool
107         isVoid() const;
108     NodeHandle 
109         shift();
110     void    
111         set(NodeHandle);
112     void 
113         setVirtual(NodeHandle v, int virtualPosition_, int virtualSize_);
114     NodeHandle 
115         operator[] (int) const;
116     void
117         deppendall();
118     void
119         append(NodeHandle);
120     void
121         deppend();
122     Context
123         *copy();
124     Context 
125         *swallow(Sit S, Context *);
126     void
127         swap(int, int);
128     Bool
129         contains(NodeHandle v) const;
130
131     KList* getKeyArray();
132     
133     eFlag sort(Sit S, XSLElement *caller = NULL, SortDefList* sortDefs_ = NULL)
134     {
135         assert(caller || !sortDefs_);
136         E( array -> sort(S, caller, this, sortDefs_) );
137         return OK;
138     }
139     void uniquize();
140     CList* getArrayForDOM();
141 protected:
142     CList 
143         *array;
144     NodeHandle 
145         currentNode;
146     void setPosition(int pos)
147     {
148         position = pos;
149     };
150     int
151         position,
152         virtualPosition,
153         virtualSize;
154         Bool isForKey;
155 };
156
157 #endif  //ifndef ContextHIncl