Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-21 10:15:33

0001 // -*- C++ -*-
0002 ///////////////////////////////////////////////////////////////////////////////
0003 // File: circulator.h                                                        //
0004 // Description: header file for circulator (circulator class)                //
0005 // This file is part of the SISCone project.                                 //
0006 // For more details, see http://projects.hepforge.org/siscone                //
0007 //                                                                           //
0008 // Copyright (c) 2006 Gavin Salam and Gregory Soyez                          //
0009 //                                                                           //
0010 // This program is free software; you can redistribute it and/or modify      //
0011 // it under the terms of the GNU General Public License as published by      //
0012 // the Free Software Foundation; either version 2 of the License, or         //
0013 // (at your option) any later version.                                       //
0014 //                                                                           //
0015 // This program is distributed in the hope that it will be useful,           //
0016 // but WITHOUT ANY WARRANTY; without even the implied warranty of            //
0017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             //
0018 // GNU General Public License for more details.                              //
0019 //                                                                           //
0020 // You should have received a copy of the GNU General Public License         //
0021 // along with this program; if not, write to the Free Software               //
0022 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA //
0023 //                                                                           //
0024 // $Revision:: 103                                                          $//
0025 // $Date:: 2007-02-18 17:07:34 +0100 (Sun, 18 Feb 2007)                     $//
0026 ///////////////////////////////////////////////////////////////////////////////
0027 
0028 #ifndef __CIRCULATOR_H__
0029 #define __CIRCULATOR_H__
0030 
0031 namespace siscone{
0032 
0033 /// \class circulator
0034 /// a circulator that is foreseen to take as template member either a
0035 /// pointer or an iterator;
0036 template<class T> class circulator { 
0037 
0038 public:
0039   /// ctor with iniitalisation from iterators
0040   ///  \param here   the current position
0041   ///  \param begin  the first position
0042   ///  \param end    the last position
0043   inline circulator(T here, T begin, T end) : m_here(here), m_begin(begin), m_end(end) {}
0044 
0045   /// copy ctor
0046   ///  \param other  the circulator to copy
0047   inline circulator(const circulator<T> & other) : m_here(other.m_here), m_begin(other.m_begin), m_end(other.m_end) {}
0048 
0049   /// set just the position without resetting the begin and end elements
0050   ///   \param other   the circulator to grab position from
0051   void set_position(const circulator<T> & other) {m_here = other.m_here;}
0052 
0053   /// set just the position without resetting the begin and end elements
0054   ///   \param pointer   the iterator to use as the new position
0055   void set_position(T pointer) {m_here = pointer;}
0056 
0057   /// get the current object
0058   T operator()() {return m_here;}
0059 
0060   /// position incrementation
0061   inline circulator<T> & operator++() { 
0062     ++m_here; 
0063     if (m_here == m_end) m_here = m_begin;
0064     return *this;
0065   }
0066 
0067   /// position decrementation
0068   inline circulator<T> & operator--() { 
0069     if (m_here == m_begin) m_here = m_end;
0070     --m_here; 
0071     return *this;
0072   }
0073   
0074   /// check if the current elements are the same
0075   /// NB: for efficiency, this checks only the here element
0076   ///  \param  other   the circulator to compare to the current one
0077   bool operator==(const circulator & other) const {return m_here == other.m_here;}
0078 
0079   /// check if the current elements are different
0080   /// NB: for efficiency, this checks only the here element
0081   ///  \param  other   the circulator to compare to the current one
0082   bool operator!=(const circulator & other) const {return m_here != other.m_here;}
0083 
0084 private:
0085   T  m_here, m_begin, m_end;   ///< the current, beginning and ending iterators/pointers
0086 };
0087 
0088 }
0089 
0090 #endif // __CIRCULATOR_H__