00001 #ifndef __LISTT_HPP__
00002 #define __LISTT_HPP__
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
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #ifndef __cplusplus
00042 #error Must use C++ compiler
00043 #endif
00044
00045
00046
00047 #include <stdlib.h>
00048 #include <assert.h>
00049
00050 #include "arch.h"
00051 #include "tdef.h"
00052
00053
00054
00055 typedef VOID * Lix;
00056 typedef LONG LIINT;
00057
00058
00059
00060 #ifndef NDEBUG
00061 #define LIST_PTRVERIFY
00062 #endif
00063
00064
00065
00066 class _PListNode {
00067 public:
00068 _PListNode *b, *f;
00069 VOID *dp;
00070 _PListNode( VOID *data=NULL ) { dp=data; };
00071 };
00072
00073 class _PList {
00074 private:
00075 _PListNode *h;
00076 protected:
00077 virtual VOID * _newData( const VOID *data ) = 0;
00078 virtual VOID _deleteData( VOID *data ) = 0;
00079 private:
00080 #ifdef LIST_PTRVERIFY
00081 Lix __lix_safe(LIINT i, CHAR*func, BOOL allow0) const;
00082 #endif
00083 _PListNode *__newNode_d( const VOID *data=NULL );
00084 _PListNode *__newNode_p( VOID *data=NULL );
00085 virtual _PListNode *__newNode_d( const _PListNode *node );
00086 virtual _PListNode *__newNode_p( _PListNode *node );
00087 virtual VOID __deleteNode_d( _PListNode *p );
00088 VOID __deleteNode_p( _PListNode *p ) { delete p; }
00089 const _PListNode *__getNode( Lix p ) const { return (_PListNode*)p; }
00090 protected:
00091 VOID ** __itemptr(Lix p) { return &(((_PListNode*)p)->dp); }
00092
00093 private:
00094 Lix __prepend(_PListNode *node);
00095 Lix __append(_PListNode *node);
00096 Lix __insbefore(Lix p, _PListNode *node);
00097 Lix __insafter(Lix p, _PListNode *node);
00098 Lix __del(Lix p, INT dir);
00099 VOID __clear(BOOL cdata);
00100 protected:
00101 VOID _clear_p(VOID) { __clear(FALSE); }
00102 VOID _clear_d(VOID) { __clear(TRUE); }
00103 private:
00104 _PList(_PList&) {};
00105 public:
00106 _PList(VOID) { h=0; }
00107 virtual ~_PList() { clear(); }
00108 protected:
00109 virtual _PList& _create_d(const _PList& a);
00110 virtual _PList& _create_p(_PList& a);
00111
00112 public:
00113 virtual BOOL OK(VOID) const;
00114 BOOL owns(Lix p) const;
00115 LIINT index (Lix p) const;
00116 Lix lix(LIINT i) const;
00117 LIINT length(VOID) const;
00118 BOOL empty(VOID) const { return h == 0; }
00119 virtual VOID clear( VOID ) { _clear_d(); };
00120 VOID reverse(VOID);
00121
00122 protected:
00123 Lix _prepend_d(const VOID* item=NULL) {return __prepend(__newNode_d(item));}
00124 Lix _append_d(const VOID* item=NULL) {return __append(__newNode_d(item));}
00125 Lix _insbefore_d(Lix p, const VOID* item=NULL) {return __insbefore(p,__newNode_d(item));}
00126 Lix _insafter_d(Lix p, const VOID* item=NULL) {return __insafter(p,__newNode_d(item));}
00127
00128 Lix _prepend_p(VOID* item=NULL) {return __prepend(__newNode_p(item));}
00129 Lix _append_p(VOID *item=NULL) {return __append(__newNode_p(item));}
00130 Lix _insbefore_p(Lix p, VOID* item=NULL) {return __insbefore(p,__newNode_p(item));}
00131 Lix _insafter_p(Lix p, VOID* item=NULL) {return __insafter(p,__newNode_p(item));}
00132
00133 Lix _prepend_d(const _PList& a);
00134 Lix _append_d(const _PList& a);
00135 Lix _insbefore_d(Lix p, const _PList& a);
00136 Lix _insafter_d(Lix p, const _PList& a);
00137
00138 Lix _prepend_p(_PList& a);
00139 Lix _append_p(_PList& a);
00140 Lix _insbefore_p(Lix p, _PList& a);
00141 Lix _insafter_p(Lix p, _PList& a);
00142
00143
00144 Lix _prepend_mv(_PList& a, Lix ni=0, Lix nf=0 );
00145
00146 Lix _append_mv(_PList& a, Lix ni=0, Lix nf=0 );
00147
00148
00149 Lix _insbefore_mv(Lix p, _PList& a, Lix ni=0, Lix nf=0 );
00150 Lix _insafter_mv(Lix p, _PList& a, Lix ni=0, Lix nf=0 );
00151
00152 Lix _del(Lix p, BOOL cdata, INT dir=1);
00153 VOID _delprev(Lix p, BOOL cdata);
00154 VOID _delnext(Lix p, BOOL cdata);
00155 Lix _delfirst(BOOL cdata);
00156 Lix _dellast(BOOL cdata);
00157 public:
00158 Lix first(VOID) const { return Lix(h); }
00159 Lix last(VOID) const { return (h == 0) ? 0 : Lix(h->b); }
00160 #ifdef LIST_PTRVERIFY
00161 Lix next(Lix p) const;
00162 Lix prev(Lix p) const;
00163 #else
00164 Lix next(Lix p) const { if (p == 0 || p == h->b) return 0; return Lix(((_PListNode*)p)->f); }
00165 Lix prev(Lix p) const { if (p == 0 || p == h) return 0; return Lix(((_PListNode*)p)->b); }
00166 #endif
00167
00168 protected:
00169 #ifdef LIST_PTRVERIFY
00170 const VOID *_item(Lix p) const;
00171 const VOID *_item_first(VOID) const;
00172 const VOID *_item_last(VOID) const;
00173 #else
00174 const VOID *_item(Lix p) const { if (p == 0) return 0; return ((_PListNode*)p)->dp; }
00175 const VOID *_item_first(VOID) const { if (h == 0) return 0; return h->dp; }
00176 const VOID *_item_last(VOID) const { if (h == 0) return 0; return h->b->dp; }
00177 #endif
00178
00179 virtual VOID __exchange_p( _PListNode *n1, _PListNode *n2 );
00180 VOID _exchange_lp( Lix p1, Lix p2 );
00181 VOID _exchange_p( Lix p1, Lix p2 );
00182 VOID _sort( INT (*comparefunc) ( const VOID *item1, const VOID *item2 ), BOOL lpmove=FALSE);
00183 Lix _movebefore_lp(Lix who, Lix where);
00184 Lix _moveafter_lp(Lix who, Lix where);
00185
00186
00187
00188 Lix _insbefore_d(LIINT i, const VOID* item=NULL);
00189 Lix _insbefore_p(LIINT i, VOID* item=NULL);
00190 Lix _insbefore_d(LIINT i, const _PList& a);
00191 Lix _insbefore_p(LIINT i, _PList& a);
00192 Lix _insbefore_mv(LIINT i, _PList& a);
00193 Lix _insafter_d(LIINT i, const VOID* item=NULL);
00194 Lix _insafter_p(LIINT i, VOID* item=NULL);
00195 Lix _insafter_d(LIINT i, const _PList& a);
00196 Lix _insafter_p(LIINT i, _PList& a);
00197 Lix _insafter_mv(LIINT i, _PList& a);
00198 VOID _del(LIINT i, BOOL cdata);
00199 VOID _delprev(LIINT i, BOOL cdata);
00200 VOID _delnext(LIINT i, BOOL cdata);
00201 const VOID* _item(LIINT i) const;
00202 VOID _exchange_lp( LIINT i1, LIINT i2 );
00203 VOID _exchange_p( LIINT i1, LIINT i2 );
00204 Lix _movebefore_lp(LIINT who, LIINT where);
00205 Lix _moveafter_lp(LIINT who, LIINT where);
00206
00207 friend class _SetPList;
00208 friend class _KVPList;
00209 };
00210
00211
00212
00213 class _SetPList: public _PList {
00214 protected:
00215 virtual BOOL _sameData( const VOID *d1, const VOID *d2 ) const = 0;
00216 Lix __seek(const _PList&a, const VOID * x) const;
00217 private:
00218 _SetPList(const _SetPList&) {};
00219 public:
00220 _SetPList(VOID) {};
00221
00222 virtual BOOL OK(VOID) const;
00223 protected:
00224 _PList& _create_d(const _PList& a);
00225 _PList& _create_p(_PList& a);
00226 protected:
00227 Lix _add_d(const VOID* x);
00228 Lix _add_p(VOID* x);
00229 VOID _add_d(const _PList& a);
00230 VOID _add_p(_PList& a);
00231 VOID _add_mv(_PList& a, Lix ni, Lix nf, BOOL ovwrt, BOOL cdata );
00232
00233 Lix _seek(const VOID *x) const { return __seek(*this,x); }
00234 BOOL _contains(const VOID *x) const { return _seek(x)!=0; }
00235 BOOL _contains(const _PList&a) const;
00236 BOOL _equals(const _PList&a, BOOL allowrep=TRUE) const;
00237 BOOL _erase(const VOID* x, BOOL cdata);
00238 BOOL _erase(const _PList& a, BOOL cdata);
00239 VOID _keep(const _PList& a, BOOL cdata);
00240 };
00241
00242
00243
00244 class _KVPListNode : public _PListNode {
00245 public:
00246 VOID *vp;
00247 _KVPListNode( VOID *key=NULL, VOID *val=NULL ) { dp=key; vp=val; };
00248 };
00249
00250 class _KVPList: public _SetPList {
00251 protected:
00252 virtual VOID * _newVal( const VOID *val) = 0;
00253 virtual VOID _deleteVal( VOID *val) = 0;
00254 virtual VOID _copyVal( VOID *dest, const VOID *src ) = 0;
00255 private:
00256 _PListNode *__newNode_d_kv( const VOID *data=NULL, const VOID *val=NULL );
00257 _PListNode *__newNode_p_kv( VOID *data=NULL, VOID *val=NULL );
00258 _PListNode *__newNode_d( const _PListNode *node ) { return __newNode_d_kv(((_KVPListNode*)node)->dp,((_KVPListNode*)node)->vp); }
00259 _PListNode *__newNode_p( _PListNode *node ) { return __newNode_p_kv(((_KVPListNode*)node)->dp,((_KVPListNode*)node)->vp); }
00260 VOID __deleteNode_d( _PListNode *p ) { _deleteData(((_KVPListNode*)p)->dp); _deleteVal(((_KVPListNode*)p)->vp); delete p; }
00261 protected:
00262 VOID ** __itemvalptr(Lix p) { return &(((_KVPListNode*)p)->vp); }
00263
00264 private:
00265 _KVPList(_KVPList&) {};
00266 public:
00267 _KVPList(VOID) { }
00268
00269 protected:
00270 Lix _prepend_d_kv(const VOID* key=NULL, const VOID* val=NULL) {return __prepend(__newNode_d_kv(key,val));}
00271 Lix _append_d_kv(const VOID* key=NULL, const VOID* val=NULL) {return __append(__newNode_d_kv(key,val));}
00272 Lix _insbefore_d_kv(Lix p, const VOID* key=NULL, const VOID* val=NULL) {return __insbefore(p,__newNode_d_kv(key,val));}
00273 Lix _insafter_d_kv(Lix p, const VOID* key=NULL, const VOID* val=NULL) {return __insafter(p,__newNode_d_kv(key,val));}
00274
00275 Lix _prepend_p_kv(VOID* item=NULL, VOID* val=NULL) {return __prepend(__newNode_p_kv(item,val));}
00276 Lix _append_p_kv(VOID *item=NULL, VOID* val=NULL) {return __append(__newNode_p_kv(item,val));}
00277 Lix _insbefore_p_kv(Lix p, VOID* item=NULL, VOID* val=NULL) {return __insbefore(p,__newNode_p_kv(item,val));}
00278 Lix _insafter_p_kv(Lix p, VOID* item=NULL, VOID* val=NULL) {return __insafter(p,__newNode_p_kv(item,val));}
00279
00280 protected:
00281 #ifdef LIST_PTRVERIFY
00282 const VOID *_itemval(Lix p) const;
00283 const VOID *_itemval_first(VOID) const;
00284 const VOID *_itemval_last(VOID) const;
00285 #else
00286 const VOID *_itemval(Lix p) const { if (p == 0) return 0; return ((_KVPListNode*)p)->vp; }
00287 const VOID *_itemval_first(VOID) const { if (h == 0) return 0; return ((_KVPListNode*)h)->vp; }
00288 const VOID *_itemval_last(VOID) const { if (h == 0) return 0; return ((_KVPListNode*)h->b)->vp; }
00289 #endif
00290 VOID __exchange_p( _PListNode *n1, _PListNode *n2 );
00291
00292
00293 Lix _insbefore_d_kv(LIINT i, const VOID* key=NULL, const VOID* val=NULL);
00294 Lix _insbefore_p_kv(LIINT i, VOID* key=NULL, VOID* val=NULL);
00295 Lix _insafter_d_kv(LIINT i, const VOID* key=NULL, const VOID* val=NULL);
00296 Lix _insafter_p_kv(LIINT i, VOID* key, VOID* val);
00297 const VOID* _itemval(LIINT i) const;
00298
00299 const VOID * _val( const VOID *key ) const;
00300 const VOID * _val( const VOID *key, const VOID *defval ) const;
00301
00302 Lix _add(const VOID* k, const VOID* v,
00303 BOOL rewrite, BOOL ovwrt, BOOL dup, BOOL cdata );
00304 VOID _add(const _PList& a, BOOL rewrite, BOOL ovwrt, BOOL dup, BOOL cdata );
00305 };
00306
00307
00308
00309 template <class T>
00310 class ListT: public _PList {
00311 protected:
00312 virtual VOID * _newData( const VOID *data ) { T *t=new T; if (data) *t=(*(T*)data); return t; }
00313 virtual VOID _deleteData( VOID *data ) { if (data) delete (T*)data; }
00314 private:
00315 ListT(const ListT<T> &) {};
00316 public:
00317 ListT() {};
00318 ~ListT() { clear(); }
00319
00320 ListT<T>& create(VOID) { return *this; }
00321 ListT<T>& create(const ListT<T>& a) { return (ListT<T>&)_create_d(a); }
00322 ListT<T>& operator = (const ListT<T>& a) { return (ListT<T>&)_create_d(a); }
00323
00324 Lix prepend(VOID) {return _prepend_d(); }
00325 Lix append(VOID) {return _append_d(); }
00326 Lix insbefore(Lix p) {return _insbefore_d(p); }
00327 Lix insafter(Lix p) {return _insafter_d(p); }
00328 Lix prepend(const T& d) {return _prepend_d((VOID*)&d); }
00329 Lix append(const T& d) {return _append_d((VOID*)&d); }
00330 Lix insbefore(Lix p, const T& d) {return _insbefore_d(p,(VOID*)&d); }
00331 Lix insafter(Lix p, const T& d) {return _insafter_d(p,(VOID*)&d); }
00332 Lix prepend(const ListT<T>& a) { return _prepend_d(a); }
00333 Lix append(const ListT<T>& a) { return _append_d(a); }
00334 Lix insbefore(Lix p, const ListT<T>& a) { return _insbefore_d(p,a); }
00335 Lix insafter(Lix p, const ListT<T>& a) { return _insafter_d(p,a); }
00336 Lix prepend_p(T* d) {return _prepend_p((VOID*)d); }
00337 Lix append_p(T* d) {return _append_p((VOID*)d); }
00338 Lix insbefore_p(Lix p, T* d) {return _insbefore_p(p,(VOID*)d); }
00339 Lix insafter_p(Lix p, T* d) {return _insafter_p(p,(VOID*)d); }
00340 Lix prepend_mv(ListT<T>& a, Lix ni=0, Lix nf=0 ) { return _prepend_mv(a,ni,nf); }
00341 Lix append_mv(ListT<T>& a, Lix ni=0, Lix nf=0) { return _append_mv(a,ni,nf); }
00342 Lix insbefore_mv(Lix p, ListT<T>& a, Lix ni=0, Lix nf=0) { return _insbefore_mv(p,a,ni,nf); }
00343 Lix insafter_mv(Lix p, ListT<T>& a, Lix ni=0, Lix nf=0) { return _insafter_mv(p,a,ni,nf); }
00344
00345 Lix del(Lix p, INT dir = 1) { return _del(p,TRUE,dir); }
00346 VOID delprev(Lix p) { _delprev(p,TRUE); }
00347 VOID delnext(Lix p) { _delnext(p,TRUE); }
00348 Lix delfirst(VOID) { return _delfirst(TRUE); }
00349 Lix dellast(VOID) { return _dellast(TRUE); }
00350
00351 const T& item(Lix p) const { return *(const T*)_item(p); }
00352 const T& operator () (Lix p) const { return *(const T*)_item(p); }
00353 const T& item_first(VOID) const { return *(const T*)_item_first(); }
00354 const T& item_last(VOID) const { return *(const T*)_item_last(); }
00355 T& item(Lix p) { return *(T*)_item(p); }
00356
00357 T& item_first(VOID) { return *(T*)_item_first(); }
00358 T& item_last(VOID) { return *(T*)_item_last(); }
00359 T* &item_p(Lix p) { return *(T**)__itemptr(p); }
00360
00361 VOID exchange( Lix p1, Lix p2 ) { _exchange_p(p1,p2 ); }
00362 VOID sortf( INT (*comparefunc) ( const T*item1, const T*item2 ))
00363 { _sort((INT (*)(const VOID*,const VOID*))comparefunc); }
00364 Lix movebefore(Lix who, Lix where) { return _movebefore_lp(who,where); }
00365 Lix moveafter(Lix who, Lix where) { return _moveafter_lp(who,where); }
00366
00367
00368 Lix insbefore(LIINT i) { return _insbefore_d(i); }
00369 Lix insbefore(LIINT i, const T& item) { return _insbefore_d(i,(VOID*)&item); }
00370 Lix insbefore(LIINT i, const ListT<T>& a) { return _insbefore_d(i,a); }
00371 Lix insbefore_mv(LIINT i, ListT<T>& a) { return _insbefore_mv(i,a); }
00372 Lix insafter(LIINT i) { return _insafter_d(i); }
00373 Lix insafter(LIINT i, const T& item) { return _insafter_d(i,(VOID*)&item); }
00374 Lix insafter(LIINT i, const ListT<T>& a) { return _insafter_d(i,a); }
00375 Lix insafter_mv(LIINT i, ListT<T>& a) { return _insafter_mv(i,a); }
00376 VOID del(LIINT i) { _del(i,TRUE); }
00377 VOID delprev(LIINT i) { _delprev(i,TRUE); }
00378 VOID delnext(LIINT i) { _delnext(i,TRUE); }
00379 const T& item(LIINT i) const { return *(const T*)_item(i); }
00380 const T& operator () (LIINT i) const { return *(const T*)_item(i); }
00381 T& item(LIINT i) { return *(T*)_item(i); }
00382
00383 VOID exchange( LIINT i1, LIINT i2 ) { _exchange_p(i1,i2 ); }
00384 Lix movebefore(LIINT who, LIINT where) { return _movebefore_lp(who,where); }
00385 Lix moveafter(LIINT who, LIINT where) { return _moveafter_lp(who,where); }
00386
00387 #ifdef KK // $$$ da problemas
00388
00389 ListT<T>& create(const SetListT<T>& a) { return (ListT<T>&)_create_d(a); };
00390 ListT<T>& operator = (const SetListT<T>& a) { return (ListT<T>&)_create_d(a); }
00391 Lix prepend(const SetListT<T>& a) { return _prepend_d(a); }
00392 Lix append(const SetListT<T>& a) { return _append_d(a); }
00393 Lix insbefore(Lix p, const SetListT<T>& a) { return _insbefore_d(p,a); }
00394 Lix insafter(Lix p, const SetListT<T>& a) { return _insafter_d(p,a); }
00395 Lix prepend_mv(SetListT<T>& a, Lix ni=0, Lix nf=0) { return _prepend_mv(a,ni,nf); }
00396 Lix append_mv(SetListT<T>& a, Lix ni=0, Lix nf=0) { return _append_mv(a,ni,nf); }
00397 Lix insbefore_mv(Lix p, SetListT<T>& a, Lix ni=0, Lix nf=0) { return _insbefore_mv(p,a,ni,nf); }
00398 Lix insafter_mv(Lix p, SetListT<T>& a, Lix ni=0, Lix nf=0) { return _insafter_mv(p,a,ni,nf); }
00399 Lix insbefore(LIINT i, const SetListT<T>& a) { return _insbefore_d(i,a); }
00400 Lix insbefore_mv(LIINT i, SetListT<T>& a) { return _insbefore_mv(i,a); }
00401 Lix insafter(LIINT i, const SetListT<T>& a) { return _insafter_d(i,a); }
00402 Lix insafter_mv(LIINT i, SetListT<T>& a) { return _insafter_mv(i,a); }
00403
00404 SetListT<T>& toSetList(VOID) { return *(SetListT<T>*)((_PList*)this); }
00405 #endif
00406 };
00407
00408
00409
00410 template <class T>
00411 class SetListT: public _SetPList {
00412 protected:
00413 virtual VOID * _newData( const VOID *data ) { T *t=new T; if (data) *t=(*(T*)data); return t; }
00414 virtual VOID _deleteData( VOID *data ) { if (data) delete (T*)data; }
00415 virtual BOOL _sameData( const VOID *d1, const VOID *d2 ) const { return (*(const T*)d1) == (*(const T*)d2); }
00416 private:
00417 SetListT(const SetListT<T> &) {};
00418 public:
00419 SetListT() {};
00420 ~SetListT() { clear(); }
00421
00422 SetListT<T>& create(VOID) { return *this; }
00423 SetListT<T>& create(const SetListT<T>& a) { return (SetListT<T>&)_create_d(a); }
00424 SetListT<T>& operator = (const SetListT<T>& a) { return (SetListT<T>&)_create_d(a); }
00425
00426 Lix _prepend(VOID) {return _prepend_d(); }
00427 Lix _append(VOID) {return _append_d(); }
00428 Lix _insbefore(Lix p) {return _insbefore_d(p); }
00429 Lix _insafter(Lix p) {return _insafter_d(p); }
00430 Lix _prepend(const T& d) {return _prepend_d((VOID*)&d); }
00431 Lix _append(const T& d) {return _append_d((VOID*)&d); }
00432 Lix _insbefore(Lix p, const T& d) {return _insbefore_d(p,(VOID*)&d); }
00433 Lix _insafter(Lix p, const T& d) {return _insafter_d(p,(VOID*)&d); }
00434 Lix _prepend(const SetListT<T>& a) { return _prepend_d(a); }
00435 Lix _append(const SetListT<T>& a) { return _append_d(a); }
00436 Lix _insbefore(Lix p, const SetListT<T>& a) { return _insbefore_d(p,a); }
00437 Lix _insafter(Lix p, const SetListT<T>& a) { return _insafter_d(p,a); }
00438 Lix _prepend_mv(SetListT<T>& a, Lix ni=0, Lix nf=0) { return _SetPList::_prepend_mv(a,ni,nf); }
00439 Lix _append_mv(SetListT<T>& a, Lix ni=0, Lix nf=0) { return _SetPList::_append_mv(a,ni,nf); }
00440 Lix _insbefore_mv(Lix p, SetListT<T>& a, Lix ni=0, Lix nf=0) { return _SetPList::_insbefore_mv(p,a,ni,nf); }
00441 Lix _insafter_mv(Lix p, SetListT<T>& a, Lix ni=0, Lix nf=0) { return _SetPList::_insafter_mv(p,a,ni,nf); }
00442
00443 Lix del(Lix p, INT dir = 1) { return _del(p,TRUE,dir); }
00444 VOID delprev(Lix p) { _delprev(p,TRUE); }
00445 VOID delnext(Lix p) { _delnext(p,TRUE); }
00446 Lix delfirst(VOID) { return _delfirst(TRUE); }
00447 Lix dellast(VOID) { return _dellast(TRUE); }
00448
00449 const T& item(Lix p) const { return *(const T*)_SetPList::_item(p); }
00450 const T& operator () (Lix p) const { return *(const T*)_SetPList::_item(p); }
00451 const T& item_first(VOID) const { return *(const T*)_SetPList::_item_first(); }
00452 const T& item_last(VOID) const { return *(const T*)_SetPList::_item_last(); }
00453 T& _item(Lix p) { return *(T*)_SetPList::_item(p); }
00454
00455 T& _item_first(VOID) { return *(T*)_SetPList::_item_first(); }
00456 T& _item_last(VOID) { return *(T*)_SetPList::_item_last(); }
00457
00458 VOID exchange( Lix p1, Lix p2 ) { _exchange_p(p1,p2 ); }
00459 VOID sortf( INT (*comparefunc) ( const T*item1, const T*item2 ))
00460 { _sort((INT (*)(const VOID*,const VOID*))comparefunc); }
00461 Lix movebefore(Lix who, Lix where) { return _movebefore_lp(who,where); }
00462 Lix moveafter(Lix who, Lix where) { return _moveafter_lp(who,where); }
00463
00464 Lix add(const T& x) { return _add_d((const VOID*)&x); }
00465 VOID add(const SetListT<T>& a) { _add_d(a); }
00466 VOID add_mv(SetListT<T>& a, Lix ni, Lix nf, BOOL ovwrt) { _add_mv(a,ni,nf,ovwrt,TRUE); }
00467
00468 Lix seek(const T& x) const { return _seek((const VOID*)&x); }
00469 BOOL contains(const T& x) const { return _contains((const VOID*)&x); }
00470 BOOL contains(const SetListT<T>&a) const { return _contains(a); }
00471 BOOL equals(const SetListT<T>&a, BOOL allowrep=TRUE) const { return _equals(a,allowrep); }
00472 BOOL erase(const T & x) { return _erase((const VOID *)&x,TRUE); }
00473 BOOL erase(const SetListT<T>& a) { return _erase(a,TRUE); }
00474 VOID keep(const SetListT<T>& a) { _keep(a,TRUE); }
00475
00476
00477 Lix _insbefore(LIINT i) { return _insbefore_d(i); }
00478 Lix _insbefore(LIINT i, const T& item) { return _insbefore_d(i,(VOID*)&item); }
00479 Lix _insbefore(LIINT i, const SetListT<T>& a) { return _insbefore_d(i,a); }
00480 Lix _insbefore_mv(LIINT i, SetListT<T>& a) { return _SetPList::_insbefore_mv(i,a); }
00481 Lix _insafter(LIINT i) { return _insafter_d(i); }
00482 Lix _insafter(LIINT i, const T& item) { return _insafter_d(i,(VOID*)&item); }
00483 Lix _insafter(LIINT i, const SetListT<T>& a) { return _insafter_d(i,a); }
00484 Lix _insafter_mv(LIINT i, SetListT<T>& a) { return _SetPList::_insafter_mv(i,a); }
00485 VOID del(LIINT i) { _del(i,TRUE); }
00486 VOID delprev(LIINT i) { _delprev(i,TRUE); }
00487 VOID delnext(LIINT i) { _delnext(i,TRUE); }
00488 const T& item(LIINT i) const { return *(const T*)_SetPList::_item(i); }
00489 const T& operator () (LIINT i) const { return *(const T*)_SetPList::_item(i); }
00490 T& _item(LIINT i) { return *(T*)_SetPList::_item(i); }
00491
00492 VOID exchange( LIINT i1, LIINT i2 ) { _exchange_p(i1,i2 ); }
00493 Lix movebefore(LIINT who, LIINT where) { return _movebefore_lp(who,where); }
00494 Lix moveafter(LIINT who, LIINT where) { return _moveafter_lp(who,where); }
00495
00496
00497 SetListT<T>& create(const ListT<T>& a) { return (SetListT<T>&)_create_d(a); }
00498 SetListT<T>& operator = (const ListT<T>& a) { return (SetListT<T>&)_create_d(a); }
00499 Lix _prepend(const ListT<T>& a) { return _prepend_d(a); }
00500 Lix _append(const ListT<T>& a) { return _append_d(a); }
00501 Lix _insbefore(Lix p, const ListT<T>& a) { return _insbefore_d(p,a); }
00502 Lix _insafter(Lix p, const ListT<T>& a) { return _insafter_d(p,a); }
00503 Lix _prepend_mv(ListT<T>& a, Lix ni=0, Lix nf=0) { return _SetPList::_prepend_mv(a,ni,nf); }
00504 Lix _append_mv(ListT<T>& a, Lix ni=0, Lix nf=0) { return _SetPList::_append_mv(a,ni,nf); }
00505 Lix _insbefore_mv(Lix p, ListT<T>& a, Lix ni=0, Lix nf=0) { return _SetPList::_insbefore_mv(p,a,ni,nf); }
00506 Lix _insafter_mv(Lix p, ListT<T>& a, Lix ni=0, Lix nf=0) { return _SetPList::_insafter_mv(p,a,ni,nf); }
00507 VOID add(const ListT<T>& a) { _add_d(a); }
00508 VOID add_mv(ListT<T>& a, Lix ni, Lix nf, BOOL ovwrt) { _add_mv(a,ni,nf,ovwrt,TRUE); }
00509 BOOL contains(const ListT<T>&a) const { return _contains(a); }
00510 BOOL equals(const ListT<T>&a, BOOL allowrep=TRUE) const { return _equals(a,allowrep); }
00511 BOOL erase(const ListT<T>& a) { return _erase(a,TRUE); }
00512 VOID keep(const ListT<T>& a) { _keep(a,TRUE); }
00513 Lix _insbefore(LIINT i, const ListT<T>& a) { return _insbefore_d(i,a); }
00514 Lix _insbefore_mv(LIINT i, ListT<T>& a) { return _SetPList::_insbefore_mv(i,a); }
00515 Lix _insafter(LIINT i, const ListT<T>& a) { return _insafter_d(i,a); }
00516 Lix _insafter_mv(LIINT i, ListT<T>& a) { return _SetPList::_insafter_mv(i,a); }
00517
00518 ListT<T>& toList(VOID) { return *(ListT<T>*)((_PList*)this); }
00519 };
00520
00521
00522
00523 template <class K, class V>
00524 class KeyValListT: public _KVPList {
00525 protected:
00526 virtual VOID * _newData( const VOID *data ) { K *t=new K; if (data) *t=(*(K*)data); return t; }
00527 virtual VOID _deleteData( VOID *data ) { if (data) delete (K*)data; }
00528 virtual BOOL _sameData( const VOID *d1, const VOID *d2 ) const { return *(K*)d1 == *(K*)d2; }
00529 virtual VOID * _newVal( const VOID *val) { V *t=new V; if (val) *t=(*(V*)val); return t; }
00530 virtual VOID _deleteVal( VOID *val) { if (val) delete (V*)val; }
00531 virtual VOID _copyVal( VOID *dest, const VOID *src ) { if (src && dest) *(V*)dest = *(V*)src; }
00532 private:
00533 KeyValListT(const KeyValListT<K,V> &) {};
00534 public:
00535 KeyValListT() {};
00536 ~KeyValListT() { clear(); }
00537
00538 KeyValListT<K,V>& create(VOID) { return *this; }
00539 KeyValListT<K,V>& create(const KeyValListT<K,V>& a) { return (KeyValListT<K,V>&)_create_d(a); }
00540 KeyValListT<K,V>& operator = (const KeyValListT<K,V>& a) { return (KeyValListT<K,V>&)_create_d(a); }
00541
00542 Lix _prepend(VOID) {return _prepend_d(); }
00543 Lix _append(VOID) {return _append_d(); }
00544 Lix _insbefore(Lix p) {return _insbefore_d(p); }
00545 Lix _insafter(Lix p) {return _insafter_d(p); }
00546 Lix _prepend(const K& d, const V& v) {return _prepend_d_kv((VOID*)&d,(VOID*)&v); }
00547 Lix _append(const K& d, const V& v) {return _append_d_kv((VOID*)&d,(VOID*)&v); }
00548 Lix _insbefore(Lix p, const K& d, const V& v) {return _insbefore_d_kv(p,(VOID*)&d,(VOID*)&v); }
00549 Lix _insafter(Lix p, const K& d, const V& v) {return _insafter_d_kv(p,(VOID*)&d,(VOID*)&v); }
00550 Lix _prepend(const KeyValListT<K,V>& a) { return _prepend_d(a); }
00551 Lix _append(const KeyValListT<K,V>& a) { return _append_d(a); }
00552 Lix _insbefore(Lix p, const KeyValListT<K,V>& a) { return _insbefore_d(p,a); }
00553 Lix _insafter(Lix p, const KeyValListT<K,V>& a) { return _insafter_d(p,a); }
00554 Lix _prepend_mv(KeyValListT<K,V>& a, Lix ni=0, Lix nf=0) { return _KVPList::_prepend_mv(a,ni,nf); }
00555 Lix _append_mv(KeyValListT<K,V>& a, Lix ni=0, Lix nf=0) { return _KVPList::_append_mv(a,ni,nf); }
00556 Lix _insbefore_mv(Lix p, KeyValListT<K,V>& a, Lix ni=0, Lix nf=0) { return _KVPList::_insbefore_mv(p,a,ni,nf); }
00557 Lix _insafter_mv(Lix p, KeyValListT<K,V>& a, Lix ni=0, Lix nf=0) { return _KVPList::_insafter_mv(p,a,ni,nf); }
00558
00559 Lix del(Lix p, INT dir = 1) { return _del(p,TRUE,dir); }
00560 VOID delprev(Lix p) { _delprev(p,TRUE); }
00561 VOID delnext(Lix p) { _delnext(p,TRUE); }
00562 Lix delfirst(VOID) { return _delfirst(TRUE); }
00563 Lix dellast(VOID) { return _dellast(TRUE); }
00564
00565 const K& itemkey(Lix p) const { return *(const K*)_item(p); }
00566 const K& itemkey_first(VOID) const { return *(const K*)_item_first(); }
00567 const K& itemkey_last(VOID) const { return *(const K*)_item_last(); }
00568 K& _itemkey(Lix p) { return *(K*)_item(p); }
00569 K& _itemkey_first(VOID) { return *(K*)_item_first(); }
00570 K& _itemkey_last(VOID) { return *(K*)_item_last(); }
00571
00572 const V& itemval(Lix p) const { return *(const V*)_itemval(p); }
00573 const V& itemval_first(VOID) const { return *(const V*)_itemval_first(); }
00574 const V& itemval_last(VOID) const { return *(const V*)_itemval_last(); }
00575 V& itemval(Lix p) { return *(V*)_itemval(p); }
00576 V& itemval_first(VOID) { return *(V*)_itemval_first(); }
00577 V& itemval_last(VOID) { return *(V*)_itemval_last(); }
00578
00579 VOID exchange( Lix p1, Lix p2 ) { _exchange_p(p1,p2 ); }
00580 VOID sortf( INT (*comparefunc) ( const K*item1, const K*item2 ))
00581 { _sort((INT (*)(const VOID*,const VOID*))comparefunc); }
00582 Lix movebefore(Lix who, Lix where) { return _movebefore_lp(who,where); }
00583 Lix moveafter(Lix who, Lix where) { return _moveafter_lp(who,where); }
00584
00585 Lix add(const K& x,const V& v, BOOL rewrite=TRUE) { return _add((const VOID*)&x,(const VOID*)&v,rewrite,TRUE,TRUE,TRUE); }
00586 VOID add(const KeyValListT<K,V>& a, BOOL rewrite=TRUE) { _add((const _PList&)a,rewrite,TRUE,TRUE,TRUE); }
00587 VOID add_mv(KeyValListT<K,V>& a, Lix ni, Lix nf, BOOL rewrite=TRUE) { _add_mv(a,ni,nf,rewrite,TRUE); }
00588
00589 Lix seek(const K& x) const { return _seek((const VOID*)&x); }
00590 BOOL contains(const K& x) const { return _contains((const VOID*)&x); }
00591 BOOL contains(const KeyValListT<K,V>&a) const { return _contains(a); }
00592 BOOL equals(const KeyValListT<K,V>&a, BOOL allowrep=TRUE) const { return _equals(a,allowrep); }
00593 BOOL erase(const K & x) { return _erase((const VOID *)&x,TRUE); }
00594 BOOL erase(const KeyValListT<K,V>& a) { return _erase(a,TRUE); }
00595 VOID keep(const KeyValListT<K,V>& a) { _keep(a,TRUE); }
00596
00597 const V& val( const K& key ) const { return *(const V*)_val((const VOID*)&key); }
00598 const V& val( const K& key, const V& defval ) const { return *(const V*)_val((const VOID*)&key,(const VOID*)&defval); }
00599
00600
00601 Lix _insbefore(LIINT i) { return _insbefore_d(i); }
00602 Lix _insbefore(LIINT i, const K& item, const V&val) { return _insbefore_d_kv(i,(VOID*)&item,(VOID*)&val); }
00603 Lix _insbefore(LIINT i, const KeyValListT<K,V>& a) { return _insbefore_d(i,a); }
00604 Lix _insbefore_mv(LIINT i, KeyValListT<K,V>& a) { return _KVPList::_insbefore_mv(i,a); }
00605 Lix _insafter(LIINT i) { return _insafter_d(i); }
00606 Lix _insafter(LIINT i, const K& item, const V&val) { return _insafter_d_kv(i,(VOID*)&item,(VOID*)&val); }
00607 Lix _insafter(LIINT i, const KeyValListT<K,V>& a) { return _insafter_d(i,a); }
00608 Lix _insafter_mv(LIINT i, KeyValListT<K,V>& a) { return _KVPList::_insafter_mv(i,a); }
00609 VOID del(LIINT i) { _del(i,TRUE); }
00610 VOID delprev(LIINT i) { _delprev(i,TRUE); }
00611 VOID delnext(LIINT i) { _delnext(i,TRUE); }
00612 const K& itemkey(LIINT i) const { return *(const K*)_item(i); }
00613 K& _itemkey(LIINT i) { return *(K*)_item(i); }
00614 VOID exchange( LIINT i1, LIINT i2 ) { _exchange_p(i1,i2); }
00615 const V& itemval(LIINT i) const { return *(const V*)_itemval(i); }
00616 V& itemval(LIINT i) { return *(V*)_itemval(i); }
00617 Lix movebefore(LIINT who, LIINT where) { return _movebefore_lp(who,where); }
00618 Lix moveafter(LIINT who, LIINT where) { return _moveafter_lp(who,where); }
00619
00620
00621 BOOL contains(const ListT<K>&a) const { return _contains(a); }
00622 BOOL equals(const ListT<K>&a, BOOL allowrep=TRUE) const { return _equals(a,allowrep); }
00623 BOOL erase(const ListT<K>& a) { return _erase(a,TRUE); }
00624 VOID keep(const ListT<K>& a) { _keep(a,TRUE); }
00625 BOOL contains(const SetListT<K>&a) const { return _contains(a); }
00626 BOOL equals(const SetListT<K>&a, BOOL allowrep=TRUE) const { return _equals(a,allowrep); }
00627 BOOL erase(const SetListT<K>& a) { return _erase(a,TRUE); }
00628 VOID keep(const SetListT<K>& a) { _keep(a,TRUE); }
00629 };
00630
00631
00632
00633 #ifdef kk
00634 template<class T>
00635 class ClassPtrT {
00636 public:
00637 T* ptr;
00638 ClassPtrT(VOID) { ptr=0; }
00639 ClassPtrT(T *t) { ptr=t; }
00640 ~ClassPtrT(VOID) { if (ptr) delete ptr; }
00641 };
00642 #endif
00643
00644
00645
00646 #endif