Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members  

Cslice_iter.h

Go to the documentation of this file.
00001 #ifndef ATLFAST_CSLICEITER_H
00002 #define ATLFAST_CSLICEITER_H
00003 #include <valarray>
00004 #include <cstddef>
00005 //=================================================
00006 //
00007 // Cslice_iter
00008 //
00009 //  from Sjoustrup's "the C++ programming language" ch 22.4.6
00010 //
00011 
00012 
00013 namespace Atlfast {
00014   using std::valarray;
00015   using std::slice;
00016 
00017   template<class T> class Cslice_iter{
00018     valarray<T>* v;
00019     slice s;
00020     size_t curr;   //index of current element
00021     T& ref(size_t i) const {return (*v)[s.start()+i*s.stride()];}
00022   public:
00023     Cslice_iter(valarray<T>* vv, slice ss): v(vv), s(ss), curr(0){}
00024     Cslice_iter end() const{
00025       Cslice_iter t = *this;
00026       t.curr=s.size();
00027       return t;
00028     }
00029     const Cslice_iter& operator++(){curr++; return *this;}
00030     Cslice_iter  operator++(int){Cslice_iter t=*this; curr++; return t;}
00031     
00032     const T& operator[] (size_t i) const  {return ref(i); }//C style subscript  
00033     const T& operator() (size_t i) const {return ref(i); }    //Fortran style subsc  
00034     const T& operator*()           const {return ref(curr); } //current element
00035 
00036     friend
00037       bool operator == (const Cslice_iter<T>& p, const Cslice_iter<T>& q){
00038       //      bool operator ==<> (const Cslice_iter<T>& p, const Cslice_iter<T>& q){
00039       return 
00040         p.curr==q.curr && 
00041         p.s.stride()==q.s.stride() && 
00042         p.s.start() == q.s.start();
00043     }
00044     
00045     friend 
00046       //      bool operator !=<> (const Cslice_iter& p, const Cslice_iter& q){
00047       bool operator != (const Cslice_iter& p, const Cslice_iter& q){
00048       return  (!p==q);
00049     }
00050  
00051     friend
00052       bool operator < (const Cslice_iter& p, const Cslice_iter& q){
00053       //      bool operator < <>(const Cslice_iter& p, const Cslice_iter& q){
00054       return 
00055         p.curr<q.curr && 
00056         p.s.stride() == q.s.stride() && 
00057         p.s.start()  == q.s.start();
00058     }
00059     
00060   };
00061 }//namespace
00062 #endif
00063 
00064 
00065 
00066 
00067 

Generated on Wed Jan 15 11:00:29 2003 for AtlfastUtils by doxygen1.3-rc1