1 /*
2 * Copyright 2006-2008 The FLWOR Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #include "stdafx.h"
17
18 #include "system/globalenv.h"
19
20 #include "runtime/booleans/booleans.h"
21 #include "runtime/util/iterator_impl.h"
22
23 #include "store/api/item.h"
24 #include "store/api/item_factory.h"
25 #include "store/api/store.h"
26
27 #include "diagnostics/xquery_diagnostics.h"
28
29 namespace zorba {
30
31 //14.6 op:is-same-node
32 bool
nextImpl(store::Item_t & result,PlanState & planState) const33 IsSameNodeIterator::nextImpl(store::Item_t& result, PlanState& planState) const
34 {
35 bool lBool;
36 store::Item_t lItem0, lItem1;
37
38 PlanIteratorState* aState;
39 DEFAULT_STACK_INIT(PlanIteratorState, aState, planState);
40
41 if (CONSUME (lItem0, 0)) {
42 if (CONSUME (lItem1, 1)) {
43 if (!lItem0->isNode() || !lItem0->isNode()) {
44 throw XQUERY_EXCEPTION(
45 err::XPTY0004,
46 ERROR_PARAMS( ZED( OpIsSameNodeMustHaveNodes ) ),
47 ERROR_LOC( loc )
48 );
49 }
50 lBool = (GENV_STORE.compareNodes(lItem0, lItem1) == 0);
51 STACK_PUSH (GENV_ITEMFACTORY->createBoolean(result, lBool),
52 aState);
53 }
54 }
55 STACK_END (aState);
56 }
57
58
59 //14.7 op:node-before
60 bool
nextImpl(store::Item_t & result,PlanState & planState) const61 NodeBeforeIterator::nextImpl(store::Item_t& result, PlanState& planState) const
62 {
63 bool lBool;
64 store::Item_t lItem0, lItem1;
65
66 PlanIteratorState* aState;
67 DEFAULT_STACK_INIT(PlanIteratorState, aState, planState);
68
69 if (CONSUME (lItem0, 0)) {
70 if (CONSUME (lItem1, 1)) {
71 if (!lItem0->isNode() || !lItem0->isNode()) {
72 throw XQUERY_EXCEPTION(
73 err::XPTY0004,
74 ERROR_PARAMS( ZED( OpNodeBeforeMustHaveNodes ) ),
75 ERROR_LOC( loc )
76 );
77 }
78 lBool = (GENV_STORE.compareNodes(lItem0, lItem1) == -1);
79 STACK_PUSH (GENV_ITEMFACTORY->createBoolean(result, lBool), aState);
80 }
81 }
82 STACK_END (aState);
83 }
84
85 //14.8 op:node-after
86 bool
nextImpl(store::Item_t & result,PlanState & planState) const87 NodeAfterIterator::nextImpl(store::Item_t& result, PlanState& planState) const
88 {
89 bool lBool;
90 store::Item_t lItem0, lItem1;
91
92 PlanIteratorState* aState;
93 DEFAULT_STACK_INIT(PlanIteratorState, aState, planState);
94
95 if (CONSUME (lItem0, 0)) {
96 if (CONSUME (lItem1, 1)) {
97 if (!lItem0->isNode() || !lItem0->isNode()) {
98 throw XQUERY_EXCEPTION(
99 err::XPTY0004,
100 ERROR_PARAMS( ZED( OpNodeAfterMustHaveNodes ) ),
101 ERROR_LOC( loc )
102 );
103 }
104 lBool = (GENV_STORE.compareNodes(lItem0, lItem1) == 1);
105 STACK_PUSH (GENV_ITEMFACTORY->createBoolean(result, lBool), aState);
106 }
107 }
108 STACK_END (aState);
109 }
110
111 } // namespace zorba
112 /* vim:set et sw=2 ts=2: */
113