summaryrefslogtreecommitdiff
path: root/flower/cursor.hh
blob: 1c61b1a76cd8fa6880fdc813e2abdc164dd9b172 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// cursor.hh

#ifndef __CURSOR_HH
#define __CURSOR_HH

#include "link.hh"
template<class T> class List;

///
template<class T>
class Cursor 
{
 public:
    Cursor( const List<T>& list, Link<T>* pointer = 0 );
    /** this isn't true, actually, #list# surely isn't const, but I get
      tired of the warning messages.  */
    
    Cursor( const Cursor<T>& cursor );
    
    /// return current T
    T& operator *();		
    operator T() { return  *(*this); }
    Cursor<T> operator =( const Cursor<T>& c );

    /// make cursor with #no# items back
    Cursor<T> operator -( int no) const;

    /// make cursor with #no# items further
    Cursor<T> operator +( int no) const;
    int operator -(Cursor<T> op) const;
    Cursor<T> operator -=(int);
    Cursor<T> operator +=(int);
    
    /// return current and move one down
    Cursor<T> operator ++( int );
    
    /// return current and move one up
    Cursor<T> operator --( int ); 

    /// point to link?
    bool ok();                  

    /// ++ items left?
    bool forward();		

    /// -- items left?
    bool backward();

    /// put (copy) after me in List
    void add( const T& thing );
    /**
      analogously to editor. ok() interpreted as at end
      of line.

      PRE: !ok, POST: added to bottom()

      PRE: ok, POST: added after me

      cursor points to same object, cursor.next() is newly added
      object.
      */

    /// put (copy) before me in List
    void insert( const T& thing );
    /**
      analogously to editor. ok() interpreted as at begin of
      line.
      
      PRE: !ok, POST: add to top()

      PRE: ok, POST: add before me

      cursor points to same object, cursor.previous()
      is newly inserted object.
      */
    
    ///
    void backspace();

    /// 
    void del();
    
    /// access the list this came from
    const List<T>& list() const ;
    Link<T>* pointer();

private:
    List<T>& list_;
    Link<T>* pointer_;
};
/** 
  add and insert extend the list
  items are always stored as copies in List, but:
  List<String> :  copies of String stored 
  List<String*> : copies of String* stored!

    the operations add and insert actually delegate the work to List class.
 */






/*
  comparisons.
  */
#include "compare.hh"

template<class T>
inline  int cursor_compare(Cursor<T> a,Cursor<T>b)
{
    return b-a;
}

template_instantiate_compare(Cursor<T>, cursor_compare, template<class T>);

#include "pcursor.hh"
#include "list.hh"
#include "cursor.inl"

#endif // __CURSOR_HH //