1 /*
2  * aiter.h
3  *
4  * Iterator functions for aXXX classes.
5  */
6 
7 /*
8  * Copyright (C) 2008 Adam Kropelin
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of version 2 of the GNU General
12  * Public License as published by the Free Software Foundation.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public
20  * License along with this program; if not, write to the Free
21  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22  * MA 02110-1335, USA.
23  */
24 
25 #ifndef __AITER_H
26 #define __AITER_H
27 
28 template <class I, class T>
29 class const_iterator
30 {
31 public:
const_iterator()32    const_iterator() {}
const_iterator(const const_iterator & rhs)33    const_iterator(const const_iterator &rhs) : _iter(rhs._iter) {}
const_iterator(const I & rhs)34    const_iterator(const I &rhs)              : _iter(rhs)       {}
35 
36    const_iterator &operator++() { ++_iter; return *this; }
37    const_iterator operator++(int) { const_iterator tmp(_iter); ++_iter; return tmp; }
38    const_iterator &operator--() { --_iter; return *this; }
39    const_iterator operator--(int) { const_iterator tmp(_iter); --_iter; return tmp; }
40 
41    const T& operator*() const { return *_iter; }
42 
43    bool operator==(const const_iterator &rhs) const { return _iter == rhs._iter; }
44    bool operator!=(const const_iterator &rhs) const { return !(*this == rhs); }
45    bool operator==(const I &rhs) const { return _iter == rhs; }
46    bool operator!=(const I &rhs) const { return !(*this == rhs); }
47 
48    const_iterator &operator=(const const_iterator &rhs)
49       { if (&rhs != this) _iter = rhs._iter; return *this; }
50    const_iterator &operator=(const I &rhs)
51       { if (&rhs != &_iter) _iter = rhs; return *this; }
52 
53 private:
54    I _iter;
55 };
56 
57 #endif // __AITER_H
58