00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef SC_LIST_H
00029 #define SC_LIST_H
00030
00031 namespace sc_core {
00032
00033
00034 class sc_plist_elem;
00035 template<class T> class sc_plist_iter;
00036
00037 typedef void (*sc_plist_map_fn)( void* data, void* arg );
00038
00039 class sc_plist_base {
00040 friend class sc_plist_base_iter;
00041
00042 public:
00043 sc_plist_base();
00044 ~sc_plist_base();
00045
00046 typedef sc_plist_elem* handle_t;
00047
00048 handle_t push_back(void* d);
00049 handle_t push_front(void* d);
00050 void* pop_back();
00051 void* pop_front();
00052 handle_t insert_before(handle_t h, void* d);
00053 handle_t insert_after(handle_t h, void* d);
00054 void* remove(handle_t h);
00055 void* get(handle_t h) const;
00056 void set(handle_t h, void* d);
00057 void mapcar( sc_plist_map_fn f, void* arg );
00058
00059 void* front() const;
00060 void* back() const;
00061
00062 void erase_all();
00063 bool empty() const { return (head == 0); }
00064 int size() const;
00065
00066 private:
00067 handle_t head;
00068 handle_t tail;
00069 };
00070
00071
00072 class sc_plist_base_iter {
00073 public:
00074 typedef sc_plist_elem* handle_t;
00075
00076 sc_plist_base_iter( sc_plist_base* l, bool from_tail = false );
00077 ~sc_plist_base_iter();
00078
00079 void reset( sc_plist_base* l, bool from_tail = false );
00080 bool empty() const;
00081 void operator++(int);
00082 void operator--(int);
00083 void* get() const;
00084 void set(void* d);
00085 void remove();
00086 void remove(int direction);
00087
00088 void set_handle(handle_t h);
00089 handle_t get_handle() const { return ptr; }
00090
00091 private:
00092 sc_plist_base* lst;
00093 sc_plist_elem* ptr;
00094 };
00095
00096
00097
00098 template< class T >
00099 class sc_plist : public sc_plist_base {
00100 friend class sc_plist_iter <T>;
00101
00102 public:
00103 typedef sc_plist_iter<T> iterator;
00104
00105 sc_plist() { }
00106 ~sc_plist() { }
00107
00108 handle_t push_back(T d) { return sc_plist_base::push_back((void*)d); }
00109 handle_t push_front(T d) { return sc_plist_base::push_front((void*)d); }
00110 T pop_back() { return (T) sc_plist_base::pop_back(); }
00111 T pop_front() { return (T) sc_plist_base::pop_front(); }
00112 handle_t insert_before(handle_t h, T d)
00113 {
00114 return sc_plist_base::insert_before(h, (void*) d);
00115 }
00116 handle_t insert_after(handle_t h, T d)
00117 {
00118 return sc_plist_base::insert_after(h, (void*) d);
00119 }
00120 T remove(handle_t h)
00121 {
00122 return (T)sc_plist_base::remove(h);
00123 }
00124 T get(handle_t h) const { return (T)sc_plist_base::get(h); }
00125 void set(handle_t h, T d) { sc_plist_base::set(h, (void*)d); }
00126
00127 T front() const { return (T)sc_plist_base::front(); }
00128 T back() const { return (T)sc_plist_base::back(); }
00129 };
00130
00131 template< class T >
00132 class sc_plist_iter : public sc_plist_base_iter {
00133 public:
00134 sc_plist_iter( sc_plist<T>* l, bool from_tail = false )
00135 : sc_plist_base_iter( l, from_tail )
00136 {
00137
00138 }
00139 sc_plist_iter( sc_plist<T>& l, bool from_tail = false )
00140 : sc_plist_base_iter( &l, from_tail )
00141 {
00142
00143 }
00144 ~sc_plist_iter()
00145 {
00146
00147 }
00148
00149 void reset( sc_plist<T>* l, bool from_tail = false )
00150 {
00151 sc_plist_base_iter::reset( l, from_tail );
00152 }
00153 void reset( sc_plist<T>& l, bool from_tail = false )
00154 {
00155 sc_plist_base_iter::reset( &l, from_tail );
00156 }
00157
00158 T operator*() const { return (T) sc_plist_base_iter::get(); }
00159 T get() const { return (T) sc_plist_base_iter::get(); }
00160 void set(T d) { sc_plist_base_iter::set((void*) d); }
00161 };
00162
00163 }
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186 #endif