athena/include/Athena/FileWriter.hpp

66 lines
1.4 KiB
C++
Raw Normal View History

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"
#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:
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
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;}
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);
FILE* _fileHandle() {return m_fileHandle;}
2014-04-20 09:14:15 +00:00
private:
#if _WIN32
std::wstring m_filename;
#else
std::string m_filename;
#endif
2014-04-20 09:14:15 +00:00
FILE* m_fileHandle;
atUint8 m_currentByte;
atUint64 m_bytePosition;
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