12 #ifndef RTCTK_COMPONENTFRAMEWORK_MATRIXBUFFER_HPP
13 #define RTCTK_COMPONENTFRAMEWORK_MATRIXBUFFER_HPP
21 template <
typename T,
typename A = std::allocator<T>>
24 using typename std::vector<T, A>::size_type;
25 using typename std::vector<T, A>::value_type;
26 using typename std::vector<T, A>::reference;
27 using typename std::vector<T, A>::const_reference;
29 constexpr
MatrixBuffer() noexcept(noexcept(A())) :
std::vector<T, A>(), m_nrows(0), m_ncols(0) {
33 :
std::vector<T, A>(other), m_nrows(other.m_nrows), m_ncols(other.m_ncols) {
37 std::vector<T, A>::operator=(other);
38 m_nrows = other.m_nrows;
39 m_ncols = other.m_ncols;
44 : std::vector<T, A>(std::forward<MatrixBuffer>(other))
45 , m_nrows(std::move(other.m_nrows))
46 , m_ncols(std::move(other.m_ncols)) {
50 std::allocator_traits<A>::propagate_on_container_move_assignment::value or
51 std::allocator_traits<A>::is_always_equal::value) {
52 std::vector<T, A>::operator=(std::forward<MatrixBuffer>(other));
53 m_nrows = std::move(other.m_nrows);
54 m_ncols = std::move(other.m_ncols);
58 constexpr
MatrixBuffer(size_type n, size_type m,
const std::vector<T, A>& data)
59 :
std::vector<T, A>(data), m_nrows(n), m_ncols(m) {
60 assert(n * m == data.size());
66 constexpr
void resize(size_type n, size_type m) {
67 std::vector<T, A>::resize(n * m);
73 constexpr
void resize(size_type n, size_type m,
const value_type& value) {
74 std::vector<T, A>::resize(n * m, value);
79 constexpr reference
operator()(size_type n, size_type m) {
80 assert(0 <= n and n < m_nrows);
81 assert(0 <= m and m < m_ncols);
82 return std::vector<T, A>::operator[](n* m_ncols + m);
85 constexpr const_reference
operator()(size_type n, size_type m)
const {
86 assert(0 <= n and n < m_nrows);
87 assert(0 <= m and m < m_ncols);
88 return std::vector<T, A>::operator[](n* m_ncols + m);
108 template <
typename T,
typename A>
110 return lhs.GetNrows() == rhs.GetNrows() and lhs.GetNcols() == rhs.GetNcols() and
111 static_cast<std::vector<T, A>
>(lhs) ==
static_cast<std::vector<T, A>
>(rhs);
118 template <
typename T,
typename A>
120 return lhs.GetNrows() != rhs.GetNrows() or lhs.GetNcols() != rhs.GetNcols() or
121 static_cast<std::vector<T, A>
>(lhs) !=
static_cast<std::vector<T, A>
>(rhs);
132 template <
typename T,
typename A>
134 if (lhs.size() < rhs.size()) {
136 }
else if (lhs.size() == rhs.size()) {
137 if (lhs.GetNrows() < rhs.GetNrows()) {
139 }
else if (lhs.GetNrows() > rhs.GetNrows()) {
143 return static_cast<std::vector<T, A>
>(lhs) <
static_cast<std::vector<T, A>
>(rhs);
150 template <
typename T,
typename A>
152 if (lhs.size() < rhs.size()) {
154 }
else if (lhs.size() == rhs.size()) {
155 if (lhs.GetNrows() < rhs.GetNrows()) {
157 }
else if (lhs.GetNrows() > rhs.GetNrows()) {
161 return static_cast<std::vector<T, A>
>(lhs) <=
static_cast<std::vector<T, A>
>(rhs);
172 template <
typename T,
typename A>
174 if (lhs.size() > rhs.size()) {
176 }
else if (lhs.size() == rhs.size()) {
177 if (lhs.GetNrows() > rhs.GetNrows()) {
179 }
else if (lhs.GetNrows() < rhs.GetNrows()) {
183 return static_cast<std::vector<T, A>
>(lhs) >
static_cast<std::vector<T, A>
>(rhs);
190 template <
typename T,
typename A>
192 if (lhs.size() > rhs.size()) {
194 }
else if (lhs.size() == rhs.size()) {
195 if (lhs.GetNrows() > rhs.GetNrows()) {
197 }
else if (lhs.GetNrows() < rhs.GetNrows()) {
201 return static_cast<std::vector<T, A>
>(lhs) >=
static_cast<std::vector<T, A>
>(rhs);
206 #endif // RTCTK_COMPONENTFRAMEWORK_MATRIXBUFFER_HPP