Electrowetting on dielectric
|
00001 #ifndef _GROUPED_ITERATORS_H_ 00002 #define _GROUPED_ITERATORS_H_ 00003 00004 #include <base/exceptions.h> 00005 00015 template<unsigned N, typename I> class IteratorGroup{ 00016 public: 00020 IteratorGroup(); 00024 IteratorGroup( const IteratorGroup<N,I> &g ); 00025 // Assignment operator. 00029 void operator=( const IteratorGroup<N,I> &g ); 00033 ~IteratorGroup(); 00034 // Referencing 00038 inline I & operator()( unsigned i ); 00042 inline const I & operator()( unsigned i ) const; 00043 protected: 00044 I tt[N]; 00045 }; 00046 00047 template<unsigned N, typename I> IteratorGroup<N,I>::IteratorGroup(){} 00048 00049 template<unsigned N, typename I> IteratorGroup<N,I>::IteratorGroup( const IteratorGroup<N,I> &g ){ 00050 for( unsigned i=0; i<N; ++i ) 00051 tt[i] = g.tt[i]; 00052 } 00053 00054 template<unsigned N, typename I> IteratorGroup<N,I>::~IteratorGroup(){} 00055 00056 template<unsigned N, typename I> inline I& IteratorGroup<N,I>::operator()( unsigned i ){ 00057 Assert( i<N, ExcIndexRange( 0, N, i ) ); 00058 return tt[i]; 00059 } 00060 00061 template<unsigned N, typename I> inline const I& IteratorGroup<N,I>::operator()( unsigned i ) const{ 00062 Assert( i<N, ExcIndexRange( 0, N, i ) ); 00063 return tt[i]; 00064 } 00065 00066 template<unsigned N, typename I> inline void IteratorGroup<N,I>::operator=( const IteratorGroup<N,I> &g ){ 00067 for( unsigned i=0; i<N; ++i ) 00068 tt[i] = g.tt[i]; 00069 } 00070 00074 template<unsigned N, typename I> inline bool operator<( const IteratorGroup<N,I> &a, 00075 const IteratorGroup<N,I> &b ){ 00076 return ( a(0) < b(0) ); 00077 } 00078 00082 template<unsigned N, typename I> inline std::size_t operator-( const IteratorGroup<N,I> &a, 00083 const IteratorGroup<N,I> &b ){ 00084 std::size_t dist = std::distance( b(0), a(0) ); 00085 Assert( dist >= 0, ExcInternalError() ); 00086 return dist; 00087 } 00088 00092 template<unsigned N, typename I> inline void advance( IteratorGroup<N,I> &t, const unsigned n ){ 00093 for( unsigned i=0; i<N; ++i ) 00094 std::advance ( t(i), n ); 00095 } 00096 00100 template<unsigned N, typename I> inline void advance_by_one( IteratorGroup<N,I> &t ){ 00101 for( unsigned i=0; i<N; ++i ) 00102 ++t(i); 00103 } 00104 00108 template<unsigned N, typename I> inline IteratorGroup<N,I> operator+( const IteratorGroup<N,I> &a, 00109 const std::size_t n ){ 00110 IteratorGroup<N,I> x( a ); 00111 advance( x, n ); 00112 return x; 00113 } 00114 00118 template<unsigned N, typename I> inline IteratorGroup<N,I> operator++( IteratorGroup<N,I> &a ){ 00119 advance_by_one( a ); 00120 return a; 00121 } 00122 00126 template<unsigned N, typename I> inline bool operator!=( const IteratorGroup<N,I> &a, 00127 const IteratorGroup<N,I> &b ){ 00128 return ( a(0) != b(0) ); 00129 } 00130 00131 #endif // GROUPED_ITERATORS_H_ 00132