|
SISCone
2.0.5
|
00001 // -*- C++ -*- 00003 // File: circulator.h // 00004 // Description: header file for circulator (circulator class) // 00005 // This file is part of the SISCone project. // 00006 // For more details, see http://projects.hepforge.org/siscone // 00007 // // 00008 // Copyright (c) 2006 Gavin Salam and Gregory Soyez // 00009 // // 00010 // This program is free software; you can redistribute it and/or modify // 00011 // it under the terms of the GNU General Public License as published by // 00012 // the Free Software Foundation; either version 2 of the License, or // 00013 // (at your option) any later version. // 00014 // // 00015 // This program is distributed in the hope that it will be useful, // 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of // 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 00018 // GNU General Public License for more details. // 00019 // // 00020 // You should have received a copy of the GNU General Public License // 00021 // along with this program; if not, write to the Free Software // 00022 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA // 00023 // // 00024 // $Revision:: 103 $// 00025 // $Date:: 2007-02-18 17:07:34 +0100 (Sun, 18 Feb 2007) $// 00027 00028 #ifndef __CIRCULATOR_H__ 00029 #define __CIRCULATOR_H__ 00030 00031 namespace siscone{ 00032 00036 template<class T> class circulator { 00037 00038 public: 00043 inline circulator(T here, T begin, T end) : m_here(here), m_begin(begin), m_end(end) {} 00044 00047 inline circulator(const circulator<T> & other) : m_here(other.m_here), m_begin(other.m_begin), m_end(other.m_end) {} 00048 00051 void set_position(const circulator<T> & other) {m_here = other.m_here;} 00052 00055 void set_position(T pointer) {m_here = pointer;} 00056 00058 T operator()() {return m_here;} 00059 00061 inline circulator<T> & operator++() { 00062 ++m_here; 00063 if (m_here == m_end) m_here = m_begin; 00064 return *this; 00065 } 00066 00068 inline circulator<T> & operator--() { 00069 if (m_here == m_begin) m_here = m_end; 00070 --m_here; 00071 return *this; 00072 } 00073 00077 bool operator==(const circulator & other) const {return m_here == other.m_here;} 00078 00082 bool operator!=(const circulator & other) const {return m_here != other.m_here;} 00083 00084 private: 00085 T m_here, m_begin, m_end; 00086 }; 00087 00088 } 00089 00090 #endif // __CIRCULATOR_H__