athena/include/Athena/FileReader.hpp

73 lines
1.5 KiB
C++
Raw Normal View History

2014-04-20 09:14:15 +00:00
#ifndef FILESTREAM_HPP
#define FILESTREAM_HPP
#include <string>
#include <memory>
#include <stdio.h>
#include "Athena/IStreamReader.hpp"
2014-04-20 09:14:15 +00:00
namespace Athena
{
namespace io
{
2015-03-01 20:42:39 +00:00
class FileReader : public IStreamReader
2014-04-20 09:14:15 +00:00
{
public:
FileReader(const std::string& filename, atInt32 cacheSize = (32 * 1024));
FileReader(const std::wstring& filename, atInt32 cacheSize = (32 * 1024));
2015-01-29 06:31:14 +00:00
virtual ~FileReader();
inline std::string filename() const
{
#if _WIN32
return utility::wideToUtf8(m_filename);
#else
return m_filename;
#endif
}
inline std::wstring wfilename() const
{
#if _WIN32
return m_filename;
#else
return utility::utf8ToWide(m_filename);
#endif
}
2015-07-01 09:28:40 +00:00
2014-04-20 09:14:15 +00:00
void open();
void close();
2015-07-01 09:28:40 +00:00
inline bool isOpen() const
{return m_fileHandle != NULL;}
2014-04-20 09:14:15 +00:00
bool save();
void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current);
atUint64 position() const;
atUint64 length() const;
atUint64 readUBytesToBuf(void* buf, atUint64 len);
void setCacheSize(const atInt32 blockSize);
FILE* _fileHandle() {return m_fileHandle;}
2015-01-29 06:20:57 +00:00
protected:
#if _WIN32
std::wstring m_filename;
#else
std::string m_filename;
#endif
2014-04-20 09:14:15 +00:00
FILE* m_fileHandle;
2015-07-10 03:05:55 +00:00
std::unique_ptr<atUint8[]> m_cacheData;
atInt32 m_blockSize;
2015-07-10 03:05:55 +00:00
atInt32 m_curBlock;
atUint64 m_offset;
2014-04-20 09:14:15 +00:00
};
} // io
} // Athena
2014-04-25 02:01:24 +00:00
#ifndef FILEREADER_BASE
2015-01-29 06:20:57 +00:00
#define FILEREADER_BASE() \
2014-04-25 02:01:24 +00:00
private: \
2015-01-29 06:20:57 +00:00
typedef Athena::io::FileReader base
2014-04-25 02:01:24 +00:00
#endif // FILEREADER_BASE
2014-04-20 09:14:15 +00:00
#endif // FILESTREAM_HPP