| 1 |
|
| 2 |
// Copyright (c) 2003-2019 Xsens Technologies B.V. or subsidiaries worldwide. |
| 3 |
// All rights reserved. |
| 4 |
// |
| 5 |
// Redistribution and use in source and binary forms, with or without modification, |
| 6 |
// are permitted provided that the following conditions are met: |
| 7 |
// |
| 8 |
// 1. Redistributions of source code must retain the above copyright notice, |
| 9 |
// this list of conditions, and the following disclaimer. |
| 10 |
// |
| 11 |
// 2. Redistributions in binary form must reproduce the above copyright notice, |
| 12 |
// this list of conditions, and the following disclaimer in the documentation |
| 13 |
// and/or other materials provided with the distribution. |
| 14 |
// |
| 15 |
// 3. Neither the names of the copyright holders nor the names of their contributors |
| 16 |
// may be used to endorse or promote products derived from this software without |
| 17 |
// specific prior written permission. |
| 18 |
// |
| 19 |
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY |
| 20 |
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 21 |
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL |
| 22 |
// THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 |
// SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT |
| 24 |
// OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 25 |
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR |
| 26 |
// TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 27 |
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.THE LAWS OF THE NETHERLANDS |
| 28 |
// SHALL BE EXCLUSIVELY APPLICABLE AND ANY DISPUTES SHALL BE FINALLY SETTLED UNDER THE RULES |
| 29 |
// OF ARBITRATION OF THE INTERNATIONAL CHAMBER OF COMMERCE IN THE HAGUE BY ONE OR MORE |
| 30 |
// ARBITRATORS APPOINTED IN ACCORDANCE WITH SAID RULES. |
| 31 |
// |
| 32 |
|
| 33 |
#ifndef XSUSHORTVECTOR_H |
| 34 |
#define XSUSHORTVECTOR_H |
| 35 |
|
| 36 |
#ifdef __cplusplus |
| 37 |
#include "xstypedefs.h" |
| 38 |
#endif |
| 39 |
#ifndef __cplusplus |
| 40 |
#define XSUSHORTVECTOR_INITIALIZER {{0,0,0}} |
| 41 |
#endif |
| 42 |
|
| 43 |
|
| 44 |
/*! \brief A vector containing 3 short values. */ |
| 45 |
struct XsUShortVector { |
| 46 |
#ifdef __cplusplus |
| 47 |
//! \brief Constructor that creates the vector with all components set to 0 |
| 48 |
inline XsUShortVector() |
| 49 |
{ |
| 50 |
m_data[0] = 0; |
| 51 |
m_data[1] = 0; |
| 52 |
m_data[2] = 0; |
| 53 |
} |
| 54 |
|
| 55 |
//! \brief Constructor that creates the vector with all components set to given values \a v1 \a v2 and \a v3 |
| 56 |
inline XsUShortVector(unsigned short v1, unsigned short v2, unsigned short v3) |
| 57 |
{ |
| 58 |
m_data[0] = v1; |
| 59 |
m_data[1] = v2; |
| 60 |
m_data[2] = v3; |
| 61 |
} |
| 62 |
|
| 63 |
//! \brief Constructor that creates the vector with all components set to values in array \a a |
| 64 |
inline explicit XsUShortVector(const unsigned short* a) |
| 65 |
{ |
| 66 |
m_data[0] = a[0]; |
| 67 |
m_data[1] = a[1]; |
| 68 |
m_data[2] = a[2]; |
| 69 |
} |
| 70 |
|
| 71 |
//! \brief Constructor that creates the vector and initializes it with data from the \a other vector |
| 72 |
inline XsUShortVector(const XsUShortVector& other) |
| 73 |
{ |
| 74 |
m_data[0] = other.m_data[0]; |
| 75 |
m_data[1] = other.m_data[1]; |
| 76 |
m_data[2] = other.m_data[2]; |
| 77 |
} |
| 78 |
|
| 79 |
//! \brief Assignment operator copies the data from the \a other vector to this vector |
| 80 |
inline XsUShortVector& operator = (const XsUShortVector& other) |
| 81 |
{ |
| 82 |
if (this != &other) |
| 83 |
{ |
| 84 |
m_data[0] = other.m_data[0]; |
| 85 |
m_data[1] = other.m_data[1]; |
| 86 |
m_data[2] = other.m_data[2]; |
| 87 |
} |
| 88 |
return *this; |
| 89 |
} |
| 90 |
|
| 91 |
//! \brief Comparison operator, returns true if the contents of the \a other vector match those of this vector |
| 92 |
inline bool operator == (const XsUShortVector& other) const |
| 93 |
{ |
| 94 |
return m_data[0] == other.m_data[0] && |
| 95 |
m_data[1] == other.m_data[1] && |
| 96 |
m_data[2] == other.m_data[2]; |
| 97 |
} |
| 98 |
|
| 99 |
//! \brief Return the size of the vector (always 3) |
| 100 |
inline XsSize size() const |
| 101 |
{ |
| 102 |
return 3; |
| 103 |
} |
| 104 |
|
| 105 |
//! \brief Return a value from the vector (needed to allow generated C# access to these elements) |
| 106 |
inline unsigned short at(int index) const |
| 107 |
{ |
| 108 |
return m_data[index]; |
| 109 |
} |
| 110 |
|
| 111 |
//! \brief Returns the \a index'th item in the vector |
| 112 |
inline unsigned short operator[](XsSize index) const |
| 113 |
{ |
| 114 |
assert(index < 3); |
| 115 |
return m_data[index]; |
| 116 |
} |
| 117 |
|
| 118 |
//! \brief Returns a reference the \a index'th item in the vector |
| 119 |
inline unsigned short& operator[](XsSize index) |
| 120 |
{ |
| 121 |
assert(index < 3); |
| 122 |
return m_data[index]; |
| 123 |
} |
| 124 |
|
| 125 |
//! \brief Returns the start of the internal data buffer |
| 126 |
inline unsigned short const* data() const |
| 127 |
{ |
| 128 |
return m_data; |
| 129 |
} |
| 130 |
private: |
| 131 |
#endif |
| 132 |
|
| 133 |
unsigned short m_data[3]; //!< vector component storage |
| 134 |
}; |
| 135 |
|
| 136 |
typedef struct XsUShortVector XsUShortVector; |
| 137 |
|
| 138 |
#endif |