SBB Host
Host communication with the self balancing bike.
Loading...
Searching...
No Matches
File.h
Go to the documentation of this file.
1
2#ifndef FILE_H
3#define FILE_H
4
5#include <stdio.h>
6#include <malloc.h>
7
8#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) || defined(__WIN32__) || defined(WIN64) || defined(_WIN64) || defined(__WIN64) || defined(__WIN64__)
9#ifndef OS_WIN
10#define OS_WIN
11#endif
12#elif defined(linux) || defined(__linux) || defined(__linux__) || defined(__GNUC__) || defined(__GNUG__) || defined(unix) || defined(__unix) || defined(__unix__)
13#ifndef OS_LINUX
14#define OS_LINUX
15#endif
16#else
17#error OS not supported
18#endif
19
20#ifdef OS_LINUX
21#define fopen_s(pFile,filename,mode) ((*(pFile))=fopen((filename),(mode)))==NULL //in linux use fopen for fopen_s
22#endif
23
30class File {
31public:
36
42 File(const char* str, const char* mode);
43
48
55 bool open(const char* str, const char* mode);
56
62 size_t print(const char* str);
63
70 size_t write(void* buf, size_t len);
71
78 size_t read(void* buf, size_t len);
79
85 size_t read(unsigned char** p_buf);
86
93 bool gets(char* str, size_t len);
94
98 void close();
99
104 bool isOpen() { return _isOpen; }
105
110 bool eof();
111 operator bool() { return _isOpen; }
112
113private:
114 FILE* p_file;
115 bool _isOpen;
116
117};
118
119#endif
A class for file reading and writing.
Definition: File.h:30
size_t print(const char *str)
Print a string.
File(const char *str, const char *mode)
Constructor.
bool open(const char *str, const char *mode)
Open the file.
bool _isOpen
true if file is open
Definition: File.h:115
bool gets(char *str, size_t len)
Get a string.
bool eof()
Check end-of-file.
void close()
Clone the file.
size_t read(void *buf, size_t len)
Read a buffer.
FILE * p_file
Pointer to the C-type file.
Definition: File.h:114
size_t read(unsigned char **p_buf)
Read all the file.
~File()
Desctructor.
File()
Constructor.
size_t write(void *buf, size_t len)
Write a buffer.
bool isOpen()
Check if open.
Definition: File.h:104