summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lout/container.cc17
-rw-r--r--lout/container.hh14
-rw-r--r--test/containers.cc14
3 files changed, 41 insertions, 4 deletions
diff --git a/lout/container.cc b/lout/container.cc
index deeede57..6a55fc2c 100644
--- a/lout/container.cc
+++ b/lout/container.cc
@@ -193,13 +193,22 @@ void Vector::sort()
qsort(array, numElements, sizeof(Object*), misc::Comparable::compareFun);
}
+Object *Vector::VectorIterator::getNext()
+{
+ if (index < vector->numElements - 1)
+ index++;
+
+ return index < vector->numElements ? vector->array[index] : NULL;
+}
+
+bool Vector::VectorIterator::hasNext()
+{
+ return index < vector->numElements - 1;
+}
-/**
- * \bug Not implemented.
- */
Collection0::AbstractIterator* Vector::createIterator()
{
- return NULL;
+ return new VectorIterator(this);
}
// ------------
diff --git a/lout/container.hh b/lout/container.hh
index f1008e82..10139211 100644
--- a/lout/container.hh
+++ b/lout/container.hh
@@ -102,11 +102,25 @@ public:
*/
class Vector: public Collection
{
+ friend class VectorIterator;
+
private:
object::Object **array;
int numAlloc, numElements;
bool ownerOfObjects;
+ class VectorIterator: public AbstractIterator
+ {
+ private:
+ Vector *vector;
+ int index;
+
+ public:
+ VectorIterator(Vector *vector) { this->vector = vector; index = -1; }
+ bool hasNext();
+ Object *getNext();
+ };
+
protected:
AbstractIterator* createIterator();
diff --git a/test/containers.cc b/test/containers.cc
index 661f68d6..059125ac 100644
--- a/test/containers.cc
+++ b/test/containers.cc
@@ -36,10 +36,24 @@ void testHashTable ()
puts (h.toString());
}
+void testVector ()
+{
+ puts ("--- testVector ---");
+
+ Vector<String> v (true, 1);
+
+ v.put (new String ("one"));
+ v.put (new String ("two"));
+ v.put (new String ("three"));
+
+ puts (v.toString());
+}
+
int main (int argc, char *argv[])
{
testHashSet ();
testHashTable ();
+ testVector ();
return 0;
}