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]; }
138 Iterator begin() noexcept {
return m_data.begin(); }
139 ConstIterator begin() const noexcept {
return m_data.begin(); }
140 Iterator end() noexcept {
return m_data.end(); }
141 ConstIterator end() const noexcept {
return m_data.end(); }
143 bool operator==(
const Vector& other)
const;
144 bool operator!=(
const Vector& other)
const;
146 std::string toString()
const;
160 Vector& operator*=(ValueType value);
161 Vector& operator/=(ValueType value);
163 inline Vector operator*(ValueType v)
const {
return Vector(*
this) *= v; }
164 inline Vector operator/(ValueType v)
const {
return Vector(*
this) /= v; }
166 friend inline Vector operator*(ValueType value,
Vector v) {
return v *= value; }
190 bool operator<(
const Vector& other)
const;
191 bool operator<=(
const Vector& other)
const;
192 bool operator>(
const Vector& other)
const;
193 bool operator>=(
const Vector& other)
const;
195 operator VectorX<ValueType>()
const;
198 std::array<ValueType, N> m_data;
201template <
typename T,
size_t N>
203operator<<(std::ostream& os,
const Vector<T, N>& v)
216extern template class IOLINK_API_IMPORT Vector<int8_t, 2>;
217extern template class IOLINK_API_IMPORT Vector<int16_t, 2>;
218extern template class IOLINK_API_IMPORT Vector<int32_t, 2>;
219extern template class IOLINK_API_IMPORT Vector<int64_t, 2>;
221extern template class IOLINK_API_IMPORT Vector<uint8_t, 2>;
222extern template class IOLINK_API_IMPORT Vector<uint16_t, 2>;
223extern template class IOLINK_API_IMPORT Vector<uint32_t, 2>;
224extern template class IOLINK_API_IMPORT Vector<uint64_t, 2>;
226extern template class IOLINK_API_IMPORT Vector<float, 2>;
227extern template class IOLINK_API_IMPORT Vector<double, 2>;
232extern template class IOLINK_API_IMPORT Vector<int8_t, 3>;
233extern template class IOLINK_API_IMPORT Vector<int16_t, 3>;
234extern template class IOLINK_API_IMPORT Vector<int32_t, 3>;
235extern template class IOLINK_API_IMPORT Vector<int64_t, 3>;
237extern template class IOLINK_API_IMPORT Vector<uint8_t, 3>;
238extern template class IOLINK_API_IMPORT Vector<uint16_t, 3>;
239extern template class IOLINK_API_IMPORT Vector<uint32_t, 3>;
240extern template class IOLINK_API_IMPORT Vector<uint64_t, 3>;
242extern template class IOLINK_API_IMPORT Vector<float, 3>;
243extern template class IOLINK_API_IMPORT Vector<double, 3>;
248extern template class IOLINK_API_IMPORT Vector<int8_t, 4>;
249extern template class IOLINK_API_IMPORT Vector<int16_t, 4>;
250extern template class IOLINK_API_IMPORT Vector<int32_t, 4>;
251extern template class IOLINK_API_IMPORT Vector<int64_t, 4>;
253extern template class IOLINK_API_IMPORT Vector<uint8_t, 4>;
254extern template class IOLINK_API_IMPORT Vector<uint16_t, 4>;
255extern template class IOLINK_API_IMPORT Vector<uint32_t, 4>;
256extern template class IOLINK_API_IMPORT Vector<uint64_t, 4>;
258extern template class IOLINK_API_IMPORT Vector<float, 4>;
259extern 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.
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.
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