IOLink IOL_v1.8.0_release
Loading...
Searching...
No Matches
Matrix.h
1#pragma once
2
3#include <array>
4#include <cstdint>
5#include <initializer_list>
6#include <ostream>
7#include <string>
8
9#include <iolink/IOLinkAPI.h>
10
11namespace iolink
12{
13
19template <typename ValueType, size_t N>
20class Matrix
21{
22public:
26 static Matrix identity();
27
33 static Matrix uniform(ValueType value);
34
40
56 explicit Matrix(const ValueType* values);
57
75 Matrix(const ValueType* values, bool isRowMajor);
76
94 explicit Matrix(std::initializer_list<ValueType> init);
95
96 bool operator==(const Matrix& other) const;
97 bool operator!=(const Matrix& other) const;
98
105 ValueType at(size_t row, size_t column) const;
106
113 ValueType operator()(size_t row, size_t column) const;
114
122 void setAt(size_t row, size_t column, ValueType value);
123
128
133
152 ValueType* data();
153
157 const ValueType* data() const;
158
162 std::string toString() const;
163
164 // ==================== //
165 // Arithmetic operators //
166 // ==================== //
167
168 Matrix operator-() const;
169
170 Matrix& operator+=(const Matrix& m);
171 Matrix& operator-=(const Matrix& m);
172
173 inline Matrix operator+(const Matrix& m) const { return Matrix(*this) += m; }
174 inline Matrix operator-(const Matrix& m) const { return Matrix(*this) -= m; }
175
176 Matrix& operator*=(ValueType value);
177 Matrix& operator/=(ValueType value);
178
179 inline Matrix operator*(ValueType v) const { return Matrix(*this) *= v; }
180 inline Matrix operator/(ValueType v) const { return Matrix(*this) /= v; }
181
182private:
183 std::array<ValueType, N * N> m_data;
184};
185
189template <typename T, size_t N>
190inline std::ostream&
191operator<<(std::ostream& os, const Matrix<T, N>& m)
192{
193 os << m.toString();
194 return os;
195}
196
197//=======================//
198// Template declarations //
199//=======================//
200
201extern template class IOLINK_API_IMPORT Matrix<float, 3>;
202extern template class IOLINK_API_IMPORT Matrix<double, 3>;
203
204extern template class IOLINK_API_IMPORT Matrix<float, 4>;
205extern template class IOLINK_API_IMPORT Matrix<double, 4>;
206
207//======================//
208// Aliases declarations //
209//======================//
210
213
216
217} // end namespace iolink