MP4v2
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:
15 enum Mode {
19 MODE_CREATE
20 };
21
23 typedef int64_t Size;
24
25public:
26 virtual ~FileProvider() { }
27
28 virtual bool open( const std::string& name, Mode mode ) = 0;
29 virtual bool seek( Size pos ) = 0;
30 virtual bool read( void* buffer, Size size, Size& nin ) = 0;
31 virtual bool write( const void* buffer, Size size, Size& nout ) = 0;
32 virtual bool truncate( Size size ) = 0;
33 virtual bool close() = 0;
34 virtual bool getSize( Size& nout ) = 0;
35
36protected:
37 FileProvider() { }
38};
39
51
52class MP4V2_EXPORT File : public FileProvider
53{
54public:
73
74 explicit File( const std::string& name = "", Mode mode = MODE_UNDEFINED,
75 FileProvider* provider = NULL );
76
85
87
103
104 bool open( const std::string& name = "", Mode mode = MODE_UNDEFINED );
105
116
117 bool close();
118
128
129 bool seek( Size pos );
130
146
147 bool read( void* buffer, Size size, Size& nin );
148
164
165 bool write( const void* buffer, Size size, Size& nout );
166
176
177 bool truncate( Size size );
178
188
189 bool getSize( Size& nout );
190
191private:
192 std::string _name;
193 bool _isOpen;
194 Mode _mode;
195 Size _size;
196 Size _position;
197 FileProvider& _provider;
198
199public:
200 const std::string& name;
201 const bool& isOpen;
202 const Mode& mode;
203 const Size& size;
204 const Size& position;
205
206public:
207 void setName( const std::string& name );
208 void setMode( Mode mode );
209};
210
212
214{
215public:
217
218 bool open( const std::string& name, Mode mode );
219 bool seek( Size pos );
220 bool read( void* buffer, Size size, Size& nin );
221 bool write( const void* buffer, Size size, Size& nout );
222 bool truncate( Size size );
223 bool close();
224 bool getSize( Size& nout );
225
226private:
227 MP4FileProvider _call;
228 void* _handle;
229 std::string _name;
230};
231
233
235{
236public:
237 CallbacksFileProvider( const MP4IOCallbacks& callbacks, void* handle );
238
239 bool open( const std::string& name, Mode mode );
240 bool seek( Size pos );
241 bool read( void* buffer, Size size, Size& nin );
242 bool write( const void* buffer, Size size, Size& nout );
243 bool truncate( Size size );
244 bool close();
245 bool getSize( Size& nout );
246
247private:
248 MP4IOCallbacks _call;
249 void* _handle;
250};
251
253
254}}} // namespace mp4v2::platform::io
255
256#endif // MP4V2_PLATFORM_IO_FILE_H
File implementation.
Definition: File.h:53
const Mode & mode
read-only: file mode
Definition: File.h:202
bool close()
Closes file.
bool truncate(Size size)
Truncate file to length in bytes.
bool write(const void *buffer, Size size, Size &nout)
Binary stream write.
const Size & size
read-only: file size
Definition: File.h:203
bool seek(Size pos)
Set current file position in bytes.
const Size & position
read-only: file position
Definition: File.h:204
bool open(const std::string &name="", Mode mode=MODE_UNDEFINED)
Open file.
bool read(void *buffer, Size size, Size &nin)
Binary stream read.
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:200
File(const std::string &name="", Mode mode=MODE_UNDEFINED, FileProvider *provider=NULL)
Constructor.
const bool & isOpen
read-only: true if file is open
Definition: File.h:201
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
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:41
Structure of functions implementing custom I/O callbacks.
Definition: file.h:60