ISLogFile.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 "ISLogFile.h"
14 #include "ISConstants.h"
15 #include <cstdarg>
16 
18 {
19 }
20 
21 cISLogFile::cISLogFile(const char* filePath, const char* mode) : cISLogFile()
22 {
23  open(filePath, mode);
24 
25 }
26 cISLogFile::cISLogFile(const std::string& filePath, const char* mode) : cISLogFile(filePath.c_str(), mode)
27 {
28 }
29 
31 {
32  close();
33 }
34 
35 bool cISLogFile::open(const char* filePath, const char* mode)
36 {
37  m_file = fopen(filePath, mode);
38  return m_file;
39 }
40 
42 {
43  if (m_file)
44  {
45  int result = fclose(m_file);
46  if (result == 0)
47  {
48  m_file = NULLPTR;
49  return true;
50  }
51  }
52  return false;
53 }
54 
56 {
57  if (m_file)
58  {
59  return (fflush(m_file) == 0);
60  } else
61  {
62  return false;
63  }
64 }
65 
67 {
68  if (m_file)
69  {
70  return (ferror(m_file) == 0);
71  }
72  else
73  {
74  return false;
75  }
76 }
77 
79 {
80  return m_file;
81 }
82 
83 int cISLogFile::putch(char ch)
84 {
85  if (m_file)
86  {
87  return fputc(ch, m_file);
88  }
89  else
90  {
91  return EOF;
92  }
93 }
94 
95 int cISLogFile::puts(const char* str)
96 {
97  if (m_file)
98  {
99  return fputs(str, m_file);
100  }
101  else
102  {
103  return EOF;
104  }
105 }
106 
107 std::size_t cISLogFile::write(const void* bytes, std::size_t len)
108 {
109  if (m_file)
110  {
111  return fwrite(bytes, 1, len, m_file);
112  }
113  else
114  {
115  return 0;
116  }
117 }
118 
119 int cISLogFile::lprintf(const char* format, ...)
120 {
121  int result;
122  va_list args;
123  va_start(args, format);
124  result = vprintf(format, args);
125  va_end(args);
126  return result;
127 }
128 
129 int cISLogFile::vprintf(const char* format, va_list args)
130 {
131  if (m_file) {
132  return ::vfprintf(m_file,format, args);
133  }
134  else
135  {
136  return -1;
137  }
138 }
139 
141 {
142  if (m_file)
143  {
144  return fgetc(m_file);
145  }
146  else
147  {
148  return EOF;
149  }
150 }
151 
152 
153 std::size_t cISLogFile::read(void* bytes, std::size_t len)
154 {
155  if (m_file)
156  {
157  return fread(bytes, 1, len, m_file);
158  }
159  else
160  {
161  return 0;
162  }
163 }
std::size_t read(void *bytes, std::size_t len) OVERRIDE
Definition: ISLogFile.cpp:153
bool close() OVERRIDE
Definition: ISLogFile.cpp:41
std::size_t write(const void *bytes, std::size_t len) OVERRIDE
Definition: ISLogFile.cpp:107
int putch(char ch) OVERRIDE
Definition: ISLogFile.cpp:83
#define NULLPTR
Definition: ISConstants.h:426
bool isOpened() OVERRIDE
Definition: ISLogFile.cpp:78
FILE * m_file
Definition: ISLogFile.h:36
int puts(const char *str) OVERRIDE
Definition: ISLogFile.cpp:95
bool good() OVERRIDE
Definition: ISLogFile.cpp:66
int getch() OVERRIDE
Definition: ISLogFile.cpp:140
#define EOF
Definition: ff.h:241
int vprintf(const char *format, va_list args) OVERRIDE
Definition: ISLogFile.cpp:129
bool flush() OVERRIDE
Definition: ISLogFile.cpp:55
int lprintf(const char *format,...) OVERRIDE
Definition: ISLogFile.cpp:119
bool open(const char *filePath, const char *mode) OVERRIDE
Definition: ISLogFile.cpp:35


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