13#ifndef RTCTK_COMPONENTFRAMEWORK_MATRIXSPAN_HPP
14#define RTCTK_COMPONENTFRAMEWORK_MATRIXSPAN_HPP
38 using typename gsl::span<T>::element_type;
39 using typename gsl::span<T>::value_type;
40 using typename gsl::span<T>::size_type;
41 using typename gsl::span<T>::pointer;
43 using typename gsl::span<T>::reference;
45 using typename gsl::span<T>::iterator;
46 using typename gsl::span<T>::reverse_iterator;
48 constexpr MatrixSpan() noexcept : gsl::span<T>(), m_nrows(0), m_ncols(0) {
52 : gsl::span<T>(other), m_nrows(other.m_nrows), m_ncols(other.m_ncols) {
56 gsl::span<T>::operator=(other);
57 m_nrows = other.m_nrows;
58 m_ncols = other.m_ncols;
63 : gsl::span<T>(std::forward<MatrixSpan>(other))
64 , m_nrows(std::move(other.m_nrows))
65 , m_ncols(std::move(other.m_ncols)) {
69 gsl::span<T>::operator=(std::forward<MatrixSpan>(other));
70 m_nrows = std::move(other.m_nrows);
71 m_ncols = std::move(other.m_ncols);
75 constexpr explicit MatrixSpan(size_type n, size_type m,
const gsl::span<T>& data)
76 : gsl::span<T>(data), m_nrows(n), m_ncols(m) {
77 assert(n * m == data.size());
81 constexpr explicit MatrixSpan(size_type n, size_type m, I first, size_type count)
82 : gsl::span<T>(first, count), m_nrows(n), m_ncols(m) {
83 assert(n * m == count);
87 constexpr explicit MatrixSpan(size_type n, size_type m, I first, I last)
88 : gsl::span<T>(first, last), m_nrows(n), m_ncols(m) {
89 assert(n * m ==
static_cast<size_type
>(std::distance(first, last)));
94 template <std::
size_t N>
95 constexpr explicit MatrixSpan(size_type n, size_type m, element_type (&array)[N]) noexcept
96 : gsl::span<T>(array), m_nrows(n), m_ncols(m) {
101 template <std::
size_t N>
102 constexpr explicit MatrixSpan(size_type n, size_type m, std::array<T, N>& array) noexcept
103 : gsl::span<T>(array), m_nrows(n), m_ncols(m) {
107 template <std::
size_t N>
108 constexpr explicit MatrixSpan(size_type n, size_type m,
const std::array<T, N>& array) noexcept
109 : gsl::span<T>(array), m_nrows(n), m_ncols(m) {
113 template <
typename R>
114 constexpr explicit MatrixSpan(size_type n, size_type m, R&& range) noexcept
115 : gsl::span<T>(std::forward<R>(range)), m_nrows(n), m_ncols(m) {
116 assert(n * m == range.size());
119 template <
typename A>
121 : gsl::span<T>(buffer.data(), buffer.size())
122 , m_nrows(buffer.GetNrows())
123 , m_ncols(buffer.GetNcols()) {
126 template <
typename A>
127 requires std::is_const_v<T> or std::is_volatile_v<T>
129 : gsl::span<T>(buffer.data(), buffer.size())
130 , m_nrows(buffer.GetNrows())
131 , m_ncols(buffer.GetNcols()) {
134 template <
typename U>
135 requires std::is_same_v<std::remove_cv_t<T>, std::remove_cv_t<U>>
137 return std::equal(this->begin(), this->end(), rhs.begin(), rhs.end());
142 assert(0 <= n and n < m_nrows);
144 assert(0 <= m and m < m_ncols);
145 return gsl::span<T>::operator[](n * m_ncols + m);
150 assert(0 <= n and n < m_nrows);
152 assert(0 <= m and m < m_ncols);
153 return gsl::span<T>::operator[](n * m_ncols + m);
165 return row * m_ncols + col;
A buffer class representing 2D matrix data.
Definition matrixBuffer.hpp:28
bool operator==(const MatrixSpan< U > &rhs) const
Definition matrixSpan.hpp:136
const T & const_reference
Definition matrixSpan.hpp:44
constexpr MatrixSpan(MatrixBuffer< std::remove_cv_t< T >, A > &buffer) noexcept
Definition matrixSpan.hpp:128
constexpr MatrixSpan(size_type n, size_type m, R &&range) noexcept
Definition matrixSpan.hpp:114
constexpr MatrixSpan(size_type n, size_type m, I first, I last)
Definition matrixSpan.hpp:87
size_type GetNrows() const
Definition matrixSpan.hpp:156
constexpr MatrixSpan(size_type n, size_type m, const gsl::span< T > &data)
Definition matrixSpan.hpp:75
constexpr MatrixSpan(const MatrixSpan &other)
Definition matrixSpan.hpp:51
constexpr MatrixSpan(MatrixBuffer< T, A > &buffer) noexcept
Definition matrixSpan.hpp:120
constexpr MatrixSpan & operator=(const MatrixSpan &other)
Definition matrixSpan.hpp:55
constexpr MatrixSpan(size_type n, size_type m, I first, size_type count)
Definition matrixSpan.hpp:81
constexpr reference operator()(size_type n, size_type m)
Definition matrixSpan.hpp:140
size_type GetNcols() const
Definition matrixSpan.hpp:160
constexpr MatrixSpan(size_type n, size_type m, element_type(&array)[N]) noexcept
Definition matrixSpan.hpp:95
constexpr MatrixSpan() noexcept
Definition matrixSpan.hpp:48
constexpr MatrixSpan(size_type n, size_type m, std::array< T, N > &array) noexcept
Definition matrixSpan.hpp:102
constexpr const_reference operator()(size_type n, size_type m) const
Definition matrixSpan.hpp:148
size_t GetElementIndex(size_t row, size_t col)
Definition matrixSpan.hpp:164
constexpr MatrixSpan(MatrixSpan &&other) noexcept
Definition matrixSpan.hpp:62
constexpr MatrixSpan & operator=(MatrixSpan &&other) noexcept
Definition matrixSpan.hpp:68
const T * const_pointer
Definition matrixSpan.hpp:42
constexpr MatrixSpan(size_type n, size_type m, const std::array< T, N > &array) noexcept
Definition matrixSpan.hpp:108
Declaration of the MatrixBuffer template class used in APIs.
Definition commandReplier.cpp:22