13#ifndef RTCTK_COMPONENTFRAMEWORK_MATRIXBUFFER_HPP
14#define RTCTK_COMPONENTFRAMEWORK_MATRIXBUFFER_HPP
27template <
typename T,
typename A = std::allocator<T>>
30 using typename std::vector<T, A>::size_type;
31 using typename std::vector<T, A>::value_type;
32 using typename std::vector<T, A>::reference;
33 using typename std::vector<T, A>::const_reference;
35 constexpr MatrixBuffer() noexcept(noexcept(A())) : std::vector<T, A>(), m_nrows(0), m_ncols(0) {
39 : std::vector<T, A>(other), m_nrows(other.m_nrows), m_ncols(other.m_ncols) {
43 std::vector<T, A>::operator=(other);
44 m_nrows = other.m_nrows;
45 m_ncols = other.m_ncols;
50 : std::vector<T, A>(std::forward<MatrixBuffer>(other))
51 , m_nrows(std::move(other.m_nrows))
52 , m_ncols(std::move(other.m_ncols)) {
56 std::allocator_traits<A>::propagate_on_container_move_assignment::value or
57 std::allocator_traits<A>::is_always_equal::value) {
58 std::vector<T, A>::operator=(std::forward<MatrixBuffer>(other));
59 m_nrows = std::move(other.m_nrows);
60 m_ncols = std::move(other.m_ncols);
64 constexpr MatrixBuffer(size_type n, size_type m,
const std::vector<T, A>& data)
65 : std::vector<T, A>(data), m_nrows(n), m_ncols(m) {
66 assert(n * m == data.size());
72 constexpr void resize(size_type n, size_type m) {
73 std::vector<T, A>::resize(n * m);
79 constexpr void resize(size_type n, size_type m,
const value_type& value) {
80 std::vector<T, A>::resize(n * m, value);
85 constexpr reference
operator()(size_type n, size_type m) {
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);
91 constexpr const_reference
operator()(size_type n, size_type m)
const {
92 assert(0 <= n and n < m_nrows);
93 assert(0 <= m and m < m_ncols);
94 return std::vector<T, A>::operator[](n* m_ncols + m);
114template <
typename T,
typename A>
116 return lhs.GetNrows() == rhs.GetNrows() and lhs.GetNcols() == rhs.GetNcols() and
117 static_cast<std::vector<T, A>
>(lhs) ==
static_cast<std::vector<T, A>
>(rhs);
124template <
typename T,
typename A>
126 return lhs.GetNrows() != rhs.GetNrows() or lhs.GetNcols() != rhs.GetNcols() or
127 static_cast<std::vector<T, A>
>(lhs) !=
static_cast<std::vector<T, A>
>(rhs);
138template <
typename T,
typename A>
140 if (lhs.size() < rhs.size()) {
142 }
else if (lhs.size() == rhs.size()) {
143 if (lhs.GetNrows() < rhs.GetNrows()) {
145 }
else if (lhs.GetNrows() > rhs.GetNrows()) {
149 return static_cast<std::vector<T, A>
>(lhs) <
static_cast<std::vector<T, A>
>(rhs);
156template <
typename T,
typename A>
158 if (lhs.size() < rhs.size()) {
160 }
else if (lhs.size() == rhs.size()) {
161 if (lhs.GetNrows() < rhs.GetNrows()) {
163 }
else if (lhs.GetNrows() > rhs.GetNrows()) {
167 return static_cast<std::vector<T, A>
>(lhs) <=
static_cast<std::vector<T, A>
>(rhs);
178template <
typename T,
typename A>
180 if (lhs.size() > rhs.size()) {
182 }
else if (lhs.size() == rhs.size()) {
183 if (lhs.GetNrows() > rhs.GetNrows()) {
185 }
else if (lhs.GetNrows() < rhs.GetNrows()) {
189 return static_cast<std::vector<T, A>
>(lhs) >
static_cast<std::vector<T, A>
>(rhs);
196template <
typename T,
typename A>
198 if (lhs.size() > rhs.size()) {
200 }
else if (lhs.size() == rhs.size()) {
201 if (lhs.GetNrows() > rhs.GetNrows()) {
203 }
else if (lhs.GetNrows() < rhs.GetNrows()) {
207 return static_cast<std::vector<T, A>
>(lhs) >=
static_cast<std::vector<T, A>
>(rhs);
A buffer class representing 2D matrix data.
Definition: matrixBuffer.hpp:28
constexpr reference operator()(size_type n, size_type m)
Definition: matrixBuffer.hpp:85
constexpr void resize(size_type n, size_type m, const value_type &value)
Definition: matrixBuffer.hpp:79
constexpr MatrixBuffer(size_type n, size_type m, const std::vector< T, A > &data)
Definition: matrixBuffer.hpp:64
size_type GetNcols() const
Definition: matrixBuffer.hpp:101
constexpr MatrixBuffer(const MatrixBuffer &other)
Definition: matrixBuffer.hpp:38
size_type GetNrows() const
Definition: matrixBuffer.hpp:97
constexpr const_reference operator()(size_type n, size_type m) const
Definition: matrixBuffer.hpp:91
constexpr MatrixBuffer(MatrixBuffer &&other) noexcept
Definition: matrixBuffer.hpp:49
constexpr MatrixBuffer() noexcept(noexcept(A()))
Definition: matrixBuffer.hpp:35
constexpr void resize(size_type n, size_type m)
Definition: matrixBuffer.hpp:72
constexpr MatrixBuffer & operator=(MatrixBuffer &&other) noexcept(std::allocator_traits< A >::propagate_on_container_move_assignment::value or std::allocator_traits< A >::is_always_equal::value)
Definition: matrixBuffer.hpp:55
constexpr MatrixBuffer & operator=(const MatrixBuffer &other)
Definition: matrixBuffer.hpp:42
Definition: commandReplier.cpp:22
bool operator<(const DataPointPath &lhs, const char *rhs) noexcept
Definition: dataPointPath.hpp:354
bool operator>=(const DataPointPath &lhs, const char *rhs) noexcept
Definition: dataPointPath.hpp:366
bool operator<=(const DataPointPath &lhs, const char *rhs) noexcept
Definition: dataPointPath.hpp:358
constexpr bool operator!=(const MatrixBuffer< T, A > &lhs, const MatrixBuffer< T, A > &rhs) noexcept
Compares two MatrixBuffer objects and returns true if they do not have the same shape or the elements...
Definition: matrixBuffer.hpp:125
bool operator==(const DataPointPath &lhs, const char *rhs) noexcept
Definition: dataPointPath.hpp:350
bool operator>(const DataPointPath &lhs, const char *rhs) noexcept
Definition: dataPointPath.hpp:362