1 | // emacs edit mode for this file is -*- C++ -*- |
---|
2 | // $Id: ftmpl_list.h,v 1.3 1997-04-30 13:08:27 schmidt Exp $ |
---|
3 | |
---|
4 | #ifndef INCL_LIST_H |
---|
5 | #define INCL_LIST_H |
---|
6 | |
---|
7 | /* |
---|
8 | $Log: not supported by cvs2svn $ |
---|
9 | Revision 1.2 1997/04/15 10:11:37 schmidt |
---|
10 | #include <config.h> added |
---|
11 | the header config.h will be included be makeheader |
---|
12 | |
---|
13 | Revision 1.1 1997/03/27 10:32:32 schmidt |
---|
14 | stream-io wrapped by NOSTREAMIO |
---|
15 | |
---|
16 | Revision 1.0 1996/05/17 11:06:32 stobbe |
---|
17 | Initial revision |
---|
18 | |
---|
19 | */ |
---|
20 | |
---|
21 | #include <factoryconf.h> |
---|
22 | |
---|
23 | #ifndef NOSTREAMIO |
---|
24 | #include <iostream.h> |
---|
25 | #endif /* NOSTREAMIO */ |
---|
26 | |
---|
27 | |
---|
28 | template <class T> |
---|
29 | class ListItem |
---|
30 | { |
---|
31 | private: |
---|
32 | ListItem * next; |
---|
33 | ListItem * prev; |
---|
34 | T * item; |
---|
35 | public: |
---|
36 | ListItem( const ListItem<T>& ); |
---|
37 | ListItem( const T&, ListItem<T>*, ListItem<T>* ); |
---|
38 | ListItem( T* , ListItem<T>* , ListItem<T>* ); |
---|
39 | ~ListItem(); |
---|
40 | ListItem<T>& operator= ( const ListItem<T>& ); |
---|
41 | ListItem<T>* getNext(); |
---|
42 | ListItem<T>* getPrev(); |
---|
43 | T& getItem(); |
---|
44 | #ifndef NOSTREAMIO |
---|
45 | void print ( ostream& ); |
---|
46 | #endif /* NOSTREAMIO */ |
---|
47 | friend class ListIterator<T>; |
---|
48 | friend class List<T>; |
---|
49 | }; |
---|
50 | |
---|
51 | template <class T> |
---|
52 | class List |
---|
53 | { |
---|
54 | private: |
---|
55 | ListItem<T> *first; |
---|
56 | ListItem<T> *last; |
---|
57 | int _length; |
---|
58 | public: |
---|
59 | List(); |
---|
60 | List( const List<T>& ); |
---|
61 | List( const T& ); |
---|
62 | ~List(); |
---|
63 | List<T>& operator= ( const List<T>& ); |
---|
64 | void insert ( const T& ); |
---|
65 | void insert ( const T&, int (*cmpf)( const T&, const T& ) ); |
---|
66 | void insert ( const T&, int (*cmpf)( const T&, const T& ), void (*insf)( T&, const T& ) ); |
---|
67 | void append ( const T& ); |
---|
68 | int isEmpty() const; |
---|
69 | int length() const; |
---|
70 | T getFirst() const; |
---|
71 | void removeFirst(); |
---|
72 | T getLast() const; |
---|
73 | void removeLast(); |
---|
74 | void sort ( int (*) ( const T&, const T& ) ); |
---|
75 | #ifndef NOSTREAMIO |
---|
76 | void print ( ostream & ) const; |
---|
77 | #endif /* NOSTREAMIO */ |
---|
78 | friend class ListIterator<T>; |
---|
79 | }; |
---|
80 | |
---|
81 | #ifndef NOSTREAMIO |
---|
82 | template <class T> |
---|
83 | ostream& operator<<( ostream & os, const List<T> & l ); |
---|
84 | #endif /* NOSTREAMIO */ |
---|
85 | |
---|
86 | template <class T> |
---|
87 | class ListIterator { |
---|
88 | private: |
---|
89 | List<T> *theList; |
---|
90 | ListItem<T> *current; |
---|
91 | public: |
---|
92 | ListIterator(); |
---|
93 | ListIterator( const ListIterator<T>& ); |
---|
94 | ListIterator( const List<T>& ); |
---|
95 | ~ListIterator(); |
---|
96 | ListIterator<T>& operator = ( const ListIterator<T>& ); |
---|
97 | ListIterator<T>& operator = ( const List<T>& ); |
---|
98 | T& getItem() const; |
---|
99 | int hasItem(); |
---|
100 | void operator++(); |
---|
101 | void operator--(); |
---|
102 | void operator++( int ); |
---|
103 | void operator--( int ); |
---|
104 | void firstItem(); |
---|
105 | void lastItem(); |
---|
106 | void insert( const T& ); |
---|
107 | void append( const T& ); |
---|
108 | void remove( int moveright ); |
---|
109 | }; |
---|
110 | |
---|
111 | template <class T> |
---|
112 | List<T> Union ( const List<T>&, const List<T>& ); |
---|
113 | |
---|
114 | template <class T> |
---|
115 | List<T> Difference ( const List<T>&, const List<T>& ); |
---|
116 | |
---|
117 | template <class T> |
---|
118 | List<T> Union ( const List<T>&, const List<T>&, int (*cmpf)( const T&, const T& ), void (*insf)( T&, const T& ) ); |
---|
119 | |
---|
120 | template <class T> |
---|
121 | T prod ( const List<T>& ); |
---|
122 | |
---|
123 | #endif /* INCL_LIST_H */ |
---|