lilypond-0.0.35
[lilypond.git] / flower / associter.hh
blob34b88df22d005f302072a3bb2d470daecb44cd0c
1 /*
2 associter.hh -- part of flowerlib
4 (c) 1996 Han-Wen Nienhuys
5 */
7 #ifndef ASSOCITER_HH
8 #define ASSOCITER_HH
10 #include "assoc.hh"
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)
21 i= next(0);
23 int next(int j) {
24 while (j < assoc_.arr.size() && assoc_.arr[j].free)
25 j++;
26 return j;
28 bool ok() const {
29 return i < assoc_.arr.size();
31 void OK()const {
32 assert(!ok() || !assoc_.arr[i].free);
34 void operator++(int) { i++; i = next(i); }
35 K key() { return assoc_.arr[i].key; }
36 V &val() { return assoc_.arr[i].val; }
39 #endif