iterator.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_ITERATOR_API_H
17 #define ZORBA_ITERATOR_API_H
18 
19 #include <zorba/config.h>
20 #include <zorba/api_shared_types.h>
21 #include <zorba/item_sequence.h>
22 
23 namespace zorba {
24 
25 /** \brief Interface for an Iterator over an instance of the XML Data Model
26  * (i.e., a sequence of items).
27  *
28  * An iterator can be in one of the following two states: open or not-open.
29  * When in open state, only methods isOpen(), next() and close() may be called.
30  * When in not-open state, only isOpen and open() may be called. The open()
31  * method changes the state from non-open to open, and the close() method
32  * changes the state from open to not-open.
33  *
34  * Iterator is not a thread-safe class, i.e., none of its methods should ever
35  * be called by two or more threads in parallel.
36  *
37  * Note: This class is reference counted. When writing multi-threaded clients,
38  * it is the responibility of the client code to synchronize assignments to the
39  * SmartPtr holding this object.
40  */
41 class ZORBA_DLL_PUBLIC Iterator : virtual public SmartObject
42 {
43  public:
44  /** \brief Destructor
45  */
46  virtual ~Iterator() {}
47 
48  /** \brief Start iterating.
49  *
50  * This function needs to be called before calling next() or close().
51  * Its purpose is to create and initialize any resources that may be
52  * needed during the iteration. It should not be called again until
53  * after close() has been called.
54  *
55  * @throw ZorbaException if an error occurs, or the iterator is open already.
56  */
57  virtual void
58  open() = 0;
59 
60  /** \brief Get the next Item of the sequence.
61  *
62  * @param aItem the next Item of the result sequence, if true is returned
63  * by the function.
64  * @return false if all the items of the sequence have been returned already
65  * by previous invocations of next(); true otherwise.
66  * @throw ZorbaException if an error occurs, or the Iterator has not been opened.
67  */
68  virtual bool
69  next(Item& aItem) = 0;
70 
71  /** \brief Stop iterating.
72  *
73  * The purpose of this method is to release resources that were allocated
74  * during open. After calling close(), neither close() nor next() may be
75  * called again. However, the iterator may be re-opened (by calling open()).
76  *
77  * @throw ZorbaException if an error occurs, or the Iterator has not been opened.
78  */
79  virtual void
80  close() = 0;
81 
82  /**
83  * brief Check whether the iterator is open or not
84  */
85  virtual bool
86  isOpen() const = 0;
87 };
88 
89 
90 } /* namespace zorba */
91 #endif
92 /* vim:set et sw=2 ts=2: */