openmw-tes3coop/components/esm/esm_writer.hpp

102 lines
2.2 KiB
C++

#ifndef _ESM_WRITER_H
#define _ESM_WRITER_H
#include <iostream>
#include <list>
#include <assert.h>
#include "esm_common.hpp"
namespace ESM {
class ESMWriter
{
struct RecordData
{
std::string name;
std::streampos position;
int size;
};
public:
int getVersion();
void setVersion(int ver);
int getType();
void setType(int type);
// void setEncoding(const std::string& encoding); // Write strings as UTF-8?
void setAuthor(const std::string& author);
void setDescription(const std::string& desc);
void addMaster(const std::string& name, uint64_t size);
void save(const std::string& file);
void save(std::ostream& file);
void close();
void writeHNString(const std::string& name, const std::string& data);
void writeHNOString(const std::string& name, const std::string& data)
{
if (!data.empty())
writeHNString(name, data);
}
template<typename T>
void writeHNT(const std::string& name, const T& data)
{
startSubRecord(name);
writeT(data);
endRecord(name);
}
template<typename T>
void writeHNT(const std::string& name, const T& data, int size)
{
startSubRecord(name);
writeT(data, size);
endRecord(name);
}
/*template<typename T>
void writeHT(const T& data)
{
writeT((unsigned int)sizeof(T));
writeT(data);
}
template<typename T>
void writeHT(const T& data, int size)
{
assert(sizeof(T) == size);
writeHT(data);
}*/
template<typename T>
void writeT(const T& data)
{
write((char*)&data, sizeof(T));
}
template<typename T>
void writeT(const T& data, int size)
{
write((char*)&data, size);
}
void startRecord(const std::string& name, uint32_t flags);
void startSubRecord(const std::string& name);
void endRecord(const std::string& name);
void writeHString(const std::string& data);
void writeName(const std::string& data);
void write(const char* data, int size);
private:
std::list<MasterData> m_masters;
std::list<RecordData> m_records;
std::ostream* m_stream;
HEDRstruct m_header;
SaveData m_saveData;
};
}
#endif