vector_item_sequence.h
Go to the documentation of this file.
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 #ifndef ZORBA_VECTOR_ITEM_SEQUENCE_API_H
17 #define ZORBA_VECTOR_ITEM_SEQUENCE_API_H
18 
19 #include <vector>
20 
21 #include <zorba/config.h>
22 #include <zorba/api_shared_types.h>
23 #include <zorba/item_sequence.h>
24 #include <zorba/iterator.h>
25 
26 namespace zorba {
27 
28  /** \brief This class is an implementation of the ItemSequence.
29  * Objects of this class return, on each next call, an
30  * Item of the vector that is passed to this object.
31  *
32  * See ItemSequence
33  */
34  class ZORBA_DLL_PUBLIC VectorItemSequence : public ItemSequence
35  {
36  class InternalIterator : public Iterator
37  {
38  private:
39  VectorItemSequence *theItemSequence;
40  std::vector<Item>::iterator theIterator;
41  std::vector<Item>::iterator theEnd;
42  bool is_open;
43  public:
44  InternalIterator(VectorItemSequence *item_sequence);
45 
46  /** \brief Start iterating.
47  *
48  * This function needs to be called before calling next().
49  * Initializes the iterator over the items vector.
50  *
51  */
52  virtual void open();
53  /** \brief Get the next Item of the vector of items from ItemSequence.
54  *
55  * @param aItem the next Item of the sequence if true is returned by the function.
56  * @return true if the vector is not exhausted, false otherwise.
57  * @throw ZorbaException if iterator is not open or an error occured.
58  */
59  virtual bool next(Item& aItem);
60  /** \brief Close the iterator.
61  *
62  * You can call close and open to reset the iterator.
63  *
64  */
65  virtual void close();
66  /**
67  * brief Check whether the iterator is open or not
68  */
69  virtual bool isOpen() const;
70  };
71  public:
72  /** \brief Constructor
73  *
74  * @param aSequence the vector containing the sequence of Items
75  */
76  VectorItemSequence(const std::vector<Item>& aSequence);
77 
78  /** \brief Destructor
79  */
80  virtual ~VectorItemSequence() { }
81 
82  /** \brief get the Iterator over the items vector
83  * @return an iterator over the items
84  */
85  virtual Iterator_t getIterator();
86 
87  protected:
88  std::vector<Item> theSequence;
89 
90  }; /* class VectorItemSequence */
91 
92 } // namespace zorba
93 #endif
94 
95 /* vim:set et sw=2 ts=2: */