~zorba-coders/zorba/bug-950621

« back to all changes in this revision

Viewing changes to src/runtime/paths/path_iterators.h

  • Committer: brantmat at ETHZ
  • Date: 2007-10-09 12:58:38 UTC
  • Revision ID: svn-v4:8046edc3-af21-0410-8661-ec7318497eea:trunk/zorba:904
commit of the new directory structure

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 *
 
3
 * @copyright
 
4
 * ========================================================================
 
5
 *      Copyright 2007 FLWOR Foundation
 
6
 *
 
7
 *      Licensed under the Apache License, Version 2.0 (the "License");
 
8
 *      you may not use this file except in compliance with the License.
 
9
 *      You may obtain a copy of the License at
 
10
 *      
 
11
 *              http://www.apache.org/licenses/LICENSE-2.0
 
12
 *      
 
13
 *      Unless required by applicable law or agreed to in writing, software
 
14
 *      distributed under the License is distributed on an "AS IS" BASIS,
 
15
 *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
16
 *      See the License for the specific language governing permissions and
 
17
 *      limitations under the License.
 
18
 * ========================================================================
 
19
 *
 
20
 * @author Markos Zaharioudakis
 
21
 * @file runtime/path_iterators.h
 
22
 *
 
23
 */
 
24
 
 
25
#ifndef XQP_PATH_ITERATORS_H
 
26
#define XQP_PATH_ITERATORS_H
 
27
 
 
28
 
 
29
#include "util/rchandle.h"
 
30
#include "exprtree/expr_consts.h"
 
31
#include "batching.h"
 
32
#include <stack>
 
33
 
 
34
 
 
35
namespace xqp {
 
36
 
 
37
 
 
38
/*******************************************************************************
 
39
 
 
40
********************************************************************************/
 
41
class KindTestIterator : public Batcher<KindTestIterator>
 
42
{
 
43
private:
 
44
  Iterator_t   theInput;
 
45
  Item_t       theQName;
 
46
  Item_t       theTypeName;
 
47
  match_test_t theTestKind;
 
48
  bool         theNilledAllowed;
 
49
 
 
50
public:
 
51
  KindTestIterator(
 
52
        yy::location loc,
 
53
        Iterator_t input,
 
54
        Item_t qname,
 
55
        Item_t tname,
 
56
        match_test_t kind,
 
57
        bool nilled = false)
 
58
    :
 
59
    Batcher<KindTestIterator>(loc),
 
60
    theInput(input),
 
61
    theQName(qname),
 
62
    theTypeName(tname),
 
63
    theTestKind(kind),
 
64
    theNilledAllowed(nilled)
 
65
  {
 
66
  }
 
67
 
 
68
  ~KindTestIterator() {}
 
69
 
 
70
public:
 
71
  Item_t nextImpl(IteratorTreeStateBlock& stateBlock);
 
72
  void resetImpl(IteratorTreeStateBlock& stateBlock);
 
73
  void releaseResourcesImpl(IteratorTreeStateBlock& stateBlock);
 
74
 
 
75
  std::ostream& _show(std::ostream& os) const;
 
76
};
 
77
 
 
78
 
 
79
/*******************************************************************************
 
80
 
 
81
********************************************************************************/
 
82
class NameTestIterator : public Batcher<NameTestIterator>
 
83
{
 
84
private:
 
85
  Iterator_t   theInput;
 
86
  Item_t       theQName;
 
87
  match_wild_t theWildKind;
 
88
 
 
89
public:
 
90
  NameTestIterator(
 
91
        yy::location loc,
 
92
        Iterator_t input,
 
93
        Item_t qname,
 
94
        match_wild_t kind)
 
95
    :
 
96
    Batcher<NameTestIterator>(loc),
 
97
    theInput(input),
 
98
    theQName(qname),
 
99
    theWildKind(kind)
 
100
  {
 
101
  }
 
102
 
 
103
  ~NameTestIterator() {}
 
104
 
 
105
public:
 
106
  Item_t nextImpl(IteratorTreeStateBlock& stateBlock);
 
107
  void resetImpl(IteratorTreeStateBlock& stateBlock);
 
108
  void releaseResourcesImpl(IteratorTreeStateBlock& stateBlock);
 
109
 
 
110
  std::ostream& _show(std::ostream& os) const;
 
111
};
 
112
 
 
113
 
 
114
/*******************************************************************************
 
115
 
 
116
********************************************************************************/
 
117
class AxisIterator
 
118
{
 
119
protected:
 
120
  Iterator_t  theInput;
 
121
  Item_t      theContextNode;
 
122
  TypeCode    theNodeKind;
 
123
 
 
124
public:
 
125
  AxisIterator(Iterator_t input)
 
126
    :
 
127
    theInput(input),
 
128
    theNodeKind(anyNode)
 
129
  {
 
130
  }
 
131
 
 
132
  virtual ~AxisIterator() {}
 
133
 
 
134
  void setNodeKind(TypeCode k) { theNodeKind = k; }
 
135
};
 
136
 
 
137
 
 
138
/*******************************************************************************
 
139
 
 
140
********************************************************************************/
 
141
class SelfAxisIterator : public Batcher<SelfAxisIterator>,
 
142
                         public AxisIterator
 
143
{
 
144
public:
 
145
  SelfAxisIterator(yy::location loc, Iterator_t input)
 
146
    :
 
147
    Batcher<SelfAxisIterator>(loc),
 
148
    AxisIterator(input)
 
149
  {
 
150
  }
 
151
 
 
152
  ~SelfAxisIterator() {}
 
153
 
 
154
public:
 
155
  Item_t nextImpl(IteratorTreeStateBlock& stateBlock);
 
156
  void resetImpl(IteratorTreeStateBlock& stateBlock);
 
157
  void releaseResourcesImpl(IteratorTreeStateBlock& stateBlock);
 
158
 
 
159
  std::ostream& _show(std::ostream& os) const;
 
160
};
 
161
 
 
162
 
 
163
/*******************************************************************************
 
164
 
 
165
********************************************************************************/
 
166
class AttributeAxisIterator : public Batcher<AttributeAxisIterator>,
 
167
                              public AxisIterator
 
168
{
 
169
private:
 
170
  Iterator_t  theAttributes;
 
171
#ifdef DEBUG
 
172
  Item_t      theCurrentAttr;
 
173
#endif
 
174
 
 
175
public:
 
176
  AttributeAxisIterator(yy::location loc, Iterator_t input)
 
177
    :
 
178
    Batcher<AttributeAxisIterator>(loc),
 
179
    AxisIterator(input)
 
180
  {
 
181
  }
 
182
 
 
183
  ~AttributeAxisIterator() {}
 
184
 
 
185
public:
 
186
  Item_t nextImpl(IteratorTreeStateBlock& stateBlock);
 
187
  void resetImpl(IteratorTreeStateBlock& stateBlock);
 
188
  void releaseResourcesImpl(IteratorTreeStateBlock& stateBlock);
 
189
 
 
190
  std::ostream& _show(std::ostream& os) const;
 
191
};
 
192
 
 
193
 
 
194
/*******************************************************************************
 
195
 
 
196
********************************************************************************/
 
197
class ParentAxisIterator : public Batcher<ParentAxisIterator>,
 
198
                           public AxisIterator
 
199
{
 
200
private:
 
201
#ifdef DEBUG
 
202
  Item_t  theParent;
 
203
#endif
 
204
 
 
205
public:
 
206
  ParentAxisIterator(yy::location loc, Iterator_t input)
 
207
    :
 
208
    Batcher<ParentAxisIterator>(loc),
 
209
    AxisIterator(input)
 
210
  {
 
211
  }
 
212
 
 
213
  ~ParentAxisIterator() {}
 
214
 
 
215
public:
 
216
  Item_t nextImpl(IteratorTreeStateBlock& stateBlock);
 
217
  void resetImpl(IteratorTreeStateBlock& stateBlock);
 
218
  void releaseResourcesImpl(IteratorTreeStateBlock& stateBlock);
 
219
 
 
220
  std::ostream& _show(std::ostream& os) const;
 
221
};
 
222
 
 
223
 
 
224
/*******************************************************************************
 
225
 
 
226
********************************************************************************/
 
227
class AncestorAxisIterator : public Batcher<AncestorAxisIterator>,
 
228
                             public AxisIterator
 
229
{
 
230
private:
 
231
  Item_t  theCurrentAnc;
 
232
 
 
233
public:
 
234
  AncestorAxisIterator(yy::location loc, Iterator_t input)
 
235
    :
 
236
    Batcher<AncestorAxisIterator>(loc),
 
237
    AxisIterator(input)
 
238
  {
 
239
  }
 
240
 
 
241
  ~AncestorAxisIterator() {}
 
242
 
 
243
public:
 
244
  Item_t nextImpl(IteratorTreeStateBlock& stateBlock);
 
245
  void resetImpl(IteratorTreeStateBlock& stateBlock);
 
246
  void releaseResourcesImpl(IteratorTreeStateBlock& stateBlock);
 
247
 
 
248
  std::ostream& _show(std::ostream& os) const;
 
249
};
 
250
 
 
251
 
 
252
/*******************************************************************************
 
253
 
 
254
********************************************************************************/
 
255
class AncestorSelfAxisIterator : public Batcher<AncestorSelfAxisIterator>,
 
256
                                 public AxisIterator
 
257
{
 
258
private:
 
259
  Item_t  theCurrentAnc;
 
260
 
 
261
public:
 
262
  AncestorSelfAxisIterator(yy::location loc, Iterator_t input)
 
263
    :
 
264
    Batcher<AncestorSelfAxisIterator>(loc),
 
265
    AxisIterator(input)
 
266
  {
 
267
  }
 
268
 
 
269
  ~AncestorSelfAxisIterator() {}
 
270
 
 
271
public:
 
272
  Item_t nextImpl(IteratorTreeStateBlock& stateBlock);
 
273
  void resetImpl(IteratorTreeStateBlock& stateBlock);
 
274
  void releaseResourcesImpl(IteratorTreeStateBlock& stateBlock);
 
275
 
 
276
  std::ostream& _show(std::ostream& os) const;
 
277
};
 
278
 
 
279
 
 
280
/*******************************************************************************
 
281
 
 
282
********************************************************************************/
 
283
class RSiblingAxisIterator : public Batcher<RSiblingAxisIterator>,
 
284
                             public AxisIterator
 
285
{
 
286
private:
 
287
  Iterator_t  theChildren;
 
288
#ifdef DEBUG
 
289
  Item_t      theRSibling;
 
290
#endif
 
291
 
 
292
public:
 
293
  RSiblingAxisIterator(yy::location loc, Iterator_t input)
 
294
    :
 
295
    Batcher<RSiblingAxisIterator>(loc),
 
296
    AxisIterator(input)
 
297
  {
 
298
  }
 
299
 
 
300
  ~RSiblingAxisIterator() {}
 
301
 
 
302
public:
 
303
  Item_t nextImpl(IteratorTreeStateBlock& stateBlock);
 
304
  void resetImpl(IteratorTreeStateBlock& stateBlock);
 
305
  void releaseResourcesImpl(IteratorTreeStateBlock& stateBlock);
 
306
 
 
307
  std::ostream& _show(std::ostream& os) const;
 
308
};
 
309
 
 
310
 
 
311
/*******************************************************************************
 
312
 
 
313
********************************************************************************/
 
314
class LSiblingAxisIterator : public Batcher<LSiblingAxisIterator>,
 
315
                             public AxisIterator
 
316
{
 
317
private:
 
318
  Iterator_t  theChildren;
 
319
#ifdef DEBUG
 
320
  Item_t      theLSibling;
 
321
#endif
 
322
 
 
323
public:
 
324
  LSiblingAxisIterator(yy::location loc, Iterator_t input)
 
325
    :
 
326
    Batcher<LSiblingAxisIterator>(loc),
 
327
    AxisIterator(input)
 
328
  {
 
329
  }
 
330
 
 
331
  ~LSiblingAxisIterator() {}
 
332
 
 
333
public:
 
334
  Item_t nextImpl(IteratorTreeStateBlock& stateBlock);
 
335
  void resetImpl(IteratorTreeStateBlock& stateBlock);
 
336
  void releaseResourcesImpl(IteratorTreeStateBlock& stateBlock);
 
337
 
 
338
  std::ostream& _show(std::ostream& os) const;
 
339
};
 
340
 
 
341
 
 
342
/*******************************************************************************
 
343
 
 
344
********************************************************************************/
 
345
class ChildAxisIterator : public Batcher<ChildAxisIterator>,
 
346
                          public AxisIterator
 
347
{
 
348
private:
 
349
  Iterator_t  theChildren;
 
350
#ifdef DEBUG
 
351
  Item_t      theCurrentChild;
 
352
#endif
 
353
 
 
354
public:
 
355
  ChildAxisIterator(yy::location loc, Iterator_t input)
 
356
    :
 
357
    Batcher<ChildAxisIterator>(loc),
 
358
    AxisIterator(input)
 
359
  {
 
360
  }
 
361
 
 
362
  ~ChildAxisIterator() {}
 
363
 
 
364
public:
 
365
  Item_t nextImpl(IteratorTreeStateBlock& stateBlock);
 
366
  void resetImpl(IteratorTreeStateBlock& stateBlock);
 
367
  void releaseResourcesImpl(IteratorTreeStateBlock& stateBlock);
 
368
 
 
369
  std::ostream& _show(std::ostream& os) const;
 
370
};
 
371
 
 
372
 
 
373
/*******************************************************************************
 
374
 
 
375
********************************************************************************/
 
376
class DescendantAxisIterator : public Batcher<DescendantAxisIterator>,
 
377
                               public AxisIterator
 
378
{
 
379
private:
 
380
  std::stack<std::pair<Item_t, Iterator_t> > theCurrentPath;
 
381
#ifdef DEBUG
 
382
  Item_t                                     theCurrentDesc;
 
383
#endif
 
384
public:
 
385
  DescendantAxisIterator(yy::location loc, Iterator_t input)
 
386
    :
 
387
    Batcher<DescendantAxisIterator>(loc),
 
388
    AxisIterator(input)
 
389
  {
 
390
  }
 
391
 
 
392
  ~DescendantAxisIterator() {}
 
393
 
 
394
public:
 
395
  Item_t nextImpl(IteratorTreeStateBlock& stateBlock);
 
396
  void resetImpl(IteratorTreeStateBlock& stateBlock);
 
397
  void releaseResourcesImpl(IteratorTreeStateBlock& stateBlock);
 
398
 
 
399
  std::ostream& _show(std::ostream& os) const;
 
400
};
 
401
 
 
402
 
 
403
/*******************************************************************************
 
404
 
 
405
********************************************************************************/
 
406
class DescendantSelfAxisIterator : public Batcher<DescendantSelfAxisIterator>,
 
407
                                   public AxisIterator
 
408
{
 
409
private:
 
410
  std::stack<std::pair<Item_t, Iterator_t> > theCurrentPath;
 
411
#ifdef DEBUG
 
412
  Item_t                                     theCurrentDesc;
 
413
#endif
 
414
public:
 
415
  DescendantSelfAxisIterator(yy::location loc, Iterator_t input)
 
416
    :
 
417
    Batcher<DescendantSelfAxisIterator>(loc),
 
418
    AxisIterator(input)
 
419
  {
 
420
  }
 
421
 
 
422
  ~DescendantSelfAxisIterator() {}
 
423
 
 
424
public:
 
425
  Item_t nextImpl(IteratorTreeStateBlock& stateBlock);
 
426
  void resetImpl(IteratorTreeStateBlock& stateBlock);
 
427
  void releaseResourcesImpl(IteratorTreeStateBlock& stateBlock);
 
428
 
 
429
  std::ostream& _show(std::ostream& os) const;
 
430
};
 
431
 
 
432
 
 
433
/*******************************************************************************
 
434
 
 
435
********************************************************************************/
 
436
class PrecedingAxisIterator : public Batcher<PrecedingAxisIterator>,
 
437
                              public AxisIterator
 
438
{
 
439
private:
 
440
  std::stack<Item_t>                         theAncestorPath;
 
441
  std::stack<std::pair<Item_t, Iterator_t> > theCurrentPath;
 
442
#ifdef DEBUG
 
443
  Item_t                                     theCurrentPrec;
 
444
#endif
 
445
public:
 
446
  PrecedingAxisIterator(yy::location loc, Iterator_t input)
 
447
    :
 
448
    Batcher<PrecedingAxisIterator>(loc),
 
449
    AxisIterator(input)
 
450
  {
 
451
  }
 
452
 
 
453
  ~PrecedingAxisIterator() {}
 
454
 
 
455
public:
 
456
  Item_t nextImpl(IteratorTreeStateBlock& stateBlock);
 
457
  void resetImpl(IteratorTreeStateBlock& stateBlock);
 
458
  void releaseResourcesImpl(IteratorTreeStateBlock& stateBlock);
 
459
 
 
460
  std::ostream& _show(std::ostream& os) const;
 
461
};
 
462
 
 
463
 
 
464
/*******************************************************************************
 
465
 
 
466
********************************************************************************/
 
467
class FollowingAxisIterator : public Batcher<FollowingAxisIterator>,
 
468
                              public AxisIterator
 
469
{
 
470
private:
 
471
  std::stack<Item_t>                         theAncestorPath;
 
472
  std::stack<std::pair<Item_t, Iterator_t> > theCurrentPath;
 
473
#ifdef DEBUG
 
474
  Item_t                                     theCurrentFollowing;
 
475
#endif
 
476
public:
 
477
  FollowingAxisIterator(yy::location loc, Iterator_t input)
 
478
    :
 
479
    Batcher<FollowingAxisIterator>(loc),
 
480
    AxisIterator(input)
 
481
  {
 
482
  }
 
483
 
 
484
  ~FollowingAxisIterator() {}
 
485
 
 
486
public:
 
487
  Item_t nextImpl(IteratorTreeStateBlock& stateBlock);
 
488
  void resetImpl(IteratorTreeStateBlock& stateBlock);
 
489
  void releaseResourcesImpl(IteratorTreeStateBlock& stateBlock);
 
490
 
 
491
  std::ostream& _show(std::ostream& os) const;
 
492
};
 
493
 
 
494
 
 
495
} /* namespace xqp */
 
496
 
 
497
#endif  /* XQP_PATH_ITERATORS_H */