summaryrefslogtreecommitdiff
path: root/flower/list.hh
blob: a45252b8c3fb9d6020e479168cd1c69ed4beecfe (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
// list.hh

#ifndef __LIST_HH
#define __LIST_HH

class ostream;
template<class T> class Cursor;
template<class T> class Link;

/// all purpose list
template<class T>
class List
{
 public:
     /// construct empty list                
    List(); 

    /// construct list from first item.  
    List( const T& thing );
    
    virtual ~List();
	
    Cursor<T> bottom();

    int size() const;
    Cursor<T> top();
    void OK() const; 
 protected:
    friend class Cursor<T>;
    friend class Link<T>;
    
    /// add after after_me
    void add( const T& thing, Cursor<T> after_me );

    /// put thing before #before_me#
    void insert( const T& thing, Cursor<T> before_me );
    virtual void remove( Cursor<T> me );
    /**
      Remove link pointed to by me.

      POST
      none; WARNING: do not use #me#.
     */
    int size_;
    Link<T>* top_;
    Link<T>* bottom_;
};
/**
  a doubly linked list; 
  List can be seen as all items written down on paper,
  from top to bottom

  class Cursor is used to extend List

   items are always stored as copies in List, but:
   #List<String># :  copies of #String# stored 
   #List<String*># : copies of #String*# stored! 
   (do not use, use \Ref{PointerList}#<String*># instead.)
 
   {\bf note:} 
   retrieving "invalid" cursors, i.e. 
   #top()/bottom()# from empty list, #find()# without success,
    results in a nonvalid Cursor ( #!ok()# )


    INVARIANTEN!
*/


/// Use for list of pointers, e.g. PointerList<AbstractType*>.
template<class T>
class PointerList : public List<T>
{
 public:
    PointerList();
    PointerList( const T& thing );

    ///
    virtual ~PointerList();
    /**
      This function deletes deletes the allocated pointers of all links. 
      #\Ref{~List}# is used to delete the links themselves.
      */ 

 protected:
    virtual void remove( Cursor<T> me );
};

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

// instantiate a template:  explicit instantiation.
#define L_instantiate(a)  template class List<a>; template class Cursor<a>; \
  template class Link<a>
#define PL_instantiate(a) L_instantiate(a *); template class PointerList<a*>

#endif // __LIST_HH //