Main MRPT website > C++ reference for MRPT 1.5.7
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-2017, 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 classes
39 
40  \par 2006-07-21, v0.1.0
41  \li Job Mulder: Updated file for release 0.1.0
42 */
43 
44 #ifndef _CRT_SECURE_NO_WARNINGS
45 #define _CRT_SECURE_NO_WARNINGS
46 #endif
47 
48 #include <string.h>
49 #include <ctype.h>
50 #include <stdio.h>
51 
52 #include "xsens_list.hpp"
53 
54 namespace xsens {
55 
56 int32_t IntList::deserialize(const char* str)
57 {
58  uint32_t tmp = *((const uint32_t *) str);
59  resize(tmp);
60 
61  memcpy(m_data,str+4,tmp*4);
62  m_count = tmp;
63  return (int32_t) (4 + tmp*4);
64 }
65 
67 {
68  if (buffer != NULL)
69  {
70  *((uint32_t*) buffer) = m_count;
72  }
73  return (int32_t) (4 + m_count*4);
74 }
75 
76 void IntList::setIncremental(const uint32_t start, const uint32_t end, const int32_t step)
77 {
78  if (step == 0)
79  return;
80  int32_t size;
81  size = 1 + (((int32_t) end - (int32_t) start) / step);
82 
83  if ((uint32_t) size > m_max)
84  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)
90  m_data[m_count++] = i;
91  else
92  for (uint32_t i = start; i > end; i += astep)
93  m_data[m_count++] = i;
94 }
95 
97 {
98  long int rd = 0;
99  long unsigned sz = 0;
100  const char* start = str;
101 
102  if (sscanf(str,"%lu:%ln",&sz,&rd) != 1)
103  return 0;
104  str += rd;
105  resize(sz);
106  m_count = sz;
107 
108  for (uint32_t i = 0; i < m_count; ++i)
109  {
110  long int auxInt;
111  if (sscanf(str,"%li%ln",&auxInt,&rd) != 1)
112  return 0;
113  m_data[i] = auxInt;
114  str += rd;
115  }
116  return (int32_t) (str - start);
117 }
118 
120 {
121  char* buf = buffer;
122  char fake[128];
123  uint32_t written = 0;
124  if (buffer == NULL)
125  buf = fake;
126  written = sprintf(buf,"%lu:",(long unsigned)m_count);
127  if (buf != fake)
128  buf += written;
129  for (uint32_t i = 0;i < m_count;++i)
130  {
131  written += sprintf(buf," %lu",static_cast<long unsigned>(m_data[i]));
132  if (buf != fake)
133  buf = buffer + written;
134  }
135  return (int32_t) written;
136 }
137 
139 {
140  char* buf = buffer;
141  char fake[128];
142  uint32_t written = 0;
143  if (buffer == NULL)
144  buf = fake;
145  written = sprintf(buf,"%lu:",static_cast<long unsigned>(m_count));
146  if (buf != fake)
147  buf += written;
148  for (uint32_t i = 0;i < m_count;++i)
149  {
150  written += sprintf(buf," 0x%lX",static_cast<long unsigned>(m_data[i]));
151  if (buf != fake)
152  buf = buffer + written;
153  }
154  return (int32_t) written;
155 }
156 
158 {
159  uint32_t add = *((uint32_t*) &value);
160  for (uint32_t i = 0; i < m_count; ++i)
161  m_data[i] += add;
162 }
163 
165 {
166  if (m_count != lst.m_count)
167  return false;
168  for (uint32_t i = 0; i < m_count; ++i)
169  if (m_data[i] != lst.m_data[i])
170  return false;
171  return true;
172 }
173 
174 } // end of xsens namespace
void addValue(int32_t value)
Definition: xsens_list.cpp:157
void BASE_IMPEXP memcpy(void *dest, size_t destSize, const void *src, size_t copyCount) MRPT_NO_THROWS
An OS and compiler independent version of "memcpy".
Definition: os.cpp:358
uint32_t m_count
The number of items currently in the list.
Definition: xsens_list.h:72
void setIncremental(const uint32_t start, const uint32_t end, const int32_t step)
Definition: xsens_list.cpp:76
int32_t readFromString(const char *str)
Definition: xsens_list.cpp:96
GLuint buffer
Definition: glext.h:3775
bool operator==(const IntList &lst)
Definition: xsens_list.cpp:164
int32_t serialize(char *buffer) const
Definition: xsens_list.cpp:66
uint32_t * m_data
The array containing the items.
Definition: xsens_list.h:70
void resize(uint32_t newSize)
Resizes the list to at least the given size.
Definition: xsens_list.hpp:132
GLuint GLuint end
Definition: glext.h:3512
int32_t writeToString(char *buffer) const
Definition: xsens_list.cpp:119
__int32 int32_t
Definition: rptypes.h:48
int32_t deserialize(const char *str)
Definition: xsens_list.cpp:56
uint32_t m_max
The current size of the data array.
Definition: xsens_list.h:71
int BASE_IMPEXP sprintf(char *buf, size_t bufSize, const char *format,...) MRPT_NO_THROWS 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:191
The namespace of all Xsens software since 2006.
Definition: cmt1.cpp:92
GLsizei const GLfloat * value
Definition: glext.h:3929
GLsizeiptr size
Definition: glext.h:3779
int32_t writeToStringHex(char *buffer) const
Definition: xsens_list.cpp:138
GLuint start
Definition: glext.h:3512
unsigned __int32 uint32_t
Definition: rptypes.h:49



Page generated by Doxygen 1.8.14 for MRPT 1.5.7 Git: 5902e14cc Wed Apr 24 15:04:01 2019 +0200 at lun oct 28 01:39:17 CET 2019