]> git.donarmstrong.com Git - lilypond.git/blob - flower/include/acursor.hh
release: 1.0.1
[lilypond.git] / flower / include / acursor.hh
1 /*
2   acursor.hh -- declare ACursor, PACursor 
3
4   source file of the Flower Library
5
6   (c)  1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9
10 #ifndef ACURSOR_HH
11 #define ACURSOR_HH
12
13 template<class T>
14 class ACursor
15 {
16 protected:
17     int idx_;
18     Array<T> &arr_;
19 public:
20     ACursor (ACursor const& s) 
21         :arr_(s.arr_)
22     {
23         idx_ = s.idx_;
24     }
25     ACursor (Array<T> const &arr)
26         arr_((Array<T>&)arr)
27     {
28         idx_ =0;
29     }
30     T thing() const { 
31         return arr_[idx_];
32     }
33     T& thing() { return arr_[idx_]; }
34     T& operator++(int) {
35         T&t = thing();
36         idx_ ++;
37         return t;
38     }
39     bool ok() { return idx_ >=0 && idx_ < arr_.size (); }
40 };
41
42
43 template<class T>
44 class PACursor : public ACursor<T*>
45 {
46 public:
47     PACursor (Link_array<T> l)
48         : ACursor (l)
49     {
50     }
51     T* ptr() { return arr_[idx_]; }
52     T *operator->() {
53         return ptr();
54     }
55     
56 };
57
58 #endif // ACURSOR_HH