2012-09-23 18:11:08 +00:00
|
|
|
#ifndef OPENMW_ESM_WRITER_H
|
|
|
|
#define OPENMW_ESM_WRITER_H
|
2012-04-06 19:04:30 +00:00
|
|
|
|
2013-03-12 08:16:03 +00:00
|
|
|
#include <iosfwd>
|
2012-04-08 15:04:52 +00:00
|
|
|
#include <list>
|
2012-04-06 19:04:30 +00:00
|
|
|
|
2013-01-06 00:37:58 +00:00
|
|
|
#include <components/to_utf8/to_utf8.hpp>
|
2012-04-06 19:04:30 +00:00
|
|
|
|
2013-03-12 08:16:03 +00:00
|
|
|
#include "esmcommon.hpp"
|
|
|
|
#include "loadtes3.hpp"
|
|
|
|
|
2012-04-06 19:04:30 +00:00
|
|
|
namespace ESM {
|
|
|
|
|
|
|
|
class ESMWriter
|
|
|
|
{
|
2012-04-08 09:51:52 +00:00
|
|
|
struct RecordData
|
|
|
|
{
|
2012-04-08 15:04:52 +00:00
|
|
|
std::string name;
|
2012-04-08 09:51:52 +00:00
|
|
|
std::streampos position;
|
2013-02-15 05:38:27 +00:00
|
|
|
size_t size;
|
2012-04-08 09:51:52 +00:00
|
|
|
};
|
|
|
|
|
2012-04-06 19:04:30 +00:00
|
|
|
public:
|
2012-04-08 15:04:52 +00:00
|
|
|
int getVersion();
|
|
|
|
void setVersion(int ver);
|
2013-01-06 00:37:58 +00:00
|
|
|
void setEncoder(ToUTF8::Utf8Encoder *encoding); // Write strings as UTF-8?
|
2012-04-06 20:25:33 +00:00
|
|
|
void setAuthor(const std::string& author);
|
|
|
|
void setDescription(const std::string& desc);
|
2013-03-12 13:33:35 +00:00
|
|
|
void setRecordCount (int count);
|
|
|
|
void setFormat (int format);
|
2012-04-06 20:25:33 +00:00
|
|
|
|
2012-04-08 15:04:52 +00:00
|
|
|
void addMaster(const std::string& name, uint64_t size);
|
|
|
|
|
2012-04-06 20:25:33 +00:00
|
|
|
void save(const std::string& file);
|
|
|
|
void save(std::ostream& file);
|
|
|
|
void close();
|
|
|
|
|
2012-04-06 19:04:30 +00:00
|
|
|
void writeHNString(const std::string& name, const std::string& data);
|
2013-02-15 05:38:27 +00:00
|
|
|
void writeHNString(const std::string& name, const std::string& data, size_t size);
|
2012-04-12 12:00:58 +00:00
|
|
|
void writeHNCString(const std::string& name, const std::string& data)
|
|
|
|
{
|
|
|
|
startSubRecord(name);
|
2012-04-13 22:14:04 +00:00
|
|
|
writeHCString(data);
|
2012-04-12 12:00:58 +00:00
|
|
|
endRecord(name);
|
|
|
|
}
|
2012-04-06 19:04:30 +00:00
|
|
|
void writeHNOString(const std::string& name, const std::string& data)
|
|
|
|
{
|
|
|
|
if (!data.empty())
|
|
|
|
writeHNString(name, data);
|
|
|
|
}
|
2012-04-13 22:14:04 +00:00
|
|
|
void writeHNOCString(const std::string& name, const std::string& data)
|
|
|
|
{
|
|
|
|
if (!data.empty())
|
|
|
|
writeHNCString(name, data);
|
|
|
|
}
|
2012-04-06 19:04:30 +00:00
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void writeHNT(const std::string& name, const T& data)
|
|
|
|
{
|
2012-04-08 15:04:52 +00:00
|
|
|
startSubRecord(name);
|
2012-04-06 19:04:30 +00:00
|
|
|
writeT(data);
|
2012-04-08 15:04:52 +00:00
|
|
|
endRecord(name);
|
2012-04-06 19:04:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void writeHNT(const std::string& name, const T& data, int size)
|
|
|
|
{
|
2012-04-08 15:04:52 +00:00
|
|
|
startSubRecord(name);
|
|
|
|
writeT(data, size);
|
|
|
|
endRecord(name);
|
2012-04-06 19:04:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void writeT(const T& data)
|
|
|
|
{
|
|
|
|
write((char*)&data, sizeof(T));
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
2013-02-15 05:38:27 +00:00
|
|
|
void writeT(const T& data, size_t size)
|
2012-04-06 19:04:30 +00:00
|
|
|
{
|
2012-04-08 15:04:52 +00:00
|
|
|
write((char*)&data, size);
|
2012-04-06 19:04:30 +00:00
|
|
|
}
|
2013-03-11 13:42:49 +00:00
|
|
|
|
2012-04-08 15:04:52 +00:00
|
|
|
void startRecord(const std::string& name, uint32_t flags);
|
|
|
|
void startSubRecord(const std::string& name);
|
|
|
|
void endRecord(const std::string& name);
|
2012-04-06 19:04:30 +00:00
|
|
|
void writeHString(const std::string& data);
|
2012-04-13 22:14:04 +00:00
|
|
|
void writeHCString(const std::string& data);
|
2012-04-06 19:04:30 +00:00
|
|
|
void writeName(const std::string& data);
|
2013-02-15 05:38:27 +00:00
|
|
|
void write(const char* data, size_t size);
|
2012-04-06 19:04:30 +00:00
|
|
|
|
|
|
|
private:
|
2012-04-08 15:04:52 +00:00
|
|
|
std::list<RecordData> m_records;
|
2012-04-08 09:51:52 +00:00
|
|
|
std::ostream* m_stream;
|
2012-04-12 12:00:58 +00:00
|
|
|
std::streampos m_headerPos;
|
2013-01-06 00:37:58 +00:00
|
|
|
ToUTF8::Utf8Encoder* m_encoder;
|
2012-04-12 12:00:58 +00:00
|
|
|
int m_recordCount;
|
2012-04-06 20:25:33 +00:00
|
|
|
|
2013-03-12 07:15:20 +00:00
|
|
|
Header mHeader;
|
2012-04-06 19:04:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|