10#ifndef LCF_READER_STRUCT_H
11#define LCF_READER_STRUCT_H
23#include "lcf/dbstring.h"
24#include "lcf/reader_lcf.h"
25#include "lcf/writer_lcf.h"
26#include "lcf/reader_xml.h"
27#include "lcf/writer_xml.h"
28#include "lcf/rpg/eventpagecondition.h"
29#include "lcf/rpg/trooppagecondition.h"
30#include "lcf/rpg/terrain.h"
31#include "lcf/rpg/equipment.h"
32#include "lcf/rpg/parameters.h"
33#include "lcf/rpg/eventcommand.h"
34#include "lcf/rpg/movecommand.h"
35#include "lcf/rpg/treemap.h"
36#include "lcf/rpg/rect.h"
37#include "lcf/rpg/savepicture.h"
38#include "lcf/rpg/terms.h"
95template <class T, Category::Index cat = TypeCategory<T>::value>
105 static void ReadLcf(T&, LcfReader& stream, uint32_t length) {
106 stream.Seek(length, LcfReader::FromCurrent);
127 static void ReadLcf(T& ref, LcfReader& stream, uint32_t length);
128 static void WriteLcf(
const T& ref, LcfWriter& stream);
129 static int LcfSize(
const T& ref, LcfWriter& stream);
130 static void WriteXml(
const T& ref, XmlWriter& stream);
136 static void ReadLcf(T& ref, LcfReader& stream, uint32_t length) {
139 static void WriteLcf(
const T& ref, LcfWriter& stream) {
142 static int LcfSize(
const T& ref, LcfWriter& stream) {
145 static void WriteXml(
const T& ref, XmlWriter& stream) {
161 static const uint32_t
value =
sizeof(T);
177 static void ReadLcf(T& ref, LcfReader& stream, uint32_t length) {
182 fprintf(stderr,
"Reading Primitive of incorrect size %" PRIu32
" (expected %" PRIu32
") at %" PRIX32
"\n",
187#ifdef LCF_DEBUG_TRACE
193#ifdef LCF_DEBUG_TRACE
194 printf(
"Invalid %s at %X\n",
typeid(T).name(), stream.Tell());
196 stream.Seek(dif, LcfReader::FromCurrent);
199 static void WriteLcf(
const T& ref, LcfWriter& stream) {
205 static void WriteXml(
const T& ref, XmlWriter& stream) {
208 static void ParseXml(T& ref,
const std::string& data) {
209 XmlReader::Read(ref, data);
212#ifdef LCF_DEBUG_TRACE
213 template <
typename U>
214 static void DebugPrint(U& ref) {
215 std::cout << ref <<
'\n';
217 static void DebugPrint(int8_t ref) {
218 std::cout << (int)ref <<
'\n';
220 static void DebugPrint(uint8_t ref) {
221 std::cout << (int)ref <<
'\n';
231 static void ReadLcf(std::vector<T>& ref, LcfReader& stream, uint32_t length) {
232 stream.Read(ref, length);
233#ifdef LCF_DEBUG_TRACE
234 typename std::vector<T>::iterator it;
236 for (it = ref.begin(); it != ref.end(); ++it) {
237 printf(
"%d, ",
static_cast<int>(*it));
242 static void WriteLcf(
const std::vector<T>& ref, LcfWriter& stream) {
245 static int LcfSize(
const std::vector<T>& ref, LcfWriter& ) {
248 static void WriteXml(
const std::vector<T>& ref, XmlWriter& stream) {
251 static void ParseXml(std::vector<T>& ref,
const std::string& data) {
252 XmlReader::Read(ref, data);
261 static void ReadLcf(int32_t& ref, LcfReader& stream, uint32_t length) {
262 if (length >= 1 && length <= 5) {
263 ref = stream.ReadInt();
264#ifdef LCF_DEBUG_TRACE
265 printf(
" %d\n", ref);
269#ifdef LCF_DEBUG_TRACE
270 printf(
"Invalid integer at %X\n", stream.Tell());
272 stream.Seek(length, LcfReader::FromCurrent);
276 static void WriteLcf(
const int32_t& ref, LcfWriter& stream) {
277 stream.WriteInt(ref);
279 static int LcfSize(
const int32_t& ref, LcfWriter& ) {
280 return LcfReader::IntSize(ref);
282 static void WriteXml(
const int32_t& ref, XmlWriter& stream) {
283 stream.WriteInt(ref);
285 static void ParseXml(int32_t& ref,
const std::string& data) {
286 XmlReader::Read(ref, data);
295 static void ReadLcf(std::string& ref, LcfReader& stream, uint32_t length) {
296 stream.ReadString(ref, length);
297#ifdef LCF_DEBUG_TRACE
298 printf(
" %s\n", ref.c_str());
301 static void WriteLcf(
const std::string& ref, LcfWriter& stream) {
304 static int LcfSize(
const std::string& ref, LcfWriter& stream) {
305 return stream.Decode(ref).size();
307 static void WriteXml(
const std::string& ref, XmlWriter& stream) {
310 static void ParseXml(std::string& ref,
const std::string& data) {
311 XmlReader::Read(ref, data);
320 static void ReadLcf(DBString& ref, LcfReader& stream, uint32_t length) {
321 stream.ReadString(ref, length);
322#ifdef LCF_DEBUG_TRACE
323 printf(
" %s\n", ref.c_str());
326 static void WriteLcf(
const DBString& ref, LcfWriter& stream) {
329 static int LcfSize(
const DBString& ref, LcfWriter& stream) {
330 return stream.Decode(ref).size();
332 static void WriteXml(
const DBString& ref, XmlWriter& stream) {
335 static void ParseXml(DBString& ref,
const std::string& data) {
336 XmlReader::Read(ref, data);
345 static void ReadLcf(DBBitArray& ref, LcfReader& stream, uint32_t length) {
346 stream.ReadBits(ref, length);
347#ifdef LCF_DEBUG_TRACE
350 print(
"%d",
static_cast<int>(b));
355 static void WriteLcf(
const DBBitArray& ref, LcfWriter& stream) {
358 static int LcfSize(
const DBBitArray& ref, LcfWriter& stream) {
362 static void WriteXml(
const DBBitArray& ref, XmlWriter& stream) {
365 static void ParseXml(DBBitArray& ref,
const std::string& data) {
366 XmlReader::Read(ref, data);
377 static void ReadLcf(T& ref, LcfReader& stream, uint32_t length) {
380 static void WriteLcf(
const T& ref, LcfWriter& stream) {
383 static int LcfSize(
const T& ref, LcfWriter& stream) {
386 static void WriteXml(
const T& ref, XmlWriter& stream) {
392 static void ParseXml(T& ref,
const std::string& data) {
409 virtual void ReadLcf(S& obj, LcfReader& stream, uint32_t length)
const = 0;
410 virtual void WriteLcf(
const S& obj, LcfWriter& stream)
const = 0;
411 virtual int LcfSize(
const S& obj, LcfWriter& stream)
const = 0;
413 virtual void WriteXml(
const S& obj, XmlWriter& stream)
const = 0;
414 virtual void BeginXml(S& obj, XmlReader& stream)
const = 0;
415 virtual void ParseXml(S& obj,
const std::string& data)
const = 0;
418 if (std::is_same<S,rpg::Terms>::value && db_is2k3 && (
id == 0x3 ||
id == 0x1)) {
433template <
class S,
class T>
437 void ReadLcf(S& obj, LcfReader& stream, uint32_t length)
const {
440 void WriteLcf(
const S& obj, LcfWriter& stream)
const {
443 int LcfSize(
const S& obj, LcfWriter& stream)
const {
446 void WriteXml(
const S& obj, XmlWriter& stream)
const {
447 stream.BeginElement(this->
name);
449 stream.EndElement(this->
name);
454 void ParseXml(S& obj,
const std::string& data)
const {
469template <
typename S,
typename T>
474 int LcfSize(
const S& obj, LcfWriter& stream)
const {
476 if ((obj.*(this->ref)) == 0) {
500 void ReadLcf(S& , LcfReader& , uint32_t )
const { }
521template <
class S,
class T>
525 void ReadLcf(S& , LcfReader& stream, uint32_t length)
const {
529 void WriteLcf(
const S& obj, LcfWriter& stream)
const {
533 int LcfSize(
const S& obj, LcfWriter& stream)
const {
535 return LcfReader::IntSize(size);
547 return (a.*
ref).size() == (b.*
ref).size();
558template <
class S,
class T>
563 void WriteLcf(
const S& obj, LcfWriter& stream)
const {
564 int size = (obj.*(this->
ref)).size();
567 int LcfSize(
const S& obj, LcfWriter& )
const {
568 int size = (obj.*(this->
ref)).size();
569 return LcfReader::IntSize(size);
587 static const bool value =
sizeof(check<T>(0)) ==
sizeof(
yes);
592template <
class S,
bool T>
598 static void ReadID(S& obj, LcfReader& stream) {
599 obj.ID = stream.ReadInt();
601 static void WriteID(
const S& obj, LcfWriter& stream) {
602 stream.WriteInt(obj.ID);
605 return LcfReader::IntSize(obj.ID);
607 static void WriteXmlTag(
const S& obj,
const std::string& name, XmlWriter& stream) {
608 stream.BeginElement(name, obj.ID);
611 for (
int i = 0; atts[i] != NULL && atts[i + 1] != NULL; i += 2) {
612 if (strcmp(atts[i],
"id") == 0)
613 obj.ID = atoi(atts[i + 1]);
621 static void WriteID(
const S& , LcfWriter& ) {}
622 static int IDSize(
const S& ) {
return 0; }
623 static void WriteXmlTag(
const S& ,
const std::string& name, XmlWriter& stream) {
624 stream.BeginElement(name);
630 bool operator() (
const char*
const& lhs,
const char*
const& rhs)
const {
631 return strcmp(lhs, rhs) < 0;
656 static void ReadLcf(S& obj, LcfReader& stream);
657 static void WriteLcf(
const S& obj, LcfWriter& stream);
658 static int LcfSize(
const S& obj, LcfWriter& stream);
659 static void WriteXml(
const S& obj, XmlWriter& stream);
660 static void BeginXml(S& obj, XmlReader& stream);
662 static void ReadLcf(std::vector<S>& obj, LcfReader& stream);
663 static void WriteLcf(
const std::vector<S>& obj, LcfWriter& stream);
664 static int LcfSize(
const std::vector<S>& obj, LcfWriter& stream);
665 static void WriteXml(
const std::vector<S>& obj, XmlWriter& stream);
666 static void BeginXml(std::vector<S>& obj, XmlReader& stream);
680 static void ReadLcf(T& ref, LcfReader& stream, uint32_t ) {
683 static void WriteLcf(
const T& ref, LcfWriter& stream) {
686 static int LcfSize(
const T& ref, LcfWriter& stream) {
689 static void WriteXml(
const T& ref, XmlWriter& stream) {
702 static void ReadLcf(std::vector<T>& ref, LcfReader& stream, uint32_t ) {
705 static void WriteLcf(
const std::vector<T>& ref, LcfWriter& stream) {
708 static int LcfSize(
const std::vector<T>& ref, LcfWriter& stream) {
711 static void WriteXml(
const std::vector<T>& ref, XmlWriter& stream) {
714 static void BeginXml(std::vector<T>& ref, XmlReader& stream) {
717 static void ParseXml(std::vector<T>& ,
const std::string& ) {
731 static constexpr size_t num_flags = std::tuple_size<
decltype(S::flags)>::value;
732 static const std::array<const char* const, num_flags>
flag_names;
736 static const char*
tag(
int idx);
737 static int idx(
const char*
tag);
739 static void ReadLcf(S& obj, LcfReader& stream, uint32_t length);
740 static void WriteLcf(
const S& obj, LcfWriter& stream);
741 static int LcfSize(
const S& obj, LcfWriter& stream);
742 static void WriteXml(
const S& obj, XmlWriter& stream);
743 static void BeginXml(S& obj, XmlReader& stream);
753 for (
size_t i = 0; i < flag_names.size(); ++i) {
754 if (std::strcmp(flag_names[i], tag) == 0) {
766 static void ReadLcf(T& ref, LcfReader& stream, uint32_t length) {
769 static void WriteLcf(
const T& ref, LcfWriter& stream) {
772 static int LcfSize(
const T& ref, LcfWriter& stream) {
775 static void WriteXml(
const T& ref, XmlWriter& stream) {
795 if (strcmp(
name, this->name) != 0)
796 stream.Error(
"Expecting %s but got %s", this->name,
name);
815 if (strcmp(
name, this->name) != 0)
816 stream.Error(
"Expecting %s but got %s", this->name,
name);
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)
IDReaderT< S, IDChecker< S >::value > IDReader
std::map< const char *const, const Field< S > *, StringComparator > tag_map_type
static tag_map_type tag_map
static field_map_type field_map
static void WriteLcf(const S &obj, LcfWriter &stream)
std::map< int, const Field< S > * > field_map_type
static void ReadLcf(S &obj, LcfReader &stream)
static const char *const name
WrapperXmlHandler(const char *const name, XmlHandler *handler)
void StartElement(XmlReader &stream, const char *name, const char **)
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 void ParseXml(DBString &ref, const std::string &data)
static void WriteXml(const DBString &ref, XmlWriter &stream)
static void WriteLcf(const DBString &ref, LcfWriter &stream)
static int LcfSize(const DBString &ref, LcfWriter &stream)
static void ReadLcf(DBString &ref, LcfReader &stream, uint32_t length)
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 WriteXml(const T &ref, XmlWriter &stream)
static void BeginXml(T &ref, XmlReader &stream)
static void ReadLcf(T &ref, LcfReader &stream, uint32_t length)
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