Mentions légales du service

Skip to content
Snippets Groups Projects
Commit ce4b73a0 authored by berenger-bramas's avatar berenger-bramas
Browse files

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
Branches
No related tags found
No related merge requests found
...@@ -134,8 +134,8 @@ public: ...@@ -134,8 +134,8 @@ public:
*/ */
Object pop(){ Object pop(){
--this->size; --this->size;
Node* newNode = this->root; Node*const FRestrict newNode = this->root;
this->root = this->root->next; this->root = this->root->next;
Object value = newNode->target; Object value = newNode->target;
delete newNode; delete newNode;
...@@ -167,21 +167,22 @@ public: ...@@ -167,21 +167,22 @@ public:
*/ */
class BasicIterator { class BasicIterator {
private: private:
Node* iter; //< current node on the list Node** iter; //< current node on the list
public: public:
/** /**
* Constructor needs the target list * Constructor needs the target list
* @param the list to iterate on * @param the list to iterate on
*/ */
BasicIterator(FList& list) : iter(list.root){ BasicIterator(FList& list) : iter(&list.root) {
} }
/** To gotoNext on the list */ /** To gotoNext on the list */
void gotoNext(){ void gotoNext(){
if(this->iter){ if( hasNotFinished() ){
this->iter = this->iter->next; // TODO bug! printf("%s %p to %p\n",((*iter) != 0?"Not null":"Null"), *iter, &((*iter)->next));
if(this->iter) Prefetch_Write(this->iter->next); iter = &((*iter)->next);
if( (*iter)->next ) Prefetch_Write( (*iter)->next->next);
} }
} }
...@@ -190,7 +191,7 @@ public: ...@@ -190,7 +191,7 @@ public:
* current iterator must be valide (hasNotFinished()) to use this function * current iterator must be valide (hasNotFinished()) to use this function
*/ */
Object& data(){ Object& data(){
return this->iter->target; return (*iter)->target;
} }
/** /**
...@@ -198,7 +199,7 @@ public: ...@@ -198,7 +199,7 @@ public:
* current iterator must be valide (hasNotFinished()) to use this function * current iterator must be valide (hasNotFinished()) to use this function
*/ */
const Object& data() const{ const Object& data() const{
return this->iter->target; return (*iter)->target;
} }
/** /**
...@@ -206,7 +207,17 @@ public: ...@@ -206,7 +207,17 @@ public:
* @return true if the current iterator can gotoNext and access to value, else false * @return true if the current iterator can gotoNext and access to value, else false
*/ */
bool hasNotFinished() const{ 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> { ...@@ -72,7 +72,7 @@ class TestList : public FUTester<TestList> {
void TestIter(){ void TestIter(){
FList<TestObject> list; FList<TestObject> list;
{ {
FList<TestObject>::BasicIterator iter(list); FList<TestObject>::ConstBasicIterator iter(list);
assert(!iter.hasNotFinished()); assert(!iter.hasNotFinished());
} }
{ {
...@@ -80,11 +80,15 @@ class TestList : public FUTester<TestList> { ...@@ -80,11 +80,15 @@ class TestList : public FUTester<TestList> {
list.push(TestObject()); list.push(TestObject());
list.push(TestObject()); list.push(TestObject());
FList<TestObject>::BasicIterator iter(list); FList<TestObject>::ConstBasicIterator iter(list);
assert(iter.hasNotFinished()); assert(iter.hasNotFinished());
int counter = 0; int counter = 0;
while(iter.hasNotFinished()){ iter.gotoNext(); ++counter; } while(iter.hasNotFinished()){
iter.gotoNext();
++counter;
}
assert(!iter.hasNotFinished()); assert(!iter.hasNotFinished());
assert(counter == list.getSize()); assert(counter == list.getSize());
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment