[6ab5981] | 1 | /* emacs edit mode for this file is -*- C++ -*- */ |
---|
[684544] | 2 | |
---|
| 3 | #ifndef INCL_LIST_H |
---|
| 4 | #define INCL_LIST_H |
---|
| 5 | |
---|
[e4fe2b] | 6 | // #include <factory/factoryconf.h> |
---|
[8c0163] | 7 | |
---|
[175e355] | 8 | #ifndef NOSTREAMIO |
---|
[1dc616] | 9 | #ifdef HAVE_IOSTREAM |
---|
| 10 | #include <iostream> |
---|
[181148] | 11 | #define OSTREAM std::ostream |
---|
[1dc616] | 12 | #elif defined(HAVE_IOSTREAM_H) |
---|
[684544] | 13 | #include <iostream.h> |
---|
[181148] | 14 | #define OSTREAM ostream |
---|
[1dc616] | 15 | #endif |
---|
[175e355] | 16 | #endif /* NOSTREAMIO */ |
---|
[684544] | 17 | |
---|
[31a2be7] | 18 | template <class T> |
---|
| 19 | class ListIterator; |
---|
| 20 | |
---|
| 21 | template <class T> |
---|
| 22 | class List; |
---|
[684544] | 23 | |
---|
[22347b6] | 24 | #ifndef NOSTREAMIO |
---|
| 25 | template <class T> |
---|
[181148] | 26 | OSTREAM& operator<< ( OSTREAM &, const List<T> &); |
---|
[22347b6] | 27 | #endif |
---|
| 28 | |
---|
[684544] | 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(); |
---|
[175e355] | 45 | #ifndef NOSTREAMIO |
---|
[181148] | 46 | void print ( OSTREAM& ); |
---|
[175e355] | 47 | #endif /* NOSTREAMIO */ |
---|
[684544] | 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& ) ); |
---|
[175e355] | 76 | #ifndef NOSTREAMIO |
---|
[181148] | 77 | void print ( OSTREAM & ) const; |
---|
| 78 | friend OSTREAM& operator<< <T>( OSTREAM & os, const List<T> & l ); |
---|
[175e355] | 79 | #endif /* NOSTREAMIO */ |
---|
[684544] | 80 | friend class ListIterator<T>; |
---|
| 81 | }; |
---|
| 82 | |
---|
[175e355] | 83 | #ifndef NOSTREAMIO |
---|
[684544] | 84 | template <class T> |
---|
[181148] | 85 | OSTREAM& operator<< ( OSTREAM & os, const List<T> & l ); |
---|
[175e355] | 86 | #endif /* NOSTREAMIO */ |
---|
[684544] | 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 | |
---|
[c48e80] | 125 | template <class T> |
---|
| 126 | bool find (const List<T>&, const T& t); |
---|
| 127 | |
---|
[6ab5981] | 128 | #endif /* ! INCL_LIST_H */ |
---|