]> git.donarmstrong.com Git - lilypond.git/blobdiff - flower/pcursor.hh
release: 0.0.39-1
[lilypond.git] / flower / pcursor.hh
index eb0e8f15f951339c26555cb0467c77dd6e607814..ea360078d1a0c53fec53e6bad315a75bc2b6617b 100644 (file)
@@ -1,4 +1,3 @@
-
 /*
   pcursor.hh -- part of flowerlib
 
@@ -8,29 +7,61 @@
 #ifndef PCURSOR_HH
 #define PCURSOR_HH
 
+#include "plist.hh"
+#include "cursor.hh"
 
-/// cursor which feels like a pointer
+/**  cursor to go with PointerList. 
+  don't create PointerList<void*>'s.
+  This cursor is just an interface class for Cursor. It takes care of the
+  appropriate type casts
+ */
 template<class T>
-struct PCursor : public Cursor<T> {
+class PCursor : private Cursor<void *> {
+    friend class IPointerList<T>;
 
-    /// make cursor with #no# items back
-    PCursor<T> operator -( int no) const {
-       return PCursor<T> (Cursor<T>::operator-(no));
+    /// delete contents
+    void junk();
+public:
+    Cursor<void*>::ok;
+    Cursor<void*>::del;
+    Cursor<void*>::backspace;
+    T get_p() {
+       T p = ptr();
+       Cursor<void*>::del();
+       return p;
     }
-
-    /// make cursor with #no# items further
-    PCursor<T> operator +( int no) const {
-       return PCursor<T> (Cursor<T>::operator+(no));
+    T get_prev() {
+       (*this)--;
+       return get_p();
     }
-    PCursor(const List<T> & l) : Cursor<T> (l) {}
+    
+    PointerList<T> &list() { return (PointerList<T>&)Cursor<void*>::list(); }
+    PCursor<T> operator++(int) { return Cursor<void*>::operator++(0);}
+    PCursor<T> operator--(int) { return Cursor<void*>::operator--(0); }
+    PCursor<T> operator+=(int i) { return Cursor<void*>::operator+=(i);}
+    PCursor<T> operator-=(int i) { return Cursor<void*>::operator-=(i); }    
+    PCursor<T> operator -(int no) const { return Cursor<void*>::operator-(no);}
+    int operator -(PCursor<T> op) const { return Cursor<void*>::operator-(op);}
+    PCursor<T> operator +( int no) const {return Cursor<void*>::operator+(no);}    PCursor(const PointerList<T> & l) : Cursor<void*> (l) {}
 
-    PCursor( const Cursor<T>& cursor ) : Cursor<T>(cursor) { }
-    T operator ->() { return  *(*this); }
+    PCursor( const Cursor<void*>& cursor ) : Cursor<void*>(cursor) { }
+    void* vptr() const { return *((Cursor<void*> &) *this); }
 
+    // should return T& ?
+    T ptr() const { return (T) vptr(); }
+    T operator ->() const { return  ptr(); }
+    operator T() { return ptr(); }
+    T operator *() { return ptr(); }
+    void add(const T& p ) { Cursor<void*>::add((void*) p); }
+    void insert(const T& p ) { Cursor<void*>::insert((void*) p);}    
+    static int compare(PCursor<T> a,PCursor<T>b) {
+       return Cursor<void*>::compare(a,b);
+    }
 };
-/**
- I like  operator->(), so here it is.
 
- Cursor to go with pointer list.
- */
+
+
+#include "compare.hh"
+template_instantiate_compare(PCursor<T>, PCursor<T>::compare, template<class T>);
+
 #endif