00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef TJLIST_H
00019 #define TJLIST_H
00020
00021 #include <tjutils/tjutils.h>
00022
00028
00029 class ListComponent {
00030 public:
00031 static const char* get_compName();
00032 };
00033
00035
00036 class ListItemBase {};
00037
00038
00039 class ListBase {
00040
00041 public:
00042 virtual ~ListBase() {}
00043 virtual void objlist_remove(ListItemBase* item) = 0;
00044 };
00045
00046
00047
00049
00050 template<class I>
00051 class ListItem : public ListItemBase {
00052
00053 public:
00054
00055 ListItem() {}
00056 ~ListItem();
00057
00058
00059 ListItem(const ListItem&) {}
00060 ListItem& operator = (const ListItem&) {return *this;}
00061
00062
00063 unsigned int numof_references() const {return objhandlers.size();}
00064
00065 const ListItemBase& append_objhandler(ListBase& objhandler) const;
00066 const ListItemBase& remove_objhandler(ListBase& objhandler) const;
00067
00068
00069 private:
00070 mutable STD_list<ListBase*> objhandlers;
00071
00072 };
00073
00074
00075
00077
00105 template<class I,class P,class R> class List : public ListBase {
00106
00107
00108 public:
00109
00113 List();
00114
00118 ~List();
00119
00124 List& operator = (const List& l);
00125
00126
00130 List& clear();
00131
00135 List& append(R item);
00136
00140 List& remove(R item);
00141
00145 unsigned int size() const {return objlist.size();}
00146
00147
00151 typedef typename STD_list<P>::iterator iter;
00152
00156 typedef typename STD_list<P>::const_iterator constiter;
00157
00161 iter get_begin() {return objlist.begin();}
00162
00166 iter get_end() {return objlist.end();}
00167
00171 constiter get_const_begin() const {return objlist.begin();}
00172
00176 constiter get_const_end() const {return objlist.end();}
00177
00178
00179 private:
00180
00181 void objlist_remove(ListItemBase* item);
00182
00183 void link_item(P ptr);
00184 void unlink_item(P ptr);
00185
00186
00187 STD_list<P> objlist;
00188
00189 };
00190
00191
00194 #endif