1 | /* emacs edit mode for this file is -*- C++ -*- */ |
---|
2 | |
---|
3 | #ifndef INCL_LIST_H |
---|
4 | #define INCL_LIST_H |
---|
5 | |
---|
6 | // #include <factory/factoryconf.h> |
---|
7 | |
---|
8 | #ifndef NOSTREAMIO |
---|
9 | #ifdef HAVE_IOSTREAM |
---|
10 | #include <iostream> |
---|
11 | #define OSTREAM std::ostream |
---|
12 | #elif defined(HAVE_IOSTREAM_H) |
---|
13 | #include <iostream.h> |
---|
14 | #define OSTREAM ostream |
---|
15 | #endif |
---|
16 | #endif /* NOSTREAMIO */ |
---|
17 | |
---|
18 | template <class T> |
---|
19 | class ListIterator; |
---|
20 | |
---|
21 | template <class T> |
---|
22 | class List; |
---|
23 | |
---|
24 | #ifndef NOSTREAMIO |
---|
25 | template <class T> |
---|
26 | OSTREAM& operator<< ( OSTREAM &, const List<T> &); |
---|
27 | #endif |
---|
28 | |
---|
29 | template <class T> |
---|
30 | class ListItem |
---|
31 | { |
---|
32 | private: |
---|
33 | ListItem * next; |
---|
34 | ListItem * prev; |
---|
35 | T * item; |
---|
36 | public: |
---|
37 | ListItem( const ListItem<T>& ); |
---|
38 | ListItem( const T&, ListItem<T>*, ListItem<T>* ); |
---|
39 | ListItem( T* , ListItem<T>* , ListItem<T>* ); |
---|
40 | ~ListItem(); |
---|
41 | ListItem<T>& operator= ( const ListItem<T>& ); |
---|
42 | ListItem<T>* getNext(); |
---|
43 | ListItem<T>* getPrev(); |
---|
44 | T& getItem(); |
---|
45 | #ifndef NOSTREAMIO |
---|
46 | void print ( OSTREAM& ); |
---|
47 | #endif /* NOSTREAMIO */ |
---|
48 | friend class ListIterator<T>; |
---|
49 | friend class List<T>; |
---|
50 | }; |
---|
51 | |
---|
52 | template <class T> |
---|
53 | class List |
---|
54 | { |
---|
55 | private: |
---|
56 | ListItem<T> *first; |
---|
57 | ListItem<T> *last; |
---|
58 | int _length; |
---|
59 | public: |
---|
60 | List(); |
---|
61 | List( const List<T>& ); |
---|
62 | List( const T& ); |
---|
63 | ~List(); |
---|
64 | List<T>& operator= ( const List<T>& ); |
---|
65 | void insert ( const T& ); |
---|
66 | void insert ( const T&, int (*cmpf)( const T&, const T& ) ); |
---|
67 | void insert ( const T&, int (*cmpf)( const T&, const T& ), void (*insf)( T&, const T& ) ); |
---|
68 | void append ( const T& ); |
---|
69 | int isEmpty() const; |
---|
70 | int length() const; |
---|
71 | T getFirst() const; |
---|
72 | void removeFirst(); |
---|
73 | T getLast() const; |
---|
74 | void removeLast(); |
---|
75 | void sort ( int (*) ( const T&, const T& ) ); |
---|
76 | #ifndef NOSTREAMIO |
---|
77 | void print ( OSTREAM & ) const; |
---|
78 | friend OSTREAM& operator<< <T>( OSTREAM & os, const List<T> & l ); |
---|
79 | #endif /* NOSTREAMIO */ |
---|
80 | friend class ListIterator<T>; |
---|
81 | }; |
---|
82 | |
---|
83 | #ifndef NOSTREAMIO |
---|
84 | template <class T> |
---|
85 | OSTREAM& operator<< ( OSTREAM & os, const List<T> & l ); |
---|
86 | #endif /* NOSTREAMIO */ |
---|
87 | |
---|
88 | template <class T> |
---|
89 | class ListIterator { |
---|
90 | private: |
---|
91 | List<T> *theList; |
---|
92 | ListItem<T> *current; |
---|
93 | public: |
---|
94 | ListIterator(); |
---|
95 | ListIterator( const ListIterator<T>& ); |
---|
96 | ListIterator( const List<T>& ); |
---|
97 | ~ListIterator(); |
---|
98 | ListIterator<T>& operator = ( const ListIterator<T>& ); |
---|
99 | ListIterator<T>& operator = ( const List<T>& ); |
---|
100 | T& getItem() const; |
---|
101 | int hasItem(); |
---|
102 | void operator++(); |
---|
103 | void operator--(); |
---|
104 | void operator++( int ); |
---|
105 | void operator--( int ); |
---|
106 | void firstItem(); |
---|
107 | void lastItem(); |
---|
108 | void insert( const T& ); |
---|
109 | void append( const T& ); |
---|
110 | void remove( int moveright ); |
---|
111 | }; |
---|
112 | |
---|
113 | template <class T> |
---|
114 | List<T> Union ( const List<T>&, const List<T>& ); |
---|
115 | |
---|
116 | template <class T> |
---|
117 | List<T> Difference ( const List<T>&, const List<T>& ); |
---|
118 | |
---|
119 | template <class T> |
---|
120 | List<T> Union ( const List<T>&, const List<T>&, int (*cmpf)( const T&, const T& ), void (*insf)( T&, const T& ) ); |
---|
121 | |
---|
122 | template <class T> |
---|
123 | T prod ( const List<T>& ); |
---|
124 | |
---|
125 | template <class T> |
---|
126 | bool find (const List<T>&, const T& t); |
---|
127 | |
---|
128 | #endif /* ! INCL_LIST_H */ |
---|