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