tjlist_code.h
1 #include <tjutils/tjlist.h>
2 #include <tjutils/tjlog.h>
3 
4 #ifdef HAVE_TYPEINFO
5 #include <typeinfo>
6 #endif
7 
8 
9 template<class I>
10  ListItem<I>::~ListItem() {
11  Log<ListComponent> odinlog("ListItem","~ListItem");
12 #ifdef HAVE_TYPEINFO
13  ODINLOG(odinlog,normalDebug) << "deleting object of type >" << typeid(I).name() << "<" << STD_endl;
14 #endif
15 
16  for(STD_list<ListBase*>::iterator it=objhandlers.begin(); it!=objhandlers.end(); ++it) {
17  (*it)->objlist_remove(this);
18  }
19  }
20 
21 template<class I>
22  const ListItemBase& ListItem<I>::append_objhandler(ListBase& objhandler) const {
23  Log<ListComponent> odinlog("ListItem","append_objhandler");
24  objhandlers.push_back(&objhandler);
25  return *this;
26  }
27 
28 template<class I>
29  const ListItemBase& ListItem<I>::remove_objhandler(ListBase& objhandler) const {
30  Log<ListComponent> odinlog("ListItem","remove_objhandler");
31  objhandlers.remove(&objhandler);
32  return *this;
33  }
34 
36 
37 
38 template<class I,class P,class R>
40  Log<ListComponent> odinlog("List","List()");
41 #ifdef HAVE_TYPEINFO
42  ODINLOG(odinlog,normalDebug) << "constructing list of >" << typeid(I).name() << "<" << STD_endl;
43 #endif
44  }
45 
46 template<class I,class P,class R>
48  Log<ListComponent> odinlog("List","~List()");
49 #ifdef HAVE_TYPEINFO
50  ODINLOG(odinlog,normalDebug) << "destructing list of >" << typeid(I).name() << "<" << STD_endl;
51 #endif
52  clear();
53  }
54 
55 template<class I,class P,class R>
57  clear();
58  for(typename STD_list<P>::const_iterator it=l.objlist.begin(); it!=l.objlist.end(); ++it) {
59  append(**it);
60  }
61  return *this;
62  }
63 
64 template<class I,class P,class R>
66  Log<ListComponent> odinlog("List","clear");
67 #ifdef HAVE_TYPEINFO
68  ODINLOG(odinlog,normalDebug) << "Clearing list of type >" << typeid(I).name() << "<" << STD_endl;
69 #endif
70  for(typename STD_list<P>::iterator it=objlist.begin(); it!=objlist.end(); ++it) {
71  ODINLOG(odinlog,normalDebug) << "Unlinking " << (*it) << STD_endl;
72 
73  unlink_item(*it);
74 
75  ODINLOG(odinlog,normalDebug) << "Unlinking done" << STD_endl;
76  }
77  objlist.erase(objlist.begin(),objlist.end());
78  return *this;
79  }
80 
81 template<class I,class P,class R>
83  Log<ListComponent> odinlog("List","append");
84 #ifdef HAVE_TYPEINFO
85  ODINLOG(odinlog,normalDebug) << "appending object of type >" << typeid(I).name() << "<" << STD_endl;
86 #endif
87  link_item(&item);
88  objlist.push_back(&item);
89  return *this;
90  }
91 
92 template<class I,class P,class R>
94  Log<ListComponent> odinlog("List","remove");
95 #ifdef HAVE_TYPEINFO
96  ODINLOG(odinlog,normalDebug) << "removing object of type >" << typeid(I).name() << "<" << STD_endl;
97 #endif
98  unlink_item(&item);
99  objlist.remove(&item);
100  return *this;
101  }
102 
103 template<class I,class P,class R>
104  void List<I,P,R>::objlist_remove(ListItemBase* item) {
105  Log<ListComponent> odinlog("List","objlist_remove");
106 #ifdef HAVE_TYPEINFO
107  ODINLOG(odinlog,normalDebug) << "deleting object of type >" << typeid(I).name() << "<" << STD_endl;
108 #endif
109  P itemItype=static_cast<P>(item);
110  if(itemItype) {
111  objlist.remove(itemItype);
112  } else {
113  ODINLOG(odinlog,errorLog) << "static_cast failed" << STD_endl;
114  }
115  }
116 
117 
118 template<class I,class P,class R>
119  void List<I,P,R>::link_item(P ptr) {
120  Log<ListComponent> odinlog("List","link_item");
121  const ListItem<I>* item=static_cast<const ListItem<I>*>(ptr);
122  if(item) {
123  item->append_objhandler(*this);
124  } else {
125  ODINLOG(odinlog,errorLog) << "static_cast failed" << STD_endl;
126  }
127  }
128 
129 template<class I,class P,class R>
130  void List<I,P,R>::unlink_item(P ptr) {
131  Log<ListComponent> odinlog("List","unlink_item");
132  const ListItem<I>* item=static_cast<const ListItem<I>*>(ptr);
133  if(item) {
134  item->remove_objhandler(*this);
135  } else {
136  ODINLOG(odinlog,errorLog) << "static_cast failed" << STD_endl;
137  }
138  }
139 
140 
141 
List & append(R item)
Definition: tjlist_code.h:82
Definition: tjlog.h:218
List()
Definition: tjlist_code.h:39
List & clear()
Definition: tjlist_code.h:65
Definition: tjlist.h:105
~List()
Definition: tjlist_code.h:47
List & operator=(const List &l)
Definition: tjlist_code.h:56
List & remove(R item)
Definition: tjlist_code.h:93