2014-04-20 02:14:15 -07:00
|
|
|
#ifndef FILESTREAM_HPP
|
|
|
|
#define FILESTREAM_HPP
|
|
|
|
|
|
|
|
#include <string>
|
2015-07-10 16:44:31 -07:00
|
|
|
#include <memory>
|
2015-05-18 14:03:13 -07:00
|
|
|
#include <stdio.h>
|
2015-07-10 16:44:31 -07:00
|
|
|
#include "Athena/IStreamReader.hpp"
|
2014-04-20 02:14:15 -07:00
|
|
|
|
|
|
|
namespace Athena
|
|
|
|
{
|
|
|
|
namespace io
|
|
|
|
{
|
2015-03-01 12:42:39 -08:00
|
|
|
class FileReader : public IStreamReader
|
2014-04-20 02:14:15 -07:00
|
|
|
{
|
|
|
|
public:
|
2015-07-09 20:46:30 -07:00
|
|
|
FileReader(const std::string& filename, atInt32 cacheSize = (32 * 1024));
|
2015-01-28 22:31:14 -08:00
|
|
|
virtual ~FileReader();
|
2015-07-01 02:28:40 -07:00
|
|
|
inline const std::string& filename() const
|
|
|
|
{return m_filename;}
|
|
|
|
|
2014-04-20 02:14:15 -07:00
|
|
|
void open();
|
|
|
|
void close();
|
2015-07-01 02:28:40 -07:00
|
|
|
inline bool isOpen() const
|
|
|
|
{return m_fileHandle != NULL;}
|
2014-04-20 02:14:15 -07:00
|
|
|
bool save();
|
2014-06-17 21:51:18 -07:00
|
|
|
void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current);
|
|
|
|
atUint64 position() const;
|
|
|
|
atUint64 length() const;
|
2015-04-10 17:04:13 -07:00
|
|
|
atUint64 readUBytesToBuf(void* buf, atUint64 len);
|
2015-07-07 19:53:39 -07:00
|
|
|
|
2015-07-09 20:46:30 -07:00
|
|
|
void setCacheSize(const atInt32 blockSize);
|
2015-01-28 22:20:57 -08:00
|
|
|
protected:
|
2014-04-20 02:14:15 -07:00
|
|
|
std::string m_filename;
|
|
|
|
FILE* m_fileHandle;
|
2015-07-09 20:05:55 -07:00
|
|
|
std::unique_ptr<atUint8[]> m_cacheData;
|
2015-07-09 20:46:30 -07:00
|
|
|
atInt32 m_blockSize;
|
2015-07-09 20:05:55 -07:00
|
|
|
atInt32 m_curBlock;
|
|
|
|
atUint64 m_offset;
|
2014-04-20 02:14:15 -07:00
|
|
|
};
|
|
|
|
} // io
|
|
|
|
} // Athena
|
|
|
|
|
2014-04-24 19:01:24 -07:00
|
|
|
#ifndef FILEREADER_BASE
|
2015-01-28 22:20:57 -08:00
|
|
|
#define FILEREADER_BASE() \
|
2014-04-24 19:01:24 -07:00
|
|
|
private: \
|
2015-01-28 22:20:57 -08:00
|
|
|
typedef Athena::io::FileReader base
|
2014-04-24 19:01:24 -07:00
|
|
|
|
|
|
|
#endif // FILEREADER_BASE
|
|
|
|
|
2014-04-20 02:14:15 -07:00
|
|
|
#endif // FILESTREAM_HPP
|