1 /* 2 Copyright (c) DataStax, Inc. 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 17 #ifndef DATASTAX_INTERNAL_VALUE_ITERATOR_HPP 18 #define DATASTAX_INTERNAL_VALUE_ITERATOR_HPP 19 20 #include "cassandra.h" 21 #include "iterator.hpp" 22 #include "serialization.hpp" 23 #include "value.hpp" 24 25 namespace datastax { namespace internal { namespace core { 26 27 class ValueIterator : public Iterator { 28 public: ValueIterator(CassIteratorType type,Decoder decoder)29 ValueIterator(CassIteratorType type, Decoder decoder) 30 : Iterator(type) 31 , decoder_(decoder) {} 32 value() const33 const Value* value() const { return &value_; } 34 35 protected: 36 Decoder decoder_; 37 Value value_; 38 }; 39 40 class CollectionIterator : public ValueIterator { 41 public: CollectionIterator(const Value * collection)42 CollectionIterator(const Value* collection) 43 : ValueIterator(CASS_ITERATOR_TYPE_COLLECTION, collection->decoder()) 44 , collection_(collection) 45 , index_(-1) 46 , count_(collection_->value_type() == CASS_VALUE_TYPE_MAP ? (2 * collection_->count()) 47 : collection->count()) {} 48 49 virtual bool next(); 50 51 private: 52 bool decode_value(); 53 54 private: 55 const Value* collection_; 56 57 int32_t index_; 58 const int32_t count_; 59 }; 60 61 class TupleIterator : public ValueIterator { 62 public: TupleIterator(const Value * tuple)63 TupleIterator(const Value* tuple) 64 : ValueIterator(CASS_ITERATOR_TYPE_TUPLE, tuple->decoder()) { 65 CollectionType::ConstPtr collection_type(tuple->data_type()); 66 next_ = collection_type->types().begin(); 67 end_ = collection_type->types().end(); 68 } 69 70 virtual bool next(); 71 72 private: 73 DataType::Vec::const_iterator next_; 74 DataType::Vec::const_iterator current_; 75 DataType::Vec::const_iterator end_; 76 }; 77 78 }}} // namespace datastax::internal::core 79 80 #endif 81