00001 #include <tjutils/tjlist.h>
00002 #include <tjutils/tjlog.h>
00003
00004 #ifdef HAVE_TYPEINFO
00005 #include <typeinfo>
00006 #endif
00007
00008
00009 template<class I>
00010 ListItem<I>::~ListItem() {
00011 Log<ListComponent> odinlog("ListItem","~ListItem");
00012 #ifdef HAVE_TYPEINFO
00013 ODINLOG(odinlog,normalDebug) << "deleting object of type >" << typeid(I).name() << "<" << STD_endl;
00014 #endif
00015
00016 for(STD_list<ListBase*>::iterator it=objhandlers.begin(); it!=objhandlers.end(); ++it) {
00017 (*it)->objlist_remove(this);
00018 }
00019 }
00020
00021 template<class I>
00022 const ListItemBase& ListItem<I>::append_objhandler(ListBase& objhandler) const {
00023 Log<ListComponent> odinlog("ListItem","append_objhandler");
00024 objhandlers.push_back(&objhandler);
00025 return *this;
00026 }
00027
00028 template<class I>
00029 const ListItemBase& ListItem<I>::remove_objhandler(ListBase& objhandler) const {
00030 Log<ListComponent> odinlog("ListItem","remove_objhandler");
00031 objhandlers.remove(&objhandler);
00032 return *this;
00033 }
00034
00036
00037
00038 template<class I,class P,class R>
00039 List<I,P,R>::List() {
00040 Log<ListComponent> odinlog("List","List()");
00041 #ifdef HAVE_TYPEINFO
00042 ODINLOG(odinlog,normalDebug) << "constructing list of >" << typeid(I).name() << "<" << STD_endl;
00043 #endif
00044 }
00045
00046 template<class I,class P,class R>
00047 List<I,P,R>::~List() {
00048 Log<ListComponent> odinlog("List","~List()");
00049 #ifdef HAVE_TYPEINFO
00050 ODINLOG(odinlog,normalDebug) << "destructing list of >" << typeid(I).name() << "<" << STD_endl;
00051 #endif
00052 clear();
00053 }
00054
00055 template<class I,class P,class R>
00056 List<I,P,R>& List<I,P,R>::operator = (const List<I,P,R>& l) {
00057 clear();
00058 for(typename STD_list<P>::const_iterator it=l.objlist.begin(); it!=l.objlist.end(); ++it) {
00059 append(**it);
00060 }
00061 return *this;
00062 }
00063
00064 template<class I,class P,class R>
00065 List<I,P,R>& List<I,P,R>::clear() {
00066 Log<ListComponent> odinlog("List","clear");
00067 #ifdef HAVE_TYPEINFO
00068 ODINLOG(odinlog,normalDebug) << "Clearing list of type >" << typeid(I).name() << "<" << STD_endl;
00069 #endif
00070 for(typename STD_list<P>::iterator it=objlist.begin(); it!=objlist.end(); ++it) {
00071 ODINLOG(odinlog,normalDebug) << "Unlinking " << (*it) << STD_endl;
00072
00073 unlink_item(*it);
00074
00075 ODINLOG(odinlog,normalDebug) << "Unlinking done" << STD_endl;
00076 }
00077 objlist.erase(objlist.begin(),objlist.end());
00078 return *this;
00079 }
00080
00081 template<class I,class P,class R>
00082 List<I,P,R>& List<I,P,R>::append(R item) {
00083 Log<ListComponent> odinlog("List","append");
00084 #ifdef HAVE_TYPEINFO
00085 ODINLOG(odinlog,normalDebug) << "appending object of type >" << typeid(I).name() << "<" << STD_endl;
00086 #endif
00087 link_item(&item);
00088 objlist.push_back(&item);
00089 return *this;
00090 }
00091
00092 template<class I,class P,class R>
00093 List<I,P,R>& List<I,P,R>::remove(R item) {
00094 Log<ListComponent> odinlog("List","remove");
00095 #ifdef HAVE_TYPEINFO
00096 ODINLOG(odinlog,normalDebug) << "removing object of type >" << typeid(I).name() << "<" << STD_endl;
00097 #endif
00098 unlink_item(&item);
00099 objlist.remove(&item);
00100 return *this;
00101 }
00102
00103 template<class I,class P,class R>
00104 void List<I,P,R>::objlist_remove(ListItemBase* item) {
00105 Log<ListComponent> odinlog("List","objlist_remove");
00106 #ifdef HAVE_TYPEINFO
00107 ODINLOG(odinlog,normalDebug) << "deleting object of type >" << typeid(I).name() << "<" << STD_endl;
00108 #endif
00109 P itemItype=static_cast<P>(item);
00110 if(itemItype) {
00111 objlist.remove(itemItype);
00112 } else {
00113 ODINLOG(odinlog,errorLog) << "static_cast failed" << STD_endl;
00114 }
00115 }
00116
00117
00118 template<class I,class P,class R>
00119 void List<I,P,R>::link_item(P ptr) {
00120 Log<ListComponent> odinlog("List","link_item");
00121 const ListItem<I>* item=static_cast<const ListItem<I>*>(ptr);
00122 if(item) {
00123 item->append_objhandler(*this);
00124 } else {
00125 ODINLOG(odinlog,errorLog) << "static_cast failed" << STD_endl;
00126 }
00127 }
00128
00129 template<class I,class P,class R>
00130 void List<I,P,R>::unlink_item(P ptr) {
00131 Log<ListComponent> odinlog("List","unlink_item");
00132 const ListItem<I>* item=static_cast<const ListItem<I>*>(ptr);
00133 if(item) {
00134 item->remove_objhandler(*this);
00135 } else {
00136 ODINLOG(odinlog,errorLog) << "static_cast failed" << STD_endl;
00137 }
00138 }
00139
00140
00141