10#ifndef LCF_READER_STRUCT_H
11#define LCF_READER_STRUCT_H
22#include "lcf/dbstring.h"
23#include "lcf/reader_lcf.h"
24#include "lcf/writer_lcf.h"
25#include "lcf/reader_xml.h"
26#include "lcf/writer_xml.h"
27#include "lcf/rpg/equipment.h"
28#include "lcf/rpg/parameters.h"
29#include "lcf/rpg/eventcommand.h"
30#include "lcf/rpg/movecommand.h"
31#include "lcf/rpg/treemap.h"
32#include "lcf/rpg/rect.h"
33#include "lcf/rpg/terms.h"
86template <class T, Category::Index cat = TypeCategory<T>::value>
96 static void ReadLcf(T&, LcfReader& stream, uint32_t length) {
97 stream.Seek(length, LcfReader::FromCurrent);
118 static void ReadLcf(T& ref, LcfReader& stream, uint32_t length);
119 static void WriteLcf(
const T& ref, LcfWriter& stream);
120 static int LcfSize(
const T& ref, LcfWriter& stream);
121 static void WriteXml(
const T& ref, XmlWriter& stream);
127 static void ReadLcf(T& ref, LcfReader& stream, uint32_t length) {
130 static void WriteLcf(
const T& ref, LcfWriter& stream) {
133 static int LcfSize(
const T& ref, LcfWriter& stream) {
136 static void WriteXml(
const T& ref, XmlWriter& stream) {
152 static const uint32_t
value =
sizeof(T);
168 static void ReadLcf(T& ref, LcfReader& stream, uint32_t length) {
173 Log::Warning(
"Reading Primitive of incorrect size %" PRIu32
" (expected %" PRIu32
") at %" PRIX32
"",
178#ifdef LCF_DEBUG_TRACE
184 Log::Warning(
"Invalid Primitive at %" PRIX32
"", stream.Tell());
185 stream.Seek(dif, LcfReader::FromCurrent);
188 static void WriteLcf(
const T& ref, LcfWriter& stream) {
194 static void WriteXml(
const T& ref, XmlWriter& stream) {
197 static void ParseXml(T& ref,
const std::string& data) {
198 XmlReader::Read(ref, data);
201#ifdef LCF_DEBUG_TRACE
202 template <
typename U>
203 static void DebugPrint(U& ref) {
204 std::cout << ref <<
'\n';
206 static void DebugPrint(int8_t ref) {
207 std::cout << (int)ref <<
'\n';
209 static void DebugPrint(uint8_t ref) {
210 std::cout << (int)ref <<
'\n';
220 static void ReadLcf(std::vector<T>& ref, LcfReader& stream, uint32_t length) {
221 stream.Read(ref, length);
222#ifdef LCF_DEBUG_TRACE
223 typename std::vector<T>::iterator it;
224 fprintf(stderr,
" ");
225 for (it = ref.begin(); it != ref.end(); ++it) {
226 fprintf(stderr,
"%d, ",
static_cast<int>(*it));
228 fprintf(stderr,
"\n");
231 static void WriteLcf(
const std::vector<T>& ref, LcfWriter& stream) {
234 static int LcfSize(
const std::vector<T>& ref, LcfWriter& ) {
237 static void WriteXml(
const std::vector<T>& ref, XmlWriter& stream) {
240 static void ParseXml(std::vector<T>& ref,
const std::string& data) {
241 XmlReader::Read(ref, data);
250 static void ReadLcf(int32_t& ref, LcfReader& stream, uint32_t length) {
251 if (length >= 1 && length <= 5) {
252 ref = stream.ReadInt();
253#ifdef LCF_DEBUG_TRACE
254 fprintf(stderr,
" %d\n", ref);
256 }
else if (length == 0) {
258#ifdef LCF_DEBUG_TRACE
259 fprintf(stderr,
" %d\n", ref);
264 stream.Seek(length, LcfReader::FromCurrent);
267 static void WriteLcf(
const int32_t& ref, LcfWriter& stream) {
268 stream.WriteInt(ref);
270 static int LcfSize(
const int32_t& ref, LcfWriter& ) {
271 return LcfReader::IntSize(ref);
273 static void WriteXml(
const int32_t& ref, XmlWriter& stream) {
274 stream.WriteInt(ref);
276 static void ParseXml(int32_t& ref,
const std::string& data) {
277 XmlReader::Read(ref, data);
286 static void ReadLcf(std::string& ref, LcfReader& stream, uint32_t length) {
287 stream.ReadString(ref, length);
288#ifdef LCF_DEBUG_TRACE
289 fprintf(stderr,
" %s\n", ref.c_str());
292 static void WriteLcf(
const std::string& ref, LcfWriter& stream) {
295 static int LcfSize(
const std::string& ref, LcfWriter& stream) {
296 return stream.Decode(ref).size();
298 static void WriteXml(
const std::string& ref, XmlWriter& stream) {
301 static void ParseXml(std::string& ref,
const std::string& data) {
302 XmlReader::Read(ref, data);
311 static void ReadLcf(DBBitArray& ref, LcfReader& stream, uint32_t length) {
312 stream.ReadBits(ref, length);
313#ifdef LCF_DEBUG_TRACE
314 fprintf(stderr,
" ");
316 fprintf(stderr,
"%d",
static_cast<int>(b));
318 fprintf(stderr,
"\n");
321 static void WriteLcf(
const DBBitArray& ref, LcfWriter& stream) {
324 static int LcfSize(
const DBBitArray& ref, LcfWriter& stream) {
328 static void WriteXml(
const DBBitArray& ref, XmlWriter& stream) {
331 static void ParseXml(DBBitArray& ref,
const std::string& data) {
332 XmlReader::Read(ref, data);
343 static void ReadLcf(T& ref, LcfReader& stream, uint32_t length) {
346 static void WriteLcf(
const T& ref, LcfWriter& stream) {
349 static int LcfSize(
const T& ref, LcfWriter& stream) {
352 static void WriteXml(
const T& ref, XmlWriter& stream) {
358 static void ParseXml(T& ref,
const std::string& data) {
375 virtual void ReadLcf(S& obj, LcfReader& stream, uint32_t length)
const = 0;
376 virtual void WriteLcf(
const S& obj, LcfWriter& stream)
const = 0;
377 virtual int LcfSize(
const S& obj, LcfWriter& stream)
const = 0;
379 virtual void WriteXml(
const S& obj, XmlWriter& stream)
const = 0;
380 virtual void BeginXml(S& obj, XmlReader& stream)
const = 0;
381 virtual void ParseXml(S& obj,
const std::string& data)
const = 0;
384 if (std::is_same<S,rpg::Terms>::value && db_is2k3 && (
id == 0x3 ||
id == 0x1)) {
399template <
class S,
class T>
403 void ReadLcf(S& obj, LcfReader& stream, uint32_t length)
const {
406 void WriteLcf(
const S& obj, LcfWriter& stream)
const {
409 int LcfSize(
const S& obj, LcfWriter& stream)
const {
412 void WriteXml(
const S& obj, XmlWriter& stream)
const {
413 stream.BeginElement(this->
name);
415 stream.EndElement(this->
name);
420 void ParseXml(S& obj,
const std::string& data)
const {
435template <
typename S,
typename T>
440 int LcfSize(
const S& obj, LcfWriter& stream)
const {
442 if ((obj.*(this->ref)) == 0) {
466 void ReadLcf(S& , LcfReader& , uint32_t )
const { }
487template <
class S,
class T>
491 void ReadLcf(S& , LcfReader& stream, uint32_t length)
const {
495 void WriteLcf(
const S& obj, LcfWriter& stream)
const {
499 int LcfSize(
const S& obj, LcfWriter& stream)
const {
501 return LcfReader::IntSize(size);
513 return (a.*
ref).size() == (b.*
ref).size();
524template <
class S,
class T>
529 void WriteLcf(
const S& obj, LcfWriter& stream)
const {
530 int size = (obj.*(this->
ref)).size();
533 int LcfSize(
const S& obj, LcfWriter& )
const {
534 int size = (obj.*(this->
ref)).size();
535 return LcfReader::IntSize(size);
558template <
class S,
bool T>
564 static void ReadID(S& obj, LcfReader& stream) {
565 obj.ID = stream.ReadInt();
567 static void WriteID(
const S& obj, LcfWriter& stream) {
568 stream.WriteInt(obj.ID);
571 return LcfReader::IntSize(obj.ID);
573 static void WriteXmlTag(
const S& obj,
const std::string& name, XmlWriter& stream) {
574 stream.BeginElement(name, obj.ID);
577 for (
int i = 0; atts[i] != NULL && atts[i + 1] != NULL; i += 2) {
578 if (strcmp(atts[i],
"id") == 0)
579 obj.ID = atoi(atts[i + 1]);
587 static void WriteID(
const S& , LcfWriter& ) {}
588 static int IDSize(
const S& ) {
return 0; }
589 static void WriteXmlTag(
const S& ,
const std::string& name, XmlWriter& stream) {
590 stream.BeginElement(name);
596 bool operator() (
const char*
const& lhs,
const char*
const& rhs)
const {
597 return strcmp(lhs, rhs) < 0;
622 static void ReadLcf(S& obj, LcfReader& stream);
623 static void WriteLcf(
const S& obj, LcfWriter& stream);
624 static int LcfSize(
const S& obj, LcfWriter& stream);
625 static void WriteXml(
const S& obj, XmlWriter& stream);
626 static void BeginXml(S& obj, XmlReader& stream);
628 static void ReadLcf(std::vector<S>& obj, LcfReader& stream);
629 static void WriteLcf(
const std::vector<S>& obj, LcfWriter& stream);
630 static int LcfSize(
const std::vector<S>& obj, LcfWriter& stream);
631 static void WriteXml(
const std::vector<S>& obj, XmlWriter& stream);
632 static void BeginXml(std::vector<S>& obj, XmlReader& stream);
646 static void ReadLcf(T& ref, LcfReader& stream, uint32_t ) {
649 static void WriteLcf(
const T& ref, LcfWriter& stream) {
652 static int LcfSize(
const T& ref, LcfWriter& stream) {
655 static void WriteXml(
const T& ref, XmlWriter& stream) {
668 static void ReadLcf(std::vector<T>& ref, LcfReader& stream, uint32_t ) {
671 static void WriteLcf(
const std::vector<T>& ref, LcfWriter& stream) {
674 static int LcfSize(
const std::vector<T>& ref, LcfWriter& stream) {
677 static void WriteXml(
const std::vector<T>& ref, XmlWriter& stream) {
680 static void BeginXml(std::vector<T>& ref, XmlReader& stream) {
683 static void ParseXml(std::vector<T>& ,
const std::string& ) {
697 static constexpr size_t num_flags = std::tuple_size<
decltype(S::flags)>::value;
698 static const std::array<const char* const, num_flags>
flag_names;
702 static const char*
tag(
int idx);
703 static int idx(
const char*
tag);
705 static void ReadLcf(S& obj, LcfReader& stream, uint32_t length);
706 static void WriteLcf(
const S& obj, LcfWriter& stream);
707 static int LcfSize(
const S& obj, LcfWriter& stream);
708 static void WriteXml(
const S& obj, XmlWriter& stream);
709 static void BeginXml(S& obj, XmlReader& stream);
719 for (
size_t i = 0; i < flag_names.size(); ++i) {
720 if (std::strcmp(flag_names[i], tag) == 0) {
732 static void ReadLcf(T& ref, LcfReader& stream, uint32_t length) {
735 static void WriteLcf(
const T& ref, LcfWriter& stream) {
738 static int LcfSize(
const T& ref, LcfWriter& stream) {
741 static void WriteXml(
const T& ref, XmlWriter& stream) {
761 if (strcmp(
name, this->name) != 0)
781 if (strcmp(
name, this->name) != 0)
static void BeginXml(S &obj, XmlReader &stream)
static const std::array< const char *const, num_flags > flag_names
static const std::array< bool, num_flags > flags_is2k3
static void ReadLcf(S &obj, LcfReader &stream, uint32_t length)
static void WriteXml(const S &obj, XmlWriter &stream)
static int idx(const char *tag)
static constexpr size_t num_flags
static int LcfSize(const S &obj, LcfWriter &stream)
static const char * tag(int idx)
static void WriteLcf(const S &obj, LcfWriter &stream)
static const char *const name
void StartElement(XmlReader &stream, const char *name, const char **)
RootXmlHandler(S &ref, const char *const name)
static void BeginXml(S &obj, XmlReader &stream)
static int LcfSize(const S &obj, LcfWriter &stream)
static void MakeFieldMap()
static const Field< S > * fields[]
static void WriteXml(const S &obj, XmlWriter &stream)
static tag_map_type tag_map
std::map< int, const Field< S > * > field_map_type
static field_map_type field_map
std::map< const char *const, const Field< S > *, StringComparator > tag_map_type
static void WriteLcf(const S &obj, LcfWriter &stream)
static void ReadLcf(S &obj, LcfReader &stream)
static const char *const name
IDReaderT< S, IDChecker< S >::value > IDReader
WrapperXmlHandler(const char *const name, XmlHandler *handler)
void StartElement(XmlReader &stream, const char *name, const char **)
void Warning(const char *fmt,...) LIKE_PRINTF
void Error(const char *fmt,...) LIKE_PRINTF
int LcfSize(const S &obj, LcfWriter &) const
void WriteLcf(const S &obj, LcfWriter &stream) const
int LcfSize(const S &obj, LcfWriter &stream) const
bool IsDefault(const S &a, const S &b, bool is2k3) const
int LcfSize(const S &, LcfWriter &) const
void WriteXml(const S &, XmlWriter &) const
void ParseXml(S &, const std::string &) const
void ReadLcf(S &, LcfReader &, uint32_t) const
void BeginXml(S &, XmlReader &) const
void WriteLcf(const S &, LcfWriter &) const
bool IsDefault(const S &, const S &, bool) const
virtual void ParseXml(S &obj, const std::string &data) const =0
bool isPresentIfDefault(bool db_is2k3) const
Field(int id, const char *name, bool present_if_default, bool is2k3)
virtual void WriteLcf(const S &obj, LcfWriter &stream) const =0
virtual void BeginXml(S &obj, XmlReader &stream) const =0
virtual bool IsDefault(const S &obj, const S &ref, bool is2k3) const =0
virtual void WriteXml(const S &obj, XmlWriter &stream) const =0
virtual void ReadLcf(S &obj, LcfReader &stream, uint32_t length) const =0
virtual int LcfSize(const S &obj, LcfWriter &stream) const =0
static yes check(type_check< int C::*, &C::ID > *)
static void WriteID(const S &, LcfWriter &)
static void ReadIDXml(S &, const char **)
static void WriteXmlTag(const S &, const std::string &name, XmlWriter &stream)
static int IDSize(const S &)
static void ReadID(S &, LcfReader &)
static void WriteID(const S &obj, LcfWriter &stream)
static void ReadID(S &obj, LcfReader &stream)
static void WriteXmlTag(const S &obj, const std::string &name, XmlWriter &stream)
static int IDSize(const S &obj)
static void ReadIDXml(S &obj, const char **atts)
static const uint32_t value
static void ReadLcf(DBBitArray &ref, LcfReader &stream, uint32_t length)
static void ParseXml(DBBitArray &ref, const std::string &data)
static void WriteLcf(const DBBitArray &ref, LcfWriter &stream)
static int LcfSize(const DBBitArray &ref, LcfWriter &stream)
static void WriteXml(const DBBitArray &ref, XmlWriter &stream)
static int LcfSize(const int32_t &ref, LcfWriter &)
static void WriteLcf(const int32_t &ref, LcfWriter &stream)
static void ParseXml(int32_t &ref, const std::string &data)
static void ReadLcf(int32_t &ref, LcfReader &stream, uint32_t length)
static void WriteXml(const int32_t &ref, XmlWriter &stream)
static void WriteXml(const std::string &ref, XmlWriter &stream)
static void ReadLcf(std::string &ref, LcfReader &stream, uint32_t length)
static int LcfSize(const std::string &ref, LcfWriter &stream)
static void WriteLcf(const std::string &ref, LcfWriter &stream)
static void ParseXml(std::string &ref, const std::string &data)
static int LcfSize(const std::vector< T > &ref, LcfWriter &)
static void ParseXml(std::vector< T > &ref, const std::string &data)
static void WriteLcf(const std::vector< T > &ref, LcfWriter &stream)
static void WriteXml(const std::vector< T > &ref, XmlWriter &stream)
static void ReadLcf(std::vector< T > &ref, LcfReader &stream, uint32_t length)
static void ReadLcf(T &ref, LcfReader &stream, uint32_t length)
static void WriteLcf(const T &ref, LcfWriter &stream)
static int LcfSize(const T &, LcfWriter &)
static void ParseXml(T &ref, const std::string &data)
static void WriteXml(const T &ref, XmlWriter &stream)
static void ReadLcf(T &ref, LcfReader &stream, uint32_t length)
static void WriteXml(const T &ref, XmlWriter &stream)
static void BeginXml(T &ref, XmlReader &stream)
static void WriteLcf(const T &ref, LcfWriter &stream)
static int LcfSize(const T &ref, LcfWriter &stream)
void BeginXml(S &, XmlReader &) const
SizeField(const T S::*ref, int id, bool present_if_default, bool is2k3)
void WriteXml(const S &, XmlWriter &) const
bool IsDefault(const S &a, const S &b, bool) const
void ReadLcf(S &, LcfReader &stream, uint32_t length) const
void ParseXml(S &, const std::string &) const
void WriteLcf(const S &obj, LcfWriter &stream) const
int LcfSize(const S &obj, LcfWriter &stream) const
bool operator()(const char *const &lhs, const char *const &rhs) const
static const Category::Index value
static void WriteLcf(const T &ref, LcfWriter &stream)
static int LcfSize(const T &ref, LcfWriter &stream)
static void ParseXml(T &, const std::string &)
static void ReadLcf(T &ref, LcfReader &stream, uint32_t length)
static void BeginXml(T &ref, XmlReader &stream)
static void WriteXml(const T &ref, XmlWriter &stream)
static int LcfSize(const T &ref, LcfWriter &stream)
static void BeginXml(T &, XmlReader &)
static void WriteXml(const T &ref, XmlWriter &stream)
static void WriteLcf(const T &ref, LcfWriter &stream)
static void ReadLcf(T &ref, LcfReader &stream, uint32_t length)
static void ParseXml(T &ref, const std::string &data)
static void WriteXml(const T &ref, XmlWriter &stream)
static void ParseXml(T &, const std::string &)
static int LcfSize(const T &ref, LcfWriter &stream)
static void WriteLcf(const T &ref, LcfWriter &stream)
static void BeginXml(T &ref, XmlReader &stream)
static void ReadLcf(T &ref, LcfReader &stream, uint32_t length)
static void ParseXml(T &, const std::string &)
static void WriteXml(const T &ref, XmlWriter &stream)
static void WriteLcf(const T &ref, LcfWriter &stream)
static void BeginXml(T &ref, XmlReader &stream)
static int LcfSize(const T &ref, LcfWriter &stream)
static void ReadLcf(T &ref, LcfReader &stream, uint32_t)
static void BeginXml(T &, XmlReader &)
static int LcfSize(const T &, LcfWriter &)
static void WriteLcf(const T &, LcfWriter &)
static void ReadLcf(T &, LcfReader &stream, uint32_t length)
static void ParseXml(T &, const std::string &)
static void WriteXml(const T &, XmlWriter &)
static void WriteLcf(const std::vector< T > &ref, LcfWriter &stream)
static void BeginXml(std::vector< T > &ref, XmlReader &stream)
static void WriteXml(const std::vector< T > &ref, XmlWriter &stream)
static void ReadLcf(std::vector< T > &ref, LcfReader &stream, uint32_t)
static int LcfSize(const std::vector< T > &ref, LcfWriter &stream)
static void ParseXml(std::vector< T > &, const std::string &)
void BeginXml(S &obj, XmlReader &stream) const
TypedField(T S::*ref, int id, const char *name, bool present_if_default, bool is2k3)
void WriteLcf(const S &obj, LcfWriter &stream) const
void ReadLcf(S &obj, LcfReader &stream, uint32_t length) const
void WriteXml(const S &obj, XmlWriter &stream) const
bool IsDefault(const S &a, const S &b, bool) const
int LcfSize(const S &obj, LcfWriter &stream) const
void ParseXml(S &obj, const std::string &data) const