singleton_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_SINGLETON_ITEM_SEQUENCE_API_H
17 #define ZORBA_SINGLETON_ITEM_SEQUENCE_API_H
18 
19 #include <zorba/config.h>
20 #include <zorba/item_sequence.h>
21 #include <zorba/iterator.h>
22 #include <zorba/item.h>
23 
24 namespace zorba {
25 
26  /** \brief A sequence that contains only one item.
27  *
28  * This class is an implementation of the ItemSequence. Objects of this class
29  * are backed by an iterator that returns on the first next call, the Item
30  * that is passed to this class' constructor.
31  *
32  * See ItemSequence
33  */
34  class ZORBA_DLL_PUBLIC SingletonItemSequence : public ItemSequence
35  {
36  class InternalIterator : public Iterator
37  {
38  private:
39  SingletonItemSequence *theItemSequence;
40  bool is_open;
41  bool theDone;
42  public:
43  InternalIterator(SingletonItemSequence *item_sequence);
44 
45  /** \brief Start iterating.
46  *
47  * This function needs to be called before calling next().
48  *
49  */
50  virtual void open();
51  /** \brief Get the one Item.
52  *
53  * @param aItem the Item if true is returned by the function.
54  * @return true if the sequence is not exhausted, false otherwise.
55  * @throw ZorbaException if iterator is not open or an error occured.
56  */
57  virtual bool next(Item& aItem);
58  /** \brief Close the iterator.
59  *
60  * You can call close and open to reset the iterator.
61  *
62  */
63  virtual void close();
64  /**
65  * brief Check whether the iterator is open or not
66  */
67  virtual bool isOpen() const;
68  };
69  public:
70  /** \brief Constructor
71  *
72  * @param aItem the single item in this sequence
73  */
74  SingletonItemSequence(const Item& aItem);
75 
76  /** \brief Destructor
77  */
78  virtual ~SingletonItemSequence() { }
79 
80  /** \brief get the Iterator over the single item
81  * @return an iterator over the one item
82  */
83  virtual Iterator_t getIterator();
84 
85  protected:
86 
88 
89  }; /* class SingletonItemSequence */
90 
91 } // namespace zorba
92 
93 #endif /* ZORBA_SINGLETON_ITEM_SEQUENCE_API_H */
94 /* vim:set et sw=2 ts=2: */
This interface represents an instance of the XQuery 1.0 and XPath 2.0 Data Model (XDM).
Definition: item_sequence.h:30
A sequence that contains only one item.
The Zorba Item interface.
Definition: item.h:60
Interface for an Iterator over an instance of the XML Data Model (i.e., a sequence of items)...
Definition: iterator.h:41
virtual ~SingletonItemSequence()
Destructor.