00001
00002
00003 #ifndef __MGFP_INCLUDE_COLLECTION_H__
00004 #define __MGFP_INCLUDE_COLLECTION_H__
00005
00006 #include <vector>
00007 #include <mgfp/config.h>
00008
00009
00010 #ifdef REGRESSION_TEST_BUILD
00011 struct CollectionTestSuite;
00012 #endif
00013
00014 namespace mgf {
00015
00029 template < class T, class A = std::allocator<T> >
00030 class MGFP_EXPORT Collection
00031 {
00032 public:
00033
00034 typedef T value_type;
00035 typedef A allocator_type;
00036
00037 typedef typename A::size_type size_type;
00038 typedef typename A::difference_type difference_type;
00039
00040 typedef typename std::vector<T, A>::iterator iterator;
00041 typedef typename std::vector<T, A>::const_iterator const_iterator;
00042 typedef typename std::vector<T, A>::reverse_iterator reverse_iterator;
00043 typedef typename std::vector<T, A>::const_reverse_iterator const_reverse_iterator;
00044 typedef typename std::vector<T, A>::pointer pointer;
00045 typedef typename std::vector<T, A>::const_pointer const_pointer;
00046 typedef typename std::vector<T, A>::reference reference;
00047 typedef typename std::vector<T, A>::const_reference const_reference;
00048
00049
00050 explicit Collection() {}
00051 Collection(const Collection& rhs) : c_(rhs.c_) {}
00052 explicit Collection(const std::vector<T, A>& rhs) : c_(rhs) {}
00053 explicit Collection(size_type n, const T& value = T()) : c_(n, value) {}
00054 template <class In> Collection(In begin, In end) : c_(begin, end) {}
00055
00056
00057 virtual ~Collection() {}
00058
00059
00060 virtual Collection& operator=(const Collection& rhs) {
00061 c_ = rhs.c_;
00062 return *this;
00063 }
00064
00065 template<typename U, typename V>
00066 friend bool operator==(const Collection<U, V>& lhs, const Collection<U, V>& rhs);
00067
00068 template <class U, class V>
00069 friend bool operator<(const Collection<U, V>& lhs, const Collection<U, V>& rhs);
00070
00071 template <class U, class V>
00072 friend void swap(Collection<U, V>& lhs, Collection<U, V>& rhs);
00073
00074
00075 template <class In> void assign(In begin, In end) {
00076 c_.assign(begin, end);
00077 }
00078 virtual void assign(size_type n, const T& value) {
00079 c_.assign(n, value);
00080 }
00081
00082
00083 virtual void push_back(const T& value) {
00084 c_.push_back(value);
00085 }
00086 virtual void pop_back(void) {
00087 c_.pop_back();
00088 }
00089
00090
00091 virtual iterator insert(iterator pos, const T& value) {
00092 return c_.insert(pos, value);
00093 }
00094 virtual void insert(iterator pos, size_type n, const T& value) {
00095 return c_.insert(pos, n, value);
00096 }
00097 template <class In> void insert(iterator pos, In begin, In end) {
00098 c_.insert(pos, begin, end);
00099 }
00100 virtual iterator erase(iterator pos) {
00101 return c_.erase(pos);
00102 }
00103 virtual iterator erase(iterator begin, iterator end) {
00104 return c_.erase(begin, end);
00105 }
00106 virtual void clear() {
00107 c_.clear();
00108 }
00109
00110
00111 virtual iterator begin() {
00112 return c_.begin();
00113 }
00114 virtual reverse_iterator rbegin() {
00115 return c_.rbegin();
00116 }
00117 virtual iterator end() {
00118 return c_.end();
00119 }
00120 virtual reverse_iterator rend() {
00121 return c_.rend();
00122 }
00123 virtual const_iterator begin() const {
00124 return c_.begin();
00125 }
00126 virtual const_iterator end() const {
00127 return c_.end();
00128 }
00129
00130
00131 virtual value_type& operator[](size_type pos) {
00132 return c_[pos];
00133 }
00134 virtual value_type& at(size_type pos) {
00135 return c_.at(pos);
00136 }
00137 virtual const value_type& operator[](size_type pos) const {
00138 return c_[pos];
00139 }
00140 virtual const value_type& at(size_type pos) const {
00141 return c_.at(pos);
00142 }
00143
00144
00145 virtual size_type size(void) const {
00146 return c_.size();
00147 }
00148 virtual size_type max_size() const {
00149 return c_.max_size();
00150 }
00151 virtual bool empty() const {
00152 return c_.empty();
00153 }
00154 virtual void resize(size_type sz, const T& value = T()) {
00155 c_.resize(sz, value);
00156 }
00157 virtual size_type capacity() const {
00158 return c_.capacity();
00159 }
00160 virtual void reserve(size_type n) {
00161 c_.reserve(n);
00162 }
00163
00164
00165 virtual void swap(Collection& rhs) {
00166 c_.swap(rhs.c_);
00167 }
00168 virtual allocator_type get_allocator() const {
00169 return c_.get_allocator();
00170 }
00171
00172 protected:
00173 #ifdef REGRESSION_TEST_BUILD
00174 friend struct ::CollectionTestSuite;
00175 #endif
00176 std::vector<T, A> c_;
00177 };
00178
00179
00180 template <class T, class A> bool operator==(const Collection<T, A>& lhs, const Collection<T, A>& rhs)
00181 {
00182 return lhs.c_ == rhs.c_;
00183 }
00184 template <class T, class A> bool operator<(const Collection<T, A>& lhs, const Collection<T, A>& rhs)
00185 {
00186 return lhs.c_ < rhs.c_;
00187 }
00188 template <class T, class A> void swap(Collection<T, A>& lhs, Collection<T, A>& rhs)
00189 {
00190 lhs.c_.swap(rhs.c_);
00191 }
00192
00193 }
00194
00195 #endif