Main MRPT website > C++ reference for MRPT 1.9.9
xsens_list.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 /*! \file
11  \brief Implementations of Cmtmath class functions.
12 
13  For information about objects in this file, see the appropriate header:
14  \ref Cmtmath.h
15 
16  \section FileCopyright Copyright Notice
17  Copyright (C) Xsens Technologies B.V., 2006. All rights reserved.
18 
19  This source code is intended for use only by Xsens Technologies BV and
20  those that have explicit written permission to use it from
21  Xsens Technologies BV.
22 
23  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
24  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
25  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
26  PARTICULAR PURPOSE.
27 
28  \section FileSwitches Switches
29  \li \c _XSENS_MATH_RANGE_CHECKS Check whether indices fall in the valid
30  range(s) of the object when set to 1 (in CmtMath.h).
31 
32  \section FileChangelog Changelog
33  \par 2006-05-31, v0.0.1
34  \li Job Mulder: Created
35 
36  \par 2006-06-08, v0.0.2
37  \li Job Mulder: Moved implementation of List to Cmtlist.hpp
38  \li Job Mulder: Removed Matlab class and integrated save functions in math
39  classes
40 
41  \par 2006-07-21, v0.1.0
42  \li Job Mulder: Updated file for release 0.1.0
43 */
44 
45 #ifndef _CRT_SECURE_NO_WARNINGS
46 #define _CRT_SECURE_NO_WARNINGS
47 #endif
48 
49 #include <string.h>
50 #include <ctype.h>
51 #include <stdio.h>
52 
53 #include "xsens_list.hpp"
54 
55 namespace xsens
56 {
57 int32_t IntList::deserialize(const char* str)
58 {
59  uint32_t tmp = *((const uint32_t*)str);
60  resize(tmp);
61 
62  memcpy(m_data, str + 4, tmp * 4);
63  m_count = tmp;
64  return (int32_t)(4 + tmp * 4);
65 }
66 
68 {
69  if (buffer != nullptr)
70  {
71  *((uint32_t*)buffer) = m_count;
72  memcpy(buffer + 4, m_data, m_count * 4);
73  }
74  return (int32_t)(4 + m_count * 4);
75 }
76 
78  const uint32_t start, const uint32_t end, const int32_t step)
79 {
80  if (step == 0) return;
81  int32_t size;
82  size = 1 + (((int32_t)end - (int32_t)start) / step);
83 
84  if ((uint32_t)size > m_max) resize(size);
85 
86  uint32_t astep = (uint32_t)step;
87  m_count = 0;
88  if (step > 0)
89  for (uint32_t i = start; i < end; i += astep) m_data[m_count++] = i;
90  else
91  for (uint32_t i = start; i > end; i += astep) m_data[m_count++] = i;
92 }
93 
95 {
96  long int rd = 0;
97  long unsigned sz = 0;
98  const char* start = str;
99 
100  if (sscanf(str, "%lu:%ln", &sz, &rd) != 1) return 0;
101  str += rd;
102  resize(sz);
103  m_count = sz;
104 
105  for (uint32_t i = 0; i < m_count; ++i)
106  {
107  long int auxInt;
108  if (sscanf(str, "%li%ln", &auxInt, &rd) != 1) return 0;
109  m_data[i] = auxInt;
110  str += rd;
111  }
112  return (int32_t)(str - start);
113 }
114 
116 {
117  char* buf = buffer;
118  char fake[128];
119  uint32_t written = 0;
120  if (buffer == nullptr) buf = fake;
121  written = sprintf(buf, "%lu:", (long unsigned)m_count);
122  if (buf != fake) buf += written;
123  for (uint32_t i = 0; i < m_count; ++i)
124  {
125  written += sprintf(buf, " %lu", static_cast<long unsigned>(m_data[i]));
126  if (buf != fake) buf = buffer + written;
127  }
128  return (int32_t)written;
129 }
130 
132 {
133  char* buf = buffer;
134  char fake[128];
135  uint32_t written = 0;
136  if (buffer == nullptr) buf = fake;
137  written = sprintf(buf, "%lu:", static_cast<long unsigned>(m_count));
138  if (buf != fake) buf += written;
139  for (uint32_t i = 0; i < m_count; ++i)
140  {
141  written +=
142  sprintf(buf, " 0x%lX", static_cast<long unsigned>(m_data[i]));
143  if (buf != fake) buf = buffer + written;
144  }
145  return (int32_t)written;
146 }
147 
149 {
150  uint32_t add = *((uint32_t*)&value);
151  for (uint32_t i = 0; i < m_count; ++i) m_data[i] += add;
152 }
153 
154 bool IntList::operator==(const IntList& lst)
155 {
156  if (m_count != lst.m_count) return false;
157  for (uint32_t i = 0; i < m_count; ++i)
158  if (m_data[i] != lst.m_data[i]) return false;
159  return true;
160 }
161 
162 } // end of xsens namespace
xsens_list.hpp
xsens::List< uint32_t >::m_data
uint32_t * m_data
The array containing the items.
Definition: xsens_list.h:77
start
GLuint start
Definition: glext.h:3528
xsens::IntList::writeToStringHex
int32_t writeToStringHex(char *buffer) const
Definition: xsens_list.cpp:131
end
GLuint GLuint end
Definition: glext.h:3528
xsens::IntList::readFromString
int32_t readFromString(const char *str)
Definition: xsens_list.cpp:94
xsens::IntList::addValue
void addValue(int32_t value)
Definition: xsens_list.cpp:148
xsens::IntList
Definition: xsens_list.h:228
xsens::IntList::writeToString
int32_t writeToString(char *buffer) const
Definition: xsens_list.cpp:115
xsens::IntList::serialize
int32_t serialize(char *buffer) const
Definition: xsens_list.cpp:67
mrpt::system::os::sprintf
int sprintf(char *buf, size_t bufSize, const char *format,...) noexcept MRPT_printf_format_check(3
An OS-independent version of sprintf (Notice the bufSize param, which may be ignored in some compiler...
Definition: os.cpp:189
xsens::List< uint32_t >::resize
void resize(uint32_t newSize)
Resizes the list to at least the given size.
Definition: xsens_list.hpp:132
xsens::IntList::operator==
bool operator==(const IntList &lst)
Definition: xsens_list.cpp:154
xsens::IntList::deserialize
int32_t deserialize(const char *str)
Definition: xsens_list.cpp:57
xsens::List< uint32_t >::m_max
uint32_t m_max
The current size of the data array.
Definition: xsens_list.h:79
buffer
GLuint buffer
Definition: glext.h:3917
int32_t
__int32 int32_t
Definition: rptypes.h:46
xsens::IntList::setIncremental
void setIncremental(const uint32_t start, const uint32_t end, const int32_t step)
Definition: xsens_list.cpp:77
value
GLsizei const GLfloat * value
Definition: glext.h:4117
size
GLsizeiptr size
Definition: glext.h:3923
xsens
The namespace of all Xsens software since 2006.
Definition: cmt1.cpp:95
uint32_t
unsigned __int32 uint32_t
Definition: rptypes.h:47
xsens::List< uint32_t >::m_count
uint32_t m_count
The number of items currently in the list.
Definition: xsens_list.h:81
mrpt::system::os::memcpy
void memcpy(void *dest, size_t destSize, const void *src, size_t copyCount) noexcept
An OS and compiler independent version of "memcpy".
Definition: os.cpp:356



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST