vector_item_sequence.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2006-2008 The FLWOR Foundation.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  * 
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 #ifndef ZORBA_VECTOR_ITEM_SEQUENCE_API_H
00017 #define ZORBA_VECTOR_ITEM_SEQUENCE_API_H
00018 
00019 #include <vector>
00020 
00021 #include <zorba/config.h>
00022 #include <zorba/api_shared_types.h>
00023 #include <zorba/item_sequence.h>
00024 #include <zorba/iterator.h>
00025 
00026 namespace zorba { 
00027 
00028   /** \brief This class is an implementation of the ItemSequence.
00029    *         Objects of this class return, on each next call, an
00030    *         Item of the vector that is passed to this object.
00031    *
00032    * See ItemSequence
00033    */
00034   class ZORBA_DLL_PUBLIC VectorItemSequence : public ItemSequence
00035   {
00036     class InternalIterator : public Iterator
00037     {
00038     private:
00039       VectorItemSequence   *theItemSequence;
00040       std::vector<Item>::iterator theIterator;
00041       std::vector<Item>::iterator theEnd;
00042       bool is_open;
00043     public:
00044       InternalIterator(VectorItemSequence *item_sequence);
00045 
00046       /** \brief Start iterating.
00047        *
00048        * This function needs to be called before calling next().
00049        * Initializes the iterator over the items vector.
00050        *
00051        */
00052       virtual void open();
00053       /** \brief Get the next Item of the vector of items from ItemSequence.
00054        *
00055        * @param aItem the next Item of the sequence if true is returned by the function.
00056        * @return true if the vector is not exhausted, false otherwise.
00057        * @throw ZorbaException if iterator is not open or an error occured.
00058        */
00059       virtual bool next(Item& aItem);
00060       /** \brief Close the iterator.
00061        *
00062        * You can call close and open to reset the iterator.
00063        *
00064        */
00065       virtual void close();
00066       /**
00067        * brief Check whether the iterator is open or not
00068        */
00069       virtual bool isOpen() const;
00070     };
00071     public:
00072       /** \brief Constructor
00073        * 
00074        * @param aSequence the vector containing the sequence of Items
00075        */
00076       VectorItemSequence(const std::vector<Item>& aSequence);
00077 
00078       /** \brief Destructor
00079        */
00080       virtual ~VectorItemSequence() { }
00081 
00082       /** \brief get the Iterator over the items vector
00083        * @return an iterator over the items
00084       */
00085       virtual Iterator_t  getIterator();
00086 
00087     protected:
00088       std::vector<Item> theSequence;
00089 
00090   }; /* class VectorItemSequence */
00091 
00092 } // namespace zorba
00093 #endif
00094 
00095 /* vim:set et sw=2 ts=2: */
blog comments powered by Disqus