Anaphe Home Page Reference Documentation

Main Page     Namespaces     Classes     Source Code    

PIterators.h

Go to the documentation of this file.
00001 #ifndef _PITERATORS_H_
00002 #define _PITERATORS_H_
00003 
00004 #include "HTL/PHistograms.h"
00005 
00010 template <class T> class HistoIterator {
00011 public:
00013   typedef HistoIterator<T>    const_iterator;
00015   typedef const HepRef(T)     const_reference;
00016 public:
00018   HistoIterator (HepRef(ooContObj) cH) : atEnd(0) ,current_(0) {
00019     histo_itr.scan(cH);
00020   }
00022   HistoIterator (HepRef(ooDBObj) dH) : atEnd(0) ,current_(0) {
00023     histo_itr.scan(dH);
00024   }
00026   // initializes current_, since the Objy iterator cannot be duplicated
00027   HistoIterator (const const_iterator &oth) {
00028     atEnd = oth.atEnd;
00029     current_ = histo_itr;
00030   }
00031 
00033   const_iterator  operator++() {
00034     if (!atEnd)
00035       if (histo_itr.next() != oocTrue) {
00036         atEnd = 1;
00037       }
00038     return *this;
00039   }
00041   const_iterator  operator++(int) {
00042     const_iterator tmp = *this;
00043     ++(*this);
00044     return tmp;
00045   }
00047   const_reference operator*() const {
00048     // If it's a copy of the iterator, current_ freezes the Objy iterator state
00049     if (!atEnd) {
00050       if (current_ != 0)
00051         return current_;
00052       else // if it's the real iterator, current_ is zero!
00053         return histo_itr;
00054     }
00055     else
00056       return 0;
00057   }
00059   operator int () const {
00060     return (!atEnd);
00061   }
00062 
00063 private:
00064   ooItr(T)  histo_itr;
00065   int atEnd;  // End of iteration over the container
00066   HepRef(T) current_;
00067 };
00068 
00070 typedef HistoIterator<PHisto1D> Histo1DItr;
00072 typedef HistoIterator<PHisto1DVar> Histo1DVarItr;
00074 typedef HistoIterator<PHisto2D> Histo2DItr;
00076 typedef HistoIterator<PHisto2DVar> Histo2DVarItr;
00078 typedef HistoIterator<PProfileHisto> ProfileHistoItr;
00079 
00080 #endif //_PITERATORS_H_


Anaphe documentation generated by Doxygen (www.doxygen.org)