rasdaman API
iterator.hh
Go to the documentation of this file.
1 /*
2 * This file is part of rasdaman community.
3 *
4 * Rasdaman community is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * Rasdaman community is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with rasdaman community. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
18 rasdaman GmbH.
19 *
20 * For more information please see <http://www.rasdaman.org>
21 * or contact Peter Baumann via <baumann@rasdaman.com>.
22 /
33 #ifndef _D_ITERATOR_
34 #define _D_ITERATOR_
35 
36 #include "raslib/error.hh"
37 
38 #ifdef __VISUALC__
39 template <class T> class r_Collection;
40 #else
41 #include "rasodmg/collection.hh"
42 #endif
43 
44 //@ManMemo: Module: {\bf rasodmg}
45 
46 
47 
48 /*@Doc:
49 
50  The template class \Ref{r_Iterator} defines the generic
51  behavior for iteration. All iterators use a consistent protocol
52  for sequentially returning each element from the collection over
53  which the iteration is defined.
54  When an iterator is constructed, it is either initialized with
55  another iterator or is set to null. When an iterator is constructed
56  via the {\tt create_iterator()} method defined in \Ref{r_Collection},
57  the iterator is initailized to point to the first element, if there
58  is one.
59 */
60 
64 template <class T>
65 class r_Iterator
66 {
67 public:
69  r_Iterator();
71  r_Iterator( const r_Iterator<T>& iter );
73  r_Iterator( r_Collection<T>& source, int removed_objects=0 );
80  ~r_Iterator();
82 
84  r_Iterator<T>& operator=( const r_Iterator<T>& iter );
87  int is_equal( const r_Iterator<T>& iter ) const;
88 
93 
95  void reset( int removed_objects=0 );
102  inline int not_done() const;
105  void advance();
106 
108  T operator*() throw( r_Error );
110  T get_element() const throw( r_Error );
111 
113  int next( T& element );
114 
116  void replace_element( const T& element );
117 
118 private:
120  int ndone;
122  r_Collection<T>* collection;
124  typename r_Collection<T>::CNode* ptr;
125 
126 };
127 
128 #include "iterator.icc"
129 
130 #ifdef EARLY_TEMPLATE
131 #ifdef __EXECUTABLE__
132 #ifdef __VISUALC__
133 #include "iterator.cpp"
134 #else
135 #include "iterator.cc"
136 #endif
137 #endif
138 #endif
139 
140 #endif
r_Iterator()
default constructor
void replace_element(const T &element)
replaces the actual element (can only be used with r_List)
Definition: collection.hh:40
Definition: error.hh:88
int not_done() const
returns 1 if there are more elements to be visited in the iteration and 0 if iteration is complete ...
T get_element() const
gets the actual element
int next(T &element)
gets the actual element, advances one element, and returns whether iteration is complete or not ...
void advance()
advances one element
T operator*()
the dereference operator gets the actual element
Definition: collection.hh:57
r_Iterator< T > & operator++()
prefix incrementor
r_Iterator< T > & operator=(const r_Iterator< T > &iter)
assignment operator
int is_equal(const r_Iterator< T > &iter) const
comparisons: equal if they point to the same element in the same collection, not equal if they point ...
void reset(int removed_objects=0)
re-initialize the iterator to the start of iteration for the same collection
~r_Iterator()
destructor