#ifndef _E_PTRLIST_ #define _E_PTRLIST_ #include #include #include template class ePtrList : public std::list { public: typedef typename std::list >::iterator std_list_T_iterator; // to remove compiler warnings typedef typename std::list >::const_iterator std_list_T_const_iterator; typedef typename std::list >::reverse_iterator std_list_T_reverse_iterator; typedef typename std::list >::const_reverse_iterator std_list_T_const_reverse_iterator; typedef typename ePtrList::iterator T_iterator; typedef typename ePtrList::const_iterator T_const_iterator; typedef typename ePtrList::reverse_iterator T_reverse_iterator; typedef typename ePtrList::const_reverse_iterator T_const_reverse_iterator; // Iterator classes class iterator; class const_iterator; class reverse_iterator; class const_reverse_iterator; // Constructors inline ePtrList(); inline ePtrList(const ePtrList&); inline ~ePtrList(); // overwritted sort method inline void sort(); // changed methods for autodelete and current implementation inline void remove(T* t); inline void clear(); inline void pop_back(); inline void pop_front(); inline void push_back(T*); inline void push_front(T*); // added methods for current implementation inline T* take(); inline void take(T* t); inline T* current(); inline T* next(); inline T* prev(); inline T* first(); inline T* last(); inline T* setCurrent(const T*); inline const T* current() const; inline const T* next() const; inline const T* prev() const; inline const T* first() const; inline const T* last() const; // added operator methods inline operator bool(); inline bool operator!(); // added methods for autodelete implementation inline void setAutoDelete(bool b); inline bool isAutoDelete(); // added compare struct ... to sort struct less; private: iterator cur; bool autoDelete; public: iterator ePtrList::begin() { // makes implicit type conversion form std::list::iterator to ePtrList::iterator return std::list::begin(); } iterator ePtrList::end() { // makes implicit type conversion form std::list::iterator to ePtrList::iterator return std::list::end(); } const_iterator ePtrList::begin() const { // makes implicit type conversion form std::list::const_iterator to ePtrList::const_iterator return std::list::begin(); } const_iterator ePtrList::end() const { // makes implicit type conversion form std::list::const_iterator to ePtrList::const_iterator return std::list::end(); } reverse_iterator ePtrList::rbegin() { // makes implicit type conversion form std::list::reverse:_iterator to ePtrList::reverse_iterator return std::list::rbegin(); } reverse_iterator ePtrList::rend() { // makes implicit type conversion form std::list::reverse_iterator to ePtrList::reverse_iterator return std::list::rend(); } const_reverse_iterator ePtrList::rbegin() const { // makes implicit type conversion form std::list::const_reverse_iterator to ePtrList::const_reverse_iterator return std::list::rbegin(); } const_reverse_iterator ePtrList::rend() const { // makes implicit type conversion form std::list::const_reverse_iterator to ePtrList::const_reverse_iterator return std::list::rend(); } iterator ePtrList::erase(iterator it) { // Remove the item it, if auto-deletion is enabled, than the list call delete for this item // If current is equal to the item that was removed, current is set to the next item in the list if (autoDelete && *it) delete *it; if (cur == it) return cur = std::list::erase(it); else return std::list::erase(it); } iterator ePtrList::erase(iterator from, iterator to) { // Remove all items between the to iterators from and to // If auto-deletion is enabled, than the list call delete for all removed items while (from != to) from = erase(from); return from; } operator iterator() { // Returns a iterator that equal to begin() of the list return begin(); } operator const_iterator() const { // Returns a const_iterator that equal to begin() of the list return begin(); } operator reverse_iterator() { // Returns a reverse_iterator that equal to rbegin() of the list return rbegin(); } operator const_reverse_iterator() const { // Returns a const_reverse_iterator that equal to rbegin() of the list return rbegin(); } std::vector* getVector() { // Creates an vector and copys all elements to this vector // returns a pointer to this new vector ( the reserved memory must deletet from the receiver !! ) std::vector* v=new std::vector(); v->reserve( size() ); for ( std_list_T_iterator it( std::list::begin() ); it != std::list::end(); it++) v->push_back( **it ); return v; } inline iterator insert_in_order( T* e ) { // added a new item to the list... in order // returns a iterator to the new item return insert( std::lower_bound( std::list::begin(), std::list::end(), e ), e ); } }; /////////////////// iterator class ///////////////////////////// template class ePtrList::iterator : public std::list::iterator { public: // Constructors iterator(const std_list_T_iterator& Q) : std_list_T_iterator(Q) { } // changed operator for pointer T* operator->() const { return *std::list::iterator::operator->(); } operator T&() const { return *operator->(); } operator T*() const { return operator->(); } iterator& operator++() { std::list::iterator::operator++(); return *this; } iterator operator++(int) { return std::list::iterator::operator++(0); } iterator& operator--() { std::list::iterator::operator--(); return *this; } iterator operator--(int) { return std::list::iterator::operator--(0); } }; /////////////////// const_iterator class ///////////////////////////// template class ePtrList::const_iterator : public std::list::const_iterator { public: // Constructors const_iterator(const std_list_T_const_iterator& Q) :std_list_T_const_iterator(Q) { } // changed operator for pointer T* operator->() const { return *std::list::const_iterator::operator->(); } operator T&() const { return *operator->(); } operator T*() const { return operator->(); } const_iterator& operator++() { std::list::const_iterator::operator++(); return *this; } const_iterator operator++(int) { return std::list::const_iterator::operator++(0); } const_iterator& operator--() { std::list::const_iterator::operator--(); return *this; } const_iterator operator--(int) { return std::list::const_iterator::operator--(0); } }; /////////////////// reverse_iterator class ///////////////////////////// template class ePtrList::reverse_iterator : public std::list::reverse_iterator { public: // Constructors reverse_iterator(const std_list_T_reverse_iterator& Q) :std_list_T_reverse_iterator(Q) { } // changed operators for pointer T* operator->() const { return *std::list::reverse_iterator::operator->(); } operator T&() const { return *operator->(); } operator T*() const { return operator->(); } reverse_iterator& operator++() { std::list::reverse_iterator::operator++(); return *this; } reverse_iterator operator++(int) { return std::list::reverse_iterator::operator++(0); } reverse_iterator& operator--() { std::list::reverse_iterator::operator--(); return *this; } reverse_iterator operator--(int) { return std::list::reverse_iterator::operator--(0); } }; /////////////////// const_reverse_iterator class ///////////////////////////// template class ePtrList::const_reverse_iterator : public std::list::const_reverse_iterator { public: // Constructors const_reverse_iterator(const std_list_T_const_reverse_iterator& Q) :std_list_T_const_reverse_iterator(Q) { } // changed operators for pointer T* operator->() const { return *std::list::const_reverse_iterator::operator->(); } operator T&() const { return *operator->(); } operator T*() const { return operator->(); } const_reverse_iterator& operator++() { std::list::const_reverse_iterator::operator++(); return *this; } const_reverse_iterator operator++(int) { return std::list::const_reverse_iterator::operator++(0); } const_reverse_iterator& operator--() { std::list::const_reverse_iterator::operator--(); return *this; } const_reverse_iterator operator--(int) { return std::list::const_reverse_iterator::operator--(0); } }; /////////////////// Default Constructor ///////////////////////////// template ePtrList::ePtrList() :cur(std::list::begin()), autoDelete(false) { } /////////////////// Copy Constructor ///////////////////////////// template ePtrList::ePtrList(const ePtrList& e) :std::list(e), cur(e.cur), autoDelete( false ) { if ( e.autoDelete ) if ( e.size() ) eDebug("Warning !! We make a Copy of a non empty ePtrList, with autoDelete enabled" "We disable autoDelete in the new ePtrList !!"); else autoDelete=true; } /////////////////// ePtrList Destructor ///////////////////////////// template inline ePtrList::~ePtrList() { // if autoDelete is enabled, delete is called for all elements in the list if (autoDelete) for (std_list_T_iterator it(std::list::begin()); it != std::list::end(); it++) delete *it; } /////////////////// ePtrList sort() ///////////////////////// template inline void ePtrList::sort() { // Sorts all items in the list. // The type T must have a operator <. std::list::sort(ePtrList::less()); } /////////////////// ePtrList remove(T*) ///////////////////////// template inline void ePtrList::remove(T* t) { // Remove all items that, equals to t, if auto-deletion is enabled, than the list call delete for the removed items // If current is equal to one of the removed items, current is set to the next valid item T_iterator it(std::list::begin()); while (it != std::list::end()) if (*it == t) { it=erase(it); break; // one item is complete removed an deleted } else it++; while (it != std::list::end()) if (*it == t) it = std::list::erase(it); // remove all other items that equals to t (no delete is called..) else it++; } /////////////////// ePtrList clear() ////////////////// template inline void ePtrList::clear() { // Remove all items from the list // If auto-deletion is enabled, than the list call delete for all items in the list erase(std::list::begin(), std::list::end()); } /////////////////// ePtrList pop_back() //////////////////// template inline void ePtrList::pop_back() { // Removes the last item from the list. If the current item ist the last, than the current is set to the new // last item in the list; // The removed item is deleted if auto-deletion is enabled. erase(--end()); } /////////////////// ePtrList pop_front() //////////////////// template inline void ePtrList::pop_front() { // Removes the first item from the list. If the current item ist the first, than the current is set to the new // first item in the list; // The removed item is deleted if auto-deletion is enabled. erase(begin()); } /////////////////// ePtrList push_back(T*) //////////////////// template inline void ePtrList::push_back(T* x) { // Add a new item at the end of the list. // The current item is set to the last item; std::list::push_back(x); last(); } /////////////////// ePtrList push_front(T*) //////////////////// template inline void ePtrList::push_front(T* x) { // Add a new item at the begin of the list. // The current item is set to the first item; std::list::push_front(x); first(); } /////////////////// ePtrList take() //////////////////// template inline T* ePtrList::take() { // Takes the current item out of the list without deleting it (even if auto-deletion is enabled). // Returns a pointer to the item taken out of the list, or null if the index is out of range. // 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. // The current item is set to null if the list becomes empty. T* tmp = *cur; cur = std::list::erase(cur); return tmp; } /////////////////// ePtrList take(T*) //////////////////// template inline void ePtrList::take(T* t) { // Takes all item with T* out of the list without deleting it (even if auto-deletion is enabled). std::list::remove(t); } /////////////////// ePtrList setCurrent(T*) //////////////////// template inline T* ePtrList::setCurrent(const T* t) { // Sets the internal current iterator to the first element that equals to t, and returns t when a item is found, // otherwise it returns 0 ! for (T_iterator it(std::list::begin()); it != std::list::end(); ++it) if (*it == t) { cur = it; return *it; } return 0; } /////////////////// ePtrList current() //////////////////// template inline T* ePtrList::current() { // Returns a pointer to the current list item. The current item may be null (implies that the current index is -1). return cur==end() ? 0 : *cur; } /////////////////// ePtrList next() //////////////////// template inline T* ePtrList::next() { // Returns a pointer to the item succeeding the current item. Returns null if the current items is null or equal to the last item. // 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. if (cur == end()) return 0; else if (++cur == end()) return 0; else return *cur; } /////////////////// ePtrList prev() //////////////////// template inline T* ePtrList::prev() { // Returns a pointer to the item preceding the current item. Returns null if the current items is null or equal to the first item. // 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. if (cur == begin()) return 0; else return *--cur; } /////////////////// ePtrList first() //////////////////// template inline T* ePtrList::first() { // Returns a pointer to the first item in the list and makes this the current list item, or null if the list is empty. return *(cur = begin()); } /////////////////// ePtrList last() //////////////////// template inline T* ePtrList::last() { // Returns a pointer to the last item in the list and makes this the current list item, or null if the list is empty. return *(cur = --end()); } /////////////////// const ePtrList current() //////////////////// template inline const T* ePtrList::current() const { // Returns a pointer to the current list item. The current item may be null (implies that the current index is not valid) return cur==end() ? 0 : *cur; } /////////////////// const ePtrList next() //////////////////// template inline const T* ePtrList::next() const { // Returns a pointer to the item succeeding the current item. Returns null if the current items is null or equal to the last item. // 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. if (cur == end()) return 0; else if (++cur == end()) return 0; else return *cur; } /////////////////// const ePtrList prev() //////////////////// template inline const T* ePtrList::prev() const { // Returns a pointer to the item preceding the current item. Returns null if the current items is null or equal to the first item. // 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. if (cur == begin()) return 0; else return *--cur; } /////////////////// const ePtrList first() //////////////////// template inline const T* ePtrList::first() const { // Returns a pointer to the first item in the list and makes this the current list item, or null if the list is empty. return *(cur = begin()); } /////////////////// const ePtrList last() //////////////////// template inline const T* ePtrList::last() const { // Returns a pointer to the last item in the list and makes this the current list item, or null if the list is empty. return *(cur = --end()); } ////////////////// struct less ////////////////////////////// template struct ePtrList::less { // operator() is used internal from the list to sort them bool operator() (const T* t1, const T* t2) { return (*t1 < *t2); } }; /////////////////// ePtrList operator bool //////////////////// template ePtrList::operator bool() { // Returns a bool that contains true, when the list is NOT empty otherwise false return !empty(); } template bool ePtrList::operator!() { // Returns a bool that contains true, when the list is empty otherwise false return empty(); } template void ePtrList::setAutoDelete(bool b) { // switched autoDelete on or off // if autoDelete is true, than the pointer list controls the heap memory behind the pointer itself // the list calls delete for the item before it removed from the list autoDelete=b; } template bool ePtrList::isAutoDelete() { // returns a bool that contains the state of autoDelete return autoDelete; } template class eSmartPtrList : public std::list > { public: typedef typename std::list, std::allocator > >::iterator std_list_T_iterator; // to remove compiler warnings typedef typename std::list, std::allocator > >::const_iterator std_list_T_const_iterator; typedef typename std::list, std::allocator > >::reverse_iterator std_list_T_reverse_iterator; typedef typename std::list, std::allocator > >::const_reverse_iterator std_list_T_const_reverse_iterator; typedef typename eSmartPtrList::iterator T_iterator; typedef typename eSmartPtrList::const_iterator T_const_iterator; typedef typename eSmartPtrList::reverse_iterator T_reverse_iterator; typedef typename eSmartPtrList::const_reverse_iterator T_const_reverse_iterator; // Iterator classes class iterator; class const_iterator; class reverse_iterator; class const_reverse_iterator; // Constructors inline eSmartPtrList(); inline eSmartPtrList(const eSmartPtrList&); inline ~eSmartPtrList(); // overwritted sort method inline void sort(); // changed methods for autodelete and current implementation inline void remove(T* t); inline void clear(); inline void pop_back(); inline void pop_front(); inline void push_back(T*); inline void push_front(T*); // added methods for current implementation // inline T* take(); // inline void take(T* t); inline T* current(); inline T* next(); inline T* prev(); inline T* first(); inline T* last(); inline T* setCurrent(const T*); inline const T* current() const; inline const T* next() const; inline const T* prev() const; inline const T* first() const; inline const T* last() const; // added operator methods inline operator bool(); inline bool operator!(); // added methods for autodelete implementation inline void setAutoDelete(bool b); inline bool isAutoDelete(); // added compare struct ... to sort struct less; private: iterator cur; bool autoDelete; public: iterator eSmartPtrList::begin() { // makes implicit type conversion form std::list::iterator to eSmartPtrList::iterator return std::list >::begin(); } iterator eSmartPtrList::end() { // makes implicit type conversion form std::list::iterator to eSmartPtrList::iterator return std::list >::end(); } const_iterator eSmartPtrList::begin() const { // makes implicit type conversion form std::list::const_iterator to eSmartPtrList::const_iterator return std::list >::begin(); } const_iterator eSmartPtrList::end() const { // makes implicit type conversion form std::list::const_iterator to eSmartPtrList::const_iterator return std::list >::end(); } reverse_iterator eSmartPtrList::rbegin() { // makes implicit type conversion form std::list::reverse:_iterator to eSmartPtrList::reverse_iterator return std::list >::rbegin(); } reverse_iterator eSmartPtrList::rend() { // makes implicit type conversion form std::list::reverse_iterator to eSmartPtrList::reverse_iterator return std::list >::rend(); } const_reverse_iterator eSmartPtrList::rbegin() const { // makes implicit type conversion form std::list::const_reverse_iterator to eSmartPtrList::const_reverse_iterator return std::list >::rbegin(); } const_reverse_iterator eSmartPtrList::rend() const { // makes implicit type conversion form std::list::const_reverse_iterator to eSmartPtrList::const_reverse_iterator return std::list >::rend(); } iterator eSmartPtrList::erase(iterator it) { // Remove the item it, if auto-deletion is enabled, than the list call delete for this item // If current is equal to the item that was removed, current is set to the next item in the list if (autoDelete && *it) delete *it; if (cur == it) return cur = std::list >::erase(it); else return std::list >::erase(it); } iterator eSmartPtrList::erase(iterator from, iterator to) { // Remove all items between the to iterators from and to // If auto-deletion is enabled, than the list call delete for all removed items while (from != to) from = erase(from); return from; } operator iterator() { // Returns a iterator that equal to begin() of the list return begin(); } operator const_iterator() const { // Returns a const_iterator that equal to begin() of the list return begin(); } operator reverse_iterator() { // Returns a reverse_iterator that equal to rbegin() of the list return rbegin(); } operator const_reverse_iterator() const { // Returns a const_reverse_iterator that equal to rbegin() of the list return rbegin(); } std::vector* getVector() { // Creates an vector and copys all elements to this vector // returns a pointer to this new vector ( the reserved memory must deletet from the receiver !! ) std::vector* v=new std::vector(); v->reserve( size() ); for ( std_list_T_iterator it( std::list >::begin() ); it != std::list >::end(); it++) v->push_back( **it ); return v; } inline iterator insert_in_order( T* e ) { // added a new item to the list... in order // returns a iterator to the new item return insert( std::lower_bound( std::list >::begin(), std::list >::end(), e ), e ); } }; /////////////////// iterator class ///////////////////////////// template class eSmartPtrList::iterator : public std::list >::iterator { public: // Constructors iterator(const std_list_T_iterator& Q) : std_list_T_iterator(Q) { } // changed operator for pointer T* operator->() const { return *std::list >::iterator::operator->(); } operator T&() const { return *operator->(); } operator T*() const { return operator->(); } iterator& operator++() { std::list >::iterator::operator++(); return *this; } iterator operator++(int) { return std::list >::iterator::operator++(0); } iterator& operator--() { std::list >::iterator::operator--(); return *this; } iterator operator--(int) { return std::list >::iterator::operator--(0); } }; /////////////////// const_iterator class ///////////////////////////// template class eSmartPtrList::const_iterator : public std::list >::const_iterator { public: // Constructors const_iterator(const std_list_T_const_iterator& Q) :std_list_T_const_iterator(Q) { } // changed operator for pointer T* operator->() const { return *std::list >::const_iterator::operator->(); } operator T&() const { return *operator->(); } operator T*() const { return operator->(); } const_iterator& operator++() { std::list >::const_iterator::operator++(); return *this; } const_iterator operator++(int) { return std::list >::const_iterator::operator++(0); } const_iterator& operator--() { std::list >::const_iterator::operator--(); return *this; } const_iterator operator--(int) { return std::list >::const_iterator::operator--(0); } }; /////////////////// reverse_iterator class ///////////////////////////// template class eSmartPtrList::reverse_iterator : public std::list >::reverse_iterator { public: // Constructors reverse_iterator(const std_list_T_reverse_iterator& Q) :std_list_T_reverse_iterator(Q) { } // changed operators for pointer T* operator->() const { return *std::list >::reverse_iterator::operator->(); } operator T&() const { return *operator->(); } operator T*() const { return operator->(); } reverse_iterator& operator++() { std::list >::reverse_iterator::operator++(); return *this; } reverse_iterator operator++(int) { return std::list >::reverse_iterator::operator++(0); } reverse_iterator& operator--() { std::list >::reverse_iterator::operator--(); return *this; } reverse_iterator operator--(int) { return std::list >::reverse_iterator::operator--(0); } }; /////////////////// const_reverse_iterator class ///////////////////////////// template class eSmartPtrList::const_reverse_iterator : public std::list >::const_reverse_iterator { public: // Constructors const_reverse_iterator(const std_list_T_const_reverse_iterator& Q) :std_list_T_const_reverse_iterator(Q) { } // changed operators for pointer T* operator->() const { return *std::list >::const_reverse_iterator::operator->(); } operator T&() const { return *operator->(); } operator T*() const { return operator->(); } const_reverse_iterator& operator++() { std::list >::const_reverse_iterator::operator++(); return *this; } const_reverse_iterator operator++(int) { return std::list >::const_reverse_iterator::operator++(0); } const_reverse_iterator& operator--() { std::list >::const_reverse_iterator::operator--(); return *this; } const_reverse_iterator operator--(int) { return std::list >::const_reverse_iterator::operator--(0); } }; /////////////////// Default Constructor ///////////////////////////// template eSmartPtrList::eSmartPtrList() :cur(std::list >::begin()), autoDelete(false) { } /////////////////// Copy Constructor ///////////////////////////// template eSmartPtrList::eSmartPtrList(const eSmartPtrList& e) :std::list >(e), cur(e.cur), autoDelete( false ) { if ( e.autoDelete ) if ( e.size() ) eDebug("Warning !! We make a Copy of a non empty eSmartPtrList, with autoDelete enabled" "We disable autoDelete in the new eSmartPtrList !!"); else autoDelete=true; } /////////////////// eSmartPtrList Destructor ///////////////////////////// template inline eSmartPtrList::~eSmartPtrList() { // if autoDelete is enabled, delete is called for all elements in the list if (autoDelete) for (std_list_T_iterator it(std::list >::begin()); it != std::list >::end(); it++) delete *it; } /////////////////// eSmartPtrList sort() ///////////////////////// template inline void eSmartPtrList::sort() { // Sorts all items in the list. // The type T must have a operator <. std::list >::sort(eSmartPtrList::less()); } /////////////////// eSmartPtrList remove(T*) ///////////////////////// template inline void eSmartPtrList::remove(T* t) { // Remove all items that, equals to t, if auto-deletion is enabled, than the list call delete for the removed items // If current is equal to one of the removed items, current is set to the next valid item T_iterator it(std::list >::begin()); while (it != std::list >::end()) if (*it == t) { it=erase(it); break; // one item is complete removed an deleted } else it++; while (it != std::list >::end()) if (*it == t) it = std::list >::erase(it); // remove all other items that equals to t (no delete is called..) else it++; } /////////////////// eSmartPtrList clear() ////////////////// template inline void eSmartPtrList::clear() { // Remove all items from the list // If auto-deletion is enabled, than the list call delete for all items in the list erase(std::list >::begin(), std::list >::end()); } /////////////////// eSmartPtrList pop_back() //////////////////// template inline void eSmartPtrList::pop_back() { // Removes the last item from the list. If the current item ist the last, than the current is set to the new // last item in the list; // The removed item is deleted if auto-deletion is enabled. erase(--end()); } /////////////////// eSmartPtrList pop_front() //////////////////// template inline void eSmartPtrList::pop_front() { // Removes the first item from the list. If the current item ist the first, than the current is set to the new // first item in the list; // The removed item is deleted if auto-deletion is enabled. erase(begin()); } /////////////////// eSmartPtrList push_back(T*) //////////////////// template inline void eSmartPtrList::push_back(T* x) { // Add a new item at the end of the list. // The current item is set to the last item; std::list >::push_back(x); last(); } /////////////////// eSmartPtrList push_front(T*) //////////////////// template inline void eSmartPtrList::push_front(T* x) { // Add a new item at the begin of the list. // The current item is set to the first item; std::list >::push_front(x); first(); } /////////////////// eSmartPtrList take() //////////////////// //template //inline T* eSmartPtrList::take() //{ //// Takes the current item out of the list without deleting it (even if auto-deletion is enabled). //// Returns a pointer to the item taken out of the list, or null if the index is out of range. //// 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. //// The current item is set to null if the list becomes empty. // T* tmp = *cur; // cur = std::list::erase(cur); // return tmp; //} /////////////////// eSmartPtrList take(T*) //////////////////// //template //inline void eSmartPtrList::take(T* t) //{ //// Takes all item with T* out of the list without deleting it (even if auto-deletion is enabled). // std::list::remove(t); //} /////////////////// eSmartPtrList setCurrent(T*) //////////////////// template inline T* eSmartPtrList::setCurrent(const T* t) { // Sets the internal current iterator to the first element that equals to t, and returns t when a item is found, // otherwise it returns 0 ! for (T_iterator it(std::list >::begin()); it != std::list >::end(); ++it) if (*it == t) { cur = it; return *it; } return 0; } /////////////////// eSmartPtrList current() //////////////////// template inline T* eSmartPtrList::current() { // Returns a pointer to the current list item. The current item may be null (implies that the current index is -1). return cur==end() ? 0 : *cur; } /////////////////// eSmartPtrList next() //////////////////// template inline T* eSmartPtrList::next() { // Returns a pointer to the item succeeding the current item. Returns null if the current items is null or equal to the last item. // 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. if (cur == end()) return 0; else if (++cur == end()) return 0; else return *cur; } /////////////////// eSmartPtrList prev() //////////////////// template inline T* eSmartPtrList::prev() { // Returns a pointer to the item preceding the current item. Returns null if the current items is null or equal to the first item. // 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. if (cur == begin()) return 0; else return *--cur; } /////////////////// eSmartPtrList first() //////////////////// template inline T* eSmartPtrList::first() { // Returns a pointer to the first item in the list and makes this the current list item, or null if the list is empty. return *(cur = begin()); } /////////////////// eSmartPtrList last() //////////////////// template inline T* eSmartPtrList::last() { // Returns a pointer to the last item in the list and makes this the current list item, or null if the list is empty. return *(cur = --end()); } /////////////////// const eSmartPtrList current() //////////////////// template inline const T* eSmartPtrList::current() const { // Returns a pointer to the current list item. The current item may be null (implies that the current index is not valid) return cur==end() ? 0 : *cur; } /////////////////// const eSmartPtrList next() //////////////////// template inline const T* eSmartPtrList::next() const { // Returns a pointer to the item succeeding the current item. Returns null if the current items is null or equal to the last item. // 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. if (cur == end()) return 0; else if (++cur == end()) return 0; else return *cur; } /////////////////// const eSmartPtrList prev() //////////////////// template inline const T* eSmartPtrList::prev() const { // Returns a pointer to the item preceding the current item. Returns null if the current items is null or equal to the first item. // 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. if (cur == begin()) return 0; else return *--cur; } /////////////////// const eSmartPtrList first() //////////////////// template inline const T* eSmartPtrList::first() const { // Returns a pointer to the first item in the list and makes this the current list item, or null if the list is empty. return *(cur = begin()); } /////////////////// const eSmartPtrList last() //////////////////// template inline const T* eSmartPtrList::last() const { // Returns a pointer to the last item in the list and makes this the current list item, or null if the list is empty. return *(cur = --end()); } ////////////////// struct less ////////////////////////////// template struct eSmartPtrList::less { // operator() is used internal from the list to sort them bool operator() (const T* t1, const T* t2) { return (*t1 < *t2); } }; /////////////////// eSmartPtrList operator bool //////////////////// template eSmartPtrList::operator bool() { // Returns a bool that contains true, when the list is NOT empty otherwise false return !empty(); } template bool eSmartPtrList::operator!() { // Returns a bool that contains true, when the list is empty otherwise false return empty(); } template void eSmartPtrList::setAutoDelete(bool b) { // switched autoDelete on or off // if autoDelete is true, than the pointer list controls the heap memory behind the pointer itself // the list calls delete for the item before it removed from the list autoDelete=b; } template bool eSmartPtrList::isAutoDelete() { // returns a bool that contains the state of autoDelete return autoDelete; } #endif // _E_PTRLIST