3#include <iolink/IOLinkAPI.h>
4#include <iolink/VectorX.h>
8#include <initializer_list>
35template <
typename T,
size_t N>
41 using Iterator =
typename std::array<T, N>::iterator;
42 using ConstIterator =
typename std::array<T, N>::const_iterator;
61 Vector(std::initializer_list<ValueType> init);
89 for (
size_t i = 0; i < N; ++i)
91 m_data[i] =
static_cast<ValueType
>(other[i]);
104 size_t size()
const {
return N; }
109 inline ValueType
at(
size_t index)
const {
return m_data[index]; }
114 inline void setAt(
size_t index, ValueType value) { m_data[index] = value; }
116 inline ValueType operator[](
size_t index)
const {
return m_data[index]; }
117 inline ValueType& operator[](
size_t index) {
return m_data[index]; }
122 inline ValueType*
data() {
return m_data.data(); }
127 inline const ValueType*
data()
const {
return m_data.data(); }
148 Iterator begin() noexcept {
return m_data.begin(); }
149 ConstIterator begin() const noexcept {
return m_data.begin(); }
150 Iterator end() noexcept {
return m_data.end(); }
151 ConstIterator end() const noexcept {
return m_data.end(); }
153 bool operator==(
const Vector& other)
const;
154 bool operator!=(
const Vector& other)
const;
156 std::string toString()
const;
170 Vector& operator*=(ValueType value);
171 Vector& operator/=(ValueType value);
173 inline Vector operator*(ValueType v)
const {
return Vector(*
this) *= v; }
174 inline Vector operator/(ValueType v)
const {
return Vector(*
this) /= v; }
176 friend inline Vector operator*(ValueType value,
Vector v) {
return v *= value; }
200 bool operator<(
const Vector& other)
const;
201 bool operator<=(
const Vector& other)
const;
202 bool operator>(
const Vector& other)
const;
203 bool operator>=(
const Vector& other)
const;
205 operator VectorX<ValueType>()
const;
208 std::array<ValueType, N> m_data;
211template <
typename T,
size_t N>
213operator<<(std::ostream& os,
const Vector<T, N>& v)
226extern template class IOLINK_API_IMPORT Vector<int8_t, 2>;
227extern template class IOLINK_API_IMPORT Vector<int16_t, 2>;
228extern template class IOLINK_API_IMPORT Vector<int32_t, 2>;
229extern template class IOLINK_API_IMPORT Vector<int64_t, 2>;
231extern template class IOLINK_API_IMPORT Vector<uint8_t, 2>;
232extern template class IOLINK_API_IMPORT Vector<uint16_t, 2>;
233extern template class IOLINK_API_IMPORT Vector<uint32_t, 2>;
234extern template class IOLINK_API_IMPORT Vector<uint64_t, 2>;
236extern template class IOLINK_API_IMPORT Vector<float, 2>;
237extern template class IOLINK_API_IMPORT Vector<double, 2>;
242extern template class IOLINK_API_IMPORT Vector<int8_t, 3>;
243extern template class IOLINK_API_IMPORT Vector<int16_t, 3>;
244extern template class IOLINK_API_IMPORT Vector<int32_t, 3>;
245extern template class IOLINK_API_IMPORT Vector<int64_t, 3>;
247extern template class IOLINK_API_IMPORT Vector<uint8_t, 3>;
248extern template class IOLINK_API_IMPORT Vector<uint16_t, 3>;
249extern template class IOLINK_API_IMPORT Vector<uint32_t, 3>;
250extern template class IOLINK_API_IMPORT Vector<uint64_t, 3>;
252extern template class IOLINK_API_IMPORT Vector<float, 3>;
253extern template class IOLINK_API_IMPORT Vector<double, 3>;
258extern template class IOLINK_API_IMPORT Vector<int8_t, 4>;
259extern template class IOLINK_API_IMPORT Vector<int16_t, 4>;
260extern template class IOLINK_API_IMPORT Vector<int32_t, 4>;
261extern template class IOLINK_API_IMPORT Vector<int64_t, 4>;
263extern template class IOLINK_API_IMPORT Vector<uint8_t, 4>;
264extern template class IOLINK_API_IMPORT Vector<uint16_t, 4>;
265extern template class IOLINK_API_IMPORT Vector<uint32_t, 4>;
266extern template class IOLINK_API_IMPORT Vector<uint64_t, 4>;
268extern template class IOLINK_API_IMPORT Vector<float, 4>;
269extern template class IOLINK_API_IMPORT Vector<double, 4>;
An arithmetic vector.
Definition Vector.h:37
Vector(std::initializer_list< ValueType > init)
Create a vector with the values contained in a bracket list.
size_t size() const
Returns the size of the vector, which also correspond to vector number of dimension.
Definition Vector.h:104
double length() const
Returns the vector's norm.
ValueType dot(const Vector &v) const
Dot product of two vectors.
Vector()
Create a vector with unitialized values.
Vector(const VectorX< ValueType > &other, ValueType padding)
Build a vector from a VectorX of same type.
const ValueType * data() const
Direct const access to the vector's data.
Definition Vector.h:127
Vector(const VectorX< ValueType > &other)
Build a Vector from a VectorX of same type.
Vector(const Vector< U, N > &other)
Build a vector from a vector storing another type.
Definition Vector.h:87
static Vector createUniform(ValueType value)
Create a vector with the given value for all components.
double squaredLength() const
Returns the vector's norm, squared.
void setAt(size_t index, ValueType value)
Set value as given index.
Definition Vector.h:114
ValueType at(size_t index) const
Access vector's value at given index.
Definition Vector.h:109
void normalize()
Normalize the vector.
ValueType * data()
Direct access to the vector's data.
Definition Vector.h:122
Vector cross(const Vector &v) const
Cross product of two vectors.
A dynamically sized arithmetic vector.
Definition VectorX.h:18
All IOLink symbols are enclosed in this namespace.
Definition ArrayX.h:8