37 #if !defined(THEOLIZER_INTERNAL_SERIALIZER_XML_H) 38 #define THEOLIZER_INTERNAL_SERIALIZER_XML_H 52 #pragma warning(disable:4251 4702) 64 #ifndef THEOLIZER_INTERNAL_DOXYGEN 76 #define THEOLIZER_INTERNAL_XML_THEOLIZER_NAME "XmlTheolizer" 78 const static char kXmlSerializerName[]=THEOLIZER_INTERNAL_XML_THEOLIZER_NAME;
79 const static unsigned kXmlSerializerVersionNo=1;
85 #define THEOLIZER_INTERNAL_XML_HEADER \ 86 "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>\n" 87 #define THEOLIZER_INTERNAL_XML_NAMESPACE "th" 88 #define THEOLIZER_INTERNAL_XML_URI "https://theolizer.com/theoride/xml-1" 100 THEOLIZER_INTERNAL_DLL std::ostream&
operator<<(std::ostream& iOStream, TagKind iTagKind);
108 Structure mStructure;
109 std::size_t mObjectId;
111 unsigned mGlobalVersionNo;
114 mStructure(Structure::
None),
115 mObjectId(kInvalidSize),
119 char const* getStructure()
const;
127 inline bool hasPropertyXml(
Property iProperty,
bool iIsSaver)
132 case Property::IsSaver:
136 case Property::EncodedString:
140 case Property::SupportModifying:
144 case Property::BinaryOpen:
156 class XmlMidOSerializer;
157 class XmlMidISerializer;
159 #define THEOLIZER_INTERNAL_INTEGRAL(dSigned, dDigits, dName1) \ 160 template<class tMidSerializer, typename tPrimitive> \ 161 struct PrimitiveName \ 167 (std::is_same<tMidSerializer, XmlMidOSerializer>::value \ 168 || std::is_same<tMidSerializer, XmlMidISerializer>::value) \ 169 && (std::numeric_limits<tPrimitive>::is_signed == dSigned) \ 170 && (std::numeric_limits<tPrimitive>::radix == 2) \ 171 && (std::numeric_limits<tPrimitive>::digits == dDigits) \ 172 && (std::numeric_limits<tPrimitive>::max_exponent == 0) \ 176 static char const* getPrimitiveName(unsigned iSerializerVersionNo) \ 178 switch(iSerializerVersionNo) \ 180 case 1: return dName1; \ 182 THEOLIZER_INTERNAL_ABORT("getPrimitiveName() : iVersionNo is illegal.");\ 187 #define THEOLIZER_INTERNAL_FLOAT(dDigits, dMaxExponent, dName1) \ 188 template<class tMidSerializer, typename tPrimitive> \ 189 struct PrimitiveName \ 195 (std::is_same<tMidSerializer, XmlMidOSerializer>::value \ 196 || std::is_same<tMidSerializer, XmlMidISerializer>::value) \ 197 && (std::numeric_limits<tPrimitive>::is_signed == 1) \ 198 && (std::numeric_limits<tPrimitive>::radix == 2) \ 199 && (std::numeric_limits<tPrimitive>::digits == dDigits) \ 200 && (std::numeric_limits<tPrimitive>::max_exponent == dMaxExponent)\ 204 static char const* getPrimitiveName(unsigned iSerializerVersionNo) \ 206 switch(iSerializerVersionNo) \ 208 case 1: return dName1; \ 210 THEOLIZER_INTERNAL_ABORT("getPrimitiveName() : iVersionNo is illegal.");\ 215 #define THEOLIZER_INTERNAL_STRING(dBytes, dName1) \ 216 template<class tMidSerializer, typename tPrimitive> \ 217 struct PrimitiveName \ 223 (std::is_same<tMidSerializer, XmlMidOSerializer>::value \ 224 || std::is_same<tMidSerializer, XmlMidISerializer>::value) \ 225 && (IsString<tPrimitive>::value) \ 226 && (sizeof(typename tPrimitive::value_type) == dBytes) \ 230 static char const* getPrimitiveName(unsigned iSerializerVersionNo) \ 232 switch(iSerializerVersionNo) \ 234 case 1: return dName1; \ 236 THEOLIZER_INTERNAL_ABORT("getPrimitiveName() : iVersionNo is illegal.");\ 241 THEOLIZER_INTERNAL_INTEGRAL(0, 1, THEOLIZER_INTERNAL_XML_NAMESPACE
":bool");
243 THEOLIZER_INTERNAL_INTEGRAL(1, 7, THEOLIZER_INTERNAL_XML_NAMESPACE
":int8");
244 THEOLIZER_INTERNAL_INTEGRAL(1, 15, THEOLIZER_INTERNAL_XML_NAMESPACE
":int16");
245 THEOLIZER_INTERNAL_INTEGRAL(1, 31, THEOLIZER_INTERNAL_XML_NAMESPACE
":int32");
246 THEOLIZER_INTERNAL_INTEGRAL(1, 63, THEOLIZER_INTERNAL_XML_NAMESPACE
":int64");
248 THEOLIZER_INTERNAL_INTEGRAL(0, 8, THEOLIZER_INTERNAL_XML_NAMESPACE
":unit8");
249 THEOLIZER_INTERNAL_INTEGRAL(0, 16, THEOLIZER_INTERNAL_XML_NAMESPACE
":uint16");
250 THEOLIZER_INTERNAL_INTEGRAL(0, 32, THEOLIZER_INTERNAL_XML_NAMESPACE
":uint32");
251 THEOLIZER_INTERNAL_INTEGRAL(0, 64, THEOLIZER_INTERNAL_XML_NAMESPACE
":uint64");
253 THEOLIZER_INTERNAL_FLOAT(24, 128, THEOLIZER_INTERNAL_XML_NAMESPACE
":float32");
254 THEOLIZER_INTERNAL_FLOAT(53, 1024, THEOLIZER_INTERNAL_XML_NAMESPACE
":float64");
255 THEOLIZER_INTERNAL_FLOAT(64, 16384, THEOLIZER_INTERNAL_XML_NAMESPACE
":float80");
257 THEOLIZER_INTERNAL_STRING(1, THEOLIZER_INTERNAL_XML_NAMESPACE
":string");
258 THEOLIZER_INTERNAL_STRING(2, THEOLIZER_INTERNAL_XML_NAMESPACE
":string");
259 THEOLIZER_INTERNAL_STRING(4, THEOLIZER_INTERNAL_XML_NAMESPACE
":string");
261 #undef THEOLIZER_INTERNAL_INTEGRAL 262 #undef THEOLIZER_INTERNAL_FLOAT 263 #undef THEOLIZER_INTERNAL_STRING 269 #ifdef THEOLIZER_INTERNAL_ENABLE_META_SERIALIZER 270 THEOLIZER_INTERNAL_DLL
271 char const* getCppNameXml(std::string
const& iPrimitiveName,
unsigned iSerializerVersionNo);
272 #endif // THEOLIZER_INTERNAL_ENABLE_META_SERIALIZER 286 #endif // THEOLIZER_INTERNAL_DOXYGEN 298 THEOLIZER_INTERNAL_FRIENDS_FOR_INTERNAL;
304 std::ostream& mOStream;
307 static const unsigned kLastVersionNo=kXmlSerializerVersionNo;
314 bool mCharIsMultiByte;
315 static char const*
const kSerializerName;
316 static std::ios_base::openmode kOpenMode;
320 std::ostream& iOStream,
321 Destinations
const& iDestinations,
322 GlobalVersionNoTableBase
const*
const iGlobalVersionNoTable,
323 unsigned iGlobalVersionNo,
324 unsigned iLastGlobalVersionNo,
326 bool iNoThrowException
346 void saveObjectId(std::size_t iObjectId, std::size_t iTypeIndex);
348 void saveControl(
int) {}
349 void saveControl(
long) {}
350 void saveControl(
long long) {}
351 void saveControl(
unsigned) {}
352 void saveControl(
unsigned long) {}
353 void saveControl(
unsigned long long) {}
354 void saveControl(std::string
const&) {}
358 class AutoReleaseTagName
361 std::string mTagName;
363 AutoReleaseTagName(
XmlMidOSerializer& iXmlMidOSerializer, std::size_t iTypeIndex);
364 ~AutoReleaseTagName();
369 #define THEOLIZER_INTERNAL_DEF_SAVE 370 #include "internal/primitive.inc" 374 void writePreElement(
bool) { };
387 std::string
const& iName,
388 Attribute
const* iAttribute=
nullptr 393 void saveGroupStart(
bool) { }
394 void saveGroupEnd(
bool) { }
398 void saveStructureStart(Structure iStructure, std::string& ioTypeName, std::size_t iOjbectId);
399 void saveStructureEnd(Structure iStructure, std::string
const& iTypeName);
403 template<
typename tType>
404 static char const* getPrimitiveName(
unsigned iSerializerVersionNo)
406 static_assert(Ignore<tType>::kFalse,
"Unknown primitive name.");
413 char const* mElementName;
414 void saveElementName(ElementsMapping iElementsMapping,
char const* iElementName)
416 if (iElementsMapping == emName)
418 mElementName = iElementName;
428 void encodeXmlString(std::string
const& iString);
432 #ifdef THEOLIZER_INTERNAL_ENABLE_META_SERIALIZER 433 static char const* getCppName(std::string
const& iPrimitiveName,
unsigned iSerializerVersionNo)
435 return getCppNameXml(iPrimitiveName, iSerializerVersionNo);
437 #endif // THEOLIZER_INTERNAL_ENABLE_META_SERIALIZER 439 #ifndef THEOLIZER_INTERNAL_DOXYGEN 445 #define THEOLIZER_INTERNAL_DEF_PRIMITIVE(dType, dSymbol) \ 447 inline char const* XmlMidOSerializer:: \ 448 getPrimitiveName<dType>(unsigned iSerializerVersionNo) \ 450 return PrimitiveName<XmlMidOSerializer, dType>::getPrimitiveName(iSerializerVersionNo);\ 452 #include "internal/primitive.inc" 454 #endif // THEOLIZER_INTERNAL_DOXYGEN 466 THEOLIZER_INTERNAL_FRIENDS_FOR_INTERNAL;
472 std::istream& mIStream;
475 static const unsigned kLastVersionNo=kXmlSerializerVersionNo;
482 bool mCharIsMultiByte;
483 static char const*
const kSerializerName;
484 static std::ios_base::openmode kOpenMode;
488 std::istream& iIStream,
489 Destinations
const& iDestinations,
490 GlobalVersionNoTableBase
const*
const iGlobalVersionNoTable,
491 unsigned iLastGlobalVersionNo,
492 std::ostream* iOStream,
493 bool iNoThrowException
509 bool isMatchTypeIndex(
size_t iSerializedTypeIndex,
510 size_t iProgramTypeIndex);
520 void loadObjectId(std::size_t& oObjectId, std::size_t iTypeIndex);
522 void loadControl(
int&) {}
523 void loadControl(
long&) {}
524 void loadControl(
long long&) {}
525 void loadControl(
unsigned&) {}
526 void loadControl(
unsigned long&) {}
527 void loadControl(
unsigned long long&) {}
528 void loadControl(std::string&) {}
532 class AutoReleaseTagName
535 std::string mTagName;
537 AutoReleaseTagName(
XmlMidISerializer& iXmlMidISerializer, std::size_t iTypeIndex);
538 ~AutoReleaseTagName();
543 #define THEOLIZER_INTERNAL_DEF_LOAD 544 #include "internal/primitive.inc" 553 ReadStat readPreElement(
bool iDoProcess=
false);
557 void disposeElement();
568 char const* loadTag(TagKind iTagKind, std::string
const& iName, Attribute* iAttribute=
nullptr);
575 std::string mTagName;
576 std::string mTypeName;
577 std::string mMemberName;
578 Attribute mAttribute;
579 TagInfo() : mValid(
false), mTagKind(TagKind::Start) { }
587 void loadGroupStart(
bool iIsTop=
false);
588 void loadGroupEnd(
bool iIsTop=
false);
592 void loadStructureStart(Structure iStructure, std::string& ioTypeName, std::size_t* oObjectId);
593 void loadStructureEnd(Structure iStructure, std::string
const& iTypeName);
594 void loadTypeName(std::string& oTypeName);
598 template<
typename tType>
599 static char const* getPrimitiveName(
unsigned iSerializerVersionNo)
601 static_assert(Ignore<tType>::kFalse,
"Unknown primitive name.");
616 std::string loadElementName(ElementsMapping iElementsMapping);
620 void decodeXmlString(std::string& iString);
630 char find_not_of(std::string
const& iSkipChars);
634 #ifdef THEOLIZER_INTERNAL_ENABLE_META_SERIALIZER 635 static char const* getCppName(std::string
const& iPrimitiveName,
unsigned iSerializerVersionNo)
637 return getCppNameXml(iPrimitiveName, iSerializerVersionNo);
639 #endif // THEOLIZER_INTERNAL_ENABLE_META_SERIALIZER 641 #ifndef THEOLIZER_INTERNAL_DOXYGEN 647 #define THEOLIZER_INTERNAL_DEF_PRIMITIVE(dType, dSymbol) \ 649 inline char const* XmlMidISerializer:: \ 650 getPrimitiveName<dType>(unsigned iSerializerVersionNo) \ 652 return PrimitiveName<XmlMidISerializer, dType>::getPrimitiveName(iSerializerVersionNo);\ 654 #include "internal/primitive.inc" 656 #endif // THEOLIZER_INTERNAL_DOXYGEN 679 THEOLIZER_INTERNAL_FRIENDS;
680 void AbstructSerializer() { }
682 static internal::Destinations
const& getDestinations()
684 static const internal::Destinations destinations{uDefault, uDestinations...};
694 constexpr
static internal::GlobalVersionNoTableBase
const*
const*
const 695 kPtrGlobalVersionNoTable=&internal::sGlobalVersionNoTable;
701 using MidSerializer::kSerializerName;
702 using BaseSerializer::mIsSaver;
706 using MidSerializer::kOpenMode;
708 #ifndef THEOLIZER_INTERNAL_DOXYGEN 709 static const bool kHasDestination=
true;
710 #endif // THEOLIZER_INTERNAL_DOXYGEN 715 std::ostream& iOStream,
716 unsigned iGlobalVersionNo=kLastGlobalVersionNo,
717 bool iNoPrettyPrint=
false,
718 bool iNoThrowException=
false 719 ) : XmlMidOSerializer
723 internal::sGlobalVersionNoTable,
725 kLastGlobalVersionNo,
734 std::ostream& iOStream,
736 bool iNoThrowException=
false 737 ) : XmlMidOSerializer
741 internal::sGlobalVersionNoTable,
742 kLastGlobalVersionNo,
743 kLastGlobalVersionNo,
752 return internal::hasPropertyXml(iProperty,
true);
758 mCharIsMultiByte=iCharIsMultiByte;
763 using BaseSerializer::getRequireClearTracking;
770 #ifndef THEOLIZER_INTERNAL_DOXYGEN 773 #endif // THEOLIZER_INTERNAL_DOXYGEN 784 THEOLIZER_INTERNAL_FRIENDS;
785 void AbstructSerializer() { }
787 static internal::Destinations
const& getDestinations()
789 static const internal::Destinations destinations{uDefault, uDestinations...};
794 constexpr
static internal::GlobalVersionNoTableBase
const*
const*
const 795 kPtrGlobalVersionNoTable=&internal::sGlobalVersionNoTable;
801 using MidSerializer::kSerializerName;
802 using BaseSerializer::mIsSaver;
806 using MidSerializer::kOpenMode;
808 #ifndef THEOLIZER_INTERNAL_DOXYGEN 809 static const bool kHasDestination=
true;
810 #endif // THEOLIZER_INTERNAL_DOXYGEN 815 std::istream& iIStream,
816 bool iNoThrowException=
false 817 ) : XmlMidISerializer
821 internal::sGlobalVersionNoTable,
822 kLastGlobalVersionNo,
831 return internal::hasPropertyXml(iProperty,
false);
837 mCharIsMultiByte=iCharIsMultiByte;
842 using BaseSerializer::getRequireClearTracking;
848 #ifndef THEOLIZER_INTERNAL_DOXYGEN 858 std::istream& iIStream,
859 std::ostream& iOStream,
860 bool iNoThrowException=
false 861 ) : XmlMidISerializer
865 internal::sGlobalVersionNoTable,
866 kLastGlobalVersionNo,
871 #endif // THEOLIZER_INTERNAL_DOXYGEN 874 #ifndef THEOLIZER_INTERNAL_DOXYGEN 877 #endif // THEOLIZER_INTERNAL_DOXYGEN 893 #endif // THEOLIZER_INTERNAL_SERIALIZER_XML_H static bool hasProperty(Property iProperty)
XmlOSerializerのプロパティ返却(3-1-3.プロパティ 参照)
ErrorInfo const & getErrorInfo() const
エラー情報返却(3-1-2.メンバ関数 参照)
unsigned getGlobalVersionNo() const
処理中のグローバル・バージョン番号返却(3-1-2.メンバ関数 参照)
void setCharIsMultiByte(bool iCharIsMultiByte)
std::stringをマルチ・パイト文字コードとして処理することを指定する
void clearTracking()
オブジェクト追跡の区切り(3-1-2.メンバ関数 参照)
bool isError()
エラー発生ならtrue(3-1-2.メンバ関数 参照)
Destination
保存先シンボルを定義するscoped enum型
THEOLIZER_INTERNAL_DLL std::ostream & operator<<(std::ostream &iOStream, CheckMode iCheckMode)
CheckModeの表示用オーバーロード
void setCharIsMultiByte(bool iCharIsMultiByte)
std::stringをマルチ・パイト文字コードとして処理するかどうか指定する
static bool hasProperty(Property iProperty)
XmlISerializerのプロパティ返却(3-1-3.プロパティ 参照)
Property
シリアライザが提供する機能(プロパティ)のリスト
CheckMode getCheckMode()
現在のCheckMode返却(3-1-2.メンバ関数 参照)