Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
IndexedIterator.h
1 /*
2  * $Id$
3  * IndexedIterator class interface
4  *
5  * This file is part of OTAWA
6  * Copyright (c) 2007-08, IRIT UPS.
7  *
8  * OTAWA is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * OTAWA is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with OTAWA; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 #ifndef ELM_INDEXED_ITERATOR_H
23 #define ELM_INDEXED_ITERATOR_H
24 
25 #include <elm/PreIterator.h>
26 
27 namespace elm {
28 
29 // IndexedIterator class
30 template <class I, class T, class C>
31 class IndexedIterator: public PreIterator<I, const T&> {
33 public:
34 
35  inline IndexedIterator(void): c(0), i(0) { }
36  inline IndexedIterator(const C& collection): c(&collection), i(0) { }
37  inline IndexedIterator(const this_t& iter): c(iter.c), i(iter.i) { }
38  inline this_t& operator=(const this_t& iter) { c = iter.c; i = iter.i; return *this; }
39 
40  inline bool ended(void) const { return !c || i >= c->size(); }
41  inline const T& item(void) const { return (*c)[i]; }
42  inline void next(void) { i++; }
43 
44 private:
45  const C *c;
46  int i;
47 };
48 
49 } // elm
50 
51 #endif // ELM_INDEXED_ITERATOR_H
elm::iter
Definition: util_WAHVector.cpp:157
elm::IndexedIterator::next
void next(void)
Definition: IndexedIterator.h:42
elm::IndexedIterator::item
const T & item(void) const
Definition: IndexedIterator.h:41
elm::IndexedIterator::IndexedIterator
IndexedIterator(void)
Definition: IndexedIterator.h:35
elm::IndexedIterator::operator=
this_t & operator=(const this_t &iter)
Definition: IndexedIterator.h:38
elm
Definition: adapter.h:26
elm::IndexedIterator::ended
bool ended(void) const
Definition: IndexedIterator.h:40
elm::IndexedIterator::IndexedIterator
IndexedIterator(const C &collection)
Definition: IndexedIterator.h:36
elm::IndexedIterator::IndexedIterator
IndexedIterator(const this_t &iter)
Definition: IndexedIterator.h:37
elm::IndexedIterator
Definition: IndexedIterator.h:31
elm::PreIterator
Definition: iter.h:28