-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataFile.h
executable file
·155 lines (129 loc) · 4.82 KB
/
DataFile.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/**
* @file DataFile.h
* @ingroup DataManagement
* @author Dominique Vaufreydaz, Grenoble Alpes University, Inria
* @copyright All right reserved.
*/
#ifndef __READ_DATA_H__
#define __READ_DATA_H__
#include <stdio.h>
#include <inttypes.h>
#include <string>
#include "Pipe.h"
namespace MobileRGBD {
/**
* @class DataFile DataFile.cpp DataFile.h
* @brief Read from a standard file of try to find a compressed version (7zip) of the file (in read mode).
* * Until now, the pipe functionality is only written for the read side.
*
* This class is used to pipe data from a 7zip file containing only one file
* when the original file is not found.
*
* @author Dominique Vaufreydaz, Grenoble Alpes University, Inria
*/
class DataFile : public Pipe
{
public:
/** @brief constructor. Set LogLevel and ShowInfos and call Init().
*/
DataFile();
/** @brief Virtual destructor, always.
*/
virtual ~DataFile();
/** @brief Open a file *always in binary mode* (why convertir \r\n as \n is enough, even on Windows (not in
* some strange app anyway). If reading is asked and the file could not be opened,
* try to open a 7zip version of the file using 7z.
*
* @param Filename [in] The file name.
* @param eMode [in] The width of the video stream.
* @return true if the file or its 7z version is opened.
*/
bool Open( const char * Filename, int eMode = READ_MODE );
/** @brief Read bytes from a the file (or pipe). Identical to fread.
*
* @param ptr [in,out] Pointer to buffer.
* @param size [in] Size of element to read.
* @param nmemb [in] Number ot element to read.
* @return Number of elements read.
*/
size_t Read( void *ptr, size_t size, size_t nmemb );
/** @brief Write bytes to a the file (or pipe). Identical to fwrite.
*
* @param ptr [in] Pointer to buffer.
* @param size [in] Size of element to read.
* @param nmemb [in] Number ot element to write.
* @return Number of elements written.
*/
size_t Write(const void *ptr, size_t size, size_t nmemb );
/** @brief Close file (or pipe). Identical to fclose/pclose.
*
*/
int Close();
/** @brief Write bytes to a the file (or pipe). Identical to fseek.
*
* @param offset [in] Number of offset bytes.
* @param whence [in] Origine of the offset (see fseek).
* @return error code, same as fseek.
*/
int Seek(int64_t offset, int whence);
/** @brief Get position in the current file/pipe.
*
*/
int64_t Tell();
/** @brief Restart file at beginning.
*
*/
void Rewind();
/** @brief Retrive current position in a file/pipe as a fpos_t_ structure (identical to fgetpos).
*
* @param pos [in,out] pointer to a fpos_t structure to fill.
* @return error code, same as fgetpos.
*/
int GetPos(fpos_t *pos);
/** @brief Retrieve current position in a file/pipe as a fpos_t_ structure (identical to fsetpos).
*
* @param pos [in] pointer to a fpos_t structure to use to set current pos in file/pipe.
* @return error code, same as fsetpos.
*/
int SetPos(fpos_t *pos);
/** @brief Return true if the file/pipe is opened.
* @return True is file/pipe is opened.
*/
bool IsOpen() { return (InternalFile != nullptr); }
/** @brief Check if a file exists
*
* @param FileName [in] File name.
* @return true if file actually exists
*/
static bool FileOrFolderExists( const char * FileName );
static bool OpenCompressedVersionFirst; /*!< Say that we want to try to open compressed version first. Useful when data are over the network. Default, false. */
protected:
bool IsPipe; /*!< Say that the InternalFile is a pipe or a usual file. Default, false. */
int64_t Pos; /*!< Say that the InternalFile is a pipe or a usual file. Default, false. */
std::string CompressedFileName;
static const size_t DropBufferSize = 1024*1024;
static char DropBuffer[DropBufferSize]; /*!< Share 1 Mib buffer to drop data when seeking forward in pipes */
/** @brief Open a file *always in binary mode*.
*
* @param Filename [in] The file name.
* @param eMode [in] The width of the video stream.
* @return true if the file version is opened.
*/
bool InternalOpen( const char * Filename, int eMode = READ_MODE );
/** @brief Open a 7z version file *always in binary mode*.
*
* @param Filename [in] The file name (without .7z extension)
* @param eMode [in] The width of the video stream.
* @return true if the 7zip is opened.
*/
bool InternalOpenCompressedVersion( const char * Filename, int eMode = READ_MODE );
/** @brief Open a 7z file *always in binary mode*.
*
* @param Filename [in] The 7zip file name.
* @param eMode [in] The width of the video stream.
* @return true if the 7zip is opened.
*/
bool InternalOpenCompressed( const char * Filename, int eMode = READ_MODE );
};
} // namespace MobileRGBD
#endif // __READ_DATA_H__