UPS: apcupsd clean sources
[tomato.git] / release / src / router / apcupsd / include / aiter.h
blob75167b64acbc7acbda431ba6c0798bfbe6c22f00
1 /*
2 * aiter.h
4 * Iterator functions for aXXX classes.
5 */
7 /*
8 * Copyright (C) 2008 Adam Kropelin
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.
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.
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., 59 Temple Place - Suite 330, Boston,
22 * MA 02111-1307, USA.
25 #ifndef __AITER_H
26 #define __AITER_H
28 template <class I, class T>
29 class const_iterator
31 public:
32 const_iterator() {}
33 const_iterator(const const_iterator &rhs) : _iter(rhs._iter) {}
34 const_iterator(const I &rhs) : _iter(rhs) {}
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; }
41 const T& operator*() const { return *_iter; }
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); }
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; }
53 private:
54 I _iter;
57 #endif // __AITER_H