]> git.donarmstrong.com Git - lilypond.git/blob - flower/pcursor.hh
release: 0.0.20
[lilypond.git] / flower / pcursor.hh
1
2 /*
3   pcursor.hh -- part of flowerlib
4
5   (c) 1996 Han-Wen Nienhuys&Jan Nieuwenhuizen
6 */
7
8 #ifndef PCURSOR_HH
9 #define PCURSOR_HH
10
11
12 /// cursor to go with PointerList
13 template<class T>
14 struct PCursor : private Cursor<void *> {
15     friend class IPointerList<T>;
16
17     /// delete contents
18     void junk();
19 public:
20     Cursor<void*>::ok;
21     Cursor<void*>::del;
22     Cursor<void*>::backspace;
23     T get() {
24         T p = ptr();
25         Cursor<void*>::del();
26         return p;
27     }
28     T get_prev() {
29         (*this)--;
30         return get();
31     }
32     
33     PointerList<T> &list() { return (PointerList<T>&)Cursor<void*>::list(); }
34     PCursor<T> operator++(int) { return Cursor<void*>::operator++(0);}
35     PCursor<T> operator--(int) { return Cursor<void*>::operator--(0); }
36     PCursor<T> operator+=(int i) { return Cursor<void*>::operator+=(i);}
37     PCursor<T> operator-=(int i) { return Cursor<void*>::operator-=(i); }    
38     PCursor<T> operator -(int no) const { return Cursor<void*>::operator-(no);}
39     int operator -(PCursor<T> op) const { return Cursor<void*>::operator-(op);}
40     PCursor<T> operator +( int no) const {return Cursor<void*>::operator+(no);}    PCursor(const PointerList<T> & l) : Cursor<void*> (l) {}
41
42     PCursor( const Cursor<void*>& cursor ) : Cursor<void*>(cursor) { }
43     void* vptr() const { return  * ((Cursor<void*> &) *this); }
44
45     // should return T& ?
46     T ptr() const { return (T) vptr(); }
47     T operator ->() const { return  ptr(); }
48     operator T() { return ptr(); }
49     T operator *() { return ptr(); }
50     void add(const T& p ) { Cursor<void*>::add((void*) p); }
51     void insert(const T& p ) { Cursor<void*>::insert((void*) p);}    
52     static int compare(PCursor<T> a,PCursor<T>b) {
53         return Cursor<void*>::compare(a,b);
54     }
55 };
56 /**
57   don't create PointerList<void*>'s.
58   This cursor is just an interface class for Cursor. It takes care of the
59   appropriate type casts
60  */
61
62
63
64 #include "compare.hh"
65 template_instantiate_compare(PCursor<T>, PCursor<T>::compare, template<class T>);
66
67 #endif