source: trunk/SISCone/circulator.h@ 23

Last change on this file since 23 was 20, checked in by Pavel Demin, 16 years ago

add SISCone library

File size: 3.1 KB
Line 
1// -*- C++ -*-
2///////////////////////////////////////////////////////////////////////////////
3// File: circulator.h //
4// Description: header file for circulator (circulator class) //
5// This file is part of the SISCone project. //
6// For more details, see http://projects.hepforge.org/siscone //
7// //
8// Copyright (c) 2006 Gavin Salam and Gregory Soyez //
9// //
10// This program is free software; you can redistribute it and/or modify //
11// it under the terms of the GNU General Public License as published by //
12// the Free Software Foundation; either version 2 of the License, or //
13// (at your option) any later version. //
14// //
15// This program is distributed in the hope that it will be useful, //
16// but WITHOUT ANY WARRANTY; without even the implied warranty of //
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
18// GNU General Public License for more details. //
19// //
20// You should have received a copy of the GNU General Public License //
21// along with this program; if not, write to the Free Software //
22// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA //
23// //
24// $Revision: 1.1 $//
25// $Date: 2008-10-02 15:20:24 $//
26///////////////////////////////////////////////////////////////////////////////
27
28#ifndef __CIRCULATOR_H__
29#define __CIRCULATOR_H__
30
31namespace siscone{
32
33/// a circulator that is foreseen to take as template member either a
34/// pointer or an iterator;
35template<class T> class circulator {
36
37public:
38 inline circulator(T here, T begin, T end) : m_here(here), m_begin(begin), m_end(end) {}
39
40 inline circulator(const circulator<T> & other) : m_here(other.m_here), m_begin(other.m_begin), m_end(other.m_end) {}
41
42 /// set just the position without resetting the begin and end elements
43 void set_position(const circulator<T> & other) {m_here = other.m_here;}
44 void set_position(T pointer) {m_here = pointer;}
45
46 T operator()() {return m_here;}
47
48 inline circulator<T> & operator++() {
49 ++m_here;
50 if (m_here == m_end) m_here = m_begin;
51 return *this;
52 }
53
54 inline circulator<T> & operator--() {
55 if (m_here == m_begin) m_here = m_end;
56 --m_here;
57 return *this;
58 }
59
60 /// NB: for efficiency, this checks only the here element
61 bool operator==(const circulator & other) const {return m_here == other.m_here;}
62 /// NB: for efficiency, this checks only the here element
63 bool operator!=(const circulator & other) const {return m_here != other.m_here;}
64
65private:
66 T m_here, m_begin, m_end;
67};
68
69}
70
71#endif // __CIRCULATOR_H__
Note: See TracBrowser for help on using the repository browser.