13 #endif // _MSC_VER > 1000
35 typedef typename std::list<T*>::iterator
iterator;
39 typedef typename std::list<T*>::reference
reference;
41 typedef typename std::list<T*>::size_type
size_type;
47 MG_DLL_DECLR
friend std::ostream& operator<< (std::ostream& out, const MGPlist<T>& lst);
65 explicit MGPlist(size_type n) : m_list(n, 0){;}
68 template <
class InputIter>
91 template <
class InputIter>
92 void assign(InputIter first, InputIter last){
93 iterator cur=
begin(), finish =
end();
94 for(; first != last && cur != finish; ++first, ++cur){
95 delete *cur; *cur = *first;
97 (first == last) ?
erase(cur, finish) :
insert(finish, first, last);
103 return m_list.back();
106 return m_list.back();
111 return m_list.begin();
114 return m_list.begin();
119 iterator first =
begin(), last =
end();
120 for(; first != last; ++first)
128 return m_list.empty();
132 const_iterator
end()
const{
142 return m_list.erase(x);
145 iterator
erase(iterator first, iterator last){
146 for(; first != last; ++first)
delete *first;
147 return m_list.erase(first, last);
152 const_iterator
find(T* obj)
const{
153 return std::find(
begin(),
end(),obj);
156 return std::find(
begin(),
end(),obj);
162 return m_list.front();
165 return m_list.front();
171 return m_list.insert(it,x);
175 template <
class InputIter>
176 void insert(iterator pos, InputIter first, InputIter last){
177 for(; first != last; ++first)
insert(pos, *first);
182 return m_list.max_size();
192 delete m_list.back();
198 delete m_list.front();
213 m_list.push_front(x);
218 return m_list.rbegin();
221 return m_list.rbegin();
225 const_reverse_iterator
rend()
const{
226 return m_list.rend();
229 return m_list.rend();
235 return m_list.erase(i);
245 template <
class Pred>
247 iterator first =
begin(), last =
end();
248 while(first != last){
249 iterator next = first;
251 if(pred(*first)) m_list.erase(first);
269 size_type
size()
const{
return m_list.size();}
274 template<
class Traits>
275 void sort(Traits _Comp){m_list.sort(_Comp);}
278 m_list.splice(pos, ls.
m_list);
281 m_list.splice(pos, ls.
m_list, i);
284 m_list.splice(pos, ls.
m_list, first, last);
300 iterator first = begin(), last = end();
301 for(; first != last; ++first)
delete *first;
316 std::ostream& operator<< (std::ostream& out, const MGPlist<T>& lst){
317 out <<
"MGPlist<T>::";
319 out<<
"number of entries="<<n<<std::endl;
321 for(itr=lst.
begin(); itr!=lst.
end(); itr++){
322 out<<i++<<
":"<<(*itr)<<std::endl;
323 if(*itr) out << (**itr) << std::endl;
void pop_front()
pop first element.
Definition: Plist.h:197
iterator end()
Definition: Plist.h:135
std::list< T * >::iterator iterator
Definition: Plist.h:35
bool empty() const
Definition: Plist.h:127
std::list< T * >::size_type size_type
Definition: Plist.h:41
MGPlist()
Constructors.
Definition: Plist.h:52
const_reverse_iterator rend() const
Return const_reverse_iterator at the end of list.
Definition: Plist.h:225
T * removeAt(iterator x)
Definition: Plist.h:259
std::list< T * > m_list
Member Data.
Definition: Plist.h:44
std::list< T * >::reverse_iterator reverse_iterator
Definition: Plist.h:37
void clear()
clear list, that is, erase all the elements in the list.
Definition: Plist.h:118
const_iterator find(T *obj) const
Definition: Plist.h:152
Defines List of newed object pointers.
Definition: Plist.h:31
void splice(iterator pos, MGPlist< T > &ls, iterator first, iterator last)
Definition: Plist.h:283
const_reference back() const
Definition: Plist.h:102
std::list< T * >::const_reverse_iterator const_reverse_iterator
Definition: Plist.h:38
MGPlist< T > & operator=(const MGPlist< T > &rhs)
operator overload
Definition: Plist.h:305
std::list< T * >::const_iterator const_iterator
Definition: Plist.h:36
void reverse()
reverse sequence.
Definition: Plist.h:266
void sort(Traits _Comp)
Definition: Plist.h:275
reference back()
Definition: Plist.h:105
void insert(iterator pos, InputIter first, InputIter last)
Insert given range denoted by [first, last) into one before pos.
Definition: Plist.h:176
const_iterator end() const
Return const_iterator at the end of list.
Definition: Plist.h:132
MGPlist(const MGPlist< T > &rhs)
Definition: Plist.h:59
size_type max_size() const
Returns the size of maximum size.
Definition: Plist.h:181
iterator find(T *obj)
Definition: Plist.h:155
void merge(MGPlist< T > &rhs)
Equivalent to call std::list::merge().
Definition: Plist.h:186
iterator erase(iterator x)
erase element x.
Definition: Plist.h:140
iterator release(iterator i)
Definition: Plist.h:234
void push_back(T *x)
push element x at the end.
Definition: Plist.h:203
MGPlist(size_type n)
Create a list whose size is n.
Definition: Plist.h:65
void unique()
Equivalent to call std::list::unique().
Definition: Plist.h:293
void splice(iterator pos, MGPlist< T > &ls)
Definition: Plist.h:277
reference front()
Definition: Plist.h:164
reverse_iterator rend()
Definition: Plist.h:228
void sort()
Equivalent to call std::list::sort().
Definition: Plist.h:272
~MGPlist()
Destroy the object and delete all pointers that this holds.
Definition: Plist.h:299
void remove_if(Pred pred)
Definition: Plist.h:246
std::list< T * >::const_reference const_reference
Definition: Plist.h:40
std::list< T * >::reference reference
Definition: Plist.h:39
size_type size() const
Return the number of items that are in the list.
Definition: Plist.h:269
iterator insert(iterator it, T *x)
Definition: Plist.h:170
void swap(MGPlist< T > &x)
Equivalent to call std::list::swap().
Definition: Plist.h:288
MGPlist(InputIter first, InputIter last)
Create a list with a range. The ownership will be transfered.
Definition: Plist.h:69
void push_back(MGPlist< T > &x)
Definition: Plist.h:206
void pop_back()
pop last element.
Definition: Plist.h:191
iterator erase(iterator first, iterator last)
erase sequence [first, last).
Definition: Plist.h:145
reverse_iterator rbegin()
Definition: Plist.h:220
void push_front(T *x)
push element x at the first.
Definition: Plist.h:212
const_reference front() const
Definition: Plist.h:161
void splice(iterator pos, MGPlist< T > &ls, iterator i)
Definition: Plist.h:280
const_iterator begin() const
Return const_iterator at the beginning of list.
Definition: Plist.h:110
iterator begin()
Definition: Plist.h:113
void assign(InputIter first, InputIter last)
member functions
Definition: Plist.h:92
const_reverse_iterator rbegin() const
Return const_reverse_iterator at the beginning of list.
Definition: Plist.h:217