xsfile.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 XSFILE_H
66 #define XSFILE_H
67 
68 #include "xstypesconfig.h"
69 #include "pstdint.h"
70 #include <stdio.h>
71 #include "xsresultvalue.h"
72 #include "xsfilepos.h"
73 #include "xsstring.h"
74 
75 #ifdef _MSC_VER
76  #define XS_MAX_FILENAME_LENGTH 512
77 #else
78  #define XS_MAX_FILENAME_LENGTH PATH_MAX
79 #endif
80 
81 #ifdef __cplusplus
82 #include "xsbytearray.h"
83 extern "C" {
84 #endif
85 #ifndef __cplusplus
86 #define XSFILE_INITIALIZER { 0 }
87 #endif
88 
89 struct XsFile;
90 
91 XSTYPES_DLL_API void XsFile_destruct(struct XsFile* thisPtr);
92 
93 XSTYPES_DLL_API XsResultValue XsFile_create(struct XsFile* thisPtr, const struct XsString* filename, int writeOnly);
94 XSTYPES_DLL_API XsResultValue XsFile_createText(struct XsFile* thisPtr, const struct XsString* filename, int writeOnly);
95 XSTYPES_DLL_API XsResultValue XsFile_open(struct XsFile* thisPtr, const struct XsString* filename, int readOnly);
96 XSTYPES_DLL_API XsResultValue XsFile_openText(struct XsFile* thisPtr, const struct XsString* filename, int readOnly);
97 XSTYPES_DLL_API XsResultValue XsFile_reopen(struct XsFile* thisPtr, const struct XsString* filename, const struct XsString* mode);
98 XSTYPES_DLL_API int XsFile_isOpen(const struct XsFile* thisPtr);
100 
101 XSTYPES_DLL_API int XsFile_exists(const struct XsString* filename);
102 
105 XSTYPES_DLL_API XsResultValue XsFile_resize(struct XsFile* thisPtr, XsFilePos fileSize);
106 XSTYPES_DLL_API XsResultValue XsFile_erase(const struct XsString* filename);
107 
108 XSTYPES_DLL_API XsFilePos XsFile_read(struct XsFile* thisPtr, void* destination, XsFilePos size, XsFilePos count);
109 XSTYPES_DLL_API XsFilePos XsFile_write(struct XsFile* thisPtr, const void* source, XsFilePos size, XsFilePos count);
110 XSTYPES_DLL_API int XsFile_getc(struct XsFile* thisPtr);
111 XSTYPES_DLL_API XsResultValue XsFile_putc(struct XsFile* thisPtr, int character);
112 XSTYPES_DLL_API char* XsFile_gets(struct XsFile* thisPtr, char* str, int num);
113 XSTYPES_DLL_API XsResultValue XsFile_puts(struct XsFile* thisPtr, const char* str);
114 
115 XSTYPES_DLL_API XsResultValue XsFile_seek(struct XsFile* thisPtr, XsFilePos offset);
117 XSTYPES_DLL_API XsFilePos XsFile_tell(struct XsFile const* thisPtr);
118 
119 XSTYPES_DLL_API int XsFile_eof(struct XsFile const* thisPtr);
120 XSTYPES_DLL_API XsResultValue XsFile_error(struct XsFile const* thisPtr);
121 XSTYPES_DLL_API XsResultValue XsFile_fullPath(const struct XsString* filename, struct XsString* fullPath);
122 
123 XSTYPES_DLL_API XsResultValue XsFile_getline(struct XsFile* thisPtr, struct XsString* line);
124 
125 XSTYPES_DLL_API FILE* XsFile_handle(struct XsFile* thisPtr);
126 
127 #ifdef __cplusplus
128 } // extern "C"
129 #endif
130 
131 struct XsFile
132 {
133 #ifdef __cplusplus
134 
135  explicit inline XsFile()
136  : m_handle(NULL)
137  {
138  // Silence -Wunused-private-field
139  // This field is used in the C back-end, but
140  // some compilers may not notice this
141  (void)m_handle;
142  }
143 
145  inline ~XsFile()
146  {
147  XsFile_destruct(this);
148  }
149 
151  inline XsResultValue create(const XsString& filename, bool writeOnly)
152  {
153  return XsFile_create(this, &filename, writeOnly ? 1 : 0);
154  }
155 
157  inline XsResultValue createText(const XsString& filename, bool writeOnly)
158  {
159  return XsFile_createText(this, &filename, writeOnly ? 1 : 0);
160  }
161 
163  inline XsResultValue open(const XsString& fileName, bool readOnly)
164  {
165  return XsFile_open(this, &fileName, readOnly ? 1 : 0);
166  }
167 
169  inline XsResultValue openText(const XsString& fileName, bool readOnly)
170  {
171  return XsFile_openText(this, &fileName, readOnly ? 1 : 0);
172  }
173 
175  inline XsResultValue reopen(const XsString& fileName, const XsString& mode)
176  {
177  return XsFile_reopen(this, &fileName, &mode);
178  }
179 
181  inline bool isOpen() const
182  {
183  return (XsFile_isOpen(this) == 0);
184  }
185 
187  static inline bool exists(const XsString& fileName)
188  {
189  return (XsFile_exists(&fileName) == 0);
190  }
191 
193  inline XsResultValue close()
194  {
195  return XsFile_close(this);
196  }
197 
199  inline XsResultValue flush()
200  {
201  return XsFile_flush(this);
202  }
203 
205  inline XsResultValue truncate(XsFilePos fileSize)
206  {
207  return XsFile_truncate(this, fileSize);
208  }
209 
211  inline XsResultValue resize(XsFilePos fileSize)
212  {
213  return XsFile_resize(this, fileSize);
214  }
215 
217  static XsResultValue erase(const XsString& filename)
218  {
219  return XsFile_erase(&filename);
220  }
221 
223  inline XsFilePos read(void* destination, XsFilePos size, XsFilePos count)
224  {
225  return XsFile_read(this, destination, size, count);
226  }
227 
229  inline XsFilePos write(const void* source, XsFilePos size, XsFilePos count)
230  {
231  return XsFile_write(this, source, size, count);
232  }
233 
235  inline XsFilePos write(XsByteArray const& source)
236  {
237  return XsFile_write(this, source.data(), 1, source.size());
238  }
239 
241  inline int getc()
242  {
243  return XsFile_getc(this);
244  }
245 
247  inline XsResultValue putc(int character)
248  {
249  return XsFile_putc(this, character);
250  }
251 
253  inline char* gets(char* destination, int maxCount)
254  {
255  return XsFile_gets(this, destination, maxCount);
256  }
257 
259  inline XsResultValue puts(const char* source)
260  {
261  return XsFile_puts(this, source);
262  }
263 
265  inline XsResultValue seek(XsFilePos offset)
266  {
267  return XsFile_seek(this, offset);
268  }
269 
271  inline XsResultValue seek_r(XsFilePos offset)
272  {
273  return XsFile_seek_r(this, offset);
274  }
275 
277  inline XsFilePos tell() const
278  {
279  return XsFile_tell(this);
280  }
281 
283  inline bool eof() const
284  {
285  return (0 != XsFile_eof(this));
286  }
287 
289  inline XsResultValue error() const
290  {
291  return XsFile_error(this);
292  }
293 
295  static XsResultValue fullPath(const XsString& filename, XsString& fullPath)
296  {
297  return XsFile_fullPath(&filename, &fullPath);
298  }
299 
301  inline XsResultValue getline(XsString& line)
302  {
303  return XsFile_getline(this, &line);
304  }
305 
307  inline XsResultValue getline(std::string& line)
308  {
309  XsString tmp;
310  XsResultValue rv = XsFile_getline(this, &tmp);
311  if (rv == XRV_OK)
312  line = tmp.toStdString();
313  return rv;
314  }
315 
317  inline FILE* handle()
318  {
319  return XsFile_handle(this);
320  }
321 private:
322 #endif
323  FILE* m_handle;
324 };
325 
326 typedef struct XsFile XsFile;
327 
328 #endif
xsstring.h
exists
ROSCPP_DECL bool exists(const std::string &service_name, bool print_failure_reason)
XsByteArray
A list of uint8_t values.
XsFile::m_handle
FILE * m_handle
Definition: xsfile.h:323
XsFile::XsFile_flush
XsResultValue XsFile_flush(struct XsFile *thisPtr)
Writes unwritten data to the file.
Definition: xsfile.c:348
XsFile::XsFile_getc
int XsFile_getc(struct XsFile *thisPtr)
Gets and returns the next byte from a file.
Definition: xsfile.c:452
XsFile::XsFile_error
XsResultValue XsFile_error(struct XsFile const *thisPtr)
Definition: xsfile.c:540
XsFile::XsFile_putc
XsResultValue XsFile_putc(struct XsFile *thisPtr, int character)
Writes a character to the file.
Definition: xsfile.c:462
XsFile::XsFile_getline
XsResultValue XsFile_getline(struct XsFile *thisPtr, struct XsString *line)
Reads a full line from the file.
Definition: xsfile.c:586
XsFile::XsFile_seek_r
XsResultValue XsFile_seek_r(struct XsFile *thisPtr, XsFilePos offset)
Moves the current file position relative to the end of the file.
Definition: xsfile.c:507
XsFile::XsFile_resize
XsResultValue XsFile_resize(struct XsFile *thisPtr, XsFilePos fileSize)
Resizes the file to fileSize bytes.
Definition: xsfile.c:368
XsFile::XsFile_exists
int XsFile_exists(const struct XsString *filename)
Checks if the file exists (can be accessed)
Definition: xsfile.c:306
XsFile::XsFile_isOpen
int XsFile_isOpen(const struct XsFile *thisPtr)
Checks if a file is open.
Definition: xsfile.c:296
XsFile::XsFile_destruct
void XsFile_destruct(struct XsFile *thisPtr)
Frees the resources of this object by closing the file if it is open.
Definition: xsfile.c:97
XsFile::XsFile_truncate
XsResultValue XsFile_truncate(struct XsFile *thisPtr, XsFilePos fileSize)
Reduces the file to a maximum size of fileSize bytes.
Definition: xsfile.c:358
XRV_OK
@ XRV_OK
0: Operation was performed successfully
Definition: xsresultvalue.h:85
XsResultValue
XsResultValue
Xsens result values.
Definition: xsresultvalue.h:82
XsFile::XsFile_puts
XsResultValue XsFile_puts(struct XsFile *thisPtr, const char *str)
Writes a null terminated c-string to the file.
Definition: xsfile.c:483
XsFile::XsFile_reopen
XsResultValue XsFile_reopen(struct XsFile *thisPtr, const struct XsString *filename, const struct XsString *mode)
Reopens a file.
Definition: xsfile.c:272
XsFile::XsFile_gets
char * XsFile_gets(struct XsFile *thisPtr, char *str, int num)
Reads characters from this file and stores them into str until (num-1) characters have been read or e...
Definition: xsfile.c:473
XsFile::XsFile_open
XsResultValue XsFile_open(struct XsFile *thisPtr, const struct XsString *filename, int readOnly)
Opens an existing binary file with name filename.
Definition: xsfile.c:184
XsFile::XsFile_create
XsResultValue XsFile_create(struct XsFile *thisPtr, const struct XsString *filename, int writeOnly)
Creates a new binary file with name filename, contents of existing files will be discarded.
Definition: xsfile.c:109
XsFile::XsFile_openText
XsResultValue XsFile_openText(struct XsFile *thisPtr, const struct XsString *filename, int readOnly)
Opens an existing binary file with name filename.
Definition: xsfile.c:217
XsFile
struct XsFile XsFile
Definition: xsfile.h:326
XsFile::XsFile_close
XsResultValue XsFile_close(struct XsFile *thisPtr)
Closes the file.
Definition: xsfile.c:323
xstypesconfig.h
pstdint.h
XsFile::XsFile_handle
FILE * XsFile_handle(struct XsFile *thisPtr)
Definition: xsfile.c:611
XsFile
Encapsulates a file, providing a platform independent interface.
Definition: xsfile.h:131
XsFile::XsFile_seek
XsResultValue XsFile_seek(struct XsFile *thisPtr, XsFilePos offset)
Moves the current file position relative to the start of the file.
Definition: xsfile.c:493
XsFile::XsFile_erase
XsResultValue XsFile_erase(const struct XsString *filename)
Deletes a file with name filename.
Definition: xsfile.c:400
XsFile::XsFile_fullPath
XsResultValue XsFile_fullPath(const struct XsString *filename, struct XsString *fullPath)
Retrieves the full path for a filename.
Definition: xsfile.c:551
XSTYPES_DLL_API
#define XSTYPES_DLL_API
Definition: xstypesconfig.h:65
XsFile::XsFile_write
XsFilePos XsFile_write(struct XsFile *thisPtr, const void *source, XsFilePos size, XsFilePos count)
Writes a number of elements to a file.
Definition: xsfile.c:443
XsFile::XsFile_eof
int XsFile_eof(struct XsFile const *thisPtr)
Definition: xsfile.c:532
XsFile::XsFile_createText
XsResultValue XsFile_createText(struct XsFile *thisPtr, const struct XsString *filename, int writeOnly)
Creates a new text file with name filename, contents of existing files will be discarded.
Definition: xsfile.c:151
xsbytearray.h
xsfilepos.h
xsresultvalue.h
XsFilePos
int64_t XsFilePos
The type that is used for positioning inside a file.
Definition: xsfilepos.h:102
XsString
A 0-terminated managed string of characters.
XsFile::XsFile_tell
XsFilePos XsFile_tell(struct XsFile const *thisPtr)
Returns the current position in the file.
Definition: xsfile.c:520
XsFile::XsFile_read
XsFilePos XsFile_read(struct XsFile *thisPtr, void *destination, XsFilePos size, XsFilePos count)
Reads a number of elements from a file.
Definition: xsfile.c:431


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