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-05-18 21:03:13 +00:00
|
|
|
FileWriter(const std::string& filename, bool overwrite = true);
|
2015-01-29 06:31:14 +00:00
|
|
|
virtual ~FileWriter();
|
2014-04-20 09:14:15 +00:00
|
|
|
|
|
|
|
void setEndian(Endian endian);
|
|
|
|
Endian endian() const;
|
|
|
|
bool isBigEndian() const;
|
|
|
|
bool isLittleEndian() const;
|
2015-05-18 21:03:13 +00:00
|
|
|
void open(bool overwrite = true);
|
2014-04-20 09:14:15 +00:00
|
|
|
void close();
|
|
|
|
bool isOpen() const;
|
2014-06-18 04:51:18 +00:00
|
|
|
void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current);
|
2015-04-11 00:04:13 +00:00
|
|
|
inline void seekAlign32() {seek(ROUND_UP_32(position()), SeekOrigin::Begin);}
|
2014-04-20 09:14:15 +00:00
|
|
|
bool atEnd() const;
|
2014-06-18 04:51:18 +00:00
|
|
|
atUint64 position() const;
|
|
|
|
atUint64 length() const;
|
2014-04-20 09:14:15 +00:00
|
|
|
|
2015-05-19 03:24:56 +00:00
|
|
|
void writeBit(bool val);
|
|
|
|
void seekBit(int bit);
|
|
|
|
void writeUByte(atUint8 val);
|
|
|
|
void writeByte(atInt8 val);
|
2015-07-01 03:01:04 +00:00
|
|
|
void writeUBytes(const atUint8* data, atUint64 len);
|
|
|
|
void writeBytes(const atInt8* data, atUint64 len);
|
2014-06-18 04:51:18 +00:00
|
|
|
void writeUint16(atUint16 val);
|
2015-05-19 03:24:56 +00:00
|
|
|
void writeInt16(atInt16 val);
|
2014-06-18 04:51:18 +00:00
|
|
|
void writeUint32(atUint32 val);
|
2015-05-19 03:24:56 +00:00
|
|
|
void writeInt32(atInt32 val);
|
2014-06-18 04:51:18 +00:00
|
|
|
void writeUint64(atUint64 val);
|
2015-05-19 03:24:56 +00:00
|
|
|
void writeInt64(atInt64 val);
|
2014-04-20 09:14:15 +00:00
|
|
|
void writeDouble(double val);
|
2015-05-19 03:24:56 +00:00
|
|
|
void writeFloat(float val);
|
|
|
|
void writeBool(bool val);
|
2015-06-19 02:55:05 +00:00
|
|
|
void writeVec3f(atVec3f vec);
|
|
|
|
void writeVec4f(atVec4f vec);
|
2015-06-19 20:12:25 +00:00
|
|
|
void writeString(const std::string& val, atInt32 fixedLen = -1);
|
|
|
|
void writeWString(const std::wstring& str, atInt32 fixedLen = -1);
|
|
|
|
void writeUnicode(const std::string& str, atInt32 fixedLen = -1);
|
2015-05-01 04:16:18 +00:00
|
|
|
void fill(atInt8 byte, atUint64 len);
|
|
|
|
void fill(atUint8 byte, atUint64 len);
|
2014-04-20 09:14:15 +00:00
|
|
|
private:
|
|
|
|
std::string m_filename;
|
|
|
|
FILE* m_fileHandle;
|
|
|
|
Endian m_endian;
|
2014-12-29 04:46:43 +00:00
|
|
|
atUint8 m_currentByte;
|
|
|
|
atUint64 m_bytePosition;
|
|
|
|
atUint8 m_bitShift;
|
2014-04-20 09:14:15 +00:00
|
|
|
bool m_bitValid;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
} // 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
|