31 #if !defined(THEOLIZER_INTERNAL_SERIALIZER_BINARY_H) 32 #define THEOLIZER_INTERNAL_SERIALIZER_BINARY_H 46 #pragma warning(disable:4100 4251 4702) 58 #ifndef THEOLIZER_INTERNAL_DOXYGEN 67 enum TagCode : uint8_t
95 ClassStartName = 0x50,
96 ClassStartOrder = 0x60
102 TagCode getByteSize(TagCode iTagKind,
unsigned iSize)
106 case 0:
return static_cast<TagCode
>(iTagKind | 0);
107 case 1:
return static_cast<TagCode
>(iTagKind | 1);
108 case 2:
return static_cast<TagCode
>(iTagKind | 2);
109 case 4:
return static_cast<TagCode
>(iTagKind | 3);
110 case 8:
return static_cast<TagCode
>(iTagKind | 4);
111 case 10:
return static_cast<TagCode
>(iTagKind | 5);
113 THEOLIZER_INTERNAL_ABORT(u8
"Illegal size in BinaryTag::getByteSize().");
117 BinaryTag() : mTagCode(
None) { }
118 BinaryTag(TagCode iTagCode) : mTagCode(iTagCode) { }
119 BinaryTag(TagCode iTagKind,
unsigned iSize) :
120 mTagCode(getByteSize(iTagKind, iSize))
123 BinaryTag(uint8_t iByte) : mTagCode(static_cast<TagCode>(iByte)) { }
124 operator TagCode()
const {
return mTagCode;}
125 operator uint8_t()
const {
return mTagCode;}
126 unsigned get()
const {
return mTagCode;}
127 BinaryTag& operator=(uint8_t iByte)
129 mTagCode=
static_cast<TagCode
>(iByte);
133 bool isPrimitive()
const 135 return ((mTagCode&KindMask)==Primitive)||(mTagCode&KindMask)==MinusValue;
137 bool isMinusValue()
const {
return (mTagCode&KindMask) == MinusValue;}
138 bool isByteString()
const {
return (mTagCode&KindMask) == ByteString;}
139 bool isClassEnd()
const {
return (mTagCode == ClassEnd);}
140 bool isClassStart()
const {
return (mTagCode==ClassStartName)||(mTagCode==ClassStartOrder);}
141 bool isClassStartName()
const {
return (mTagCode==ClassStartName);}
142 bool isClassStartOrder()
const {
return (mTagCode==ClassStartOrder);}
143 bool isTagCode(TagCode iTagCode)
const {
return (mTagCode == iTagCode);}
145 TagCode getKind()
const 147 return static_cast<TagCode
>(mTagCode & KindMask);
150 unsigned getSize()
const 152 switch(mTagCode & SizeMask)
161 THEOLIZER_INTERNAL_DATA_ERROR(u8
"Illegal BinaryTag size(TagCode=0x%02x).",
get());
178 const static char kBinarySerializerName[]=
"BinaryTheolizer";
179 const static unsigned kBinarySerializerVersionNo=1;
186 inline bool hasPropertyBinary(
Property iProperty,
bool iIsSaver)
191 case Property::IsSaver:
195 case Property::EncodedString:
199 case Property::SupportModifying:
203 case Property::BinaryOpen:
215 class BinaryMidOSerializer;
216 class BinaryMidISerializer;
218 #define THEOLIZER_INTERNAL_INTEGRAL(dSigned, dDigits, dName1) \ 219 template<class tMidSerializer, typename tPrimitive> \ 220 struct PrimitiveName \ 226 (std::is_same<tMidSerializer, BinaryMidOSerializer>::value \ 227 || std::is_same<tMidSerializer, BinaryMidISerializer>::value) \ 228 && (std::numeric_limits<tPrimitive>::is_signed == dSigned) \ 229 && (std::numeric_limits<tPrimitive>::radix == 2) \ 230 && (std::numeric_limits<tPrimitive>::digits == dDigits) \ 231 && (std::numeric_limits<tPrimitive>::max_exponent == 0) \ 235 static char const* getPrimitiveName(unsigned iSerializerVersionNo) \ 237 switch(iSerializerVersionNo) \ 239 case 1: return dName1; \ 241 THEOLIZER_INTERNAL_ABORT("getPrimitiveName() : iVersionNo is illegal.");\ 246 #define THEOLIZER_INTERNAL_FLOAT(dDigits, dMaxExponent, dName1) \ 247 template<class tMidSerializer, typename tPrimitive> \ 248 struct PrimitiveName \ 254 (std::is_same<tMidSerializer, BinaryMidOSerializer>::value \ 255 || std::is_same<tMidSerializer, BinaryMidISerializer>::value) \ 256 && (std::numeric_limits<tPrimitive>::is_signed == 1) \ 257 && (std::numeric_limits<tPrimitive>::radix == 2) \ 258 && (std::numeric_limits<tPrimitive>::digits == dDigits) \ 259 && (std::numeric_limits<tPrimitive>::max_exponent == dMaxExponent)\ 263 static char const* getPrimitiveName(unsigned iSerializerVersionNo) \ 265 switch(iSerializerVersionNo) \ 267 case 1: return dName1; \ 269 THEOLIZER_INTERNAL_ABORT("getPrimitiveName() : iVersionNo is illegal.");\ 274 #define THEOLIZER_INTERNAL_STRING(dBytes, dName1) \ 275 template<class tMidSerializer, typename tPrimitive> \ 276 struct PrimitiveName \ 282 (std::is_same<tMidSerializer, BinaryMidOSerializer>::value \ 283 || std::is_same<tMidSerializer, BinaryMidISerializer>::value) \ 284 && (IsString<tPrimitive>::value) \ 285 && (sizeof(typename tPrimitive::value_type) == dBytes) \ 289 static char const* getPrimitiveName(unsigned iSerializerVersionNo) \ 291 switch(iSerializerVersionNo) \ 293 case 1: return dName1; \ 295 THEOLIZER_INTERNAL_ABORT("getPrimitiveName() : iVersionNo is illegal.");\ 300 THEOLIZER_INTERNAL_INTEGRAL(0, 1,
"bool");
302 THEOLIZER_INTERNAL_INTEGRAL(1, 7,
"int8");
303 THEOLIZER_INTERNAL_INTEGRAL(1, 15,
"int16");
304 THEOLIZER_INTERNAL_INTEGRAL(1, 31,
"int32");
305 THEOLIZER_INTERNAL_INTEGRAL(1, 63,
"int64");
307 THEOLIZER_INTERNAL_INTEGRAL(0, 8,
"unit8");
308 THEOLIZER_INTERNAL_INTEGRAL(0, 16,
"uint16");
309 THEOLIZER_INTERNAL_INTEGRAL(0, 32,
"uint32");
310 THEOLIZER_INTERNAL_INTEGRAL(0, 64,
"uint64");
312 THEOLIZER_INTERNAL_FLOAT(24, 128,
"float32");
313 THEOLIZER_INTERNAL_FLOAT(53, 1024,
"float64");
314 THEOLIZER_INTERNAL_FLOAT(64, 16384,
"float80");
316 THEOLIZER_INTERNAL_STRING(1,
"String");
317 THEOLIZER_INTERNAL_STRING(2,
"U16string");
318 THEOLIZER_INTERNAL_STRING(4,
"U32string");
320 #undef THEOLIZER_INTERNAL_INTEGRAL 321 #undef THEOLIZER_INTERNAL_FLOAT 322 #undef THEOLIZER_INTERNAL_STRING 328 #ifdef THEOLIZER_INTERNAL_ENABLE_META_SERIALIZER 329 THEOLIZER_INTERNAL_DLL
330 char const* getCppNameBinary(std::string
const& iPrimitiveName,
unsigned iSerializerVersionNo);
331 #endif // THEOLIZER_INTERNAL_ENABLE_META_SERIALIZER 333 #endif // THEOLIZER_INTERNAL_DOXYGEN 357 THEOLIZER_INTERNAL_FRIENDS_FOR_INTERNAL;
363 std::ostream& mOStream;
365 static const unsigned kLastVersionNo=kBinarySerializerVersionNo;
372 static char const*
const kSerializerName;
373 static std::ios_base::openmode kOpenMode;
377 std::ostream& iOStream,
378 Destinations
const& iDestinations,
379 GlobalVersionNoTableBase
const*
const iGlobalVersionNoTable,
380 unsigned iGlobalVersionNo,
381 unsigned iLastGlobalVersionNo,
383 bool iNoThrowException
402 void saveSigned(
long long iControl);
405 unsigned long long iControl,
406 BinaryTag::TagCode iTagCode=BinaryTag::TagCode::Primitive
409 void saveControl(
int iControl) {saveSigned(iControl);}
410 void saveControl(
long iControl) {saveSigned(iControl);}
411 void saveControl(
long long iControl) {saveSigned(iControl);}
412 void saveControl(
unsigned iControl) {saveUnsigned(iControl);}
413 void saveControl(
unsigned long iControl) {saveUnsigned(iControl);}
414 void saveControl(
unsigned long long iControl) {saveUnsigned(iControl);}
415 void saveControl(std::string
const& iControl) {saveByteString(iControl);}
419 template<
typename tType>
420 void saveFloat(tType iFloat);
422 #define THEOLIZER_INTERNAL_DEF_SAVE 423 #include "internal/primitive.inc" 427 void saveByteString(std::string
const& iString);
431 void writePreElement(
bool iDoProcess=
false) { }
441 void saveGroupStart(
bool iIsTop=
false);
442 void saveGroupEnd(
bool iIsTop=
false);
446 void saveStructureStart(Structure iStructure, std::string& ioTypeName, std::size_t iOjbectId);
447 void saveStructureEnd(Structure iStructure, std::string
const& iTypeName);
451 template<
typename tType>
452 static char const* getPrimitiveName(
unsigned iSerializerVersionNo)
454 static_assert(Ignore<tType>::kFalse,
"Unknown primitive name.");
461 void saveElementName(ElementsMapping iElementsMapping,
char const* iElementName)
463 if (iElementsMapping == emName)
465 saveByteString(iElementName);
471 void writeByte(uint8_t iByte);
475 #ifdef THEOLIZER_INTERNAL_ENABLE_META_SERIALIZER 476 static char const* getCppName(std::string
const& iPrimitiveName,
unsigned iSerializerVersionNo)
478 return getCppNameBinary(iPrimitiveName, iSerializerVersionNo);
480 #endif // THEOLIZER_INTERNAL_ENABLE_META_SERIALIZER 482 #ifndef THEOLIZER_INTERNAL_DOXYGEN 488 #define THEOLIZER_INTERNAL_DEF_PRIMITIVE(dType, dSymbol) \ 490 inline char const* BinaryMidOSerializer:: \ 491 getPrimitiveName<dType>(unsigned iSerializerVersionNo) \ 493 return PrimitiveName<BinaryMidOSerializer, dType>::getPrimitiveName(iSerializerVersionNo);\ 495 #include "internal/primitive.inc" 497 #endif // THEOLIZER_INTERNAL_DOXYGEN 509 THEOLIZER_INTERNAL_FRIENDS_FOR_INTERNAL;
515 std::istream& mIStream;
517 BinaryTag mBinaryTag;
519 static const unsigned kLastVersionNo=kBinarySerializerVersionNo;
526 static char const*
const kSerializerName;
527 static std::ios_base::openmode kOpenMode;
531 std::istream& iIStream,
532 Destinations
const& iDestinations,
533 GlobalVersionNoTableBase
const*
const iGlobalVersionNoTable,
534 unsigned iLastGlobalVersionNo,
535 std::ostream* iOStream,
536 bool iNoThrowException
551 bool isMatchTypeIndex(
size_t iSerializedTypeIndex,
552 size_t iProgramTypeIndex);
560 long long loadSigned();
561 unsigned long long loadUnsigned(BinaryTag::TagCode iTagCode=BinaryTag::TagCode::Primitive);
563 void loadControl(
int& oControl) {oControl=
static_cast<int>(loadSigned());}
564 void loadControl(
long& oControl) {oControl=
static_cast<long>(loadSigned());}
565 void loadControl(
long long& oControl) {oControl=loadSigned();}
566 void loadControl(
unsigned& oControl) {oControl=
static_cast<unsigned>(loadSigned());}
567 void loadControl(
unsigned long& oControl) {oControl=
static_cast<unsigned long>(loadSigned());}
568 void loadControl(
unsigned long long& oControl) {oControl=loadSigned();}
569 void loadControl(std::string& oControl) {loadByteString(oControl);}
573 template<
typename tType>
574 void loadFloat(tType& oFloat);
576 #define THEOLIZER_INTERNAL_DEF_LOAD 577 #include "internal/primitive.inc" 581 void loadByteString(std::string& iString);
589 ReadStat readPreElement(
bool iDoProcess=
false);
593 void disposeElement();
605 void loadGroupStart(
bool iIsTop=
false);
606 void loadGroupEnd(
bool iIsTop=
false);
610 void loadStructureStart(Structure iStructure, std::string& ioTypeName, std::size_t* oObjectId);
611 void loadStructureEnd(Structure iStructure, std::string
const& iTypeName);
615 template<
typename tType>
616 static char const* getPrimitiveName(
unsigned iSerializerVersionNo)
618 static_assert(Ignore<tType>::kFalse,
"Unknown primitive name.");
633 std::string loadElementName(ElementsMapping iElementsMapping);
646 #ifdef THEOLIZER_INTERNAL_ENABLE_META_SERIALIZER 647 static char const* getCppName(std::string
const& iPrimitiveName,
unsigned iSerializerVersionNo)
649 return getCppNameBinary(iPrimitiveName, iSerializerVersionNo);
651 #endif // THEOLIZER_INTERNAL_ENABLE_META_SERIALIZER 653 #ifndef THEOLIZER_INTERNAL_DOXYGEN 659 #define THEOLIZER_INTERNAL_DEF_PRIMITIVE(dType, dSymbol) \ 661 inline char const* BinaryMidISerializer:: \ 662 getPrimitiveName<dType>(unsigned iSerializerVersionNo) \ 664 return PrimitiveName<BinaryMidISerializer, dType>::getPrimitiveName(iSerializerVersionNo);\ 666 #include "internal/primitive.inc" 668 #endif // THEOLIZER_INTERNAL_DOXYGEN 689 THEOLIZER_INTERNAL_FRIENDS;
691 void AbstructSerializer() { }
693 static internal::Destinations
const& getDestinations()
695 static const internal::Destinations destinations{uDefault, uDestinations...};
705 constexpr
static internal::GlobalVersionNoTableBase
const*
const*
const 706 kPtrGlobalVersionNoTable=&internal::sGlobalVersionNoTable;
712 using MidSerializer::kSerializerName;
713 using BaseSerializer::mIsSaver;
717 using MidSerializer::kOpenMode;
719 #ifndef THEOLIZER_INTERNAL_DOXYGEN 720 static const bool kHasDestination=
true;
721 #endif // THEOLIZER_INTERNAL_DOXYGEN 726 std::ostream& iOStream,
727 unsigned iGlobalVersionNo=kLastGlobalVersionNo,
729 bool iNoThrowException=
false 730 ) : BinaryMidOSerializer
734 internal::sGlobalVersionNoTable,
736 kLastGlobalVersionNo,
745 std::ostream& iOStream,
747 bool iNoThrowException=
false 748 ) : BinaryMidOSerializer
752 internal::sGlobalVersionNoTable,
753 kLastGlobalVersionNo,
754 kLastGlobalVersionNo,
763 return internal::hasPropertyBinary(iProperty,
true);
768 using BaseSerializer::getRequireClearTracking;
774 #ifndef THEOLIZER_INTERNAL_DOXYGEN 777 #endif // THEOLIZER_INTERNAL_DOXYGEN 786 THEOLIZER_INTERNAL_FRIENDS;
788 void AbstructSerializer() { }
790 static internal::Destinations
const& getDestinations()
792 static const internal::Destinations destinations{uDefault, uDestinations...};
797 constexpr
static internal::GlobalVersionNoTableBase
const*
const*
const 798 kPtrGlobalVersionNoTable=&internal::sGlobalVersionNoTable;
804 using MidSerializer::kSerializerName;
805 using BaseSerializer::mIsSaver;
809 using MidSerializer::kOpenMode;
811 #ifndef THEOLIZER_INTERNAL_DOXYGEN 812 static const bool kHasDestination=
true;
813 #endif // THEOLIZER_INTERNAL_DOXYGEN 818 std::istream& iIStream,
819 bool iNoThrowException=
false 820 ) : BinaryMidISerializer
824 internal::sGlobalVersionNoTable,
825 kLastGlobalVersionNo,
834 return internal::hasPropertyBinary(iProperty,
false);
840 using BaseSerializer::getRequireClearTracking;
846 #ifndef THEOLIZER_INTERNAL_DOXYGEN 856 std::istream& iIStream,
857 std::ostream& iOStream,
858 bool iNoThrowException=
false 859 ) : BinaryMidISerializer
863 internal::sGlobalVersionNoTable,
864 kLastGlobalVersionNo,
869 #endif // THEOLIZER_INTERNAL_DOXYGEN 872 #ifndef THEOLIZER_INTERNAL_DOXYGEN 875 #endif // THEOLIZER_INTERNAL_DOXYGEN 891 #endif // THEOLIZER_INTERNAL_SERIALIZER_BINARY_H
ErrorInfo const & getErrorInfo() const
エラー情報返却(3-1-2.メンバ関数 参照)
unsigned getGlobalVersionNo() const
処理中のグローバル・バージョン番号返却(3-1-2.メンバ関数 参照)
void clearTracking()
オブジェクト追跡の区切り(3-1-2.メンバ関数 参照)
static bool hasProperty(Property iProperty)
BinaryISerializerのプロパティ返却(3-1-3.プロパティ 参照)
static bool hasProperty(Property iProperty)
BinaryOSerializerのプロパティ返却(3-1-3.プロパティ 参照)
bool isError()
エラー発生ならtrue(3-1-2.メンバ関数 参照)
Destination
保存先シンボルを定義するscoped enum型
Property
シリアライザが提供する機能(プロパティ)のリスト
CheckMode getCheckMode()
現在のCheckMode返却(3-1-2.メンバ関数 参照)