Commit ce4b73a0 authored by berenger-bramas's avatar berenger-bramas

Improve the test of the list and add a "remove" method to iterator.

Please note that iterator basic is bugged.

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/scalfmm/scalfmm/trunk@260 2616d619-271b-44dc-8df4-d4a8f33a7222
parent 32c48e99
......@@ -134,8 +134,8 @@ public:
*/
Object pop(){
--this->size;
Node* newNode = this->root;
this->root = this->root->next;
Node*const FRestrict newNode = this->root;
this->root = this->root->next;
Object value = newNode->target;
delete newNode;
......@@ -167,21 +167,22 @@ public:
*/
class BasicIterator {
private:
Node* iter; //< current node on the list
Node** iter; //< current node on the list
public:
/**
* Constructor needs the target list
* @param the list to iterate on
*/
BasicIterator(FList& list) : iter(list.root){
BasicIterator(FList& list) : iter(&list.root) {
}
/** To gotoNext on the list */
void gotoNext(){
if(this->iter){
this->iter = this->iter->next;
if(this->iter) Prefetch_Write(this->iter->next);
if( hasNotFinished() ){
// TODO bug! printf("%s %p to %p\n",((*iter) != 0?"Not null":"Null"), *iter, &((*iter)->next));
iter = &((*iter)->next);
if( (*iter)->next ) Prefetch_Write( (*iter)->next->next);
}
}
......@@ -190,7 +191,7 @@ public:
* current iterator must be valide (hasNotFinished()) to use this function
*/
Object& data(){
return this->iter->target;
return (*iter)->target;
}
/**
......@@ -198,7 +199,7 @@ public:
* current iterator must be valide (hasNotFinished()) to use this function
*/
const Object& data() const{
return this->iter->target;
return (*iter)->target;
}
/**
......@@ -206,7 +207,17 @@ public:
* @return true if the current iterator can gotoNext and access to value, else false
*/
bool hasNotFinished() const{
return iter;
return (*iter) != 0;
}
/** Remove an element
*/
void remove() {
if( hasNotFinished() ){
Node* temp = (*iter)->next;
delete (*iter);
(*iter) = temp;
}
}
};
......
......@@ -72,7 +72,7 @@ class TestList : public FUTester<TestList> {
void TestIter(){
FList<TestObject> list;
{
FList<TestObject>::BasicIterator iter(list);
FList<TestObject>::ConstBasicIterator iter(list);
assert(!iter.hasNotFinished());
}
{
......@@ -80,11 +80,15 @@ class TestList : public FUTester<TestList> {
list.push(TestObject());
list.push(TestObject());
FList<TestObject>::BasicIterator iter(list);
FList<TestObject>::ConstBasicIterator iter(list);
assert(iter.hasNotFinished());
int counter = 0;
while(iter.hasNotFinished()){ iter.gotoNext(); ++counter; }
while(iter.hasNotFinished()){
iter.gotoNext();
++counter;
}
assert(!iter.hasNotFinished());
assert(counter == list.getSize());
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment