added code for mp3 and jpeg parsing
added interface for data sources
This commit is contained in:
50
data/formats/DataSourcePosixFile.h
Normal file
50
data/formats/DataSourcePosixFile.h
Normal file
@@ -0,0 +1,50 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
|
||||
/** file on the desktop (posix) filesystem */
|
||||
class DataSourcePosixFile {
|
||||
|
||||
FILE* f = nullptr;
|
||||
|
||||
public:
|
||||
|
||||
DataSourcePosixFile() {
|
||||
|
||||
}
|
||||
|
||||
DataSourcePosixFile(const char* file) {
|
||||
f = fopen(file, "rw");
|
||||
if (!f) {
|
||||
throw std::runtime_error(std::string("failed to open file: ") + file);
|
||||
}
|
||||
}
|
||||
|
||||
~DataSourcePosixFile() {
|
||||
if (f) {fclose(f);}
|
||||
}
|
||||
|
||||
uint32_t curPos() const {
|
||||
return ftell(f);
|
||||
}
|
||||
|
||||
void seekTo(uint32_t pos) {
|
||||
fseek(f, pos, SEEK_SET);
|
||||
}
|
||||
|
||||
uint32_t read(uint32_t bytes, uint8_t* dst) {
|
||||
return fread(dst, bytes, 1, f) * bytes;
|
||||
}
|
||||
|
||||
uint32_t write(uint32_t bytes, const uint8_t* src) {
|
||||
return fwrite(src, bytes, 1, f) * bytes;
|
||||
}
|
||||
|
||||
/** read an entity */
|
||||
template <typename T> void readType(T& dst) {
|
||||
read(sizeof(T), (uint8_t*) &dst);
|
||||
}
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user