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/LICENSE2.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_COLLECTIONS_COLLECTIONS_IMPL_H 18 #define ZORBA_RUNTIME_COLLECTIONS_COLLECTIONS_IMPL_H 19 20 #include "common/shared_types.h" 21 22 #include "runtime/base/unarybase.h" 23 #include "runtime/collections/collections_base.h" 24 25 namespace zorba{ 26 27 /******************************************************************************* 28 Iterator to optimize a fn:count(collection) expression 29 30 theCollectionType: 31 ------------------ 32 Whether the Collection is a W3C or Zorba Collection and if it's dynamic or 33 static collection module. 34 ********************************************************************************/ 35 class CountCollectionIterator : public NaryBaseIterator<CountCollectionIterator, 36 PlanIteratorState> 37 { 38 public: 39 enum CollectionType 40 { 41 W3C = 0, 42 ZORBASTATIC = 1, 43 ZORBADYNAMIC = 2 44 }; 45 46 protected: 47 CollectionType theCollectionType; 48 49 public: 50 SERIALIZABLE_CLASS(CountCollectionIterator); 51 52 SERIALIZABLE_CLASS_CONSTRUCTOR2T(CountCollectionIterator, 53 NaryBaseIterator<CountCollectionIterator, PlanIteratorState>); 54 55 void serialize(::zorba::serialization::Archiver& ar); 56 57 public: 58 CountCollectionIterator( 59 static_context* sctx, 60 const QueryLoc& loc, 61 std::vector<PlanIter_t>& children, 62 CollectionType collectionType); 63 64 ~CountCollectionIterator(); 65 isZorbaCollection()66 bool isZorbaCollection() const { return W3C != theCollectionType; } 67 isDynamic()68 bool isDynamic() const { return ZORBADYNAMIC == theCollectionType; } 69 70 void accept(PlanIterVisitor& v) const; 71 72 bool nextImpl(store::Item_t& result, PlanState& aPlanState) const; 73 74 protected: 75 store::Collection_t getZorbaCollection(PlanState& planState) const; 76 77 store::Collection_t getW3CCollection(PlanState& planState) const; 78 }; 79 80 } //namespace zorba 81 #endif /* ZORBA_RUNTIME_COLLECTIONS_COLLECTIONS_IMPL_H */ 82 /* vim:set et sw=2 ts=2: */ 83 84