00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef MTL_TRIVIAL_INSERTER_INCLUDE
00013 #define MTL_TRIVIAL_INSERTER_INCLUDE
00014
00015 #include <boost/numeric/mtl/operation/update.hpp>
00016 #include <boost/numeric/mtl/matrix/element_matrix.hpp>
00017 #include <boost/numeric/mtl/matrix/element_array.hpp>
00018
00019 namespace mtl { namespace detail {
00020
00021
00022
00023 template <typename Matrix, typename Updater = mtl::operations::update_store<typename Matrix::value_type> >
00024 struct trivial_inserter
00025 {
00026 typedef trivial_inserter self;
00027 typedef Matrix matrix_type;
00028 typedef typename matrix_type::size_type size_type;
00029 typedef typename matrix_type::value_type value_type;
00030 typedef operations::update_proxy<self, size_type> proxy_type;
00031
00032 explicit trivial_inserter(matrix_type& matrix, size_type) : matrix(matrix) {}
00033
00034 proxy_type operator() (size_type row, size_type col)
00035 {
00036 return proxy_type(*this, row, col);
00037 }
00038
00039
00040 private:
00041
00042 struct bracket_proxy
00043 {
00044 bracket_proxy(self& ref, size_type row) : ref(ref), row(row) {}
00045
00046 proxy_type operator[](size_type col)
00047 {
00048 return proxy_type(ref, row, col);
00049 }
00050
00051 self& ref;
00052 size_type row;
00053 };
00054
00055 public:
00056
00057 bracket_proxy operator[] (size_type row)
00058 {
00059 return bracket_proxy(*this, row);
00060 }
00061
00062 template <typename Value>
00063 void update(size_type row, size_type col, Value val)
00064 {
00065 Updater() (matrix(row, col), val);
00066 }
00067
00068 template <typename Modifier, typename Value>
00069 void modify(size_type row, size_type col, Value val)
00070 {
00071 Modifier() (matrix(row, col), val);
00072 }
00073
00074
00075 template <typename EMatrix, typename Rows, typename Cols>
00076 self& operator<< (const matrix::element_matrix_t<EMatrix, Rows, Cols>& elements)
00077 {
00078 for (unsigned ri= 0; ri < elements.rows.size(); ri++)
00079 for (unsigned ci= 0; ci < elements.cols.size(); ci++)
00080 update (elements.rows[ri], elements.cols[ci], elements.matrix(ri, ci));
00081 return *this;
00082 }
00083
00084 template <typename EMatrix, typename Rows, typename Cols>
00085 self& operator<< (const matrix::element_array_t<EMatrix, Rows, Cols>& elements)
00086 {
00087 for (unsigned ri= 0; ri < elements.rows.size(); ri++)
00088 for (unsigned ci= 0; ci < elements.cols.size(); ci++)
00089 update (elements.rows[ri], elements.cols[ci], elements.array[ri][ci]);
00090 return *this;
00091 }
00092
00093 protected:
00094 matrix_type& matrix;
00095 };
00096
00097 }}
00098
00099 #endif // MTL_TRIVIAL_INSERTER_INCLUDE