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