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_SINGLETON_ITEM_SEQUENCE_API_H 00017 #define ZORBA_SINGLETON_ITEM_SEQUENCE_API_H 00018 00019 #include <zorba/config.h> 00020 #include <zorba/item_sequence.h> 00021 #include <zorba/iterator.h> 00022 #include <zorba/item.h> 00023 00024 namespace zorba { 00025 00026 /** \brief A sequence that contains only one item. 00027 * 00028 * This class is an implementation of the ItemSequence. Objects of this class 00029 * are backed by an iterator that returns on the first next call, the Item 00030 * that is passed to this class' constructor. 00031 * 00032 * See ItemSequence 00033 */ 00034 class ZORBA_DLL_PUBLIC SingletonItemSequence : public ItemSequence 00035 { 00036 class InternalIterator : public Iterator 00037 { 00038 private: 00039 SingletonItemSequence *theItemSequence; 00040 bool is_open; 00041 bool theDone; 00042 public: 00043 InternalIterator(SingletonItemSequence *item_sequence); 00044 00045 /** \brief Start iterating. 00046 * 00047 * This function needs to be called before calling next(). 00048 * 00049 */ 00050 virtual void open(); 00051 /** \brief Get the one Item. 00052 * 00053 * @param aItem the Item if true is returned by the function. 00054 * @return true if the sequence is not exhausted, false otherwise. 00055 * @throw ZorbaException if iterator is not open or an error occured. 00056 */ 00057 virtual bool next(Item& aItem); 00058 /** \brief Close the iterator. 00059 * 00060 * You can call close and open to reset the iterator. 00061 * 00062 */ 00063 virtual void close(); 00064 /** 00065 * brief Check whether the iterator is open or not 00066 */ 00067 virtual bool isOpen() const; 00068 }; 00069 public: 00070 /** \brief Constructor 00071 * 00072 * @param aItem the single item in this sequence 00073 */ 00074 SingletonItemSequence(const Item& aItem); 00075 00076 /** \brief Destructor 00077 */ 00078 virtual ~SingletonItemSequence() { } 00079 00080 /** \brief get the Iterator over the single item 00081 * @return an iterator over the one item 00082 */ 00083 virtual Iterator_t getIterator(); 00084 00085 protected: 00086 00087 Item theItem; 00088 00089 }; /* class SingletonItemSequence */ 00090 00091 } // namespace zorba 00092 00093 #endif /* ZORBA_SINGLETON_ITEM_SEQUENCE_API_H */ 00094 /* vim:set et sw=2 ts=2: */