1 #ifndef __lib_base_rawfile_h
2 #define __lib_base_rawfile_h
5 #include <lib/base/object.h>
7 class iDataSource: public iObject
10 virtual off_t lseek(off_t offset, int whence)=0;
11 virtual ssize_t read(void *buf, size_t count)=0; /* NOTE: you must be able to handle short reads! */
12 virtual off_t length()=0;
13 virtual off_t position()=0;
14 virtual int valid()=0;
15 virtual eSingleLock &getLock()=0;
16 virtual bool is_shared()=0;
19 class iDataSourcePositionRestorer
21 ePtr<iDataSource> &m_source;
24 iDataSourcePositionRestorer(ePtr<iDataSource> &source)
27 if (m_source->is_shared())
28 m_position = m_source->position();
30 ~iDataSourcePositionRestorer()
32 if (m_source->is_shared())
33 m_source->lseek(m_position, SEEK_SET);
37 class eRawFile: public iDataSource
39 DECLARE_REF(eRawFile);
44 int open(const char *filename, int cached = 0);
46 off_t lseek(off_t offset, int whence);
48 ssize_t read(void *buf, size_t count); /* NOTE: you must be able to handle short reads! */
52 eSingleLock &getLock();
53 bool is_shared() { return ref.count > 1; }
55 int m_fd; /* for uncached */
56 FILE *m_file; /* for cached */
58 std::string m_basename;
59 off_t m_splitsize, m_totallength, m_current_offset, m_base_offset, m_last_offset;
63 int switchOffset(off_t off);
64 FILE *openFileCached(int nr);
65 int openFileUncached(int nr);