00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef POINTAINER_H
00032 #define POINTAINER_H
00033
00034 #ifdef NO_MEMBER_TEMPLATES
00035 #include <functional>
00036 #endif
00037
00038 template <typename Cnt>
00039 class pointainer : public Cnt
00040 {
00041 public:
00042 using typename Cnt::size_type;
00043 using typename Cnt::difference_type;
00044 using typename Cnt::reference;
00045 using typename Cnt::const_reference;
00046 using typename Cnt::value_type;
00047 using typename Cnt::iterator;
00048 using typename Cnt::const_iterator;
00049 using typename Cnt::reverse_iterator;
00050 using typename Cnt::const_reverse_iterator;
00051 typedef pointainer<Cnt> its_type;
00052
00053 pointainer() {}
00054 pointainer(const Cnt& c) : Cnt(c) {}
00055 its_type& operator=(const Cnt& c) {Cnt::operator=(c); return *this;}
00056 ~pointainer() {clean_all();}
00057
00058 void clear() {clean_all(); Cnt::clear();}
00059 iterator erase(iterator i) {clean(i); return Cnt::erase(i);}
00060 iterator erase(iterator f, iterator l) {clean(f,l); return Cnt::erase(f,l);}
00061
00062
00063 size_type erase(const value_type& v)
00064 {
00065 iterator i = find(v);
00066 size_type found(i != end());
00067 if (found)
00068 erase(i);
00069 return found;
00070 }
00071
00072
00073 void pop_front() {clean(begin()); Cnt::pop_front();}
00074 void pop_back() {iterator i(end()); clean(--i); Cnt::pop_back();}
00075 void resize(size_type s, value_type c = value_type())
00076 {
00077 if (s < size())
00078 clean(begin()+s, end());
00079 Cnt::resize(s, c);
00080 }
00081 #ifndef NO_MEMBER_TEMPLATES
00082 template <class InIter> void assign(InIter f, InIter l)
00083 #else
00084 void assign(iterator f, iterator l)
00085 #endif
00086 {
00087 clean_all();
00088 Cnt::assign(f,l);
00089 }
00090 #ifndef NO_MEMBER_TEMPLATES
00091 template <class Size, class T> void assign(Size n, const T& t = T())
00092 #else
00093 void assign(size_t n, const value_type& t = value_type())
00094 #endif
00095 {
00096 clean_all();
00097 Cnt::assign(n,t);
00098 }
00099
00100
00101 void remove(const value_type& v)
00102 {
00103 clean( std::find(begin(), end(), v) );
00104 Cnt::remove(v);
00105 }
00106 #ifndef NO_MEMBER_TEMPLATES
00107 template <class Pred>
00108 #else
00109 typedef std::binder2nd<std::not_equal_to<value_type> > Pred;
00110 #endif
00111 void remove_if(Pred pr)
00112 {
00113 for (iterator i = begin(); i != end(); ++i)
00114 if (pr(*i))
00115 clean(i);
00116 Cnt::remove_if(pr);
00117 }
00118
00119 private:
00120 void clean(iterator i) {delete *i;}
00121 void clean(iterator f, iterator l) {while (f != l) clean(f++);}
00122 void clean_all() {clean( begin(), end() );}
00123
00124
00125 pointainer(const its_type&) {}
00126 its_type& operator=(const its_type&) {}
00127 };
00128
00129 #endif // POINTAINER_H