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