10 #ifndef LCF_READER_STRUCT_H
11 #define LCF_READER_STRUCT_H
13 #ifdef LCF_DEBUG_TRACE
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"
39 #include "lcf/rpg/saveeasyrpgtext.h"
40 #include "lcf/rpg/saveeasyrpgwindow.h"
100 template <class T, Category::Index cat = TypeCategory<T>::value>
110 static void ReadLcf(T&, LcfReader& stream, uint32_t length) {
111 stream.Seek(length, LcfReader::FromCurrent);
132 static void ReadLcf(T& ref, LcfReader& stream, uint32_t length);
133 static void WriteLcf(
const T& ref, LcfWriter& stream);
134 static int LcfSize(
const T& ref, LcfWriter& stream);
135 static void WriteXml(
const T& ref, XmlWriter& stream);
141 static void ReadLcf(T& ref, LcfReader& stream, uint32_t length) {
144 static void WriteLcf(
const T& ref, LcfWriter& stream) {
147 static int LcfSize(
const T& ref, LcfWriter& stream) {
150 static void WriteXml(
const T& ref, XmlWriter& stream) {
166 static const uint32_t
value =
sizeof(T);
182 static void ReadLcf(T& ref, LcfReader& stream, uint32_t length) {
187 fprintf(stderr,
"Reading Primitive of incorrect size %" PRIu32
" (expected %" PRIu32
") at %" PRIX32
"\n",
192 #ifdef LCF_DEBUG_TRACE
198 #ifdef LCF_DEBUG_TRACE
199 printf(
"Invalid %s at %X\n",
typeid(T).name(), stream.Tell());
201 stream.Seek(dif, LcfReader::FromCurrent);
204 static void WriteLcf(
const T& ref, LcfWriter& stream) {
210 static void WriteXml(
const T& ref, XmlWriter& stream) {
213 static void ParseXml(T& ref,
const std::string& data) {
214 XmlReader::Read(ref, data);
217 #ifdef LCF_DEBUG_TRACE
218 template <
typename U>
219 static void DebugPrint(U& ref) {
220 std::cout << ref <<
'\n';
222 static void DebugPrint(int8_t ref) {
223 std::cout << (int)ref <<
'\n';
225 static void DebugPrint(uint8_t ref) {
226 std::cout << (int)ref <<
'\n';
236 static void ReadLcf(std::vector<T>& ref, LcfReader& stream, uint32_t length) {
237 stream.Read(ref, length);
238 #ifdef LCF_DEBUG_TRACE
239 typename std::vector<T>::iterator it;
241 for (it = ref.begin(); it != ref.end(); ++it) {
242 printf(
"%d, ",
static_cast<int>(*it));
247 static void WriteLcf(
const std::vector<T>& ref, LcfWriter& stream) {
250 static int LcfSize(
const std::vector<T>& ref, LcfWriter& ) {
253 static void WriteXml(
const std::vector<T>& ref, XmlWriter& stream) {
256 static void ParseXml(std::vector<T>& ref,
const std::string& data) {
257 XmlReader::Read(ref, data);
266 static void ReadLcf(int32_t& ref, LcfReader& stream, uint32_t length) {
267 if (length >= 1 && length <= 5) {
268 ref = stream.ReadInt();
269 #ifdef LCF_DEBUG_TRACE
270 printf(
" %d\n", ref);
274 #ifdef LCF_DEBUG_TRACE
275 printf(
"Invalid integer at %X\n", stream.Tell());
277 stream.Seek(length, LcfReader::FromCurrent);
281 static void WriteLcf(
const int32_t& ref, LcfWriter& stream) {
282 stream.WriteInt(ref);
284 static int LcfSize(
const int32_t& ref, LcfWriter& ) {
285 return LcfReader::IntSize(ref);
287 static void WriteXml(
const int32_t& ref, XmlWriter& stream) {
288 stream.WriteInt(ref);
290 static void ParseXml(int32_t& ref,
const std::string& data) {
291 XmlReader::Read(ref, data);
300 static void ReadLcf(std::string& ref, LcfReader& stream, uint32_t length) {
301 stream.ReadString(ref, length);
302 #ifdef LCF_DEBUG_TRACE
303 printf(
" %s\n", ref.c_str());
306 static void WriteLcf(
const std::string& ref, LcfWriter& stream) {
309 static int LcfSize(
const std::string& ref, LcfWriter& stream) {
310 return stream.Decode(ref).size();
312 static void WriteXml(
const std::string& ref, XmlWriter& stream) {
315 static void ParseXml(std::string& ref,
const std::string& data) {
316 XmlReader::Read(ref, data);
325 static void ReadLcf(DBBitArray& ref, LcfReader& stream, uint32_t length) {
326 stream.ReadBits(ref, length);
327 #ifdef LCF_DEBUG_TRACE
330 print(
"%d",
static_cast<int>(b));
335 static void WriteLcf(
const DBBitArray& ref, LcfWriter& stream) {
338 static int LcfSize(
const DBBitArray& ref, LcfWriter& stream) {
342 static void WriteXml(
const DBBitArray& ref, XmlWriter& stream) {
345 static void ParseXml(DBBitArray& ref,
const std::string& data) {
346 XmlReader::Read(ref, data);
357 static void ReadLcf(T& ref, LcfReader& stream, uint32_t length) {
360 static void WriteLcf(
const T& ref, LcfWriter& stream) {
363 static int LcfSize(
const T& ref, LcfWriter& stream) {
366 static void WriteXml(
const T& ref, XmlWriter& stream) {
372 static void ParseXml(T& ref,
const std::string& data) {
389 virtual void ReadLcf(S& obj, LcfReader& stream, uint32_t length)
const = 0;
390 virtual void WriteLcf(
const S& obj, LcfWriter& stream)
const = 0;
391 virtual int LcfSize(
const S& obj, LcfWriter& stream)
const = 0;
393 virtual void WriteXml(
const S& obj, XmlWriter& stream)
const = 0;
394 virtual void BeginXml(S& obj, XmlReader& stream)
const = 0;
395 virtual void ParseXml(S& obj,
const std::string& data)
const = 0;
398 if (std::is_same<S,rpg::Terms>::value && db_is2k3 && (
id == 0x3 ||
id == 0x1)) {
413 template <
class S,
class T>
417 void ReadLcf(S& obj, LcfReader& stream, uint32_t length)
const {
420 void WriteLcf(
const S& obj, LcfWriter& stream)
const {
423 int LcfSize(
const S& obj, LcfWriter& stream)
const {
426 void WriteXml(
const S& obj, XmlWriter& stream)
const {
427 stream.BeginElement(this->
name);
429 stream.EndElement(this->
name);
434 void ParseXml(S& obj,
const std::string& data)
const {
449 template <
typename S,
typename T>
454 int LcfSize(
const S& obj, LcfWriter& stream)
const {
456 if ((obj.*(this->ref)) == 0) {
475 template <
typename S>
480 void ReadLcf(S& , LcfReader& , uint32_t )
const { }
501 template <
class S,
class T>
505 void ReadLcf(S& , LcfReader& stream, uint32_t length)
const {
509 void WriteLcf(
const S& obj, LcfWriter& stream)
const {
513 int LcfSize(
const S& obj, LcfWriter& stream)
const {
515 return LcfReader::IntSize(size);
527 return (a.*
ref).size() == (b.*
ref).size();
538 template <
class S,
class T>
543 void WriteLcf(
const S& obj, LcfWriter& stream)
const {
544 int size = (obj.*(this->
ref)).size();
547 int LcfSize(
const S& obj, LcfWriter& )
const {
548 int size = (obj.*(this->
ref)).size();
549 return LcfReader::IntSize(size);
567 static const bool value =
sizeof(check<T>(0)) ==
sizeof(
yes);
572 template <
class S,
bool T>
578 static void ReadID(S& obj, LcfReader& stream) {
579 obj.ID = stream.ReadInt();
581 static void WriteID(
const S& obj, LcfWriter& stream) {
582 stream.WriteInt(obj.ID);
585 return LcfReader::IntSize(obj.ID);
587 static void WriteXmlTag(
const S& obj,
const std::string& name, XmlWriter& stream) {
588 stream.BeginElement(name, obj.ID);
591 for (
int i = 0; atts[i] != NULL && atts[i + 1] != NULL; i += 2) {
592 if (strcmp(atts[i],
"id") == 0)
593 obj.ID = atoi(atts[i + 1]);
601 static void WriteID(
const S& , LcfWriter& ) {}
602 static int IDSize(
const S& ) {
return 0; }
603 static void WriteXmlTag(
const S& ,
const std::string& name, XmlWriter& stream) {
604 stream.BeginElement(name);
610 bool operator() (
const char*
const& lhs,
const char*
const& rhs)
const {
611 return strcmp(lhs, rhs) < 0;
636 static void ReadLcf(S& obj, LcfReader& stream);
637 static void WriteLcf(
const S& obj, LcfWriter& stream);
638 static int LcfSize(
const S& obj, LcfWriter& stream);
639 static void WriteXml(
const S& obj, XmlWriter& stream);
640 static void BeginXml(S& obj, XmlReader& stream);
642 static void ReadLcf(std::vector<S>& obj, LcfReader& stream);
643 static void WriteLcf(
const std::vector<S>& obj, LcfWriter& stream);
644 static int LcfSize(
const std::vector<S>& obj, LcfWriter& stream);
645 static void WriteXml(
const std::vector<S>& obj, XmlWriter& stream);
646 static void BeginXml(std::vector<S>& obj, XmlReader& stream);
660 static void ReadLcf(T& ref, LcfReader& stream, uint32_t ) {
663 static void WriteLcf(
const T& ref, LcfWriter& stream) {
666 static int LcfSize(
const T& ref, LcfWriter& stream) {
669 static void WriteXml(
const T& ref, XmlWriter& stream) {
682 static void ReadLcf(std::vector<T>& ref, LcfReader& stream, uint32_t ) {
685 static void WriteLcf(
const std::vector<T>& ref, LcfWriter& stream) {
688 static int LcfSize(
const std::vector<T>& ref, LcfWriter& stream) {
691 static void WriteXml(
const std::vector<T>& ref, XmlWriter& stream) {
694 static void BeginXml(std::vector<T>& ref, XmlReader& stream) {
697 static void ParseXml(std::vector<T>& ,
const std::string& ) {
711 static constexpr
size_t num_flags = std::tuple_size<decltype(S::flags)>::value;
712 static const std::array<const char* const, num_flags>
flag_names;
716 static const char*
tag(
int idx);
717 static int idx(
const char*
tag);
719 static void ReadLcf(S& obj, LcfReader& stream, uint32_t length);
720 static void WriteLcf(
const S& obj, LcfWriter& stream);
721 static int LcfSize(
const S& obj, LcfWriter& stream);
722 static void WriteXml(
const S& obj, XmlWriter& stream);
723 static void BeginXml(S& obj, XmlReader& stream);
733 for (
size_t i = 0; i < flag_names.size(); ++i) {
734 if (std::strcmp(flag_names[i], tag) == 0) {
746 static void ReadLcf(T& ref, LcfReader& stream, uint32_t length) {
749 static void WriteLcf(
const T& ref, LcfWriter& stream) {
752 static int LcfSize(
const T& ref, LcfWriter& stream) {
755 static void WriteXml(
const T& ref, XmlWriter& stream) {
775 if (strcmp(
name, this->name) != 0)
776 stream.Error(
"Expecting %s but got %s", this->name,
name);
795 if (strcmp(
name, this->name) != 0)
796 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 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