]> git.donarmstrong.com Git - lilypond.git/blob - flower/include/pcursor.hh
release: 0.0.68pre
[lilypond.git] / flower / include / pcursor.hh
1 /*
2   pcursor.hh -- part of flowerlib
3
4   (c) 1996 Han-Wen Nienhuys&Jan Nieuwenhuizen
5 */
6
7 #ifndef PCURSOR_HH
8 #define PCURSOR_HH
9
10 #include "plist.hh"
11 #include "cursor.hh"
12
13 /**  cursor to go with Link_list. 
14   don't create Link_list<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 class PCursor : private Cursor<void *> {
20     friend class Pointer_list<T>;
21
22     /// delete contents
23     void junk();
24 public:
25     Cursor<void*>::ok;
26     Cursor<void*>::del;
27     Cursor<void*>::backspace;
28     Cursor<void*>::next;
29     Cursor<void*>::previous;
30
31     T remove_p() {
32         T p = ptr();
33         Cursor<void*>::del();
34         return p;
35     }
36     T remove_prev_p() {
37         assert( ok() );
38         (*this)--;
39         return remove_p();
40     }
41     
42     Link_list<T> &list() { return (Link_list<T>&)Cursor<void*>::list(); }
43     PCursor<T> operator++(int) { return Cursor<void*>::operator++(0);}
44     PCursor<T> operator--(int) { return Cursor<void*>::operator--(0); }
45     PCursor<T> operator+=(int i) { return Cursor<void*>::operator+=(i);}
46     PCursor<T> operator-=(int i) { return Cursor<void*>::operator-=(i); }    
47     PCursor<T> operator -(int no) const { return Cursor<void*>::operator-(no);}
48     int operator -(PCursor<T> op) const { return Cursor<void*>::operator-(op);}
49     PCursor<T> operator +( int no) const {return Cursor<void*>::operator+(no);}    PCursor(const Link_list<T> & l) : Cursor<void*> (l) {}
50     PCursor() : Cursor<void*> () {}
51     PCursor( const Cursor<void*>& cursor ) : Cursor<void*>(cursor) { }
52     void* vptr() const { return *((Cursor<void*> &) *this); }
53
54     // should return T& ?
55     T ptr() const { return (T) vptr(); }
56     T operator ->() const { return  ptr(); }
57     operator T() { return ptr(); }
58     T operator *() { return ptr(); }
59     void add(T const & p ) { Cursor<void*>::add((void*) p); }
60     void insert(T const & p ) { Cursor<void*>::insert((void*) p);}    
61     static int compare(PCursor<T> a,PCursor<T>b) {
62         return Cursor<void*>::compare(a,b);
63     }
64 };
65
66
67
68 #include "compare.hh"
69 template_instantiate_compare(PCursor<T>, PCursor<T>::compare, template<class T>);
70
71 #endif