10 #ifndef LCF_READER_STRUCT_H 11 #define LCF_READER_STRUCT_H 13 #ifdef LCF_DEBUG_TRACE 90 template <class T, Category::Index cat = TypeCategory<T>::value>
132 static const uint32_t
value =
sizeof(T);
153 fprintf(stderr,
"Reading Primitive of incorrect size %" PRIu32
" (expected %" PRIu32
") at %" PRIX32
"\n",
158 #ifdef LCF_DEBUG_TRACE 164 #ifdef LCF_DEBUG_TRACE 165 printf(
"Invalid %s at %X\n",
typeid(T).name(), stream.
Tell());
183 #ifdef LCF_DEBUG_TRACE 184 template <
typename U>
185 static void DebugPrint(U& ref) {
186 std::cout << ref <<
'\n';
188 static void DebugPrint(int8_t ref) {
189 std::cout << (int)ref <<
'\n';
191 static void DebugPrint(uint8_t ref) {
192 std::cout << (int)ref <<
'\n';
203 stream.
Read(ref, length);
204 #ifdef LCF_DEBUG_TRACE 205 typename std::vector<T>::iterator it;
207 for (it = ref.begin(); it != ref.end(); ++it) {
208 printf(
"%d, ", static_cast<int>(*it));
233 if (length >= 1 && length <= 5) {
235 #ifdef LCF_DEBUG_TRACE 236 printf(
" %d\n", ref);
240 #ifdef LCF_DEBUG_TRACE 241 printf(
"Invalid integer at %X\n", stream.
Tell());
268 #ifdef LCF_DEBUG_TRACE 269 printf(
" %s\n", ref.c_str());
276 return stream.
Decode(ref).size();
326 virtual bool IsDefault(
const S& obj,
const S& ref)
const = 0;
329 virtual void ParseXml(S& obj,
const std::string&
data)
const = 0;
332 if (std::is_same<S,RPG::Terms>::value && db_is2k3 && (
id == 0x3 ||
id == 0x1)) {
347 template <
class S,
class T>
383 template <
typename S,
typename T>
390 if ((obj.*(this->ref)) == 0) {
409 template <
typename S>
435 template <
class S,
class T>
437 const std::vector<T> S::*
ref;
461 return (a.*
ref).size() == (b.*
ref).size();
472 template <
class S,
class T>
478 int size = (obj.*(this->
ref)).size();
482 int size = (obj.*(this->
ref)).size();
501 static const bool value =
sizeof(check<T>(0)) ==
sizeof(
yes);
506 template <
class S,
bool T>
525 for (
int i = 0; atts[i] != NULL && atts[i + 1] != NULL; i += 2) {
526 if (strcmp(atts[i],
"id") == 0)
527 obj.ID = atoi(atts[i + 1]);
536 static int IDSize(
const S& ) {
return 0; }
544 bool operator() (
const char*
const& lhs,
const char*
const& rhs)
const {
545 return strcmp(lhs, rhs) < 0;
631 static void ParseXml(std::vector<T>& ,
const std::string& ) {
645 static constexpr
size_t num_flags = std::tuple_size<decltype(S::flags)>::value;
646 static const std::array<const char* const, num_flags>
flag_names;
649 static const char*
tag(
int idx);
650 static int idx(
const char*
tag);
669 for (
size_t i = 0; i < flag_names.size(); ++i) {
670 if (std::strcmp(flag_names[i], tag) == 0) {
711 if (strcmp(
name, this->name) != 0)
712 stream.
Error(
"Expecting %s but got %s", this->name,
name);
731 if (strcmp(
name, this->name) != 0)
732 stream.
Error(
"Expecting %s but got %s", this->name,
name);
void WriteLcf(const S &, LcfWriter &) const
RootXmlHandler(S &ref, const char *const name)
WrapperXmlHandler(const char *const name, XmlHandler *handler)
static void ParseXml(T &, const std::string &)
SizeField(const std::vector< T > S::*ref, int id, bool present_if_default, bool is2k3)
void ParseXml(S &, const std::string &) const
static void WriteXml(const T &ref, XmlWriter &stream)
int LcfSize(const S &obj, LcfWriter &stream) const
static int LcfSize(const S &obj, LcfWriter &stream)
void ReadLcf(S &obj, LcfReader &stream, uint32_t length) const
static int LcfSize(const T &ref, LcfWriter &stream)
static const char *const name
static void WriteLcf(const std::vector< T > &ref, LcfWriter &stream)
int LcfSize(const S &, LcfWriter &) const
void StartElement(XmlReader &stream, const char *name, const char **)
void StartElement(XmlReader &stream, const char *name, const char **)
Field< RPG::Actor > const * fields[]
static void WriteXml(const S &obj, XmlWriter &stream)
void Seek(size_t pos, SeekMode mode=FromStart)
void SetHandler(XmlHandler *handler)
static void ReadLcf(S &obj, LcfReader &stream)
void ReadLcf(S &, LcfReader &, uint32_t) const
virtual void BeginXml(S &obj, XmlReader &stream) const =0
static int idx(const char *tag)
virtual void WriteLcf(const S &obj, LcfWriter &stream) const =0
void BeginElement(const std::string &name)
std::string Decode(const std::string &str_to_encode)
static const Category::Index value
static void ReadLcf(std::vector< T > &ref, LcfReader &stream, uint32_t)
static void ParseXml(std::vector< T > &, const std::string &)
virtual bool IsDefault(const S &obj, const S &ref) const =0
static void WriteLcf(const T &ref, LcfWriter &stream)
static void BeginXml(T &ref, XmlReader &stream)
static int LcfSize(const T &ref, LcfWriter &stream)
TypedField(T S::*ref, int id, const char *name, bool present_if_default, bool is2k3)
void WriteXml(const S &, XmlWriter &) const
int LcfSize(const S &obj, LcfWriter &stream) const
void Read(void *ptr, size_t size, size_t nmemb)
static void MakeFieldMap()
static void WriteLcf(const T &ref, LcfWriter &stream)
void BeginXml(S &obj, XmlReader &stream) const
void EndElement(const std::string &name)
void ParseXml(S &, const std::string &) const
std::map< const char *const, const Field< S > *, StringComparator > tag_map_type
static void ReadLcf(T &ref, LcfReader &stream, uint32_t length)
void Error(const char *fmt,...)
static void WriteXml(const std::string &ref, XmlWriter &stream)
void BeginXml(S &, XmlReader &) const
static int LcfSize(const int32_t &ref, LcfWriter &)
static void WriteXmlTag(const S &obj, const std::string &name, XmlWriter &stream)
static int LcfSize(const T &, LcfWriter &)
static void BeginXml(S &obj, XmlReader &stream)
static void ParseXml(std::vector< T > &ref, const std::string &data)
void BeginXml(S &, XmlReader &) const
static void ReadLcf(S &obj, LcfReader &stream, uint32_t length)
static void ReadID(S &obj, LcfReader &stream)
static const char * tag(int idx)
static void WriteXml(const S &obj, XmlWriter &stream)
static void BeginXml(S &obj, XmlReader &stream)
void Write(const void *ptr, size_t size, size_t nmemb)
static void WriteLcf(const T &ref, LcfWriter &stream)
static void ParseXml(T &, const std::string &)
static void WriteXml(const int32_t &ref, XmlWriter &stream)
static void WriteXml(const std::vector< T > &ref, XmlWriter &stream)
static void WriteLcf(const S &obj, LcfWriter &stream)
static void ReadLcf(std::string &ref, LcfReader &stream, uint32_t length)
static void WriteLcf(const std::vector< T > &ref, LcfWriter &stream)
static void WriteLcf(const std::string &ref, LcfWriter &stream)
static const std::array< const char *const, num_flags > flag_names
static void ParseXml(std::string &ref, const std::string &data)
static void ReadLcf(T &ref, LcfReader &stream, uint32_t length)
void ReadString(std::string &ref, size_t size)
static int LcfSize(const std::vector< T > &ref, LcfWriter &stream)
void WriteLcf(const S &obj, LcfWriter &stream) const
static const char *const name
static constexpr size_t num_flags
static void WriteXml(const T &ref, XmlWriter &stream)
virtual void ParseXml(S &obj, const std::string &data) const =0
static void ReadLcf(T &ref, LcfReader &stream, uint32_t length)
static int LcfSize(const std::vector< T > &ref, LcfWriter &)
bool IsDefault(const S &a, const S &b) const
int LcfSize(const S &obj, LcfWriter &) const
static int LcfSize(const T &ref, LcfWriter &stream)
static void ParseXml(T &ref, const std::string &data)
void WriteLcf(const S &obj, LcfWriter &stream) const
static int LcfSize(const std::string &ref, LcfWriter &stream)
static void WriteLcf(const T &ref, LcfWriter &stream)
void WriteXml(const S &, XmlWriter &) const
virtual void WriteXml(const S &obj, XmlWriter &stream) const =0
static void WriteXml(const T &ref, XmlWriter &stream)
static field_map_type field_map
void ParseXml(S &obj, const std::string &data) const
static void BeginXml(std::vector< T > &ref, XmlReader &stream)
static void WriteXmlTag(const S &, const std::string &name, XmlWriter &stream)
static void WriteLcf(const S &obj, LcfWriter &stream)
static void ReadIDXml(S &, const char **)
static int LcfSize(const T &ref, LcfWriter &stream)
static void BeginXml(T &ref, XmlReader &stream)
static void WriteLcf(const int32_t &ref, LcfWriter &stream)
virtual void ReadLcf(S &obj, LcfReader &stream, uint32_t length) const =0
static void BeginXml(T &ref, XmlReader &stream)
static void ParseXml(T &, const std::string &)
static yes check(type_check< int C::*, &C::ID > *)
static void ReadID(S &, LcfReader &)
static int IDSize(const S &obj)
static void ParseXml(T &ref, const std::string &data)
static void WriteID(const S &obj, LcfWriter &stream)
static int IntSize(unsigned int x)
static void BeginXml(T &ref, XmlReader &stream)
bool IsDefault(const S &, const S &) const
bool IsDefault(const S &a, const S &b) const
static void WriteXml(const T &ref, XmlWriter &stream)
static void ReadIDXml(S &obj, const char **atts)
void WriteXml(const S &obj, XmlWriter &stream) const
static int IDSize(const S &)
bool isPresentIfDefault(bool db_is2k3) const
void WriteLcf(const S &obj, LcfWriter &stream) const
int LcfSize(const S &obj, LcfWriter &stream) const
static void WriteXml(const T &ref, XmlWriter &stream)
virtual int LcfSize(const S &obj, LcfWriter &stream) const =0
static int LcfSize(const S &obj, LcfWriter &stream)
const std::vector< T > S::* ref
IDReaderT< S, IDChecker< S >::value > IDReader
static void ReadLcf(std::vector< T > &ref, LcfReader &stream, uint32_t length)
static void WriteLcf(const T &ref, LcfWriter &stream)
static const std::array< bool, num_flags > flags_is2k3
static void ParseXml(int32_t &ref, const std::string &data)
static void WriteXml(const T &ref, XmlWriter &stream)
void ReadLcf(S &, LcfReader &stream, uint32_t length) const
bool IsDefault(const S &a, const S &b) const
Field(int id, const char *name, bool present_if_default, bool is2k3)
static void ReadLcf(T &ref, LcfReader &stream, uint32_t length)
static void ReadLcf(T &ref, LcfReader &stream, uint32_t)
static void WriteXml(const std::vector< T > &ref, XmlWriter &stream)
std::map< int, const Field< S > * > field_map_type
static void WriteID(const S &, LcfWriter &)
static void WriteLcf(const T &ref, LcfWriter &stream)
static void ReadLcf(T &ref, LcfReader &stream, uint32_t length)
static const uint32_t value
static int LcfSize(const T &ref, LcfWriter &stream)
static void Read(T &ref, const std::string &data)
static tag_map_type tag_map
static void ReadLcf(int32_t &ref, LcfReader &stream, uint32_t length)
bool operator()(const char *const &lhs, const char *const &rhs) const
static void BeginXml(T &, XmlReader &)