Go to the documentation of this file.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 #ifndef MED_Vector_HeaderFile
00029 #define MED_Vector_HeaderFile
00030
00031 #include <vector>
00032 #include <stdexcept>
00033
00034
00035 # define MED_TVECTOR_CHECK_RANGE
00036
00037
00038 namespace MED
00039 {
00040
00042 template<typename _Tp, typename _Alloc = std::allocator<_Tp> >
00043 class TVector : public std::vector<_Tp, _Alloc>
00044 {
00045 public:
00046 typedef size_t size_type;
00047
00048 typedef std::vector<_Tp, _Alloc> superclass;
00049 typedef typename superclass::allocator_type allocator_type;
00050
00051 typedef _Tp value_type;
00052 typedef value_type& reference;
00053 typedef const value_type& const_reference;
00054
00055 protected:
00056 void
00057 check_range(size_type __n) const
00058 {
00059 if (__n >= this->size())
00060 throw std::out_of_range("TVector [] access out of range");
00061 }
00062
00063 const_reference
00064 get_value(size_type __n) const
00065 {
00066 return superclass::operator[](__n);
00067 }
00068
00069 reference
00070 get_value(size_type __n)
00071 {
00072 return superclass::operator[](__n);
00073 }
00074
00075 public:
00076 explicit
00077 TVector(const allocator_type& __a = allocator_type()):
00078 superclass(__a)
00079 {}
00080
00081 TVector(size_type __n, const value_type& __val,
00082 const allocator_type& __a = allocator_type()):
00083 superclass(__n, __val, __a)
00084 {}
00085
00086 explicit
00087 TVector(size_type __n):
00088 superclass(__n)
00089 {}
00090
00091 TVector(const TVector& __x):
00092 superclass(__x)
00093 {}
00094
00095 template<typename _InputIterator>
00096 TVector(_InputIterator __first, _InputIterator __last,
00097 const allocator_type& __a = allocator_type()):
00098 superclass(__first, __last, __a)
00099 {}
00100
00101 template<typename _Yp, typename _Al>
00102 TVector(TVector<_Yp, _Al> __y):
00103 superclass(__y.begin(), __y.end())
00104 {}
00105
00106 TVector&
00107 operator=(const TVector& __x)
00108 {
00109 superclass::operator=(__x);
00110 return *this;
00111 }
00112
00113 template<typename _Yp, typename _Al>
00114 TVector&
00115 operator=(TVector<_Yp, _Al> __y)
00116 {
00117 this->assign(__y.begin(), __y.end());
00118 return *this;
00119 }
00120
00121 reference
00122 operator[](size_type __n)
00123 {
00124 #if defined(MED_TVECTOR_CHECK_RANGE)
00125 check_range(__n);
00126 #endif
00127 return get_value(__n);
00128 }
00129
00130 const_reference
00131 operator[](size_type __n) const
00132 {
00133 #if defined(MED_TVECTOR_CHECK_RANGE)
00134 check_range(__n);
00135 #endif
00136 return get_value(__n);
00137 }
00138
00139 reference
00140 at(size_type __n)
00141 {
00142 check_range(__n);
00143 return get_value(__n);
00144 }
00145
00146 const_reference
00147 at(size_type __n) const
00148 {
00149 check_range(__n);
00150 return get_value(__n);
00151 }
00152 };
00153
00154 }
00155
00156 #undef MED_TVECTOR_CHECK_RANGE
00157
00158 #endif