diff gen/utils.h @ 1262:ec1d9dc1d32a

Fixed struct default initializers.
author Tomas Lindquist Olsen <tomas.l.olsen gmail com>
date Sat, 25 Apr 2009 18:26:54 +0200
parents 79758fd2f48a
children
line wrap: on
line diff
--- a/gen/utils.h	Wed Apr 22 14:49:49 2009 -0600
+++ b/gen/utils.h	Sat Apr 25 18:26:54 2009 +0200
@@ -7,35 +7,57 @@
 template<class C>
 struct ArrayIter
 {
-    Array& array;
+    Array* array;
     size_t index;
 
     ArrayIter(Array& arr, size_t idx = 0)
+    :   array(&arr), index(idx)
+    { }
+    ArrayIter(Array* arr, size_t idx = 0)
     :   array(arr), index(idx)
-    { }
+    { assert(arr && "null array"); }
+
+    ArrayIter<C>& operator=(const Array& arr)
+    {
+        array = &arr;
+        index = 0;
+        return *this;
+    }
+    ArrayIter<C>& operator=(const Array* arr)
+    {
+        assert(arr && "null array");
+        array = arr;
+        index = 0;
+        return *this;
+    }
 
     bool done()
     {
-        return index >= array.dim;
+        return index >= array->dim;
     }
     bool more()
     {
-        return index < array.dim;
+        return index < array->dim;
     }
 
-    C* get()
-    {
-        return static_cast<C*>(array.data[index]);
+    C* get() {
+        return static_cast<C*>(array->data[index]);
     }
-    C* operator->()
-    {
-        return static_cast<C*>(array.data[index]);
+    C* operator->() {
+        return get();
+    }
+    C* operator*() {
+        return get();
     }
 
     void next()
     {
         ++index;
     }
+
+    bool operator==(const ArrayIter<C>& other) {
+        return &array->data[index] == &other.array->data[other.index];
+    }
 };
 
 // some aliases