31 typedef typename std::vector<T*>::iterator
iterator;
35 typedef typename std::vector<T*>::reference
reference;
37 typedef typename std::vector<T*>::size_type
size_type;
44 MG_DLL_DECLR
friend std::ostream& operator<< (std::ostream& out, const MGPvector<T>& vector);
55 explicit MGPvector(size_type len) : m_vector(len, 0){;}
66 :m_vector(rhs.m_vector){
73 :m_vector(rhs.
size()){
75 for(
int i=0; i<n; i++){
76 m_vector[i]=
new T(*(rhs[i]));
81 template <
class InputIter>
100 return m_vector[pos];
115 template <
class InputIter>
116 void assign(InputIter first, InputIter last){
117 iterator cur=
begin();
118 for(; first != last && cur !=
end(); ++first, ++cur){
119 delete *cur; *cur = *first;
125 delete m_vector[pos];
130 const_reference
at(size_type n)
const{
131 return m_vector.at(n);
133 reference
at(size_type n){
134 return m_vector.at(n);
140 return m_vector.back();
143 return m_vector.back();
148 return m_vector.begin();
152 return m_vector.begin();
157 return m_vector.capacity();
162 for(iterator i =
begin(); i !=
end(); ++i)
170 return m_vector.empty();
174 const_iterator
end()
const{
175 return m_vector.end();
179 return m_vector.end();
185 return m_vector.erase(x);
190 iterator del = m_vector.begin() + i;
192 return m_vector.erase(del);
196 iterator
erase(iterator first, iterator last){
197 iterator cur = first;
198 for(; cur != last; ++cur)
delete *cur;
199 return m_vector.erase(first, last);
205 return m_vector.front();
208 return m_vector.front();
213 const_reference
get(size_type i)
const{
216 reference
get(size_type i){
222 return m_vector.insert(pos, ptr);
225 template <
class InputIter>
226 void insert(iterator pos, InputIter first, InputIter last){
227 for(; first != last; ++first){
228 pos =
insert(pos, *first);
235 return m_vector[i]==0;
240 return m_vector.max_size();
245 delete m_vector.back();
251 m_vector.push_back(x);
264 return m_vector.rbegin();
268 return m_vector.rbegin();
273 const_reverse_iterator
rend()
const{
274 return m_vector.rend();
279 return m_vector.rend();
286 T* ret = m_vector[i];
294 m_vector.assign(
size(), static_cast<T*>(0));
307 T* ret = m_vector[i];
308 iterator del = m_vector.begin() + i;
315 size_type i,n=
size();
317 for(i=0; i<nhalf; i++){
318 size_type nmim1=n-i-1;
319 T* pointer=m_vector[nmim1];
320 m_vector[nmim1]=m_vector[i];
332 void reset(size_type i, T* ptr = 0){
343 return m_vector.size();
357 for(
iterator i = begin(); i != end(); ++i)
delete *i;
376 if(oldn<n) m_vector.resize(n,0);
378 for(
size_type i=n; i<oldn; i++)
delete m_vector[i];
384 std::ostream& operator<< (std::ostream& out, const MGPvector<T>& vector){
385 out <<
"MGPvector<T>::";
387 out<<
"number of entries="<<n<<std::endl;
389 for(itr=vector.
begin(); itr!=vector.
end(); itr++){
390 out<<i++<<
":"<<(*itr)<<
":";
391 if(*itr) out << (**itr) << std::endl;
const_iterator begin() const
Return const_iterator that points to the first element in the sequence.
Definition: Pvector.h:147
std::vector< T * >::reverse_iterator reverse_iterator
Definition: Pvector.h:33
bool empty() const
Definition: Pvector.h:169
MGPvector(const MGPvector< T > &rhs)
Definition: Pvector.h:65
MGPvector< T > & operator=(const MGPvector< T > &rhs)
Definition: Pvector.h:361
MGPvector(InputIter first, InputIter last)
Create a vector with given range [first, last).
Definition: Pvector.h:82
std::vector< T * >::size_type size_type
Definition: Pvector.h:37
const_iterator end() const
Return const_iterator that points one past the last element.
Definition: Pvector.h:174
T * removeAt(size_type i)
Definition: Pvector.h:306
void assign(size_type pos, T *ptr)
Definition: Pvector.h:124
std::vector< T * >::const_iterator const_iterator
Definition: Pvector.h:32
void push_back(MGPvector< T > &dst)
Definition: Pvector.h:257
MGPvector(size_type len)
Definition: Pvector.h:55
void assign(InputIter first, InputIter last)
Definition: Pvector.h:116
const_reference at(size_type n) const
Equivalent to call vector::at(n).
Definition: Pvector.h:130
const_reverse_iterator rbegin() const
Return const_reverse_iterator that points the end of the sequence.
Definition: Pvector.h:263
size_type size() const
Return the number of items that are in the sequence.
Definition: Pvector.h:342
const_reference front() const
Definition: Pvector.h:204
T * release(size_type i)
Definition: Pvector.h:285
void reset(size_type i, T *ptr=0)
delete the i-th element and replace it with ptr.
Definition: Pvector.h:332
void clear()
clear Sequence, that is, erase all the elements in the sequence.
Definition: Pvector.h:161
iterator insert(iterator pos, T *ptr)
Insert ptr into vector at pos.
Definition: Pvector.h:221
size_type capacity() const
Equivalent to call vector::capacity().
Definition: Pvector.h:156
MGPvector(T *ptr)
Construct MGPvector of length 1 that contains ptr.
Definition: Pvector.h:58
const_reference back() const
Definition: Pvector.h:139
size_type max_size() const
Returns the size of maximum size.
Definition: Pvector.h:239
iterator erase(size_type i)
erase i-th element x.
Definition: Pvector.h:189
T * removeAt(iterator i)
Definition: Pvector.h:299
std::vector< T * >::reference reference
Definition: Pvector.h:35
~MGPvector()
Destroy the object and delete all pointers that this object holds.
Definition: Pvector.h:356
reference front()
Definition: Pvector.h:207
std::vector< T * >::iterator iterator
Definition: Pvector.h:31
iterator begin()
Return iterator that points to the first element in the sequence.
Definition: Pvector.h:151
iterator end()
Return iterator that points one past the last element.
Definition: Pvector.h:178
void swap(MGPvector< T > &x)
Definition: Pvector.h:346
void push_back(T *x)
push element x at the end.
Definition: Pvector.h:250
MGPvector()
void constructor
Definition: Pvector.h:49
reference back()
Definition: Pvector.h:142
bool is_null(size_type i) const
Test if i-th element is null.
Definition: Pvector.h:234
reverse_iterator rbegin()
Return reverse_iterator that points the end of the sequence.
Definition: Pvector.h:267
reverse_iterator rend()
Definition: Pvector.h:278
reference operator[](size_type pos)
Definition: Pvector.h:98
void reverse_sequence()
reverse the sequence of the elements.
Definition: Pvector.h:314
const_reverse_iterator rend() const
Definition: Pvector.h:273
iterator erase(iterator x)
erase the element at x.
Definition: Pvector.h:183
void insert(iterator pos, InputIter first, InputIter last)
Insert the range [first, last) into the vector at pos.
Definition: Pvector.h:226
void pop_back()
pop last element.
Definition: Pvector.h:244
reference at(size_type n)
Definition: Pvector.h:133
std::vector< T * > m_vector
Member data.
Definition: Pvector.h:40
iterator erase(iterator first, iterator last)
erase sequence [first, last).
Definition: Pvector.h:196
MGPvector(const std::vector< const T * > &rhs)
Conversion constructor.
Definition: Pvector.h:72
void release_all()
Definition: Pvector.h:293
std::vector< T * >::const_reference const_reference
Definition: Pvector.h:36
Defines Vector of newed object pointers.
Definition: Pvector.h:27
void resize(size_type n)
Definition: Pvector.h:374
void reserve(size_type n)
Definition: Pvector.h:327
std::vector< T * >::const_reverse_iterator const_reverse_iterator
Definition: Pvector.h:34
const_reference operator[](size_type pos) const
Subscript access.
Definition: Pvector.h:94