-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreader.h
More file actions
48 lines (43 loc) · 963 Bytes
/
Copy pathreader.h
File metadata and controls
48 lines (43 loc) · 963 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <stdio.h>
/**
* fürs wave file lesen
*/
class Reader {
public:
Reader(const std::string &fileName) {
this->f=fopen(fileName.c_str(),"r");
if(!this->f) {
throw std::runtime_error("error opening " + fileName);
}
};
~Reader() {
fclose(this->f);
}
int32_t ReadInt32() {
int32_t ret;
fread(&ret,1,sizeof(ret),this->f);
return ret;
}
int16_t ReadInt16( ) {
int16_t ret;
fread(&ret,1,sizeof(ret),this->f);
return ret;
}
int ReadData(int len, std::string &dst) {
unsigned char *buffer;
buffer=(unsigned char *) malloc(len);
if(fread(buffer,1,len,f) != (size_t) len) {
throw std::runtime_error("error reading file data");
}
dst.assign((char*) buffer, len);
free(buffer);
return len;
}
// void Seek(int skipsize, SeekOrigin::Current ) {
// SEEK_SET, SEEK_CUR, or SEEK_END
void Seek(int skipsize, int a ) {
abort(); // not yet implemented
}
private:
FILE *f;
};