7 #ifndef LCF_READER_STRUCT_H
8 #define LCF_READER_STRUCT_H
16 #include <boost/preprocessor/cat.hpp>
17 #include <boost/preprocessor/stringize.hpp>
80 template <class T, Category::Index cat = TypeCategory<T>::value>
122 static const uint32_t
value =
sizeof(T);
163 stream.
Read(ref, length);
164 #ifdef LCF_DEBUG_TRACE
165 typename std::vector<T>::iterator it;
167 for (it = ref.begin(); it != ref.end(); ++it) {
193 if (length >= 1 || length <= 5) {
195 #ifdef LCF_DEBUG_TRACE
196 printf(
" %d\n", ref);
200 #ifdef LCF_DEBUG_TRACE
201 printf(
"Invalid integer at %s\n", stream->
Tell());
228 #ifdef LCF_DEBUG_TRACE
229 printf(
" %s\n", ref.c_str());
236 return stream.
Decode(ref).size();
274 template <
class S,
class T>
309 virtual bool IsDefault(
const S& obj,
const S& ref)
const = 0;
312 virtual void ParseXml(S& obj,
const std::string&
data)
const = 0;
315 id(id), name(name) {}
326 static yes&
check(
void(C::*)(
void));
328 static no&
check(...);
330 static const bool value =
sizeof(check<T>(0)) ==
sizeof(
yes);
348 template <
class T,
bool comparable>
367 static bool IsEqual(
const std::vector<T>& a,
const std::vector<T>& b) {
368 return a.empty() && b.empty();
376 return impl_type::IsEqual(a, b);
383 template <
class S,
class T>
412 Field<S>(id, name), ref(ref) {}
418 template <
class S,
class T>
420 const std::vector<T> S::*
ref;
444 return (a.*
ref).empty() && (b.*
ref).empty();
448 Field<S>(id,
""), ref(ref) {}
463 static no
check(...);
465 static const bool value =
sizeof(check<T>(0)) ==
sizeof(
yes);
470 template <
class S,
bool T>
489 for (
int i = 0; atts[i] != NULL && atts[i + 1] != NULL; i += 2) {
490 if (strcmp(atts[i],
"id") == 0)
491 obj.ID = atoi(atts[i + 1]);
500 static int IDSize(
const S& ) {
return 0; }
508 bool operator() (
const char*
const& lhs,
const char*
const& rhs)
const {
509 return strcmp(lhs, rhs) < 0;
595 static void ParseXml(std::vector<T>& ,
const std::string& ) {
607 Flag(
bool S::*
ref,
const char*
const name) : ref(ref), name(name) {}
614 typedef std::map<const char* const, const Flag*, StringComparator>
tag_map_type;
665 name(name), handler(handler) {}
668 if (strcmp(name, this->name) != 0)
669 stream.
Error(
"Expecting %s but got %s", this->name, name);
688 if (strcmp(name, this->name) != 0)
689 stream.
Error(
"Expecting %s but got %s", this->name, name);
705 #define LCF_STRUCT_FIELDS_BEGIN() \
707 char const* const Struct<RPG::LCF_CURRENT_STRUCT>::name = BOOST_PP_STRINGIZE(LCF_CURRENT_STRUCT); \
709 Field<RPG::LCF_CURRENT_STRUCT> const* Struct<RPG::LCF_CURRENT_STRUCT>::fields[] = { \
711 #define LCF_STRUCT_FIELDS_END() \
714 #define LCF_STRUCT_TYPED_FIELD(T, REF) \
715 new TypedField<RPG::LCF_CURRENT_STRUCT, T>( \
716 &RPG::LCF_CURRENT_STRUCT::REF \
717 , LCF_CHUNK_SUFFIX::BOOST_PP_CAT(Chunk, LCF_CURRENT_STRUCT)::REF \
718 , BOOST_PP_STRINGIZE(REF) \
721 #define LCF_STRUCT_SIZE_FIELD(T, REF) \
722 new SizeField<RPG::LCF_CURRENT_STRUCT, T>( \
723 &RPG::LCF_CURRENT_STRUCT::REF \
724 , LCF_CHUNK_SUFFIX::BOOST_PP_CAT(Chunk, LCF_CURRENT_STRUCT)::BOOST_PP_CAT(REF, _size) \
RootXmlHandler(S &ref, const char *const name)
static void ReadLcf(S &obj, T S::*ref, LcfReader &stream, uint32_t length)
WrapperXmlHandler(const char *const name, XmlHandler *handler)
static bool IsEqual(const T &, const T &)
static void ParseXml(T &, const std::string &)
static void WriteXml(const T &ref, XmlWriter &stream)
Compare_Traits_Impl< T, Compare_Test< T >::value > impl_type
static void BeginXml(S &obj, XmlReader &stream)
static int LcfSize(const T &ref, LcfWriter &stream)
static void WriteLcf(const std::vector< T > &ref, LcfWriter &stream)
static tag_map_type tag_map
void StartElement(XmlReader &stream, const char *name, const char **)
void StartElement(XmlReader &stream, const char *name, const char **)
static void WriteXml(const S &obj, XmlWriter &stream)
void Seek(size_t pos, SeekMode mode=FromStart)
void SetHandler(XmlHandler *handler)
virtual void BeginXml(S &obj, XmlReader &stream) const =0
static int LcfSize(const S &obj, const T S::*ref, LcfWriter &stream)
virtual void WriteLcf(const S &obj, LcfWriter &stream) const =0
void BeginElement(const std::string &name)
void WriteXml(const S &, XmlWriter &) const
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)
void Read(void *ptr, size_t size, size_t nmemb)
static void WriteLcf(const T &ref, LcfWriter &stream)
void EndElement(const std::string &name)
void ReadLcf(S &, LcfReader &stream, uint32_t length) const
static yes & check(void(C::*)(void))
Field(int id, const char *name)
static void ReadLcf(T &ref, LcfReader &stream, uint32_t length)
void Error(const char *fmt,...)
static void WriteXml(const std::string &ref, XmlWriter &stream)
static void WriteXmlTag(const S &obj, const std::string &name, XmlWriter &stream)
static int LcfSize(const T &, LcfWriter &)
void BeginXml(S &obj, XmlReader &stream) const
static void ParseXml(std::vector< T > &ref, const std::string &data)
static void MakeFieldMap()
void BeginXml(S &, XmlReader &) const
static void ReadLcf(S &obj, LcfReader &stream, uint32_t length)
static void ReadID(S &obj, LcfReader &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 bool IsEqual(const std::vector< T > &a, const std::vector< T > &b)
static bool IsEqual(const T &a, const T &b)
static void WriteXml(const std::vector< T > &ref, XmlWriter &stream)
TypedField(T S::*ref, int id, const char *name)
static void WriteLcf(const S &obj, LcfWriter &stream)
static void ParseXml(int &ref, const std::string &data)
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 void WriteLcf(const int &ref, LcfWriter &stream)
static void ParseXml(std::string &ref, const std::string &data)
static void ReadLcf(T &ref, LcfReader &stream, uint32_t length)
static tag_map_type tag_map
static void ReadLcf(int &ref, LcfReader &stream, uint32_t length)
void ReadString(std::string &ref, size_t size)
static int LcfSize(const std::vector< T > &ref, LcfWriter &stream)
static const char *const name
void WriteLcf(const S &obj, LcfWriter &stream) const
static void WriteXml(const T &ref, XmlWriter &stream)
IDReaderT< S, IDChecker< S >::value > IDReader
bool IsDefault(const S &a, const S &b) const
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 &)
static int LcfSize(const T &ref, LcfWriter &stream)
std::map< const char *const, const Field< S > *, StringComparator > tag_map_type
Flag(bool S::*ref, const char *const name)
static void ParseXml(T &ref, const std::string &data)
static int LcfSize(const std::string &ref, LcfWriter &stream)
static void WriteLcf(const T &ref, LcfWriter &stream)
std::map< const char *const, const Flag *, StringComparator > tag_map_type
virtual void WriteXml(const S &obj, XmlWriter &stream) const =0
static void WriteXml(const T &ref, XmlWriter &stream)
SizeField(const std::vector< T > S::*ref, int id)
static void BeginXml(std::vector< T > &ref, XmlReader &stream)
void ParseXml(S &obj, const std::string &data) const
static void WriteXmlTag(const S &, const std::string &name, XmlWriter &stream)
static void ReadLcf(S &obj, LcfReader &stream)
static void ReadIDXml(S &, const char **)
static int LcfSize(const T &ref, LcfWriter &stream)
static void BeginXml(T &ref, XmlReader &stream)
int LcfSize(const S &obj, LcfWriter &stream) const
virtual void ReadLcf(S &obj, LcfReader &stream, uint32_t length) const =0
static void ParseXml(S &obj, T S::*ref, const std::string &data)
static void BeginXml(T &ref, XmlReader &stream)
static void ParseXml(T &, const std::string &)
static void ReadID(S &, LcfReader &)
static int IDSize(const S &obj)
void WriteLcf(const S &obj, LcfWriter &stream) const
static void ParseXml(T &ref, const std::string &data)
static const uint32_t max_size
static void WriteID(const S &obj, LcfWriter &stream)
static int LcfSize(const S &obj, LcfWriter &stream)
static int IntSize(unsigned int x)
static void BeginXml(T &ref, XmlReader &stream)
std::map< int, const Field< S > * > field_map_type
static void WriteXml(const int &ref, XmlWriter &stream)
static const char *const name
static void WriteXml(const S &obj, const T S::*ref, XmlWriter &stream)
static field_map_type field_map
static void WriteXml(const T &ref, XmlWriter &stream)
static void ReadIDXml(S &obj, const char **atts)
static int IDSize(const S &)
static int LcfSize(const int &ref, LcfWriter &)
static const Field< S > * fields[]
static void WriteXml(const T &ref, XmlWriter &stream)
static void WriteLcf(const S &obj, LcfWriter &stream)
int LcfSize(const S &obj, LcfWriter &stream) const
virtual int LcfSize(const S &obj, LcfWriter &stream) const =0
static int LcfSize(const S &obj, LcfWriter &stream)
const std::vector< T > S::* ref
static yes check(type_check< int C::*,&C::ID > *)
void WriteXml(const S &obj, XmlWriter &stream) const
static void BeginXml(S &obj, T S::*ref, XmlReader &stream)
static void ReadLcf(std::vector< T > &ref, LcfReader &stream, uint32_t length)
static void WriteLcf(const T &ref, LcfWriter &stream)
static void WriteXml(const T &ref, XmlWriter &stream)
static void WriteLcf(const S &obj, const T S::*ref, LcfWriter &stream)
void ReadLcf(S &obj, LcfReader &stream, uint32_t length) const
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)
const Flags< flags_type >::Flag * flags[]
void ParseXml(S &, const std::string &) const
static void WriteID(const S &, LcfWriter &)
bool IsDefault(const S &a, const S &b) const
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)
bool operator()(const char *const &lhs, const char *const &rhs) const
static void Read(T &ref, const std::string &data)
static void WriteXml(const S &obj, XmlWriter &stream)
static bool IsEqual(const T &a, const T &b)
static void BeginXml(T &, XmlReader &)