/*
 $Id: triangtempl.c,v 1.1 1996/10/10 10:01:31 roitzsch Exp $
 (C)opyright 1996 by Konrad-Zuse-Center, Berlin
 All rights reserved.
 Part of the Kaskade distribution
*/

#include "triangtempl.h"

//-------------------------------------------------------------------------

template<class T>

DListIter<T>:: DListIter(const Stack<DList<T>*> &stackPar, int reqLevelPar)

	: reqLevel(reqLevelPar), stack(stackPar)
{
    reset();
}
//-------------------------------------------------------------------------

template<class T> void DListIter<T>:: reset()
{
    elem = 0;

    if (reqLevel < 0) { level = stack.l;  high = stack.h;  }	// all levels
    else	      { level = reqLevel; high = reqLevel; }
}
//-------------------------------------------------------------------------

template<class T>  T* DListIter<T>:: all()
{
    if (elem != 0)					// iterate rest of list
    {
	for (elem=elem->next; elem; elem=elem->next)  
	    if (!elem->refined()) return elem;	

	if (++level > high) return 0;		// end of stack reached
    }

    while (1)					  // iterate new lists on stack
    {
	for (elem=stack[level]->first; elem; elem=elem->next)
          if (!elem->refined()) return elem;

	if (++level > high) return 0;		// end of stack reached
    }
}
//-------------------------------------------------------------------------

template<class T>  T* DListIter<T>:: allOfHistory()
{
    if (elem != 0)					// iterate rest of list
    {
	for (elem=elem->next; elem; elem=elem->next)  return elem;	
	if (++level > high) return 0;		// end of stack reached
    }

    while (1)					  // iterate new lists on stack
    {
	for (elem=stack[level]->first; elem; elem=elem->next)  return elem;
	if (++level > high) return 0;		// end of stack reached
    }
}
