Mercurial > audlegacy-plugins
comparison src/console/Data_Reader.h @ 341:986f098da058 trunk
[svn] - merge in blargg's changes
author | nenolod |
---|---|
date | Thu, 07 Dec 2006 15:20:41 -0800 |
parents | fb513e10174e |
children |
comparison
equal
deleted
inserted
replaced
340:9e5a7158fa80 | 341:986f098da058 |
---|---|
2 | 2 |
3 // File_Extractor 0.4.0 | 3 // File_Extractor 0.4.0 |
4 #ifndef DATA_READER_H | 4 #ifndef DATA_READER_H |
5 #define DATA_READER_H | 5 #define DATA_READER_H |
6 | 6 |
7 #undef DATA_READER_H | 7 #include "blargg_common.h" |
8 // allow blargg_config.h to #include Data_Reader.h | |
9 #include "blargg_config.h" | |
10 #ifndef DATA_READER_H | |
11 #define DATA_READER_H | |
12 | 8 |
13 // Supports reading and finding out how many bytes are remaining | 9 // Supports reading and finding out how many bytes are remaining |
14 class Data_Reader { | 10 class Data_Reader { |
15 public: | 11 public: |
16 Data_Reader() { } | |
17 virtual ~Data_Reader() { } | 12 virtual ~Data_Reader() { } |
18 | 13 |
19 static const char eof_error []; // returned by read() when request goes beyond end | 14 static const char eof_error []; // returned by read() when request goes beyond end |
20 | |
21 typedef const char* error_t; // NULL if successful | |
22 | 15 |
23 // Read at most count bytes and return number actually read, or <= 0 if error | 16 // Read at most count bytes and return number actually read, or <= 0 if error |
24 virtual long read_avail( void*, long n ) = 0; | 17 virtual long read_avail( void*, long n ) = 0; |
25 | 18 |
26 // Read exactly count bytes and return error if they couldn't be read | 19 // Read exactly count bytes and return error if they couldn't be read |
27 virtual error_t read( void*, long count ); | 20 virtual blargg_err_t read( void*, long count ); |
28 | 21 |
29 // Number of bytes remaining until end of file | 22 // Number of bytes remaining until end of file |
30 virtual long remain() const = 0; | 23 virtual long remain() const = 0; |
31 | 24 |
32 // Read and discard count bytes | 25 // Read and discard count bytes |
33 virtual error_t skip( long count ); | 26 virtual blargg_err_t skip( long count ); |
34 | 27 |
28 public: | |
29 Data_Reader() { } | |
30 typedef blargg_err_t error_t; // deprecated | |
35 private: | 31 private: |
36 // noncopyable | 32 // noncopyable |
37 Data_Reader( const Data_Reader& ); | 33 Data_Reader( const Data_Reader& ); |
38 Data_Reader& operator = ( const Data_Reader& ); | 34 Data_Reader& operator = ( const Data_Reader& ); |
39 }; | 35 }; |
46 | 42 |
47 // Current position in file | 43 // Current position in file |
48 virtual long tell() const = 0; | 44 virtual long tell() const = 0; |
49 | 45 |
50 // Go to new position | 46 // Go to new position |
51 virtual error_t seek( long ) = 0; | 47 virtual blargg_err_t seek( long ) = 0; |
52 | 48 |
53 long remain() const; | 49 long remain() const; |
54 error_t skip( long n ); | 50 blargg_err_t skip( long n ); |
55 }; | 51 }; |
56 | 52 |
57 // Disk file reader | 53 // Disk file reader |
58 class Std_File_Reader : public File_Reader { | 54 class Std_File_Reader : public File_Reader { |
59 public: | 55 public: |
60 error_t open( const char* path ); | 56 blargg_err_t open( const char* path ); |
61 void close(); | 57 void close(); |
62 | 58 |
63 public: | 59 public: |
64 Std_File_Reader(); | 60 Std_File_Reader(); |
65 ~Std_File_Reader(); | 61 ~Std_File_Reader(); |
66 long size() const; | 62 long size() const; |
67 error_t read( void*, long ); | 63 blargg_err_t read( void*, long ); |
68 long read_avail( void*, long ); | 64 long read_avail( void*, long ); |
69 long tell() const; | 65 long tell() const; |
70 error_t seek( long ); | 66 blargg_err_t seek( long ); |
71 private: | 67 private: |
72 void* file_; | 68 void* file_; |
73 }; | 69 }; |
74 | 70 |
75 // Treats range of memory as a file | 71 // Treats range of memory as a file |
79 | 75 |
80 public: | 76 public: |
81 long size() const; | 77 long size() const; |
82 long read_avail( void*, long ); | 78 long read_avail( void*, long ); |
83 long tell() const; | 79 long tell() const; |
84 error_t seek( long ); | 80 blargg_err_t seek( long ); |
85 private: | 81 private: |
86 const char* const begin; | 82 const char* const begin; |
87 const long size_; | 83 const long size_; |
88 long pos; | 84 long pos; |
89 }; | 85 }; |
107 Remaining_Reader( void const* header, long size, Data_Reader* ); | 103 Remaining_Reader( void const* header, long size, Data_Reader* ); |
108 | 104 |
109 public: | 105 public: |
110 long remain() const; | 106 long remain() const; |
111 long read_avail( void*, long ); | 107 long read_avail( void*, long ); |
112 error_t read( void*, long ); | 108 blargg_err_t read( void*, long ); |
113 private: | 109 private: |
114 char const* header; | 110 char const* header; |
115 char const* header_end; | 111 char const* header_end; |
116 Data_Reader* in; | 112 Data_Reader* in; |
117 long read_first( void* out, long count ); | 113 long read_first( void* out, long count ); |
118 }; | 114 }; |
119 | 115 |
120 // Invokes callback function to read data. Size of data must be specified in advance. | 116 // Invokes callback function to read data. Size of data must be specified in advance. |
121 class Callback_Reader : public Data_Reader { | 117 class Callback_Reader : public Data_Reader { |
122 public: | 118 public: |
123 typedef error_t (*callback_t)( void* data, void* out, long count ); | 119 typedef const char* (*callback_t)( void* data, void* out, long count ); |
124 Callback_Reader( callback_t, long size, void* data = 0 ); | 120 Callback_Reader( callback_t, long size, void* data = 0 ); |
125 public: | 121 public: |
126 long read_avail( void*, long ); | 122 long read_avail( void*, long ); |
127 error_t read( void*, long ); | 123 blargg_err_t read( void*, long ); |
128 long remain() const; | 124 long remain() const; |
129 private: | 125 private: |
130 callback_t const callback; | 126 callback_t const callback; |
131 void* const data; | 127 void* const data; |
132 long remain_; | 128 long remain_; |
134 | 130 |
135 #ifdef HAVE_ZLIB_H | 131 #ifdef HAVE_ZLIB_H |
136 // Gzip compressed file reader | 132 // Gzip compressed file reader |
137 class Gzip_File_Reader : public File_Reader { | 133 class Gzip_File_Reader : public File_Reader { |
138 public: | 134 public: |
139 error_t open( const char* path ); | 135 blargg_err_t open( const char* path ); |
140 void close(); | 136 void close(); |
141 | 137 |
142 public: | 138 public: |
143 Gzip_File_Reader(); | 139 Gzip_File_Reader(); |
144 ~Gzip_File_Reader(); | 140 ~Gzip_File_Reader(); |
145 long size() const; | 141 long size() const; |
146 long read_avail( void*, long ); | 142 long read_avail( void*, long ); |
147 long tell() const; | 143 long tell() const; |
148 error_t seek( long ); | 144 blargg_err_t seek( long ); |
149 private: | 145 private: |
150 void* file_; | 146 void* file_; |
151 long size_; | 147 long size_; |
152 }; | 148 }; |
153 #endif | 149 #endif |
154 | 150 |
155 #endif | 151 #endif |
156 #endif |