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