]> git.donarmstrong.com Git - lilypond.git/commitdiff
flower-1.0.5
authorfred <fred>
Tue, 5 Nov 1996 16:55:42 +0000 (16:55 +0000)
committerfred <fred>
Tue, 5 Nov 1996 16:55:42 +0000 (16:55 +0000)
flower/associter.hh [new file with mode: 0644]

diff --git a/flower/associter.hh b/flower/associter.hh
new file mode 100644 (file)
index 0000000..6103f22
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+  associter.hh -- part of flowerlib
+
+  (c) 1996 Han-Wen Nienhuys
+*/
+
+#ifndef ASSOCITER_HH
+#define ASSOCITER_HH
+
+#include "assoc.hh"
+
+/// an iterator for the #Assoc# class
+template<class K, class V>
+struct Assoc_iter {
+    int i;
+    Assoc<K,V> &assoc_;
+    
+    Assoc_iter(Assoc<K,V> &a) :
+       assoc_(a)
+    {  
+       i= next(0);
+    }
+    int next(int j) {
+       while (j < assoc_.arr.sz() && assoc_.arr[j].free)
+           j++;
+       return j;
+    }
+    bool ok() const {
+       return i < assoc_.arr.sz();
+    }
+    void OK()const {
+       assert(!ok() || !assoc_.arr[i].free);
+    }
+    void operator++(int) { i++; i = next(i); }
+    K key() { return assoc_.arr[i].key; }
+    V &val() { return assoc_.arr[i].val; }    
+};
+/*
+  Iterator
+ */
+
+#endif