]> git.donarmstrong.com Git - lilypond.git/blob - flower/include/assoc-iter.hh
release: 0.1.11
[lilypond.git] / flower / include / assoc-iter.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     /// we don't want to be bothered by const correctness
18     Assoc_iter (const Assoc<K,V> &a) :
19         assoc_((Assoc<K,V> &)a)
20     {   
21         i= next (0);
22     }
23     int next (int j) {
24         while (j < assoc_.arr.size() && assoc_.arr[j].free)
25             j++;
26         return j;
27     }
28     bool ok() const {
29         return i < assoc_.arr.size();
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 #endif