Go to the documentation of this file.
13 #include <type_traits>
26 if (!field_map.empty())
28 for (
int i = 0; fields[i] != NULL; i++)
29 field_map[fields[i]->
id] = fields[i];
36 for (
int i = 0; fields[i] != NULL; i++)
37 tag_map[fields[i]->name] = fields[i];
62 while (!stream.
Eof()) {
64 if (chunk_info.
ID == 0)
69 auto it = field_map.find(chunk_info.
ID);
70 if (it != field_map.end()) {
71 #ifdef LCF_DEBUG_TRACE
72 printf(
"0x%02x (size: %" PRIu32
", pos: 0x%" PRIx32
"): %s\n", chunk_info.
ID, chunk_info.
length, stream.
Tell(), it->second->name);
74 const uint32_t off = stream.
Tell();
75 it->second->ReadLcf(obj, stream, chunk_info.
length);
76 const uint32_t bytes_read = stream.
Tell() - off;
77 if (bytes_read != chunk_info.
length) {
78 fprintf(stderr,
"Warning: Corrupted Chunk 0x%02" PRIx32
" (size: %" PRIu32
", pos: 0x%" PRIx32
"): %s : Read %" PRIu32
" bytes! Reseting...\n",
79 chunk_info.
ID, chunk_info.
length, off, it->second->name, bytes_read);
84 stream.
Skip(chunk_info);
90 typename std::enable_if<std::is_same<T, RPG::Save>::value ||
91 std::is_same<T, RPG::Database>::value>::type
97 typename std::enable_if<!std::is_same<T, RPG::Save>::value &&
98 !std::is_same<T, RPG::Database>::value>::type
109 for (
int i = 0; fields[i] != NULL; i++) {
111 if (!db_is2k3 && field->
is2k3) {
114 if (field->
id < last)
115 std::cerr <<
"field order mismatch: " << field->
id
117 <<
" in struct " << name
123 auto len = field->
LcfSize(obj, stream);
130 conditional_zero_writer<S>(stream);
138 for (
int i = 0; fields[i] != NULL; i++) {
140 if (!db_is2k3 && field->
is2k3) {
148 int size = field->
LcfSize(obj, stream);
158 IDReader::WriteXmlTag(obj, name, stream);
159 for (
int i = 0; fields[i] != NULL; i++) {
217 for (
int i = 0; i < count; i++) {
218 IDReader::ReadID(vec[i], stream);
225 int count = vec.size();
227 for (
int i = 0; i < count; i++) {
228 IDReader::WriteID(vec[i], stream);
236 int count = vec.size();
238 for (
int i = 0; i < count; i++) {
239 result += IDReader::IDSize(vec[i]);
247 int count = vec.size();
248 for (
int i = 0; i < count; i++)
260 ref.resize(
ref.size() + 1);
static void MakeFieldMap()
void Error(const char *fmt,...)
void StartElement(XmlReader &stream, const char *name, const char **atts)
void SetHandler(XmlHandler *handler)
static int LcfSize(const S &obj, LcfWriter &stream)
StructVectorXmlHandler(std::vector< S > &ref)
virtual void WriteLcf(const S &obj, LcfWriter &stream) const =0
void EndElement(const std::string &name)
void Seek(size_t pos, SeekMode mode=FromStart)
bool isPresentIfDefault(bool db_is2k3) const
void StartElement(XmlReader &stream, const char *name, const char **)
static void WriteXml(const S &obj, XmlWriter &stream)
virtual int LcfSize(const S &obj, LcfWriter &stream) const =0
StructFieldXmlHandler(S &ref)
virtual void WriteXml(const S &obj, XmlWriter &stream) const =0
static void WriteLcf(const S &obj, LcfWriter &stream)
static int IntSize(unsigned int x)
static void BeginXml(S &obj, XmlReader &stream)
static void ReadLcf(S &obj, LcfReader &stream)
std::enable_if< std::is_same< T, RPG::Save >::value||std::is_same< T, RPG::Database >::value >::type conditional_zero_writer(LcfWriter &)
void StartElement(XmlReader &stream, const char *name, const char **atts)
virtual bool IsDefault(const S &obj, const S &ref) const =0
void Skip(const struct LcfReader::Chunk &chunk_info)
void EndElement(XmlReader &, const char *)
void CharacterData(XmlReader &, const std::string &data)