Back to index

CSortedListIterator.h

 
//----------------------------------------------------------------------------- 
//  $Header: /tmp_mnt/asis/offline/ceres/cool/project/RCS/CSortedListIterator.h,v 1.1 1997/04/25 15:05:49 messer Exp $ 
// 
//  COOL Program Library   
//  Copyright (C) CERES collaboration, 1996 
// 
//  Declaration of template class CSortedListIterator. 
// 
//----------------------------------------------------------------------------- 
#ifndef CSORTEDLISTITERATOR_H 
#define CSORTEDLISTITERATOR_H 
 
#include "CSortedList.h" 
 
template <class T> class CSortedListIterator { 
public: 
  CSortedListIterator(CSortedList<T>&); 
  virtual ~CSortedListIterator(); 
 
  CBoolean	operator++();		// advance to next position  
  CBoolean	operator+=(size_t);	// advance n positions 
  T*		operator()();		// advance to next item and retuns pointer to it 
 
  T*		key() const;		// return pointer to object at current position 
  void		reset(); 
   
  size_t	pos() const;		// return current position (no STL equivalent) 
 
protected: 
  CSortedList<T>& list;  
  size_t	  index;    
}; 
 
 
template <class T> inline void CSortedListIterator<T>::reset() 
{ 
   index =  ~(size_t) 0; 
} 
 
template <class T> inline CSortedListIterator<T>::CSortedListIterator(CSortedList<T>& lis) : list(lis) 
{ 
   reset(); 
} 
 
template <class T> inline CSortedListIterator<T>::~CSortedListIterator() { /* nop */ } 
 
template <class T> inline CBoolean CSortedListIterator<T>::operator++() 
{ 
   index++; 
   return (index < list.length()); 
} 
 
template <class T> inline CBoolean CSortedListIterator<T>::operator+=(size_t n) 
{ 
   index += n; 
   return (index < list.length());    
} 
 
template <class T> inline T* CSortedListIterator<T>::operator()() 
{ 
   index++; 
   if (index < list.length()) 
      return list(index); 
   else 
      return 0; 
} 
 
template <class T> inline T* CSortedListIterator<T>::key() const 
{ 
   if (index < list.length()) 
      return list(index); 
   else 
      return 0; 
} 
 
template <class T> inline size_t CSortedListIterator<T>::pos() const 
{ 
   return index; 
} 
 
#ifdef RW_COMPILE_INSTANTIATE 
// does not yet exist: #include "CSortedListIterator.C" 
#endif 
 
 
#endif /* CSORTEDLISTITERATOR_H */ 

Back to index