libplatform/io/File.h Source File
File.h
1#ifndef MP4V2_PLATFORM_IO_FILE_H
2#define MP4V2_PLATFORM_IO_FILE_H
3
4namespace mp4v2 { namespace platform { namespace io {
5
7
8class MP4V2_EXPORT FileProvider
9{
10public:
11 static FileProvider& standard();
12
13public:
21
23 typedef int64_t Size;
24
25public:
26 virtual ~FileProvider() { }
27
28 virtual bool open( std::string name, Mode mode ) = 0;
29 virtual bool seek( Size pos ) = 0;
30 virtual bool read( void* buffer, Size size, Size& nin, Size maxChunkSize ) = 0;
31 virtual bool write( const void* buffer, Size size, Size& nout, Size maxChunkSize ) = 0;
32 virtual bool close() = 0;
33 virtual bool getSize( Size& nout ) = 0;
34
35protected:
36 FileProvider() { }
37};
38
50
51class MP4V2_EXPORT File : public FileProvider
52{
53public:
72
73 explicit File( std::string name = "", Mode mode = MODE_UNDEFINED, FileProvider* = NULL );
74
83
85
99
100 bool open( std::string name = "", Mode mode = MODE_UNDEFINED );
101
112
113 bool close();
114
124
125 bool seek( Size pos );
126
144
145 bool read( void* buffer, Size size, Size& nin, Size maxChunkSize = 0 );
146
164
165 bool write( const void* buffer, Size size, Size& nout, Size maxChunkSize = 0 );
166
176
177 bool getSize( Size& nout );
178
179private:
180 std::string _name;
181 bool _isOpen;
182 Mode _mode;
183 Size _size;
184 Size _position;
185 FileProvider& _provider;
186
187public:
188 const std::string& name;
189 const bool& isOpen;
190 const Mode& mode;
191 const Size& size;
192 const Size& position;
193
194public:
195 void setName( const std::string& name );
196 void setMode( Mode mode );
197};
198
200
202{
203public:
205
206 bool open( std::string name, Mode mode );
207 bool seek( Size pos );
208 bool read( void* buffer, Size size, Size& nin, Size maxChunkSize );
209 bool write( const void* buffer, Size size, Size& nout, Size maxChunkSize );
210 bool close();
211 bool getSize( Size& nout );
212
213private:
214 MP4FileProvider _call;
215 void* _handle;
216};
217
219
220}}} // namespace mp4v2::platform::io
221
222#endif // MP4V2_PLATFORM_IO_FILE_H
File implementation.
Definition File.h:52
const Mode & mode
read-only: file mode
Definition File.h:190
bool close()
Closes file.
const Size & size
read-only: file size
Definition File.h:191
bool seek(Size pos)
Set current file position in bytes.
const Size & position
read-only: file position
Definition File.h:192
bool write(const void *buffer, Size size, Size &nout, Size maxChunkSize=0)
Binary stream write.
bool read(void *buffer, Size size, Size &nin, Size maxChunkSize=0)
Binary stream read.
bool open(std::string name="", Mode mode=MODE_UNDEFINED)
Open file.
bool getSize(Size &nout)
Get size of file in bytes.
const std::string & name
read-only: file pathname or empty-string if not applicable
Definition File.h:188
const bool & isOpen
read-only: true if file is open
Definition File.h:189
File(std::string name="", Mode mode=MODE_UNDEFINED, FileProvider *=NULL)
Constructor.
Mode
file operation mode flags
Definition File.h:15
@ MODE_MODIFY
file may be read/written
Definition File.h:18
@ MODE_UNDEFINED
undefined
Definition File.h:16
@ MODE_READ
file may be read
Definition File.h:17
@ MODE_CREATE
file will be created/truncated for read/write
Definition File.h:19
int64_t Size
type used to represent all file sizes and offsets
Definition File.h:23
Structure of functions implementing custom file provider.
Definition file.h:37