From 43b59c680125a2475cf7197cc7b5dcdf66bfd728 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Mon, 15 Aug 2016 17:33:53 +1000 Subject: [PATCH] matrix: add begin/end family of methods --- matrix.hpp | 10 ++++++++ matrix.ipp | 72 ++++++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 63 insertions(+), 19 deletions(-) diff --git a/matrix.hpp b/matrix.hpp index c87ebcc3..e57c55c7 100644 --- a/matrix.hpp +++ b/matrix.hpp @@ -30,9 +30,19 @@ namespace util { static const size_t rows = S; static const size_t cols = S; + // index operators return a pointer into the data array so that + // multidimensional array syntax can be used transparently on this + // type. T* operator[] (size_t); const T* operator[] (size_t) const; + const T* begin (void) const; + const T* end (void) const; + T* begin (void); + T* end (void); + const T* cbegin (void) const; + const T* cend (void) const; + matrix& transpose (void); matrix transposed (void) const; diff --git a/matrix.ipp b/matrix.ipp index dd949aaa..6eb6a154 100644 --- a/matrix.ipp +++ b/matrix.ipp @@ -39,25 +39,59 @@ util::matrix::operator[] (size_t idx) const return this->values[idx]; } -/////////////////////////////////////////////////////////////////////////////// -//template -//vector<3,T> -//matrix::operator* (vector<3,T> v) const -//{ -// return ( -// *this * v.template homog () -// ).template redim<3> (); -//} -// -// -////----------------------------------------------------------------------------- -//template -//point<3,T> -//matrix::operator* (point<3,T> p) const -//{ -// return (*this * p.template homog ()).template redim<3> (); -//} -// + +//----------------------------------------------------------------------------- +template +const T* +util::matrix::begin (void) const +{ + return &(*this)[0][0]; +} + + +//----------------------------------------------------------------------------- +template +const T* +util::matrix::end (void) const +{ + return &(*this)[S][0]; +} + + +//----------------------------------------------------------------------------- +template +const T* +util::matrix::cbegin (void) const +{ + return begin (); +} + + +//----------------------------------------------------------------------------- +template +const T* +util::matrix::cend (void) const +{ + return end (); +} + + +//----------------------------------------------------------------------------- +template +T* +util::matrix::begin (void) +{ + return &(*this)[0][0]; +} + + +//----------------------------------------------------------------------------- +template +T* +util::matrix::end (void) +{ + return &(*this)[S][0]; +} ///////////////////////////////////////////////////////////////////////////////