~ubuntu-branches/ubuntu/wily/xmms2/wily

« back to all changes in this revision

Viewing changes to src/plugins/gme/gme/Data_Reader.h

  • Committer: Bazaar Package Importer
  • Author(s): Benjamin Drung
  • Date: 2008-07-04 16:23:34 UTC
  • mfrom: (1.1.5 upstream) (6.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080704162334-b3esbkcapt8wbrk4
Tags: 0.5DrLecter-2ubuntu1
* Merge from debian unstable (LP: #241098), remaining changes:
  + debian/control:
    + Update Maintainer field
    + add lpia to xmms2-plugin-alsa supported architectures
    + Added liba52-0.7.4-dev to build depends
  + debian/rules: Added patch, patch-stamp and unpatch
  + changed 01_gcc4.3.patch:
    + src/include/xmmsclient/xmmsclient++/helpers.h: Added #include <climits>
* New upstream relase fixes LP: #212566, #222341

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Data reader interface for uniform access
 
2
 
 
3
// File_Extractor 0.4.0
 
4
#ifndef DATA_READER_H
 
5
#define DATA_READER_H
 
6
 
 
7
#include "blargg_common.h"
 
8
 
 
9
// Supports reading and finding out how many bytes are remaining
 
10
class Data_Reader {
 
11
public:
 
12
        virtual ~Data_Reader() { }
 
13
        
 
14
        static const char eof_error []; // returned by read() when request goes beyond end
 
15
        
 
16
        // Read at most count bytes and return number actually read, or <= 0 if error
 
17
        virtual long read_avail( void*, long n ) = 0;
 
18
        
 
19
        // Read exactly count bytes and return error if they couldn't be read
 
20
        virtual blargg_err_t read( void*, long count );
 
21
        
 
22
        // Number of bytes remaining until end of file
 
23
        virtual long remain() const = 0;
 
24
        
 
25
        // Read and discard count bytes
 
26
        virtual blargg_err_t skip( long count );
 
27
        
 
28
public:
 
29
        Data_Reader() { }
 
30
        typedef blargg_err_t error_t; // deprecated
 
31
private:
 
32
        // noncopyable
 
33
        Data_Reader( const Data_Reader& );
 
34
        Data_Reader& operator = ( const Data_Reader& );
 
35
};
 
36
 
 
37
// Supports seeking in addition to Data_Reader operations
 
38
class File_Reader : public Data_Reader {
 
39
public:
 
40
        // Size of file
 
41
        virtual long size() const = 0;
 
42
        
 
43
        // Current position in file
 
44
        virtual long tell() const = 0;
 
45
        
 
46
        // Go to new position
 
47
        virtual blargg_err_t seek( long ) = 0;
 
48
        
 
49
        long remain() const;
 
50
        blargg_err_t skip( long n );
 
51
};
 
52
 
 
53
// Disk file reader
 
54
class Std_File_Reader : public File_Reader {
 
55
public:
 
56
        blargg_err_t open( const char* path );
 
57
        void close();
 
58
        
 
59
public:
 
60
        Std_File_Reader();
 
61
        ~Std_File_Reader();
 
62
        long size() const;
 
63
        blargg_err_t read( void*, long );
 
64
        long read_avail( void*, long );
 
65
        long tell() const;
 
66
        blargg_err_t seek( long );
 
67
private:
 
68
        void* file_;
 
69
};
 
70
 
 
71
// Treats range of memory as a file
 
72
class Mem_File_Reader : public File_Reader {
 
73
public:
 
74
        Mem_File_Reader( const void*, long size );
 
75
        
 
76
public:
 
77
        long size() const;
 
78
        long read_avail( void*, long );
 
79
        long tell() const;
 
80
        blargg_err_t seek( long );
 
81
private:
 
82
        const char* const begin;
 
83
        const long size_;
 
84
        long pos;
 
85
};
 
86
 
 
87
// Makes it look like there are only count bytes remaining
 
88
class Subset_Reader : public Data_Reader {
 
89
public:
 
90
        Subset_Reader( Data_Reader*, long count );
 
91
 
 
92
public:
 
93
        long remain() const;
 
94
        long read_avail( void*, long );
 
95
private:
 
96
        Data_Reader* in;
 
97
        long remain_;
 
98
};
 
99
 
 
100
// Joins already-read header and remaining data into original file (to avoid seeking)
 
101
class Remaining_Reader : public Data_Reader {
 
102
public:
 
103
        Remaining_Reader( void const* header, long size, Data_Reader* );
 
104
 
 
105
public:
 
106
        long remain() const;
 
107
        long read_avail( void*, long );
 
108
        blargg_err_t read( void*, long );
 
109
private:
 
110
        char const* header;
 
111
        char const* header_end;
 
112
        Data_Reader* in;
 
113
        long read_first( void* out, long count );
 
114
};
 
115
 
 
116
// Invokes callback function to read data. Size of data must be specified in advance.
 
117
class Callback_Reader : public Data_Reader {
 
118
public:
 
119
        typedef const char* (*callback_t)( void* data, void* out, long count );
 
120
        Callback_Reader( callback_t, long size, void* data = 0 );
 
121
public:
 
122
        long read_avail( void*, long );
 
123
        blargg_err_t read( void*, long );
 
124
        long remain() const;
 
125
private:
 
126
        callback_t const callback;
 
127
        void* const data;
 
128
        long remain_;
 
129
};
 
130
 
 
131
#ifdef HAVE_ZLIB_H
 
132
// Gzip compressed file reader
 
133
class Gzip_File_Reader : public File_Reader {
 
134
public:
 
135
        blargg_err_t open( const char* path );
 
136
        void close();
 
137
        
 
138
public:
 
139
        Gzip_File_Reader();
 
140
        ~Gzip_File_Reader();
 
141
        long size() const;
 
142
        long read_avail( void*, long );
 
143
        long tell() const;
 
144
        blargg_err_t seek( long );
 
145
private:
 
146
        void* file_;
 
147
        long size_;
 
148
};
 
149
#endif
 
150
 
 
151
#endif