]> git.donarmstrong.com Git - lilypond.git/blob - flower/associter.hh
release: 0.0.5
[lilypond.git] / flower / associter.hh
1 /*
2   associter.hh -- part of flowerlib
3
4   (c) 1996 Han-Wen Nienhuys
5 */
6
7 #ifndef ASSOCITER_HH
8 #define ASSOCITER_HH
9
10 #include "assoc.hh"
11
12 /// an iterator for the #Assoc# class
13 template<class K, class V>
14 struct Assoc_iter {
15     int i;
16     Assoc<K,V> &assoc_;
17     
18     Assoc_iter(Assoc<K,V> &a) :
19         assoc_(a)
20     {   
21         i= next(0);
22     }
23     int next(int j) {
24         while (j < assoc_.arr.sz() && assoc_.arr[j].free)
25             j++;
26         return j;
27     }
28     bool ok() const {
29         return i < assoc_.arr.sz();
30     }
31     void OK()const {
32         assert(!ok() || !assoc_.arr[i].free);
33     }
34     void operator++(int) { i++; i = next(i); }
35     K key() { return assoc_.arr[i].key; }
36     V &val() { return assoc_.arr[i].val; }    
37 };
38 /*
39   Iterator
40  */
41
42 #endif