Back to index

CListIterator.h

 
//----------------------------------------------------------------------------- 
//  $Header: /tmp_mnt/asis/offline/ceres/cool/project/RCS/CListIterator.h,v 2.1 1996/10/04 08:42:54 voigt Exp $ 
// 
//  COOL Program Library   
//  Copyright (C) CERES collaboration, 1996 
// 
//  Declaration of template class CListIterator. 
// 
//----------------------------------------------------------------------------- 
#ifndef CLISTITERATOR_H 
#define CLISTITERATOR_H 
 
#include "CList.h" 
 
template <class T> class CListIterator { 
public: 
  CListIterator(CList<T>&); 
  virtual ~CListIterator(); 
 
  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: 
  CList<T>&	list;  
  size_t	index;    
}; 
 
 
template <class T> inline void CListIterator<T>::reset() 
{ 
   index =  ~(size_t) 0; 
} 
 
template <class T> inline CListIterator<T>::CListIterator(CList<T>& lis) : list(lis) 
{ 
   reset(); 
} 
 
template <class T> inline CListIterator<T>::~CListIterator() { /* nop */ } 
 
template <class T> inline CBoolean CListIterator<T>::operator++() 
{ 
   index++; 
   return (index < list.length()); 
} 
 
template <class T> inline CBoolean CListIterator<T>::operator+=(size_t n) 
{ 
   index += n; 
   return (index < list.length());    
} 
 
template <class T> inline T* CListIterator<T>::operator()() 
{ 
   index++; 
   if (index < list.length()) 
      return list(index); 
   else 
      return 0; 
} 
 
template <class T> inline T* CListIterator<T>::key() const 
{ 
   if (index < list.length()) 
      return list(index); 
   else 
      return 0; 
} 
 
template <class T> inline size_t CListIterator<T>::pos() const 
{ 
   return index; 
} 
 
#endif /* CLISTITERATOR_H */ 

Back to index