Coverage Report

Created: 2026-11-12 07:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/vlc/contrib/contrib-build/game-music-emu/gme/Data_Reader.h
Line
Count
Source
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
#ifdef HAVE_ZLIB_H
10
#include <zlib.h>
11
#endif
12
13
// Supports reading and finding out how many bytes are remaining
14
class Data_Reader {
15
public:
16
3.82k
  virtual ~Data_Reader() { }
17
18
  static const char eof_error []; // returned by read() when request goes beyond end
19
20
  // Read at most count bytes and return number actually read, or <= 0 if error
21
  virtual long read_avail( void*, long n ) = 0;
22
23
  // Read exactly count bytes and return error if they couldn't be read
24
  virtual blargg_err_t read( void*, long count );
25
26
  // Number of bytes remaining until end of file
27
  virtual long remain() const = 0;
28
29
  // Read and discard count bytes
30
  virtual blargg_err_t skip( long count );
31
32
public:
33
3.82k
  Data_Reader() { }
34
  typedef blargg_err_t error_t; // deprecated
35
private:
36
  // noncopyable
37
  Data_Reader( const Data_Reader& );
38
  Data_Reader& operator = ( const Data_Reader& );
39
};
40
41
// Supports seeking in addition to Data_Reader operations
42
class File_Reader : public Data_Reader {
43
public:
44
  // Size of file
45
  virtual long size() const = 0;
46
47
  // Current position in file
48
  virtual long tell() const = 0;
49
50
  // Go to new position
51
  virtual blargg_err_t seek( long ) = 0;
52
53
  long remain() const;
54
  blargg_err_t skip( long n );
55
};
56
57
// Disk file reader
58
class Std_File_Reader : public File_Reader {
59
public:
60
  blargg_err_t open( const char* path );
61
  void close();
62
63
public:
64
  Std_File_Reader();
65
  ~Std_File_Reader();
66
  long size() const;
67
  blargg_err_t read( void*, long );
68
  long read_avail( void*, long );
69
  long tell() const;
70
  blargg_err_t seek( long );
71
private:
72
  void* file_; // Either FILE* or zlib's gzFile
73
#ifdef HAVE_ZLIB_H
74
  long size_; // TODO: Fix ABI compat
75
#endif /* HAVE_ZLIB_H */
76
};
77
78
// Treats range of memory as a file
79
class Mem_File_Reader : public File_Reader {
80
public:
81
  Mem_File_Reader( const void*, long size );
82
#ifdef HAVE_ZLIB_H
83
  ~Mem_File_Reader( );
84
#endif /* HAVE_ZLIB_H */
85
86
public:
87
  long size() const;
88
  long read_avail( void*, long );
89
  long tell() const;
90
  blargg_err_t seek( long );
91
private:
92
#ifdef HAVE_ZLIB_H
93
  bool gz_decompress();
94
#endif /* HAVE_ZLIB_H */
95
96
  const char* m_begin;
97
  long m_size;
98
  long m_pos;
99
#ifdef HAVE_ZLIB_H
100
  bool m_ownedPtr = false; // set if we must free m_begin
101
#endif /* HAVE_ZLIB_H */
102
};
103
104
105
// Makes it look like there are only count bytes remaining
106
class Subset_Reader : public Data_Reader {
107
public:
108
  Subset_Reader( Data_Reader*, long count );
109
110
public:
111
  long remain() const;
112
  long read_avail( void*, long );
113
private:
114
  Data_Reader* in;
115
  long remain_;
116
};
117
118
// Joins already-read header and remaining data into original file (to avoid seeking)
119
class Remaining_Reader : public Data_Reader {
120
public:
121
  Remaining_Reader( void const* header, long size, Data_Reader* );
122
123
public:
124
  long remain() const;
125
  long read_avail( void*, long );
126
  blargg_err_t read( void*, long );
127
private:
128
  char const* header;
129
  char const* header_end;
130
  Data_Reader* in;
131
  long read_first( void* out, long count );
132
};
133
134
// Invokes callback function to read data. Size of data must be specified in advance.
135
class Callback_Reader : public Data_Reader {
136
public:
137
  typedef const char* (*callback_t)( void* data, void* out, int count );
138
  Callback_Reader( callback_t, long size, void* data = 0 );
139
public:
140
  long read_avail( void*, long );
141
  blargg_err_t read( void*, long );
142
  long remain() const;
143
private:
144
  callback_t const callback;
145
  void* const data;
146
  long remain_;
147
};
148
149
#endif