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 #pragma once 17 #ifndef ZORBA_RUNTIME_JSON_CONSTRUCTORS 18 #define ZORBA_RUNTIME_JSON_CONSTRUCTORS 19 20 #ifdef ZORBA_WITH_JSON 21 22 #include "common/shared_types.h" 23 24 #include "runtime/base/narybase.h" 25 #include "runtime/base/binarybase.h" 26 27 #include "store/api/copymode.h" 28 29 namespace zorba { 30 31 32 /********************************************************************************* 33 34 *********************************************************************************/ 35 class JSONArrayIteratorState : public PlanIteratorState 36 { 37 public: 38 std::vector<store::CopyMode> theCopyModes; 39 std::vector<store::Iterator_t> theSourcesWrappers; 40 41 public: 42 void open( 43 PlanState& planState, 44 const std::vector<PlanIter_t>& sources, 45 const std::vector<bool>& copyInputs); 46 }; 47 48 49 class JSONArrayIterator : public NaryBaseIterator<JSONArrayIterator, 50 JSONArrayIteratorState> 51 { 52 protected: 53 std::vector<bool> theCopyInputs; 54 55 public: 56 SERIALIZABLE_CLASS(JSONArrayIterator); 57 58 SERIALIZABLE_CLASS_CONSTRUCTOR2T( 59 JSONArrayIterator, 60 NaryBaseIterator<JSONArrayIterator, JSONArrayIteratorState>); 61 62 void serialize(::zorba::serialization::Archiver& ar); 63 64 public: 65 JSONArrayIterator( 66 static_context* sctx, 67 const QueryLoc& loc, 68 std::vector<PlanIter_t>& content, 69 bool copyInput); 70 isConstructor()71 bool isConstructor() const { return true; } 72 73 void accept(PlanIterVisitor& v) const; 74 75 void openImpl(PlanState& planState, uint32_t& offset); 76 77 bool nextImpl(store::Item_t& result, PlanState& planState) const; 78 }; 79 80 81 /********************************************************************************* 82 83 *********************************************************************************/ 84 class JSONObjectIteratorState : public PlanIteratorState 85 { 86 public: 87 std::vector<store::CopyMode> theCopyModes; 88 std::vector<store::Iterator_t> theSourcesWrappers; 89 90 public: 91 void open( 92 PlanState& planState, 93 const std::vector<PlanIter_t>& sources, 94 const std::vector<bool>& copyInputs); 95 }; 96 97 98 class JSONObjectIterator : public NaryBaseIterator<JSONObjectIterator, 99 JSONObjectIteratorState> 100 { 101 protected: 102 std::vector<bool> theCopyInputs; 103 bool theIsAccumulating; 104 105 public: 106 SERIALIZABLE_CLASS(JSONObjectIterator); 107 108 SERIALIZABLE_CLASS_CONSTRUCTOR2T( 109 JSONObjectIterator, 110 NaryBaseIterator<JSONObjectIterator, JSONObjectIteratorState>); 111 112 void serialize(::zorba::serialization::Archiver& ar); 113 114 public: 115 JSONObjectIterator( 116 static_context* sctx, 117 const QueryLoc& loc, 118 std::vector<PlanIter_t>& children, 119 bool copyInput, 120 bool accumulating); 121 isConstructor()122 bool isConstructor() const { return true; } 123 124 void accept(PlanIterVisitor& v) const; 125 126 void openImpl(PlanState& planState, uint32_t& offset); 127 128 bool nextImpl(store::Item_t& result, PlanState& planState) const; 129 }; 130 131 132 /********************************************************************************* 133 134 *********************************************************************************/ 135 class JSONDirectObjectIterator : public NaryBaseIterator<JSONDirectObjectIterator, 136 PlanIteratorState> 137 { 138 protected: 139 std::vector<bool> theCopyInputs; 140 141 public: 142 SERIALIZABLE_CLASS(JSONDirectObjectIterator); 143 144 SERIALIZABLE_CLASS_CONSTRUCTOR2T(JSONDirectObjectIterator, 145 NaryBaseIterator<JSONDirectObjectIterator, PlanIteratorState>); 146 147 void serialize(::zorba::serialization::Archiver& ar); 148 149 public: 150 JSONDirectObjectIterator( 151 static_context* sctx, 152 const QueryLoc& loc, 153 std::vector<PlanIter_t>& names, 154 std::vector<PlanIter_t>& values, 155 bool copyInput); 156 isConstructor()157 bool isConstructor() const { return true; } 158 159 void accept(PlanIterVisitor& v) const; 160 161 bool nextImpl(store::Item_t& result, PlanState& planState) const; 162 }; 163 164 165 } 166 167 #endif // ZORBA_WITH_JSON 168 169 #endif 170