• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • Directories
  • File List
  • File Members

it_index.hpp

Go to the documentation of this file.
00001 /*
00002   CLAW - a C++ Library Absolutely Wonderful
00003 
00004   CLAW is a free library without any particular aim but being useful to 
00005   anyone.
00006 
00007   Copyright (C) 2005-2008 Julien Jorge
00008 
00009   This library is free software; you can redistribute it and/or
00010   modify it under the terms of the GNU Lesser General Public
00011   License as published by the Free Software Foundation; either
00012   version 2.1 of the License, or (at your option) any later version.
00013 
00014   This library is distributed in the hope that it will be useful,
00015   but WITHOUT ANY WARRANTY; without even the implied warranty of
00016   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017   Lesser General Public License for more details.
00018 
00019   You should have received a copy of the GNU Lesser General Public
00020   License along with this library; if not, write to the Free Software
00021   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00022 
00023   contact: julien_jorge@yahoo.fr
00024 */
00030 #ifndef __CLAW_IT_INDEX_HPP__
00031 #define __CLAW_IT_INDEX_HPP__
00032 
00033 #include <iostream>
00034 
00035 namespace claw
00036 {
00042   template<class T> class it_index
00043   {
00044   private:
00046     T   m_it;
00048     int m_index;
00049 
00050   public:
00052     it_index() 
00053       : m_it(), m_index()
00054     { }
00055 
00061     it_index(const T& it, int index=0) 
00062       : m_it(it), m_index(index)
00063     { }
00064 
00069     it_index( const it_index<T>& that ) 
00070       : m_it( that.m_it ), m_index( that.m_index )
00071     { }
00072 
00078     void set( const T& it, int index )
00079     {
00080       m_it = it;
00081       m_index = index;
00082     }
00083 
00084     bool operator<( const it_index<T>& that ) const
00085     { return m_index < that.m_index; }
00086 
00087     bool operator<( const T& it ) const { return m_it < it; }
00088     bool operator<( int index ) const { return m_index < index; }
00089   
00090     bool operator<=( const it_index<T>& that ) const
00091     { return (*this < that) || (*this == that); }
00092     bool operator<=( const T& it ) const { return m_it <= it; }
00093     bool operator<=( int index ) const { return m_index <= index; }
00094   
00095     bool operator>( const it_index<T>& that ) const
00096     { return m_index > that.m_index; }
00097     bool operator>( const T& it ) const { return m_it > it; }
00098     bool operator>( int index ) const { return m_index > index; }
00099         
00100     bool operator>=( const it_index<T>& that ) const
00101     { return (*this > that) || (*this == that); }
00102     bool operator>=( const T& it ) const { return m_it >= it; }
00103     bool operator>=( int index ) const { return m_index >= index; }
00104 
00105     bool operator==( const it_index<T>& that ) const
00106     { return (m_it == that.m_it) && (m_index == that.m_index); }
00107     bool operator==( const T& it ) const { return m_it == it; }
00108     bool operator==( int index ) const { return m_index==index; }
00109 
00110     bool operator!=( const it_index<T>& that ) const
00111     { return !(*this == *that); }
00112     bool operator!=( const T& it ) const { return m_it != it; }
00113     bool operator!=( int index ) const { return m_index!=index; }
00114 
00115     it_index<T> operator+( int index ) const
00116     { return it_index<T>(m_it + index, m_index + index); }
00117     it_index<T> operator-( int index ) const
00118     { return it_index<T>(m_it - index, m_index - index); }
00119     it_index<T> operator*( int index ) const
00120     { return it_index<T>(m_it + (index-1) * m_index, m_index * index); }
00121     it_index<T> operator/( int index ) const
00122     { return it_index<T>(m_it - (m_index - m_index/index), m_index / index); }
00123   
00124     typename T::value_type operator*() { return *m_it; }
00125 
00126     // Préincrément
00127     it_index<T>& operator++() 
00128     {
00129       ++m_it;
00130       ++m_index;
00131       return *this;
00132     }
00133 
00134     // Postincrément
00135     it_index<T> operator++(int) 
00136     {
00137       it_index<T> r(*this);
00138       ++(this);
00139       return r;
00140     }
00141 
00142     // Préincrément
00143     it_index<T>& operator--() 
00144     {
00145       --m_it;
00146       --m_index;
00147       return *this;
00148     }
00149 
00150     // Postincrément
00151     it_index<T> operator--(int) 
00152     {
00153       it_index<T> r(*this);
00154       --(this);
00155       return r;
00156     }
00157 
00158     it_index<T>& operator+=( int index ) 
00159     { 
00160       m_it += index;
00161       m_index += index;
00162       return *this;
00163     }
00164   
00165     it_index<T>& operator-=( int index ) 
00166     { 
00167       m_it -= index;
00168       m_index -= index;
00169       return *this;
00170     }
00171   
00172     it_index<T>& operator*=( int index ) 
00173     { 
00174       m_it += (index-1) * m_index;
00175       m_index *= index;
00176       return *this;
00177     }
00178   
00179     it_index<T>& operator/=( int index ) 
00180     { 
00181       m_it -= m_index - m_index/index;
00182       m_index /= index;
00183       return *this;
00184     }
00185   
00186     operator int() const { return m_index; }
00187     operator T() const { return m_it; }
00188   
00189   }; // it_index;
00190 
00191 } // namespace claw
00192 
00193 #endif // __CLAW_IT_INDEX_HPP__

Generated on Wed Sep 29 2010 for CLAW Library (a C++ Library Absolutely Wonderful) by  doxygen 1.7.1