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