ISStream.cpp
Go to the documentation of this file.
1 /*
2 MIT LICENSE
3 
4 Copyright (c) 2014-2021 Inertial Sense, Inc. - http://inertialsense.com
5 
6 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions :
7 
8 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9 
10 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11 */
12 
13 #include "ISStream.h"
14 #include "ISUtilities.h"
15 
16 #ifndef _FILE_OFFSET_BITS
17 #define _FILE_OFFSET_BITS 64
18 #endif
19 
21 {
22  Close();
23 }
24 
26 {
27  m_file = NULLPTR;
28 }
29 
30 bool cISFileStream::Open(const std::string& path, const char* mode)
31 {
32  Close();
33  m_file = openFile(path.c_str(), mode);
34  return (m_file != NULLPTR);
35 }
36 
37 int cISFileStream::Read(void* buffer, int count)
38 {
39  if (m_file != NULLPTR)
40  {
41  return (int)fread(buffer, 1, count, m_file);
42  }
43  return -1;
44 }
45 
46 int cISFileStream::Write(const void* buffer, int count)
47 {
48  if (m_file != NULLPTR)
49  {
50  return (int)fwrite(buffer, 1, count, m_file);
51  }
52  return -1;
53 }
54 
56 {
57  if (m_file != NULLPTR)
58  {
59  return fflush(m_file);
60  }
61  return -1;
62 }
63 
65 {
66  int status = 0;
67  if (m_file != NULLPTR)
68  {
69  status = fclose(m_file);
70  m_file = NULLPTR;
71  }
72  return status;
73 }
74 
76 {
77  if (m_file != NULLPTR)
78  {
79 
80 #if PLATFORM_IS_WINDOWS
81 
82  long long pos = _ftelli64(m_file);
83  _fseeki64(m_file, 0, SEEK_END);
84  long long fileSize = _ftelli64(m_file);
85  _fseeki64(m_file, pos, SEEK_SET);
86  return fileSize - pos;
87 
88 #else
89 
90  long long pos = ftello(m_file);
91  fseeko(m_file, 0, SEEK_END);
92  long long fileSize = ftello(m_file);
93  fseeko(m_file, pos, SEEK_SET);
94  return fileSize - pos;
95 
96 #endif
97 
98  }
99  return 0;
100 }
101 
103 {
104  if (m_file != NULLPTR)
105  {
106  return (feof(m_file) != 0);
107  }
108  return true;
109 }
int Read(void *buffer, int count) OVERRIDE
Definition: ISStream.cpp:37
int Close() OVERRIDE
Definition: ISStream.cpp:64
size_t count(InputIterator first, InputIterator last, T const &item)
Definition: catch.hpp:3206
int Flush() OVERRIDE
Definition: ISStream.cpp:55
virtual ~cISStream()
Definition: ISStream.cpp:20
#define NULLPTR
Definition: ISConstants.h:426
FILE * openFile(const char *path, const char *mode)
long long GetBytesAvailableToRead() OVERRIDE
Definition: ISStream.cpp:75
bool Open(const std::string &path, const char *mode)
Definition: ISStream.cpp:30
int Write(const void *buffer, int count) OVERRIDE
Definition: ISStream.cpp:46
virtual int Close()
Definition: ISStream.h:65


inertial_sense_ros
Author(s):
autogenerated on Sun Feb 28 2021 03:17:57