From faf11bcb934fcf064670c249f8e2dcf2d8daabce Mon Sep 17 00:00:00 2001 From: Guillaume Bittoun Date: Thu, 10 Jul 2014 10:10:06 +0000 Subject: [PATCH] arraynd: proxy implementation --- src/lol/math/arraynd.h | 278 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 276 insertions(+), 2 deletions(-) diff --git a/src/lol/math/arraynd.h b/src/lol/math/arraynd.h index eb153fce..90968370 100644 --- a/src/lol/math/arraynd.h +++ b/src/lol/math/arraynd.h @@ -29,6 +29,277 @@ namespace lol { +template +class arraynd_proxy +{ +public: + + typedef array array_type; + typedef arraynd_proxy subproxy; + + inline arraynd_proxy(array_type * array, vec_t const & sizes, size_t index, size_t accumulator) : + m_array(array), + m_sizes(sizes), + m_index(index), + m_accumulator(accumulator) + { + } + + inline subproxy operator[](size_t pos) + { + return subproxy(m_array, this->m_sizes, m_index + pos * m_accumulator, m_accumulator * m_sizes[N - L]); + } + +private: + + array_type * m_array; + vec_t const & m_sizes; + size_t m_index; + size_t m_accumulator; +}; + + +template +class arraynd_proxy +{ +public: + + typedef array array_type; + + inline arraynd_proxy(array_type * array, vec_t const & sizes, size_t index, size_t accumulator) : + m_array(array), + m_sizes(sizes), + m_index(index), + m_accumulator(accumulator) + { + } + + inline typename array_type::element_t & operator[](size_t pos) + { + return m_array[m_index + pos * m_accumulator]; + } + +private: + + array_type * m_array; + vec_t const & m_sizes; + size_t m_index; + size_t m_accumulator; +}; + + +template +class arraynd_proxy +{ +public: + + typedef array array_type; + + inline arraynd_proxy(array_type * array, vec_t const & sizes, size_t index, size_t accumulator) : + m_array(array), + m_sizes(sizes), + m_index(index), + m_accumulator(accumulator) + { + } + + inline typename array_type::element_t & operator[](size_t pos) + { + return m_array[m_index + pos * m_accumulator]; + } + +private: + + array_type * m_array; + vec_t const & m_sizes; + size_t m_index; + size_t m_accumulator; +}; + + +template +class arraynd_proxy +{ +public: + + typedef array array_type; + + inline arraynd_proxy(array_type * array, vec_t const & sizes, size_t index, size_t accumulator) : + m_array(array), + m_sizes(sizes), + m_index(index), + m_accumulator(accumulator) + { + } + + inline typename array_type::element_t & operator[](size_t pos) + { + return m_array[m_index + pos * m_accumulator]; + } + +private: + + array_type * m_array; + vec_t const & m_sizes; + size_t m_index; + size_t m_accumulator; +}; + + +template +class arraynd_proxy +{ +public: + + typedef array array_type; + + inline arraynd_proxy(array_type * array, vec_t const & sizes, size_t index, size_t accumulator) : + m_array(array), + m_sizes(sizes), + m_index(index), + m_accumulator(accumulator) + { + } + + inline typename array_type::element_t & operator[](size_t pos) + { + return m_array[m_index + pos * m_accumulator]; + } + +private: + + array_type * m_array; + vec_t const & m_sizes; + size_t m_index; + size_t m_accumulator; +}; + + +template +class arraynd_proxy +{ +public: + + typedef array array_type; + + inline arraynd_proxy(array_type * array, vec_t const & sizes, size_t index, size_t accumulator) : + m_array(array), + m_sizes(sizes), + m_index(index), + m_accumulator(accumulator) + { + } + + inline typename array_type::element_t & operator[](size_t pos) + { + return m_array[m_index + pos * m_accumulator]; + } + +private: + + array_type * m_array; + vec_t const & m_sizes; + size_t m_index; + size_t m_accumulator; +}; + + +template +class arraynd_proxy +{ +public: + + typedef array array_type; + + inline arraynd_proxy(array_type * array, vec_t const & sizes, size_t index, size_t accumulator) : + m_array(array), + m_sizes(sizes), + m_index(index), + m_accumulator(accumulator) + { + } + + inline typename array_type::element_t & operator[](size_t pos) + { + return m_array[m_index + pos * m_accumulator]; + } + +private: + + array_type * m_array; + vec_t const & m_sizes; + size_t m_index; + size_t m_accumulator; +}; + + +template +class arraynd_proxy +{ +public: + + typedef array array_type; + + inline arraynd_proxy(array_type * array, vec_t const & sizes, size_t index, size_t accumulator) : + m_array(array), + m_sizes(sizes), + m_index(index), + m_accumulator(accumulator) + { + } + + inline typename array_type::element_t & operator[](size_t pos) + { + return m_array[m_index + pos * m_accumulator]; + } + +private: + + array_type * m_array; + vec_t const & m_sizes; + size_t m_index; + size_t m_accumulator; +}; + + +template +class arraynd_proxy +{ +public: + + typedef array array_type; + + inline arraynd_proxy(array_type * array, vec_t const & sizes, size_t index, size_t accumulator) : + m_array(array), + m_sizes(sizes), + m_index(index), + m_accumulator(accumulator) + { + } + + inline typename array_type::element_t & operator[](size_t pos) + { + return m_array[m_index + pos * m_accumulator]; + } + +private: + + array_type * m_array; + vec_t const & m_sizes; + size_t m_index; + size_t m_accumulator; +}; + + template @@ -37,22 +308,25 @@ class arraynd : protected array public: typedef array super; typedef typename super::element_t element_t; + typedef arraynd_proxy proxy; inline arraynd() : + super(), m_sizes() { } inline arraynd(vec_t sizes, element_t e = element_t()) : + super(), m_sizes(sizes) { SetSize(m_sizes, e); } /* Access elements directly using an ivec3 index */ - inline element_t const &operator [](ivec3 pos) const + inline proxy operator [](size_t pos) const { - return element_t(); // TODO + return proxy(this, m_sizes, pos, m_sizes[0]); } inline size_t ComputeTotalSize(vec_t sizes)