ODIN
tjlist.h
1 /***************************************************************************
2  tjlist.h - description
3  -------------------
4  begin : Mon Aug 5 2002
5  copyright : (C) 2000-2021 by Thies H. Jochimsen
6  email : thies@jochimsen.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef TJLIST_H
19 #define TJLIST_H
20 
21 #include <tjutils/tjutils.h>
22 
28 // for debugging List
29 class ListComponent {
30  public:
31  static const char* get_compName();
32 };
33 
35 
36 class ListItemBase {};
37 
38 
39 class ListBase {
40 
41  public:
42  virtual ~ListBase() {}
43  virtual void objlist_remove(ListItemBase* item) = 0;
44 };
45 
46 
47 
49 
50 template<class I>
51 class ListItem : public ListItemBase {
52 
53  public:
54 
55  ListItem() {}
56  ~ListItem();
57 
58  // empty copy and assignment operator to avoid copying of 'objhandlers' member
59  ListItem(const ListItem&) {}
60  ListItem& operator = (const ListItem&) {return *this;}
61 
62 
63  unsigned int numof_references() const {return objhandlers.size();}
64 
65  const ListItemBase& append_objhandler(ListBase& objhandler) const;
66  const ListItemBase& remove_objhandler(ListBase& objhandler) const;
67 
68 
69  private:
70  mutable STD_list<ListBase*> objhandlers;
71 
72 };
73 
74 
75 
77 
105 template<class I,class P,class R> class List : public ListBase {
106 
107 
108  public:
109 
113  List();
114 
118  ~List();
119 
124  List& operator = (const List& l);
125 
126 
130  List& clear();
131 
135  List& append(R item);
136 
140  List& remove(R item);
141 
145  unsigned int size() const {return objlist.size();}
146 
147 
151  typedef typename STD_list<P>::iterator iter;
152 
156  typedef typename STD_list<P>::const_iterator constiter;
157 
161  iter get_begin() {return objlist.begin();}
162 
166  iter get_end() {return objlist.end();}
167 
171  constiter get_const_begin() const {return objlist.begin();}
172 
176  constiter get_const_end() const {return objlist.end();}
177 
178 
179  private:
180 
181  void objlist_remove(ListItemBase* item);
182 
183  void link_item(P ptr);
184  void unlink_item(P ptr);
185 
186 
187  STD_list<P> objlist;
188 
189 };
190 
191 
194 #endif
Definition: tjlist.h:105
STD_list< P >::iterator iter
Definition: tjlist.h:151
unsigned int size() const
Definition: tjlist.h:145
constiter get_const_end() const
Definition: tjlist.h:176
iter get_begin()
Definition: tjlist.h:161
List()
Definition: tjlist_code.h:39
iter get_end()
Definition: tjlist.h:166
STD_list< P >::const_iterator constiter
Definition: tjlist.h:156
constiter get_const_begin() const
Definition: tjlist.h:171
List & remove(R item)
Definition: tjlist_code.h:93
List & operator=(const List &l)
Definition: tjlist_code.h:56
List & append(R item)
Definition: tjlist_code.h:82
List & clear()
Definition: tjlist_code.h:65
~List()
Definition: tjlist_code.h:47