00001
00002 #ifndef INSTIGATE_STL_MATRIX
00003 #define INSTIGATE_STL_MATRIX
00004
00054
00055 #include "concept.hpp"
00056
00057
00058 #include <generic/_assignable.hpp>
00059 #include <generic/_default_constructible.hpp>
00060
00061
00062 #include <cassert>
00063
00064
00065 namespace instigate {
00066 namespace stl {
00074 namespace matrix {
00075 template<typename T>
00076 struct interface;
00077 template<typename T>
00078 struct requirements;
00079 }
00080 }
00081 }
00082
00095 template <typename T>
00096 struct instigate::stl::matrix::interface
00097 : instigate::generic::assignable::interface<T>
00098 , instigate::generic::default_constructible::interface<T>
00099 {
00101 typedef typename T::size_type size_type;
00102
00104 typedef typename T::value_type::value_type value_type;
00105
00115 static size_type get_number_of_rows(const T& x)
00116 {
00117 return x.size();
00118 }
00119
00129 static size_type get_number_of_columns(const T& x)
00130 {
00131 assert(0 < x.size());
00132 return x[0].size();
00133 }
00134
00143 static value_type get_element(const T& x,
00144 const size_type& r,
00145 const size_type& c)
00146 {
00147 assert(get_number_of_rows(x) > r);
00148 assert(get_number_of_columns(x) > c);
00149 return x[r][c];
00150 }
00151
00160 static void set_element(T& x,
00161 const size_type& r,
00162 const size_type& c,
00163 const value_type& v)
00164 {
00165 assert(get_number_of_rows(x) > r);
00166 assert(get_number_of_columns(x) > c);
00167 x[r][c] = v;
00168 }
00169
00177 static void construct(T& x, const size_type& r, const size_type& c)
00178 {
00179 x.resize(r);
00180 for (size_type i = 0; i < r; ++i) {
00181 x[i].resize(c);
00182 }
00183 }
00184 };
00185
00192 template <typename T>
00193 struct instigate::stl::matrix::requirements
00194 {
00195 private:
00196
00201 void require_get_element(const T& x,
00202 const typename instigate::stl::
00203 matrix:: interface<T>::size_type& r,
00204 const typename instigate::stl::
00205 matrix:: interface<T>::size_type& c)
00206 {
00207 typedef instigate::stl::matrix::interface<T> I;
00208 typedef typename I::value_type V;
00209 V v = I::get_element(x, r, c);
00210 }
00211
00216 void require_set_element(T& x,
00217 const typename instigate::stl::
00218 matrix:: interface<T>::size_type& r,
00219 const typename instigate::stl::
00220 matrix:: interface<T>::size_type& c,
00221 const typename instigate::stl::
00222 matrix:: interface<T>::value_type& v)
00223 {
00224 typedef instigate::stl::matrix::interface<T> I;
00225 I::set_element(x, r, c, v);
00226 }
00227
00232 void require_get_number_of_rows(const T& x)
00233 {
00234 typedef instigate::stl::matrix::interface<T> I;
00235 typedef typename I::size_type S;
00236 S s = I::get_number_of_rows(x);
00237 }
00238
00243 void require_get_number_of_columns(const T& x)
00244 {
00245 typedef instigate::stl::matrix::interface<T> I;
00246 typedef typename I::size_type S;
00247 S s = I::get_number_of_columns(x);
00248 }
00249
00251 public:
00257 requirements()
00258 {
00259 (void)require_get_element;
00260 (void)require_set_element;
00261 (void)require_get_number_of_rows;
00262 (void)require_get_number_of_columns;
00263
00264 }
00265
00267 private:
00269 requirements(const requirements&) throw();
00270
00272 requirements& operator=(const requirements&) throw();
00273
00274
00275 };
00276
00277
00278
00279 #endif // INSTIGATE_STL_MATRIX
00280