MINT2
PolymorphVector.h
Go to the documentation of this file.
1 #ifndef MINT_POLYMORPH_VECTOR
2 #define MINT_POLYMORPH_VECTOR
3 
4 #include <vector>
5 
6 namespace MINT{
7 template<typename T>
9 
10  protected:
11  std::vector<T> _vec;
12 
13  public:
15  PolymorphVector(unsigned int N) : _vec(N){}
16  PolymorphVector(unsigned int N, const T& c) : _vec(N, c){}
17  PolymorphVector(const PolymorphVector& other) : _vec(other._vec){}
18  PolymorphVector(const typename std::vector<T>& other) : _vec(other){}
19 
20  virtual ~PolymorphVector(){}
21 
22  std::vector<T>& theVector(){return _vec;}
23  const std::vector<T>& theVector()const {return _vec;}
24 
25 
26  T& operator[](unsigned int i){return _vec[i];}
27  const T& operator[](unsigned int i) const{return _vec[i];}
28 
29  T& at(unsigned int i){return _vec.at(i);}
30  const T& at(unsigned int i) const{return _vec.at(i);}
31 
32  typename std::vector<T>::iterator begin(){return _vec.begin();}
33  typename std::vector<T>::const_iterator begin() const{return _vec.begin();}
34 
35  typename std::vector<T>::iterator end(){return _vec.end();}
36  typename std::vector<T>::const_iterator end() const{return _vec.end();}
37 
38  typename std::vector<T>::iterator find(const T& c){return _vec.find(c);}
39  typename std::vector<T>::const_iterator find(const T& c) const{return _vec.find(c);}
40 
41  T& front() {return _vec.front();}
42  const T& front()const {return _vec.front();}
43  T& back() {return _vec.back();}
44  const T& back()const {return _vec.back();}
45 
46  unsigned int size() const{return _vec.size();}
47  bool empty() const{return _vec.empty();}
48 
49 
50  void push_back(const T& c){_vec.push_back(c);}
51  void pop_back(){_vec.pop_back();}
52 
53  void erase(typename std::vector<T>::iterator pos){_vec.erase(pos);}
54  void erase(typename std::vector<T>::iterator first,
55  typename std::vector<T>::iterator last){
56  _vec.erase(first, last);
57  }
58 
60  _vec = other._vec;
61  return *this;
62  }
63 
64  void clear(){_vec.clear();}
65  void resize(unsigned int N){_vec.resize(N);}
66  void resize(unsigned int N, const T& c){_vec.resize(N, c);}
67 
68  operator const typename std::vector<T>& ()const{
69  return this->theVector();
70  }
71  operator typename std::vector<T>& (){
72  return this->theVector();
73  }
74 
75  bool operator==(const MINT::PolymorphVector<T>& v2) const{
76  return _vec == v2.theVector();
77  }
78  bool operator!=(const MINT::PolymorphVector<T>& v2) const{
79  return !(_vec == v2.theVector());
80  }
81  bool operator<(const MINT::PolymorphVector<T>& v2) const{
82  return _vec < v2.theVector();
83  }
84  bool operator>(const MINT::PolymorphVector<T>& v2) const{
85  return v2 < _vec.theVector();
86  }
87 
88  };
89 
90 
91 }// namespace MINT
92 
93 #endif
std::vector< T >::const_iterator end() const
bool operator==(const MINT::PolymorphVector< T > &v2) const
PolymorphVector(unsigned int N, const T &c)
std::vector< T >::iterator end()
void resize(unsigned int N)
void push_back(const T &c)
std::vector< T >::const_iterator find(const T &c) const
PolymorphVector(const PolymorphVector &other)
bool operator!=(const MINT::PolymorphVector< T > &v2) const
bool operator<(const MINT::PolymorphVector< T > &v2) const
void resize(unsigned int N, const T &c)
std::vector< T >::const_iterator begin() const
const T & at(unsigned int i) const
PolymorphVector(unsigned int N)
T & operator[](unsigned int i)
const T & back() const
T & at(unsigned int i)
void erase(typename std::vector< T >::iterator pos)
std::vector< T >::iterator begin()
PolymorphVector< T > & operator=(const PolymorphVector< T > &other)
void erase(typename std::vector< T >::iterator first, typename std::vector< T >::iterator last)
const std::vector< T > & theVector() const
const T & operator[](unsigned int i) const
unsigned int size() const
std::vector< T > & theVector()
std::vector< T > _vec
bool operator>(const MINT::PolymorphVector< T > &v2) const
const T & front() const
PolymorphVector(const typename std::vector< T > &other)
std::vector< T >::iterator find(const T &c)