Skip to content

Commit

Permalink
Initialize tableiterator in assignment like in constructor, cherry-pick
Browse files Browse the repository at this point in the history
  • Loading branch information
tammojan committed Dec 13, 2017
1 parent 9ccb009 commit 123770f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions tables/Tables/TableIter.cc
Expand Up @@ -103,6 +103,7 @@ TableIterator& TableIterator::operator= (const TableIterator& iter)
if (iter.tabIterPtr_p != 0) {
tabIterPtr_p = iter.tabIterPtr_p->clone();
subTable_p = iter.table();
next(); // Get first subtable, as in constructor
}
return *this;
}
Expand Down
26 changes: 26 additions & 0 deletions tables/Tables/test/tTableIter.cc
Expand Up @@ -200,6 +200,32 @@ void doiter3()
iter2 = iter1;
AlwaysAssertExit(iter2.table().nrow() == iter1.table().nrow());

// Test that copied new iterator gives the same number of rows
int iter1count = 0;
while(!iter1.pastEnd()) { iter1.next(); iter1count++; }
int iter2count = 0;
while(!iter2.pastEnd()) { iter2.next(); iter2count++; }
AlwaysAssertExit(iter1count == iter2count);
iter1.reset();
iter2.reset();

// Test that copied new iterator does not copy the state
iter1.next();
iter1.next(); // Advance iter1 by two, so state changes
iter1count = 0;
iter2 = iter1; // iter2 should be 'clean' and iterate 2 more than iter1
TableIterator iter3 = iter1;
iter3.copyState(iter1); // iter3 should iterate as much as iter1
while(!iter1.pastEnd()) { iter1.next(); iter1count++; }
iter2count = 0;
while(!iter2.pastEnd()) { iter2.next(); iter2count++; }
AlwaysAssertExit(iter2count == iter1count + 2);
int iter3count = 0;
while(!iter3.pastEnd()) { iter3.next(); iter3count++; }
AlwaysAssertExit(iter3count == iter1count);

iter1.reset();

Int nr = 0;
float l3 = -1;
while (!iter1.pastEnd()) {
Expand Down

0 comments on commit 123770f

Please sign in to comment.