2014-04-20 09:14:15 +00:00
|
|
|
#ifndef FILEWRITER_HPP
|
|
|
|
#define FILEWRITER_HPP
|
|
|
|
|
2015-03-01 20:42:39 +00:00
|
|
|
#include "Athena/IStreamWriter.hpp"
|
2015-05-21 04:57:27 +00:00
|
|
|
#include <stdio.h>
|
2014-04-20 09:14:15 +00:00
|
|
|
|
|
|
|
namespace Athena
|
|
|
|
{
|
|
|
|
namespace io
|
|
|
|
{
|
2015-03-01 20:42:39 +00:00
|
|
|
class FileWriter : public IStreamWriter
|
2014-04-20 09:14:15 +00:00
|
|
|
{
|
|
|
|
public:
|
2015-11-23 03:08:48 +00:00
|
|
|
FileWriter(const std::string& filename, bool overwrite = true, bool globalErr=true);
|
|
|
|
FileWriter(const std::wstring& filename, bool overwrite = true, bool globalErr=true);
|
2015-01-29 06:31:14 +00:00
|
|
|
virtual ~FileWriter();
|
2014-04-20 09:14:15 +00:00
|
|
|
|
2015-11-14 05:53:13 +00:00
|
|
|
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-05-18 21:03:13 +00:00
|
|
|
void open(bool overwrite = true);
|
2014-04-20 09:14:15 +00:00
|
|
|
void close();
|
2015-07-01 09:28:40 +00:00
|
|
|
inline bool isOpen() const
|
|
|
|
{return m_fileHandle != NULL;}
|
2014-06-18 04:51:18 +00:00
|
|
|
void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current);
|
|
|
|
atUint64 position() const;
|
|
|
|
atUint64 length() const;
|
2015-07-01 03:01:04 +00:00
|
|
|
void writeUBytes(const atUint8* data, atUint64 len);
|
2015-07-08 02:53:39 +00:00
|
|
|
|
2015-10-23 22:23:04 +00:00
|
|
|
FILE* _fileHandle() {return m_fileHandle;}
|
2014-04-20 09:14:15 +00:00
|
|
|
private:
|
2015-07-22 18:59:40 +00:00
|
|
|
#if _WIN32
|
2015-11-14 05:53:13 +00:00
|
|
|
std::wstring m_filename;
|
|
|
|
#else
|
|
|
|
std::string m_filename;
|
2015-07-22 18:59:40 +00:00
|
|
|
#endif
|
2014-04-20 09:14:15 +00:00
|
|
|
FILE* m_fileHandle;
|
2014-12-29 04:46:43 +00:00
|
|
|
atUint8 m_currentByte;
|
|
|
|
atUint64 m_bytePosition;
|
2015-11-23 03:08:48 +00:00
|
|
|
bool m_globalErr;
|
2014-04-20 09:14:15 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
} // Athena
|
2014-04-25 02:01:24 +00:00
|
|
|
|
|
|
|
#ifndef FILEWRITER_BASE
|
2015-03-01 20:42:39 +00:00
|
|
|
#define FILEWRITER_BASE() \
|
2014-04-25 02:01:24 +00:00
|
|
|
private: \
|
|
|
|
typedef Athena::io::FileWriter base;
|
|
|
|
|
|
|
|
#endif // FILEWRITER_BASE
|
2014-04-20 09:14:15 +00:00
|
|
|
#endif // FILEWRITER_HPP
|