37 #if !defined(THEOLIZER_INTERNAL_SERIALIZER_JSON_H) 38 #define THEOLIZER_INTERNAL_SERIALIZER_JSON_H 52 #pragma warning(disable:4251 4702) 74 #ifndef THEOLIZER_INTERNAL_DOXYGEN 76 const static char kJsonSerializerName[]=
"JsonTheolizer";
77 const static unsigned kJsonSerializerVersionNo=1;
84 inline bool hasPropertyJson(
Property iProperty,
bool iIsSaver)
89 case Property::IsSaver:
93 case Property::EncodedString:
97 case Property::SupportModifying:
101 case Property::BinaryOpen:
113 class JsonMidOSerializer;
114 class JsonMidISerializer;
116 #define THEOLIZER_INTERNAL_INTEGRAL(dSigned, dDigits, dName1) \ 117 template<class tMidSerializer, typename tPrimitive> \ 118 struct PrimitiveName \ 124 (std::is_same<tMidSerializer, JsonMidOSerializer>::value \ 125 || std::is_same<tMidSerializer, JsonMidISerializer>::value) \ 126 && (std::numeric_limits<tPrimitive>::is_signed == dSigned) \ 127 && (std::numeric_limits<tPrimitive>::radix == 2) \ 128 && (std::numeric_limits<tPrimitive>::digits == dDigits) \ 129 && (std::numeric_limits<tPrimitive>::max_exponent == 0) \ 133 static char const* getPrimitiveName(unsigned iSerializerVersionNo) \ 135 switch(iSerializerVersionNo) \ 137 case 1: return dName1; \ 139 THEOLIZER_INTERNAL_ABORT("getPrimitiveName() : iVersionNo is illegal.");\ 144 #define THEOLIZER_INTERNAL_FLOAT(dDigits, dMaxExponent, dName1) \ 145 template<class tMidSerializer, typename tPrimitive> \ 146 struct PrimitiveName \ 152 (std::is_same<tMidSerializer, JsonMidOSerializer>::value \ 153 || std::is_same<tMidSerializer, JsonMidISerializer>::value) \ 154 && (std::numeric_limits<tPrimitive>::is_signed == 1) \ 155 && (std::numeric_limits<tPrimitive>::radix == 2) \ 156 && (std::numeric_limits<tPrimitive>::digits == dDigits) \ 157 && (std::numeric_limits<tPrimitive>::max_exponent == dMaxExponent)\ 161 static char const* getPrimitiveName(unsigned iSerializerVersionNo) \ 163 switch(iSerializerVersionNo) \ 165 case 1: return dName1; \ 167 THEOLIZER_INTERNAL_ABORT("getPrimitiveName() : iVersionNo is illegal.");\ 172 #define THEOLIZER_INTERNAL_STRING(dBytes, dName1) \ 173 template<class tMidSerializer, typename tPrimitive> \ 174 struct PrimitiveName \ 180 (std::is_same<tMidSerializer, JsonMidOSerializer>::value \ 181 || std::is_same<tMidSerializer, JsonMidISerializer>::value) \ 182 && (IsString<tPrimitive>::value) \ 183 && (sizeof(typename tPrimitive::value_type) == dBytes) \ 187 static char const* getPrimitiveName(unsigned iSerializerVersionNo) \ 189 switch(iSerializerVersionNo) \ 191 case 1: return dName1; \ 193 THEOLIZER_INTERNAL_ABORT("getPrimitiveName() : iVersionNo is illegal.");\ 198 THEOLIZER_INTERNAL_INTEGRAL(0, 1,
"bool");
200 THEOLIZER_INTERNAL_INTEGRAL(1, 7,
"int8");
201 THEOLIZER_INTERNAL_INTEGRAL(1, 15,
"int16");
202 THEOLIZER_INTERNAL_INTEGRAL(1, 31,
"int32");
203 THEOLIZER_INTERNAL_INTEGRAL(1, 63,
"int64");
205 THEOLIZER_INTERNAL_INTEGRAL(0, 8,
"unit8");
206 THEOLIZER_INTERNAL_INTEGRAL(0, 16,
"uint16");
207 THEOLIZER_INTERNAL_INTEGRAL(0, 32,
"uint32");
208 THEOLIZER_INTERNAL_INTEGRAL(0, 64,
"uint64");
210 THEOLIZER_INTERNAL_FLOAT(24, 128,
"float32");
211 THEOLIZER_INTERNAL_FLOAT(53, 1024,
"float64");
212 THEOLIZER_INTERNAL_FLOAT(64, 16384,
"float80");
214 THEOLIZER_INTERNAL_STRING(1,
"string");
215 THEOLIZER_INTERNAL_STRING(2,
"string");
216 THEOLIZER_INTERNAL_STRING(4,
"string");
218 #undef THEOLIZER_INTERNAL_INTEGRAL 219 #undef THEOLIZER_INTERNAL_FLOAT 220 #undef THEOLIZER_INTERNAL_STRING 226 #ifdef THEOLIZER_INTERNAL_ENABLE_META_SERIALIZER 227 THEOLIZER_INTERNAL_DLL
228 char const* getCppNameJson(std::string
const& iPrimitiveName,
unsigned iSerializerVersionNo);
229 #endif // THEOLIZER_INTERNAL_ENABLE_META_SERIALIZER 243 #endif // THEOLIZER_INTERNAL_DOXYGEN 255 THEOLIZER_INTERNAL_FRIENDS_FOR_INTERNAL;
261 std::ostream& mOStream;
265 static const unsigned kLastVersionNo=kJsonSerializerVersionNo;
272 bool mCharIsMultiByte;
273 static char const*
const kSerializerName;
274 static std::ios_base::openmode kOpenMode;
278 std::ostream& iOStream,
279 Destinations
const& iDestinations,
280 GlobalVersionNoTableBase
const*
const iGlobalVersionNoTable,
281 unsigned iGlobalVersionNo,
282 unsigned iLastGlobalVersionNo,
285 bool iNoThrowException
304 void saveControl(
int iControl) {savePrimitive(iControl);}
305 void saveControl(
long iControl) {savePrimitive(iControl);}
306 void saveControl(
long long iControl) {savePrimitive(iControl);}
307 void saveControl(
unsigned iControl) {savePrimitive(iControl);}
308 void saveControl(
unsigned long iControl) {savePrimitive(iControl);}
309 void saveControl(
unsigned long long iControl) {savePrimitive(iControl);}
310 void saveControl(std::string
const& iControl) {encodeJsonString(iControl);}
314 #define THEOLIZER_INTERNAL_DEF_SAVE 315 #include "internal/primitive.inc" 319 void writePreElement(
bool iDoProcess=
false);
329 void saveGroupStart(
bool iIsTop=
false);
330 void saveGroupEnd(
bool iIsTop=
false);
334 void saveStructureStart(Structure iStructure, std::string& ioTypeName, std::size_t iOjbectId);
335 void saveStructureEnd(Structure iStructure, std::string
const& iTypeName);
339 template<
typename tType>
340 static char const* getPrimitiveName(
unsigned iSerializerVersionNo)
342 static_assert(Ignore<tType>::kFalse,
"Unknown primitive name.");
349 void saveElementName(ElementsMapping iElementsMapping,
char const* iElementName)
351 if (iElementsMapping == emName)
353 encodeJsonString(iElementName);
360 void writeCommaIndent(
bool iWriteComma=
false);
364 void encodeJsonString(std::string
const& iString);
368 #ifdef THEOLIZER_INTERNAL_ENABLE_META_SERIALIZER 369 static char const* getCppName(std::string
const& iPrimitiveName,
unsigned iSerializerVersionNo)
371 return getCppNameJson(iPrimitiveName, iSerializerVersionNo);
373 #endif // THEOLIZER_INTERNAL_ENABLE_META_SERIALIZER 375 #ifndef THEOLIZER_INTERNAL_DOXYGEN 381 #define THEOLIZER_INTERNAL_DEF_PRIMITIVE(dType, dSymbol) \ 383 inline char const* JsonMidOSerializer:: \ 384 getPrimitiveName<dType>(unsigned iSerializerVersionNo) \ 386 return PrimitiveName<JsonMidOSerializer, dType>::getPrimitiveName(iSerializerVersionNo);\ 388 #include "internal/primitive.inc" 390 #endif // THEOLIZER_INTERNAL_DOXYGEN 402 THEOLIZER_INTERNAL_FRIENDS_FOR_INTERNAL;
408 std::istream& mIStream;
412 static const unsigned kLastVersionNo=kJsonSerializerVersionNo;
419 bool mCharIsMultiByte;
420 static char const*
const kSerializerName;
421 static std::ios_base::openmode kOpenMode;
425 std::istream& iIStream,
426 Destinations
const& iDestinations,
427 GlobalVersionNoTableBase
const*
const iGlobalVersionNoTable,
428 unsigned iLastGlobalVersionNo,
429 std::ostream* iOStream,
430 bool iNoThrowException
445 bool isMatchTypeIndex(
size_t iSerializedTypeIndex,
446 size_t iProgramTypeIndex);
456 void loadControl(
int& oControl) {loadPrimitive(oControl);}
457 void loadControl(
long& oControl) {loadPrimitive(oControl);}
458 void loadControl(
long long& oControl) {loadPrimitive(oControl);}
459 void loadControl(
unsigned& oControl) {loadPrimitive(oControl);}
460 void loadControl(
unsigned long& oControl) {loadPrimitive(oControl);}
461 void loadControl(
unsigned long long& oControl) {loadPrimitive(oControl);}
462 void loadControl(std::string& oControl) {decodeJsonString(oControl);}
466 #define THEOLIZER_INTERNAL_DEF_LOAD 467 #include "internal/primitive.inc" 475 ReadStat readPreElement(
bool iDoProcess=
false);
479 void disposeElement();
491 void loadGroupStart(
bool iIsTop=
false);
492 void loadGroupEnd(
bool iIsTop=
false);
496 void loadStructureStart(Structure iStructure, std::string& ioTypeName, std::size_t* oObjectId);
497 void loadStructureEnd(Structure iStructure, std::string
const& iTypeName);
501 template<
typename tType>
502 static char const* getPrimitiveName(
unsigned iSerializerVersionNo)
504 static_assert(Ignore<tType>::kFalse,
"Unknown primitive name.");
519 std::string loadElementName(ElementsMapping iElementsMapping);
527 bool readComma(
bool iReadComma=
false);
532 bool checkTerminal(
char iIn);
536 void decodeJsonString(std::string& iString);
546 char find_not_of(std::string
const& iSkipChars);
550 #ifdef THEOLIZER_INTERNAL_ENABLE_META_SERIALIZER 551 static char const* getCppName(std::string
const& iPrimitiveName,
unsigned iSerializerVersionNo)
553 return getCppNameJson(iPrimitiveName, iSerializerVersionNo);
555 #endif // THEOLIZER_INTERNAL_ENABLE_META_SERIALIZER 557 #ifndef THEOLIZER_INTERNAL_DOXYGEN 563 #define THEOLIZER_INTERNAL_DEF_PRIMITIVE(dType, dSymbol) \ 565 inline char const* JsonMidISerializer:: \ 566 getPrimitiveName<dType>(unsigned iSerializerVersionNo) \ 568 return PrimitiveName<JsonMidISerializer, dType>::getPrimitiveName(iSerializerVersionNo);\ 570 #include "internal/primitive.inc" 572 #endif // THEOLIZER_INTERNAL_DOXYGEN 595 THEOLIZER_INTERNAL_FRIENDS;
596 void AbstructSerializer() { }
598 static internal::Destinations
const& getDestinations()
600 static const internal::Destinations destinations{uDefault, uDestinations...};
610 constexpr
static internal::GlobalVersionNoTableBase
const*
const*
const 611 kPtrGlobalVersionNoTable=&internal::sGlobalVersionNoTable;
617 using MidSerializer::kSerializerName;
618 using BaseSerializer::mIsSaver;
622 using MidSerializer::kOpenMode;
624 #ifndef THEOLIZER_INTERNAL_DOXYGEN 625 static const bool kHasDestination=
true;
626 #endif // THEOLIZER_INTERNAL_DOXYGEN 631 std::ostream& iOStream,
632 unsigned iGlobalVersionNo=kLastGlobalVersionNo,
634 bool iNoPrettyPrint=
false,
635 bool iNoThrowException=
false 636 ) : JsonMidOSerializer
640 internal::sGlobalVersionNoTable,
642 kLastGlobalVersionNo,
652 std::ostream& iOStream,
654 bool iNoPrettyPrint=
false,
655 bool iNoThrowException=
false 656 ) : JsonMidOSerializer
660 internal::sGlobalVersionNoTable,
661 kLastGlobalVersionNo,
662 kLastGlobalVersionNo,
672 return internal::hasPropertyJson(iProperty,
true);
678 mCharIsMultiByte=iCharIsMultiByte;
683 using BaseSerializer::getRequireClearTracking;
690 #ifndef THEOLIZER_INTERNAL_DOXYGEN 693 #endif // THEOLIZER_INTERNAL_DOXYGEN 704 THEOLIZER_INTERNAL_FRIENDS;
705 void AbstructSerializer() { }
707 static internal::Destinations
const& getDestinations()
709 static const internal::Destinations destinations{uDefault, uDestinations...};
714 constexpr
static internal::GlobalVersionNoTableBase
const*
const*
const 715 kPtrGlobalVersionNoTable=&internal::sGlobalVersionNoTable;
721 using MidSerializer::kSerializerName;
722 using BaseSerializer::mIsSaver;
726 using MidSerializer::kOpenMode;
728 #ifndef THEOLIZER_INTERNAL_DOXYGEN 729 static const bool kHasDestination=
true;
730 #endif // THEOLIZER_INTERNAL_DOXYGEN 735 std::istream& iIStream,
736 bool iNoThrowException=
false 737 ) : JsonMidISerializer
741 internal::sGlobalVersionNoTable,
742 kLastGlobalVersionNo,
751 return internal::hasPropertyJson(iProperty,
false);
757 mCharIsMultiByte=iCharIsMultiByte;
762 using BaseSerializer::getRequireClearTracking;
768 #ifndef THEOLIZER_INTERNAL_DOXYGEN 778 std::istream& iIStream,
779 std::ostream& iOStream,
780 bool iNoThrowException=
false 781 ) : JsonMidISerializer
785 internal::sGlobalVersionNoTable,
786 kLastGlobalVersionNo,
791 #endif // THEOLIZER_INTERNAL_DOXYGEN 794 #ifndef THEOLIZER_INTERNAL_DOXYGEN 797 #endif // THEOLIZER_INTERNAL_DOXYGEN 813 #endif // THEOLIZER_INTERNAL_SERIALIZER_JSON_H
ErrorInfo const & getErrorInfo() const
エラー情報返却(3-1-2.メンバ関数 参照)
unsigned getGlobalVersionNo() const
処理中のグローバル・バージョン番号返却(3-1-2.メンバ関数 参照)
void clearTracking()
オブジェクト追跡の区切り(3-1-2.メンバ関数 参照)
static bool hasProperty(Property iProperty)
JsonOSerializerのプロパティ返却(3-1-3.プロパティ 参照)
void setCharIsMultiByte(bool iCharIsMultiByte)
std::stringをマルチ・パイト文字コードとして処理するかどうか指定する
bool isError()
エラー発生ならtrue(3-1-2.メンバ関数 参照)
Destination
保存先シンボルを定義するscoped enum型
void setCharIsMultiByte(bool iCharIsMultiByte)
std::stringをマルチ・パイト文字コードとして処理することを指定する
static bool hasProperty(Property iProperty)
JsonISerializerのプロパティ返却(3-1-3.プロパティ 参照)
Property
シリアライザが提供する機能(プロパティ)のリスト
CheckMode getCheckMode()
現在のCheckMode返却(3-1-2.メンバ関数 参照)