head     1.4;
branch   ;
access   ;
symbols  ;
locks    ; strict;
comment  @// @;


1.4
date     92.08.14.15.48.01;  author thoth;  state Exp;
branches ;
next     1.3;

1.3
date     92.07.26.16.27.30;  author thoth;  state Exp;
branches ;
next     1.2;

1.2
date     92.07.21.11.20.57;  author thoth;  state Exp;
branches ;
next     1.1;

1.1
date     92.07.16.11.55.56;  author thoth;  state Exp;
branches ;
next     ;


desc
@implementation of the Boxy IntPointSet iterator object
@


1.4
log
@Iterators no longer use multiple inheritance.  They now use
IntPointSets (and the hashing that implies).
@
text
@// Emacs: -*- C++ -*-
static char rcsid[] = "$Id: BoxyIPSIter.cc,v 1.3 92/07/26 16:27:30 thoth Exp Locker: thoth $";

// 
// $Log:	BoxyIPSIter.cc,v $
// Revision 1.3  92/07/26  16:27:30  thoth
// Added some comments so people might be able to understand the code.
// 
// Revision 1.2  92/07/21  11:20:57  thoth
// used a Point for the current index
// 
// Revision 1.1  92/07/16  11:55:56  thoth
// Initial revision
// 
// 

#include "BoxyIPSIter.h"

#pragma implementation

BoxyIPSIter::BoxyIPSIter(const IntPointSet& x, BoxyIPS *b)
: BaseIPSIter(x),
  curr(b->start)
{
    box = b;
}

BoxyIPSIter::BoxyIPSIter(const BoxyIPSIter &x)
: BaseIPSIter(x.domain),
  curr(x.curr)
{
    box = x.box;
}

int BoxyIPSIter::next(IntPoint& ip)
{
    // This only happens if the previous call to next caused
    // curr to carry past its beginning (which means we ran out of points).
    if (this->curr[0] > box->end[0])
	return 0;

    // prepare the parameter for when we return;
    ip = this->curr;

    // increment curr to the lexicographically next point in the point set.
    unsigned i = box->dimen - 1;
    while (1) {
	if (++this->curr[i] > box->end[i] && i!=0) {
	    // We have overflowed the current "digit".
	    // Reset this digit and allow the loop to run around for
	    // the carry.
	    this->curr[i] = box->start[i];
	} else {
	    // Either there is no overflow or we have run out of digits to
	    // carry into.  We can provide the user with a point in any case.

	    break;

	    // on the next call to the next() method, an overflow will
	    // be detected.
	}
	// There was an overflow.  We will loop again using the next
	// higher significant digit.
	i--;
    }

    // Whatever happened during the increment operation doesn't matter here.
    // we knew we had a value to return when we realized curr was in bounds.
    // If the increment operation totally overflowed, then the next call
    // to next() will be unable to provide a point and the test at the
    // beginning will handle it appropriately.
    return 1;
}
@


1.3
log
@Added some comments so people might be able to understand the code.
@
text
@d2 1
a2 1
static char rcsid[] = "$Id: BoxyIPSIter.cc,v 1.2 92/07/21 11:20:57 thoth Exp Locker: thoth $";
d6 3
d21 3
a23 5
BoxyIPSIter::BoxyIPSIter(const BoxyIPS& bps)
: BoxyIPS(bps),
  // the following should work, but the compiler is hosed
  // curr(bps.start)
  curr(bps.min())
d25 1
d28 7
d39 1
a39 1
    if (this->curr[0] > this->end[0])
d46 1
a46 1
    unsigned i = this->dimen-1;
d48 1
a48 1
	if (++this->curr[i] > this->end[i] && i!=0) {
d52 1
a52 1
	    this->curr[i] = this->start[i];
@


1.2
log
@used a Point for the current index
@
text
@d2 1
a2 1
static char rcsid[] = "$Id: BoxyIPSIter.cc,v 1.1 92/07/16 11:55:56 thoth Exp Locker: thoth $";
d6 3
d28 2
d33 1
d36 1
d40 3
d45 3
d49 3
d53 2
d58 5
@


1.1
log
@Initial revision
@
text
@d2 1
a2 1
static char rcsid[] = "$Id$";
d5 3
a7 1
// $Log$
d9 1
d15 5
a19 1
BoxyIPSIter::BoxyIPSIter(const BoxyIPS& bps) : BoxyIPS(bps)
a20 4
    this->curr = new int[this->dimen];
    for (unsigned i=0; i < this->dimen; i++) {
	this->curr[i] = this->start[i];
    }
a24 1
    unsigned i = this->dimen-1;;
d28 1
a28 1
    ip = IntPoint(this->curr, this->dimen);
d30 1
a30 1
    i = this->dimen-1;
@
