xsstringstreaming.h
Go to the documentation of this file.
1 
2 // Copyright (c) 2003-2021 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 
34 // Copyright (c) 2003-2021 Xsens Technologies B.V. or subsidiaries worldwide.
35 // All rights reserved.
36 //
37 // Redistribution and use in source and binary forms, with or without modification,
38 // are permitted provided that the following conditions are met:
39 //
40 // 1. Redistributions of source code must retain the above copyright notice,
41 // this list of conditions, and the following disclaimer.
42 //
43 // 2. Redistributions in binary form must reproduce the above copyright notice,
44 // this list of conditions, and the following disclaimer in the documentation
45 // and/or other materials provided with the distribution.
46 //
47 // 3. Neither the names of the copyright holders nor the names of their contributors
48 // may be used to endorse or promote products derived from this software without
49 // specific prior written permission.
50 //
51 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
52 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
53 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
54 // THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 // SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
56 // OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR
58 // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
59 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.THE LAWS OF THE NETHERLANDS
60 // SHALL BE EXCLUSIVELY APPLICABLE AND ANY DISPUTES SHALL BE FINALLY SETTLED UNDER THE RULES
61 // OF ARBITRATION OF THE INTERNATIONAL CHAMBER OF COMMERCE IN THE HAGUE BY ONE OR MORE
62 // ARBITRATORS APPOINTED IN ACCORDANCE WITH SAID RULES.
63 //
64 
65 #ifndef XSSTRINGSTREAMING_H
66 #define XSSTRINGSTREAMING_H
67 
68 #ifdef __cplusplus
69 #include "xsstring.h"
70 #include "xsvector.h"
71 #include "xsmatrix.h"
72 #include "xsquaternion.h"
73 
74 #ifndef XSENS_NO_STL
75 #include <ostream>
76 namespace std
77 {
78 template<typename _CharT, typename _Traits>
79 basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& o, XsVector const& xv)
80 {
81  o << "V<" << xv.size() << ">(";
82  for (XsSize i = 0; i < xv.size() - 1; i++)
83  o << xv[i] << ", ";
84  return (o << xv[xv.size() - 1] << ")");
85 }
86 
87 template<typename _CharT, typename _Traits>
88 basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& o, XsMatrix const& xm)
89 {
90  o << "M<" << xm.rows() << "," << xm.cols() << ">(";
91  for (XsSize r = 0; r < xm.rows(); ++r)
92  {
93  for (XsSize c = 0; c < xm.cols() - 1; ++c)
94  o << xm[r][c] << ", ";
95  o << xm[r][xm.cols() - 1];
96  if (r < xm.rows() - 1)
97  o << "\n";
98  }
99  o << ")";
100  return o;
101 }
102 
103 template<typename _CharT, typename _Traits>
104 basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& o, XsQuaternion const& xq)
105 {
106  o << "Q(";
107  for (int i = 0; i < 3; i++)
108  o << xq[i] << ", ";
109  return (o << xq[3] << ")");
110 }
111 }
112 #endif
113 
114 inline XsString& operator<<(XsString& o, XsSize const& v)
115 {
116  char buffer[32]; // 2e64 = 1.8e19 so this should be enough
117  sprintf(buffer, "%" PRINTF_SIZET_MODIFIER "u", v);
118  o << XsString(buffer);
119  return o;
120 }
121 
122 inline XsString& operator<<(XsString& o, XsReal const& v)
123 {
124  char buffer[64];
125  sprintf(buffer, "%g", v);
126  o << XsString(buffer);
127  return o;
128 }
129 
130 inline XsString& operator<<(XsString& o, XsVector const& xv)
131 {
132  o << "V<" << xv.size() << ">(";
133  for (XsSize i = 0; i < xv.size() - 1; i++)
134  o << xv[i] << ", ";
135  return (o << xv[xv.size() - 1] << ")");
136 }
137 
138 inline XsString& operator<<(XsString& o, XsMatrix const& xm)
139 {
140  o << "M<" << xm.rows() << "," << xm.cols() << ">(";
141  for (XsSize r = 0; r < xm.rows(); ++r)
142  {
143  if (xm.cols())
144  {
145  if (r > 0)
146  o << "\t";
147  for (XsSize c = 0; c < xm.cols() - 1; ++c)
148  o << xm[r][c] << ", ";
149  o << xm[r][xm.cols() - 1];
150  if (r < xm.rows() - 1)
151  o << "\n";
152  }
153  }
154  o << ")";
155  return o;
156 }
157 
158 inline XsString& operator<<(XsString& o, XsQuaternion const& xq)
159 {
160  o << "Q(";
161  for (int i = 0; i < 3; i++)
162  o << xq[i] << ", ";
163  return (o << xq[3] << ")");
164 }
165 
166 #endif
167 
168 #endif
XsString
struct XsString XsString
Definition: xsstring.h:87
xsstring.h
XsMatrix
A class that represents a matrix of real numbers.
Definition: xsmatrix.h:107
XsVector
A class that represents a vector of real numbers.
Definition: xsvector.h:113
xsquaternion.h
xsvector.h
XsQuaternion
A class that implements a quaternion.
Definition: xsquaternion.h:102
xsmatrix.h
XsReal
double XsReal
Defines the floating point type used by the Xsens libraries.
Definition: xstypedefs.h:73
XsSize
size_t XsSize
XsSize must be unsigned number!
Definition: xstypedefs.h:74
std
operator<<
std::ostream & operator<<(std::ostream &os, JlHexLogger< char > const &hex)
Definition: journaller.cpp:388
XsString
A 0-terminated managed string of characters.


xsens_mti_driver
Author(s):
autogenerated on Sun Sep 3 2023 02:43:20