remove non working python refcount debugging code
[enigma2.git] / lib / base / eptrlist.h
1 #ifndef _E_PTRLIST_
2 #define _E_PTRLIST_
3
4 #include <list>
5 #include <vector>
6 #include <algorithm>
7 #include <lib/base/smartptr.h>
8 #include <lib/base/eerror.h>
9
10 template <class T>
11 class ePtrList : public std::list<T*>
12 {
13 public:
14         typedef typename std::list<T*, std::allocator<T*> >::iterator std_list_T_iterator;  // to remove compiler warnings
15         typedef typename std::list<T*, std::allocator<T*> >::const_iterator std_list_T_const_iterator;
16         typedef typename std::list<T*, std::allocator<T*> >::reverse_iterator std_list_T_reverse_iterator;
17         typedef typename std::list<T*, std::allocator<T*> >::const_reverse_iterator std_list_T_const_reverse_iterator;
18         typedef typename ePtrList<T>::iterator T_iterator;
19         typedef typename ePtrList<T>::const_iterator T_const_iterator;
20         typedef typename ePtrList<T>::reverse_iterator T_reverse_iterator;
21         typedef typename ePtrList<T>::const_reverse_iterator T_const_reverse_iterator;
22
23 // Iterator classes
24         class iterator;
25         class const_iterator;
26         class reverse_iterator;
27         class const_reverse_iterator;
28
29 // Constructors
30         inline ePtrList();
31         inline ePtrList(const ePtrList&);
32         inline ~ePtrList();
33
34 // overwritted sort method
35         inline void sort();
36
37 // changed methods for autodelete and current implementation
38         inline void remove(T* t);
39         inline void clear();
40         inline void pop_back();
41         inline void pop_front();
42         inline void push_back(T*);
43         inline void push_front(T*);
44
45 // added methods for current implementation
46         inline T* take();
47         inline void take(T* t);
48         inline T* current();
49         inline T* next();
50         inline T* prev();
51         inline T* first();
52         inline T* last();
53         inline T* setCurrent(const T*);
54         inline const T* current() const;
55         inline const T* next() const;
56         inline const T* prev() const;
57         inline const T* first() const;
58         inline const T* last() const;
59
60 // added operator methods
61         inline operator bool();
62         inline bool operator!();
63
64 // added compare struct ... to sort
65         struct less;
66 private:
67         iterator cur;
68 public:
69         iterator begin()
70         {                               
71         //      makes implicit type conversion form std::list::iterator to ePtrList::iterator
72                 return std::list<T*>::begin();          
73         }
74
75         iterator end()
76         {                               
77         //      makes implicit type conversion form std::list::iterator to ePtrList::iterator
78                 return std::list<T*>::end();            
79         }
80
81         const_iterator begin() const
82         {                               
83         //      makes implicit type conversion form std::list::const_iterator to ePtrList::const_iterator
84                 return std::list<T*>::begin();          
85         }
86
87         const_iterator end() const
88         {                               
89         //      makes implicit type conversion form std::list::const_iterator to ePtrList::const_iterator
90                 return std::list<T*>::end();            
91         }
92
93         reverse_iterator rbegin()
94         {                               
95         //      makes implicit type conversion form std::list::reverse:_iterator to ePtrList::reverse_iterator
96                 return std::list<T*>::rbegin();         
97         }
98
99         reverse_iterator rend()
100         {                               
101         //      makes implicit type conversion form std::list::reverse_iterator to ePtrList::reverse_iterator
102                 return std::list<T*>::rend();           
103         }
104
105         const_reverse_iterator rbegin() const
106         {                               
107         //      makes implicit type conversion form std::list::const_reverse_iterator to ePtrList::const_reverse_iterator
108                 return std::list<T*>::rbegin();         
109         }
110
111         const_reverse_iterator rend() const
112         {                               
113         //      makes implicit type conversion form std::list::const_reverse_iterator to ePtrList::const_reverse_iterator
114                 return std::list<T*>::rend();           
115         }
116
117         iterator erase(iterator it)
118         {
119         //      Remove the item it, if auto-deletion is enabled, than the list call delete for this item
120         //  If current is equal to the item that was removed, current is set to the next item in the list
121                 if (cur == it)
122                         return cur = std::list<T*>::erase(it);
123                 else
124                         return std::list<T*>::erase(it);
125         }
126
127         iterator erase(iterator from, iterator to)
128         {
129         //      Remove all items between the to iterators from and to
130         //      If auto-deletion is enabled, than the list call delete for all removed items
131                 while (from != to)
132                         from = erase(from);
133         
134                 return from;
135         }
136
137         operator iterator()     
138         {
139         //      Returns a iterator that equal to begin() of the list
140                 return begin(); 
141         }
142
143         operator const_iterator() const
144         {
145         //      Returns a const_iterator that equal to begin() of the list
146                 return begin(); 
147         }
148
149         operator reverse_iterator()
150         {
151         //      Returns a reverse_iterator that equal to rbegin() of the list
152                 return rbegin();        
153         }
154
155         operator const_reverse_iterator() const 
156         {
157         //      Returns a const_reverse_iterator that equal to rbegin() of the list
158                 return rbegin();        
159         }
160
161         std::vector<T>* getVector()
162         {
163                 // Creates an vector and copys all elements to this vector
164                 // returns a pointer to this new vector ( the reserved memory must deletet from the receiver !! )
165                 std::vector<T>* v=new std::vector<T>();
166                 v->reserve( std::list<T>::size() );
167     for ( std_list_T_iterator it( std::list<T*>::begin() ); it != std::list<T*>::end(); it++)
168                         v->push_back( **it );
169
170                 return v;
171         }
172
173         inline iterator insert_in_order( T* e )
174         {
175                 // added a new item to the list... in order
176                 // returns a iterator to the new item
177                 return insert( std::lower_bound( std::list<T*>::begin(), std::list<T*>::end(), e, less()), e );
178         }
179
180 };
181
182 /////////////////// iterator class /////////////////////////////
183 template <class T>
184 class ePtrList<T>::iterator : public std::list<T*>::iterator
185 {
186 public:
187         // Constructors
188         iterator(const std_list_T_iterator& Q)          : std_list_T_iterator(Q)        {       }
189
190         // changed operator for pointer
191         T* operator->() const
192         {
193                 return *std::list<T*>::iterator::operator->();
194         }
195
196         operator T&() const
197         {
198                 return *operator->();
199         }
200         
201         operator T*() const
202         {
203                 return operator->();
204         }
205
206         iterator& operator++()
207         {
208                 std::list<T*>::iterator::operator++();
209                 return *this;
210         }
211
212         iterator operator++(int)
213         {
214                 return std::list<T*>::iterator::operator++(0);
215         }
216
217         iterator& operator--()
218         {
219                 std::list<T*>::iterator::operator--();
220                 return *this;
221         }
222
223         iterator operator--(int)
224         {
225                 return std::list<T*>::iterator::operator--(0);
226         }
227 };
228
229 /////////////////// const_iterator class /////////////////////////////
230 template <class T>
231 class ePtrList<T>::const_iterator : public std::list<T*>::const_iterator
232 {
233 public:
234         // Constructors
235         const_iterator(const std_list_T_const_iterator& Q)              :std_list_T_const_iterator(Q)   {       }
236
237         // changed operator for pointer
238         T* operator->() const
239         {
240                 return *std::list<T*>::const_iterator::operator->();
241         }
242
243         operator T&() const
244         {
245                 return *operator->();
246         }
247
248         operator T*() const
249         {
250                 return operator->();
251         }
252
253         const_iterator& operator++()
254         {
255                 std::list<T*>::const_iterator::operator++();
256                 return *this;
257         }
258
259         const_iterator operator++(int)
260         {
261                 return std::list<T*>::const_iterator::operator++(0);
262         }
263
264         const_iterator& operator--()
265         {
266                 std::list<T*>::const_iterator::operator--();
267                 return *this;
268         }
269
270         const_iterator operator--(int)
271         {
272                 return std::list<T*>::const_iterator::operator--(0);
273         }
274 };
275
276 /////////////////// reverse_iterator class /////////////////////////////
277 template <class T>
278 class ePtrList<T>::reverse_iterator : public std::list<T*>::reverse_iterator
279 {
280 public:
281         // Constructors
282         reverse_iterator(const std_list_T_reverse_iterator& Q)          :std_list_T_reverse_iterator(Q) {       }
283
284         // changed operators for pointer
285         T* operator->() const
286         {
287                 return *std::list<T*>::reverse_iterator::operator->();
288         }
289
290         operator T&() const
291         {
292                 return *operator->();
293         }
294
295         operator T*() const
296         {
297                 return operator->();
298         }
299
300         reverse_iterator& operator++()
301         {
302                 std::list<T*>::reverse_iterator::operator++();
303                 return *this;
304         }
305
306         reverse_iterator operator++(int)
307         {
308                 return std::list<T*>::reverse_iterator::operator++(0);
309         }
310
311         reverse_iterator& operator--()
312         {
313                 std::list<T*>::reverse_iterator::operator--();
314                 return *this;
315         }
316
317         reverse_iterator operator--(int)
318         {
319                 return std::list<T*>::reverse_iterator::operator--(0);
320         }
321 };
322
323 /////////////////// const_reverse_iterator class /////////////////////////////
324 template <class T>
325 class ePtrList<T>::const_reverse_iterator : public std::list<T*>::const_reverse_iterator
326 {
327 public:
328         // Constructors
329         const_reverse_iterator(const std_list_T_const_reverse_iterator& Q)              :std_list_T_const_reverse_iterator(Q)   {       }
330
331         // changed operators for pointer
332         T* operator->() const
333         {
334                 return *std::list<T*>::const_reverse_iterator::operator->();
335         }
336
337         operator T&() const
338         {
339                 return *operator->();
340         }
341
342         operator T*() const
343         {
344                 return operator->();
345         }
346
347         const_reverse_iterator& operator++()
348         {
349                 std::list<T*>::const_reverse_iterator::operator++();
350                 return *this;
351         }
352
353         const_reverse_iterator operator++(int)
354         {
355                 return std::list<T*>::const_reverse_iterator::operator++(0);
356         }
357
358         const_reverse_iterator& operator--()
359         {
360                 std::list<T*>::const_reverse_iterator::operator--();
361                 return *this;
362         }
363
364         const_reverse_iterator operator--(int)
365         {
366                 return std::list<T*>::const_reverse_iterator::operator--(0);
367         }
368 };
369
370 /////////////////// Default Constructor /////////////////////////////
371 template <class T>
372 ePtrList<T>::ePtrList()
373     :cur(std::list<T*>::begin())
374 {               
375
376 }
377
378 /////////////////// Copy Constructor /////////////////////////////
379 template <class T>
380 ePtrList<T>::ePtrList(const ePtrList& e)
381         :std::list<T*>(e), cur(e.cur)
382 {               
383 }
384
385 /////////////////// ePtrList Destructor /////////////////////////////
386 template <class T>
387 inline ePtrList<T>::~ePtrList()
388 {
389 }
390
391 /////////////////// ePtrList sort() /////////////////////////
392 template <class T>
393 inline void ePtrList<T>::sort()
394 {               
395 //      Sorts all items in the list.
396 //      The type T must have a operator <.
397         std::list<T*>::sort(typename ePtrList<T>::less());
398 }       
399
400 /////////////////// ePtrList remove(T*) /////////////////////////
401 template <class T>
402 inline void ePtrList<T>::remove(T* t)
403 {
404 //      Remove all items that, equals to t, if auto-deletion is enabled, than the list call delete for the removed items
405 //  If current is equal to one of the removed items, current is set to the next valid item
406         T_iterator it(std::list<T*>::begin());
407
408         while (it != std::list<T*>::end())
409                 if (*it == t)
410                 {
411                         it=erase(it);
412                         break;  // one item is complete removed an deleted
413                 }
414                 else
415                         it++;
416         
417         while (it != std::list<T*>::end())
418                 if (*it == t)
419                         it = std::list<T*>::erase(it);  // remove all other items that equals to t (no delete is called..)
420                 else
421                         it++;
422                         
423 }
424
425 /////////////////// ePtrList clear() //////////////////
426 template <class T>
427 inline void ePtrList<T>::clear()        
428 {               
429 //      Remove all items from the list
430 //      If auto-deletion is enabled, than the list call delete for all items in the list
431         erase(std::list<T*>::begin(), std::list<T*>::end());    
432 }
433
434 /////////////////// ePtrList pop_back() ////////////////////
435 template <class T>
436 inline void ePtrList<T>::pop_back()
437 {
438 //      Removes the last item from the list. If the current item ist the last, than the current is set to the new
439 //      last item in the list;
440 //      The removed item is deleted if auto-deletion is enabled.
441         erase(--end());
442 }
443
444 /////////////////// ePtrList pop_front() ////////////////////
445 template <class T>
446 inline void ePtrList<T>::pop_front()
447 {
448 //      Removes the first item from the list. If the current item ist the first, than the current is set to the new
449 //      first item in the list;
450 //      The removed item is deleted if auto-deletion is enabled.
451         erase(begin());
452 }
453
454 /////////////////// ePtrList push_back(T*) ////////////////////
455 template <class T>
456 inline void ePtrList<T>::push_back(T* x)        
457 {               
458 // Add a new item at the end of the list.
459 // The current item is set to the last item;
460         std::list<T*>::push_back(x);
461         last(); 
462 }
463
464 /////////////////// ePtrList push_front(T*) ////////////////////
465 template <class T>
466 inline void ePtrList<T>::push_front(T* x)       
467 {               
468 // Add a new item at the begin of the list.
469 // The current item is set to the first item;
470         std::list<T*>::push_front(x);
471         first();        
472 }
473
474 /////////////////// ePtrList take() ////////////////////
475 template <class T>
476 inline T* ePtrList<T>::take()
477 {
478 // Takes the current item out of the list without deleting it (even if auto-deletion is enabled).
479 // Returns a pointer to the item taken out of the list, or null if the index is out of range.
480 // The item after the taken item becomes the new current list item if the taken item is not the last item in the list. If the last item is taken, the new last item becomes the current item.
481 // The current item is set to null if the list becomes empty.
482         T* tmp = *cur;
483         cur = std::list<T*>::erase(cur);
484         return tmp;
485 }
486
487 /////////////////// ePtrList take(T*) ////////////////////
488 template <class T>
489 inline void ePtrList<T>::take(T* t)
490 {
491 // Takes all item with T* out of the list without deleting it (even if auto-deletion is enabled).
492         std::list<T*>::remove(t);
493 }
494
495 /////////////////// ePtrList setCurrent(T*) ////////////////////
496 template <class T>
497 inline T* ePtrList<T>::setCurrent(const T* t)
498 {
499         // Sets the internal current iterator to the first element that equals to t, and returns t when a item is found,
500         // otherwise it returns 0 !
501         for (T_iterator it(std::list<T*>::begin()); it != std::list<T*>::end(); ++it)
502                 if (*it == t)
503                 {
504                         cur = it;
505                         return *it;
506                 }
507
508         return 0;
509 }
510
511 /////////////////// ePtrList current() ////////////////////
512 template <class T>
513 inline T* ePtrList<T>::current()
514 {
515 //      Returns a pointer to the current list item. The current item may be null (implies that the current index is -1).
516         return cur==end() ? 0 : *cur;   
517 }
518
519 /////////////////// ePtrList next() ////////////////////
520 template <class T>
521 inline T* ePtrList<T>::next()
522 {
523 //      Returns a pointer to the item succeeding the current item. Returns null if the current items is null or equal to the last item.
524 //      Makes the succeeding item current. If the current item before this function call was the last item, the current item will be set to null. If the current item was null, this function does nothing.
525         if (cur == end())
526                 return 0;
527         else
528                 if (++cur == end())
529                         return 0;
530                 else
531                         return *cur;
532 }
533
534 /////////////////// ePtrList prev() ////////////////////
535 template <class T>
536 inline T* ePtrList<T>::prev()
537 {
538 //      Returns a pointer to the item preceding the current item. Returns null if the current items is null or equal to the first item.
539 //      Makes the preceding item current. If the current item before this function call was the first item, the current item will be set to null. If the current item was null, this function does nothing.
540         if (cur == begin())
541                 return 0;
542         else
543                 return *--cur;
544 }
545
546 /////////////////// ePtrList first() ////////////////////
547 template <class T>
548 inline T* ePtrList<T>::first()
549 {
550 // Returns a pointer to the first item in the list and makes this the current list item, or null if the list is empty.
551         return *(cur = begin());        
552 }
553
554 /////////////////// ePtrList last() ////////////////////
555 template <class T>
556 inline T* ePtrList<T>::last()
557 {
558 //      Returns a pointer to the last item in the list and makes this the current list item, or null if the list is empty.
559         return *(cur = --end());
560 }
561
562 /////////////////// const ePtrList current() ////////////////////
563 template <class T>
564 inline const T* ePtrList<T>::current() const
565 {
566 //      Returns a pointer to the current list item. The current item may be null (implies that the current index is not valid)
567         return cur==end() ? 0 : *cur;   
568 }
569
570 /////////////////// const ePtrList next() ////////////////////
571 template <class T>
572 inline const T* ePtrList<T>::next() const
573 {
574 //      Returns a pointer to the item succeeding the current item. Returns null if the current items is null or equal to the last item.
575 //      Makes the succeeding item current. If the current item before this function call was the last item, the current item will be set to null. If the current item was null, this function does nothing.
576         if (cur == end())
577                 return 0;
578         else
579                 if (++cur == end())
580                         return 0;
581                 else
582                         return *cur;
583 }
584
585 /////////////////// const ePtrList prev() ////////////////////
586 template <class T>
587 inline const T* ePtrList<T>::prev() const
588 {
589 //      Returns a pointer to the item preceding the current item. Returns null if the current items is null or equal to the first item.
590 //      Makes the preceding item current. If the current item before this function call was the first item, the current item will be set to null. If the current item was null, this function does nothing.
591         if (cur == begin())
592                 return 0;
593         else
594                 return *--cur;
595 }
596
597 /////////////////// const ePtrList first() ////////////////////
598 template <class T>
599 inline const T* ePtrList<T>::first() const
600 {
601 // Returns a pointer to the first item in the list and makes this the current list item, or null if the list is empty.
602         return *(cur = begin());        
603 }
604
605 /////////////////// const ePtrList last() ////////////////////
606 template <class T>
607 inline const T* ePtrList<T>::last() const
608 {
609 //      Returns a pointer to the last item in the list and makes this the current list item, or null if the list is empty.
610         return *(cur = --end());
611 }
612
613 ////////////////// struct less //////////////////////////////
614 template <class T>
615 struct ePtrList<T>::less
616 {
617 //      operator() is used internal from the list to sort them
618         bool operator() (const T* t1, const T* t2)
619         {
620                 return (*t1 < *t2);
621         }
622 };
623
624 /////////////////// ePtrList operator bool ////////////////////
625 template <class T>
626 ePtrList<T>::operator bool()    
627 {
628 //      Returns a bool that contains true, when the list is NOT empty otherwise false
629         return !std::list<T*>::empty(); 
630 }
631
632 template <class T>
633 bool ePtrList<T>::operator!()   
634 {
635 //      Returns a bool that contains true, when the list is empty otherwise false
636         return std::list<T*>::empty();  
637 }
638
639 template <class T>
640 class eSmartPtrList : public std::list<ePtr<T> >
641 {
642 public:
643         typedef typename std::list<ePtr<T>, std::allocator<ePtr<T> > >::iterator std_list_T_iterator;  // to remove compiler warnings
644         typedef typename std::list<ePtr<T>, std::allocator<ePtr<T> > >::const_iterator std_list_T_const_iterator;
645         typedef typename std::list<ePtr<T>, std::allocator<ePtr<T> > >::reverse_iterator std_list_T_reverse_iterator;
646         typedef typename std::list<ePtr<T>, std::allocator<ePtr<T> > >::const_reverse_iterator std_list_T_const_reverse_iterator;
647         typedef typename eSmartPtrList<T>::iterator T_iterator;
648         typedef typename eSmartPtrList<T>::const_iterator T_const_iterator;
649         typedef typename eSmartPtrList<T>::reverse_iterator T_reverse_iterator;
650         typedef typename eSmartPtrList<T>::const_reverse_iterator T_const_reverse_iterator;
651
652 // Iterator classes
653         class iterator;
654         class const_iterator;
655         class reverse_iterator;
656         class const_reverse_iterator;
657
658 // Constructors
659         inline eSmartPtrList();
660         inline eSmartPtrList(const eSmartPtrList&);
661         inline ~eSmartPtrList();
662
663 // overwritted sort method
664         inline void sort();
665
666 // changed methods for autodelete and current implementation
667         inline void remove(T* t);
668         inline void clear();
669         inline void pop_back();
670         inline void pop_front();
671         inline void push_back(T*);
672         inline void push_front(T*);
673
674 // added methods for current implementation
675 //      inline T* take();
676 //      inline void take(T* t);
677         inline T* current();
678         inline T* next();
679         inline T* prev();
680         inline T* first();
681         inline T* last();
682         inline T* setCurrent(const T*);
683         inline const T* current() const;
684         inline const T* next() const;
685         inline const T* prev() const;
686         inline const T* first() const;
687         inline const T* last() const;
688
689 // added operator methods
690         inline operator bool();
691         inline bool operator!();
692
693 // added compare struct ... to sort
694         struct less;
695 private:
696         iterator cur;
697 public:
698         iterator begin()
699         {                               
700         //      makes implicit type conversion form std::list::iterator to eSmartPtrList::iterator
701                 return std::list<ePtr<T> >::begin();            
702         }
703
704         iterator end()
705         {                               
706         //      makes implicit type conversion form std::list::iterator to eSmartPtrList::iterator
707                 return std::list<ePtr<T> >::end();              
708         }
709
710         const_iterator begin() const
711         {                               
712         //      makes implicit type conversion form std::list::const_iterator to eSmartPtrList::const_iterator
713                 return std::list<ePtr<T> >::begin();            
714         }
715
716         const_iterator end() const
717         {                               
718         //      makes implicit type conversion form std::list::const_iterator to eSmartPtrList::const_iterator
719                 return std::list<ePtr<T> >::end();              
720         }
721
722         reverse_iterator rbegin()
723         {                               
724         //      makes implicit type conversion form std::list::reverse:_iterator to eSmartPtrList::reverse_iterator
725                 return std::list<ePtr<T> >::rbegin();           
726         }
727
728         reverse_iterator rend()
729         {                               
730         //      makes implicit type conversion form std::list::reverse_iterator to eSmartPtrList::reverse_iterator
731                 return std::list<ePtr<T> >::rend();             
732         }
733
734         const_reverse_iterator rbegin() const
735         {                               
736         //      makes implicit type conversion form std::list::const_reverse_iterator to eSmartPtrList::const_reverse_iterator
737                 return std::list<ePtr<T> >::rbegin();           
738         }
739
740         const_reverse_iterator rend() const
741         {                               
742         //      makes implicit type conversion form std::list::const_reverse_iterator to eSmartPtrList::const_reverse_iterator
743                 return std::list<ePtr<T> >::rend();             
744         }
745
746         iterator erase(iterator it)
747         {
748         //      Remove the item it, if auto-deletion is enabled, than the list call delete for this item
749         //  If current is equal to the item that was removed, current is set to the next item in the list
750
751                 if (cur == it)
752                         return cur = std::list<ePtr<T> >::erase(it);
753                 else
754                         return std::list<ePtr<T> >::erase(it);
755         }
756
757         iterator erase(iterator from, iterator to)
758         {
759         //      Remove all items between the to iterators from and to
760         //      If auto-deletion is enabled, than the list call delete for all removed items
761                 while (from != to)
762                         from = erase(from);
763         
764                 return from;
765         }
766
767         operator iterator()     
768         {
769         //      Returns a iterator that equal to begin() of the list
770                 return begin(); 
771         }
772
773         operator const_iterator() const
774         {
775         //      Returns a const_iterator that equal to begin() of the list
776                 return begin(); 
777         }
778
779         operator reverse_iterator()
780         {
781         //      Returns a reverse_iterator that equal to rbegin() of the list
782                 return rbegin();        
783         }
784
785         operator const_reverse_iterator() const 
786         {
787         //      Returns a const_reverse_iterator that equal to rbegin() of the list
788                 return rbegin();        
789         }
790
791         std::vector<T>* getVector()
792         {
793                 // Creates an vector and copys all elements to this vector
794                 // returns a pointer to this new vector ( the reserved memory must deletet from the receiver !! )
795                 std::vector<T>* v=new std::vector<T>();
796                 v->reserve( std::list<T>::size() );
797     for ( std_list_T_iterator it( std::list<ePtr<T> >::begin() ); it != std::list<ePtr<T> >::end(); it++)
798                         v->push_back( **it );
799
800                 return v;
801         }
802
803         inline iterator insert_in_order( T* e )
804         {
805                 // added a new item to the list... in order
806                 // returns a iterator to the new item
807                 return insert( std::lower_bound( std::list<ePtr<T> >::begin(), e, std::list<ePtr<T> >::end()), e );
808         }
809
810 };
811
812 /////////////////// iterator class /////////////////////////////
813 template <class T>
814 class eSmartPtrList<T>::iterator : public std::list<ePtr<T> >::iterator
815 {
816 public:
817         // Constructors
818         iterator(const std_list_T_iterator& Q)          : std_list_T_iterator(Q)        {       }
819
820         // changed operator for pointer
821         T* operator->() const
822         {
823                 return *std::list<ePtr<T> >::iterator::operator->();
824         }
825
826         operator T&() const
827         {
828                 return *operator->();
829         }
830         
831         operator T*() const
832         {
833                 return operator->();
834         }
835
836         iterator& operator++()
837         {
838                 std::list<ePtr<T> >::iterator::operator++();
839                 return *this;
840         }
841
842         iterator operator++(int)
843         {
844                 return std::list<ePtr<T> >::iterator::operator++(0);
845         }
846
847         iterator& operator--()
848         {
849                 std::list<ePtr<T> >::iterator::operator--();
850                 return *this;
851         }
852
853         iterator operator--(int)
854         {
855                 return std::list<ePtr<T> >::iterator::operator--(0);
856         }
857 };
858
859 /////////////////// const_iterator class /////////////////////////////
860 template <class T>
861 class eSmartPtrList<T>::const_iterator : public std::list<ePtr<T> >::const_iterator
862 {
863 public:
864         // Constructors
865         const_iterator(const std_list_T_const_iterator& Q)              :std_list_T_const_iterator(Q)   {       }
866
867         // changed operator for pointer
868         T* operator->() const
869         {
870                 return *std::list<ePtr<T> >::const_iterator::operator->();
871         }
872
873         operator T&() const
874         {
875                 return *operator->();
876         }
877
878         operator T*() const
879         {
880                 return operator->();
881         }
882
883         const_iterator& operator++()
884         {
885                 std::list<ePtr<T> >::const_iterator::operator++();
886                 return *this;
887         }
888
889         const_iterator operator++(int)
890         {
891                 return std::list<ePtr<T> >::const_iterator::operator++(0);
892         }
893
894         const_iterator& operator--()
895         {
896                 std::list<ePtr<T> >::const_iterator::operator--();
897                 return *this;
898         }
899
900         const_iterator operator--(int)
901         {
902                 return std::list<ePtr<T> >::const_iterator::operator--(0);
903         }
904 };
905
906 /////////////////// reverse_iterator class /////////////////////////////
907 template <class T>
908 class eSmartPtrList<T>::reverse_iterator : public std::list<ePtr<T> >::reverse_iterator
909 {
910 public:
911         // Constructors
912         reverse_iterator(const std_list_T_reverse_iterator& Q)          :std_list_T_reverse_iterator(Q) {       }
913
914         // changed operators for pointer
915         T* operator->() const
916         {
917                 return *std::list<ePtr<T> >::reverse_iterator::operator->();
918         }
919
920         operator T&() const
921         {
922                 return *operator->();
923         }
924
925         operator T*() const
926         {
927                 return operator->();
928         }
929
930         reverse_iterator& operator++()
931         {
932                 std::list<ePtr<T> >::reverse_iterator::operator++();
933                 return *this;
934         }
935
936         reverse_iterator operator++(int)
937         {
938                 return std::list<ePtr<T> >::reverse_iterator::operator++(0);
939         }
940
941         reverse_iterator& operator--()
942         {
943                 std::list<ePtr<T> >::reverse_iterator::operator--();
944                 return *this;
945         }
946
947         reverse_iterator operator--(int)
948         {
949                 return std::list<ePtr<T> >::reverse_iterator::operator--(0);
950         }
951 };
952
953 /////////////////// const_reverse_iterator class /////////////////////////////
954 template <class T>
955 class eSmartPtrList<T>::const_reverse_iterator : public std::list<ePtr<T> >::const_reverse_iterator
956 {
957 public:
958         // Constructors
959         const_reverse_iterator(const std_list_T_const_reverse_iterator& Q)              :std_list_T_const_reverse_iterator(Q)   {       }
960
961         // changed operators for pointer
962         T* operator->() const
963         {
964                 return *std::list<ePtr<T> >::const_reverse_iterator::operator->();
965         }
966
967         operator T&() const
968         {
969                 return *operator->();
970         }
971
972         operator T*() const
973         {
974                 return operator->();
975         }
976
977         const_reverse_iterator& operator++()
978         {
979                 std::list<ePtr<T> >::const_reverse_iterator::operator++();
980                 return *this;
981         }
982
983         const_reverse_iterator operator++(int)
984         {
985                 return std::list<ePtr<T> >::const_reverse_iterator::operator++(0);
986         }
987
988         const_reverse_iterator& operator--()
989         {
990                 std::list<ePtr<T> >::const_reverse_iterator::operator--();
991                 return *this;
992         }
993
994         const_reverse_iterator operator--(int)
995         {
996                 return std::list<ePtr<T> >::const_reverse_iterator::operator--(0);
997         }
998 };
999
1000 /////////////////// Default Constructor /////////////////////////////
1001 template <class T>
1002 eSmartPtrList<T>::eSmartPtrList()
1003     :cur(std::list<ePtr<T> >::begin())
1004 {               
1005
1006 }
1007
1008 /////////////////// Copy Constructor /////////////////////////////
1009 template <class T>
1010 eSmartPtrList<T>::eSmartPtrList(const eSmartPtrList& e)
1011         :std::list<ePtr<T> >(e), cur(e.cur)
1012 {               
1013 }
1014
1015 /////////////////// eSmartPtrList Destructor /////////////////////////////
1016 template <class T>
1017 inline eSmartPtrList<T>::~eSmartPtrList()
1018 {
1019 }
1020
1021
1022 /////////////////// eSmartPtrList sort() /////////////////////////
1023 template <class T>
1024 inline void eSmartPtrList<T>::sort()
1025 {               
1026 //      Sorts all items in the list.
1027 //      The type T must have a operator <.
1028         std::list<ePtr<T> >::sort(eSmartPtrList<T>::less());
1029 }       
1030
1031 /////////////////// eSmartPtrList remove(T*) /////////////////////////
1032 template <class T>
1033 inline void eSmartPtrList<T>::remove(T* t)
1034 {
1035 //      Remove all items that, equals to t, if auto-deletion is enabled, than the list call delete for the removed items
1036 //  If current is equal to one of the removed items, current is set to the next valid item
1037         T_iterator it(std::list<ePtr<T> >::begin());
1038
1039         while (it != std::list<ePtr<T> >::end())
1040                 if (*it == t)
1041                 {
1042                         it=erase(it);
1043                         break;  // one item is complete removed an deleted
1044                 }
1045                 else
1046                         it++;
1047         
1048         while (it != std::list<ePtr<T> >::end())
1049                 if (*it == t)
1050                         it = std::list<ePtr<T> >::erase(it);  // remove all other items that equals to t (no delete is called..)
1051                 else
1052                         it++;
1053                         
1054 }
1055
1056 /////////////////// eSmartPtrList clear() //////////////////
1057 template <class T>
1058 inline void eSmartPtrList<T>::clear()   
1059 {               
1060 //      Remove all items from the list
1061 //      If auto-deletion is enabled, than the list call delete for all items in the list
1062         erase(std::list<ePtr<T> >::begin(), std::list<ePtr<T> >::end());        
1063 }
1064
1065 /////////////////// eSmartPtrList pop_back() ////////////////////
1066 template <class T>
1067 inline void eSmartPtrList<T>::pop_back()
1068 {
1069 //      Removes the last item from the list. If the current item ist the last, than the current is set to the new
1070 //      last item in the list;
1071 //      The removed item is deleted if auto-deletion is enabled.
1072         erase(--end());
1073 }
1074
1075 /////////////////// eSmartPtrList pop_front() ////////////////////
1076 template <class T>
1077 inline void eSmartPtrList<T>::pop_front()
1078 {
1079 //      Removes the first item from the list. If the current item ist the first, than the current is set to the new
1080 //      first item in the list;
1081 //      The removed item is deleted if auto-deletion is enabled.
1082         erase(begin());
1083 }
1084
1085 /////////////////// eSmartPtrList push_back(T*) ////////////////////
1086 template <class T>
1087 inline void eSmartPtrList<T>::push_back(T* x)   
1088 {               
1089 // Add a new item at the end of the list.
1090 // The current item is set to the last item;
1091         std::list<ePtr<T> >::push_back(x);
1092         last(); 
1093 }
1094
1095 /////////////////// eSmartPtrList push_front(T*) ////////////////////
1096 template <class T>
1097 inline void eSmartPtrList<T>::push_front(T* x)  
1098 {               
1099 // Add a new item at the begin of the list.
1100 // The current item is set to the first item;
1101         std::list<ePtr<T> >::push_front(x);
1102         first();        
1103 }
1104
1105 /////////////////// eSmartPtrList setCurrent(T*) ////////////////////
1106 template <class T>
1107 inline T* eSmartPtrList<T>::setCurrent(const T* t)
1108 {
1109         // Sets the internal current iterator to the first element that equals to t, and returns t when a item is found,
1110         // otherwise it returns 0 !
1111         for (T_iterator it(std::list<ePtr<T> >::begin()); it != std::list<ePtr<T> >::end(); ++it)
1112                 if (*it == t)
1113                 {
1114                         cur = it;
1115                         return *it;
1116                 }
1117
1118         return 0;
1119 }
1120
1121 /////////////////// eSmartPtrList current() ////////////////////
1122 template <class T>
1123 inline T* eSmartPtrList<T>::current()
1124 {
1125 //      Returns a pointer to the current list item. The current item may be null (implies that the current index is -1).
1126         return cur==end() ? 0 : *cur;   
1127 }
1128
1129 /////////////////// eSmartPtrList next() ////////////////////
1130 template <class T>
1131 inline T* eSmartPtrList<T>::next()
1132 {
1133 //      Returns a pointer to the item succeeding the current item. Returns null if the current items is null or equal to the last item.
1134 //      Makes the succeeding item current. If the current item before this function call was the last item, the current item will be set to null. If the current item was null, this function does nothing.
1135         if (cur == end())
1136                 return 0;
1137         else
1138                 if (++cur == end())
1139                         return 0;
1140                 else
1141                         return *cur;
1142 }
1143
1144 /////////////////// eSmartPtrList prev() ////////////////////
1145 template <class T>
1146 inline T* eSmartPtrList<T>::prev()
1147 {
1148 //      Returns a pointer to the item preceding the current item. Returns null if the current items is null or equal to the first item.
1149 //      Makes the preceding item current. If the current item before this function call was the first item, the current item will be set to null. If the current item was null, this function does nothing.
1150         if (cur == begin())
1151                 return 0;
1152         else
1153                 return *--cur;
1154 }
1155
1156 /////////////////// eSmartPtrList first() ////////////////////
1157 template <class T>
1158 inline T* eSmartPtrList<T>::first()
1159 {
1160 // Returns a pointer to the first item in the list and makes this the current list item, or null if the list is empty.
1161         return *(cur = begin());        
1162 }
1163
1164 /////////////////// eSmartPtrList last() ////////////////////
1165 template <class T>
1166 inline T* eSmartPtrList<T>::last()
1167 {
1168 //      Returns a pointer to the last item in the list and makes this the current list item, or null if the list is empty.
1169         return *(cur = --end());
1170 }
1171
1172 /////////////////// const eSmartPtrList current() ////////////////////
1173 template <class T>
1174 inline const T* eSmartPtrList<T>::current() const
1175 {
1176 //      Returns a pointer to the current list item. The current item may be null (implies that the current index is not valid)
1177         return cur==end() ? 0 : *cur;   
1178 }
1179
1180 /////////////////// const eSmartPtrList next() ////////////////////
1181 template <class T>
1182 inline const T* eSmartPtrList<T>::next() const
1183 {
1184 //      Returns a pointer to the item succeeding the current item. Returns null if the current items is null or equal to the last item.
1185 //      Makes the succeeding item current. If the current item before this function call was the last item, the current item will be set to null. If the current item was null, this function does nothing.
1186         if (cur == end())
1187                 return 0;
1188         else
1189                 if (++cur == end())
1190                         return 0;
1191                 else
1192                         return *cur;
1193 }
1194
1195 /////////////////// const eSmartPtrList prev() ////////////////////
1196 template <class T>
1197 inline const T* eSmartPtrList<T>::prev() const
1198 {
1199 //      Returns a pointer to the item preceding the current item. Returns null if the current items is null or equal to the first item.
1200 //      Makes the preceding item current. If the current item before this function call was the first item, the current item will be set to null. If the current item was null, this function does nothing.
1201         if (cur == begin())
1202                 return 0;
1203         else
1204                 return *--cur;
1205 }
1206
1207 /////////////////// const eSmartPtrList first() ////////////////////
1208 template <class T>
1209 inline const T* eSmartPtrList<T>::first() const
1210 {
1211 // Returns a pointer to the first item in the list and makes this the current list item, or null if the list is empty.
1212         return *(cur = begin());        
1213 }
1214
1215 /////////////////// const eSmartPtrList last() ////////////////////
1216 template <class T>
1217 inline const T* eSmartPtrList<T>::last() const
1218 {
1219 //      Returns a pointer to the last item in the list and makes this the current list item, or null if the list is empty.
1220         return *(cur = --end());
1221 }
1222
1223 ////////////////// struct less //////////////////////////////
1224 template <class T>
1225 struct eSmartPtrList<T>::less
1226 {
1227 //      operator() is used internal from the list to sort them
1228         bool operator() (const T* t1, const T* t2)
1229         {
1230                 return (*t1 < *t2);
1231         }
1232 };
1233
1234 /////////////////// eSmartPtrList operator bool ////////////////////
1235 template <class T>
1236 eSmartPtrList<T>::operator bool()       
1237 {
1238 //      Returns a bool that contains true, when the list is NOT empty otherwise false
1239         return !std::list<T>::empty();  
1240 }
1241
1242 template <class T>
1243 bool eSmartPtrList<T>::operator!()      
1244 {
1245 //      Returns a bool that contains true, when the list is empty otherwise false
1246         return std::list<T>::empty();   
1247 }
1248
1249 #endif // _E_PTRLIST