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