Qualia  0.2
XFile.h
Go to the documentation of this file.
1 /*
2  * XFile.h
3  *
4  * Abstract interface for files.
5  *
6  * This file is part of Qualia https://github.com/sofian/qualia
7  *
8  * The code is an adaptation of code from Torch 3.1.
9  * (c) 2013 Sofian Audry -- info(@)sofianaudry(.)com
10  * (c) 2003--2004 Ronan Collobert (collober@idiap.ch)
11  *
12  * This program is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation, either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see <http://www.gnu.org/licenses/>.
24  */
25 #ifndef X_FILE_INC
26 #define X_FILE_INC
27 
28 #include <qualia/core/common.h>
29 #include <string.h>
30 
31 #ifndef SEEK_SET // from stdio.h
32 #define SEEK_SET 0x0
33 #define SEEK_CUR 0x1
34 #define SEEK_END 0x2
35 #endif
36 
44 class XFile
45 {
46  public:
47 
49  XFile();
50 
53  virtual int read(void *ptr, int block_size, int n_blocks) = 0;
54 
57  virtual int write(const void *ptr, int block_size, int n_blocks) = 0;
58 
63  int taggedRead(void *ptr, int block_size, int n_blocks, const char *tag);
64 
66  int taggedWrite(const void *ptr, int block_size, int n_blocks, const char *tag);
67 
69  virtual int eof() = 0;
70 
72  virtual int flush() = 0;
73 
75  virtual int seek(long offset, int whence) = 0;
76 
78  virtual long tell() = 0;
79 
81  virtual void rewind() = 0;
82 
84  //virtual int printf(const char *format, ...) = 0;
85 
87  //virtual int scanf(const char *format, void *ptr) = 0;
88 
90  virtual char *gets(char *dest, int size_) = 0;
91 
92  virtual long size();
93 
94  //-----
95 
96  virtual ~XFile();
97 };
98 
99 #endif