37 #if !defined(THEOLIZER_INTERNAL_CORE_ASSORTED_H) 38 #define THEOLIZER_INTERNAL_CORE_ASSORTED_H 46 #include "../report.h" 58 #pragma warning(disable:4100 4251) 70 #ifndef THEOLIZER_INTERNAL_DOXYGEN 77 #define THEOLIZER_INTERNAL_VER_DEBUG(dStatements) THEOLIZER_INTERNAL_UNPAREN dStatements 79 #define THEOLIZER_INTERNAL_VER_DEBUG(dStatements) 88 #define THEOLIZER_INTERNAL_DISABLE_NULL_REFERENCE 96 #if !defined(THEOLIZER_NO_ANALYZE) && !defined(THEOLIZER_WRITE_CODE) 97 #define THEOLIZER_WRITE_CODE 100 #endif // THEOLIZER_INTERNAL_DOXYGEN 113 #define THEOLIZER_PROVIDED_BY(dVendor) 120 namespace theolizer{
namespace destination{ }}
132 #ifndef THEOLIZER_INTERNAL_DOXYGEN 144 template<
class tPolyRangeBase,
class tValueType>
147 tPolyRangeBase& mPolyRange;
149 PolyReferencer(tPolyRangeBase& iPolyRange) : mPolyRange(iPolyRange)
152 tValueType& operator*()
154 THEOLIZER_INTERNAL_ASSERT(mPolyRange.mHolder.get(), THEOLIZER_INTERNAL_BUG);
155 return mPolyRange.mHolder->front();
157 tValueType
const& operator*()
const 159 THEOLIZER_INTERNAL_ASSERT(mPolyRange.mHolder.get(), THEOLIZER_INTERNAL_BUG);
160 return mPolyRange.mHolder->front();
164 THEOLIZER_INTERNAL_ASSERT(mPolyRange.mHolder.get(), THEOLIZER_INTERNAL_BUG);
165 mPolyRange.mHolder->drop_front();
167 bool operator!=(PolyReferencer
const& iRhs)
const 169 if (!mPolyRange.mHolder.get())
171 return !mPolyRange.mHolder->empty();
179 template<
class tValueType>
187 virtual tValueType & front() = 0;
188 virtual tValueType
const& front()
const = 0;
189 virtual void drop_front() = 0;
190 virtual bool empty()
const = 0;
191 virtual std::size_t size() = 0;
195 virtual ~HolderBase() { }
200 template<
typename tIterator>
201 struct Holder :
public HolderBase
207 Holder(tIterator&& iBegin, tIterator&& iEnd, std::size_t iCount) :
208 mBegin(std::forward<tIterator>(iBegin)),
209 mEnd (std::forward<tIterator>(iEnd)),
218 tValueType
const& front()
const 229 return mBegin == mEnd;
239 template<
class,
class>
friend class PolyReferencer;
240 typedef PolyReferencer<PolyRange, tValueType> PolyReferencer_t;
244 std::unique_ptr<HolderBase> mHolder;
251 template<
typename tIterator>
252 PolyRange(tIterator&& iBegin, tIterator&& iEnd, std::size_t iCount) :
255 new Holder<tIterator>
257 std::forward<tIterator>(iBegin),
258 std::forward<tIterator>(iEnd),
264 PolyReferencer_t begin() {
return PolyReferencer_t(*
this);}
265 PolyReferencer_t end() {
return PolyReferencer_t(*
this);}
270 return mHolder->size();
297 template<
class tType,
size_t... tDims>
301 typedef tType CoveredElements;
304 CoveredElements mElement;
307 CoveredElements& getElement() {
return mElement;}
310 template<
class tType,
size_t tFirst,
size_t... tDims>
311 struct ArrayImpl<tType, tFirst, tDims...>
313 typedef typename ArrayImpl<tType, tDims...>::type type[tFirst];
314 typedef ArrayImpl<tType, tDims...> CoveredElements[tFirst];
317 CoveredElements mElements;
320 CoveredElements& getElements() {
return mElements;}
323 template<
class tType,
size_t... tDims>
324 using Array =
typename ArrayImpl<tType, tDims...>::type;
326 template<
class tType,
size_t... tDims>
327 using CoveredArray = ArrayImpl<tType, tDims...>;
337 THEOLIZER_INTERNAL_DLL
void checkDataShort(
bool iIsPass, std::string
const& iLoc);
338 THEOLIZER_INTERNAL_DLL
void checkExtraData(
bool iIsPass, std::string
const& iLoc);
352 class THEOLIZER_INTERNAL_DLL BitString
354 static int const kUnsignedSize=std::numeric_limits<unsigned>::digits;
355 static unsigned const kUnsignedMax =std::numeric_limits<unsigned>::max();
356 std::unique_ptr<unsigned[]> mBitList;
360 void expandList(
unsigned iIndex);
362 BitString() : mBitList(), mDataCount(0) { }
364 BitString(BitString&& iRhs) noexcept :
365 mBitList(std::move(iRhs.mBitList)),
366 mDataCount(iRhs.mDataCount)
370 void add(
unsigned iBitNo);
373 void add(
unsigned iIndex,
unsigned iData);
376 bool isOne(
unsigned iBitNo)
const;
379 std::string to_string(
unsigned iStart=0,
unsigned iEnd=kUnsignedMax)
const;
382 unsigned* begin()
const {
return &mBitList[0];}
383 unsigned* end()
const {
return &mBitList[mDataCount];}
386 #endif // THEOLIZER_INTERNAL_DOXYGEN 407 #ifndef THEOLIZER_INTERNAL_DOXYGEN 417 enum :
unsigned {All=0};
430 namespace destination
442 #define THEOLIZER_INTERNAL_DESTINATION(dSymbol) \ 443 namespace destination{namespace{ \ 444 Destination const dSymbol=static_cast<Destination>(internal::bits::dSymbol);\ 455 class THEOLIZER_INTERNAL_DLL Destinations
457 static unsigned const kAlways = (1u << static_cast<unsigned>(theolizerD::All));
458 internal::BitString mDestinations;
468 Destinations(std::initializer_list<Destination>
const& iDestinationList)
470 add(iDestinationList);
473 Destinations(Destinations&& iRhs) noexcept :
474 mDestinations(std::move(iRhs.mDestinations))
481 void add(std::initializer_list<Destination>
const& iDestinationList)
483 for (
auto destination : iDestinationList)
485 unsigned aBitNo =
static_cast<unsigned>(destination);
486 mDestinations.add(aBitNo);
490 void add(Destinations
const& iRhs)
494 mDestinations.add(static_cast<unsigned>(aIndexer.getIndex()), aIndexer.front());
502 bool isMatch(Destinations
const& iRhs,
bool iIsJustMatch=
false)
const 504 auto aLhs=mDestinations.begin();
506 for (
auto aRhs : iRhs.mDestinations)
512 if ((!iIsJustMatch) && ((*aLhs & 1) || (aRhs & 1)))
529 std::string to_string()
const 531 return mDestinations.to_string(0, 1)+
":"+mDestinations.to_string(1);
533 friend std::ostream&
operator<<(std::ostream& iOStream, Destinations
const& iDestinations)
535 iOStream << iDestinations.to_string();
551 struct GlobalVersionKey
553 std::type_index mTypeIndex;
554 std::size_t mListIndex;
555 GlobalVersionKey(std::type_index iTypeIndex, std::size_t iListIndex) :
556 mTypeIndex(iTypeIndex), mListIndex(iListIndex)
565 THEOLIZER_INTERNAL_DLL
void addGlobalVersionKey
567 GlobalVersionKey
const& iKey,
568 std::vector<GlobalVersionKey>& oKeyList
572 THEOLIZER_INTERNAL_DLL
bool findGlobalVersionKey
574 std::vector<GlobalVersionKey>
const& iKeyList,
575 std::type_index iTypeIndex,
576 std::size_t& oListIndex
583 class GlobalVersionNoTableBase
586 GlobalVersionNoTableBase() { }
587 ~GlobalVersionNoTableBase() { }
589 virtual char const* getTableName()
const {
return "";}
591 virtual unsigned getLocalVersionNo
593 unsigned iGlobalVersionNo,
594 std::type_index iStdTypeIndex
597 virtual unsigned getGlobalVersionNo
599 unsigned iLocalVersionNo,
600 std::type_index iStdTypeIndex
604 GlobalVersionNoTableBase(
const GlobalVersionNoTableBase&) =
delete;
605 GlobalVersionNoTableBase( GlobalVersionNoTableBase&&) =
delete;
606 GlobalVersionNoTableBase& operator=(
const GlobalVersionNoTableBase&) =
delete;
607 GlobalVersionNoTableBase& operator=( GlobalVersionNoTableBase&&) =
delete;
615 template<
unsigned uLastGlobalVersionNo>
616 class GlobalVersionNoTable :
public GlobalVersionNoTableBase
618 static_assert(uLastGlobalVersionNo != 0,
"Global VersionNo.0 is illegal.");
623 struct LocalVersionNo
625 unsigned mLocalVersionNo[uLastGlobalVersionNo];
628 std::vector<LocalVersionNo> mLocalVersionNoList;
633 std::vector<GlobalVersionKey> mKeyList;
638 GlobalVersionNoTable() { }
640 static GlobalVersionNoTableBase* getInstance()
642 static GlobalVersionNoTable instance;
649 template<
typename... tLocalVersionNoList>
650 void add(std::type_info
const& iTypeInfo, tLocalVersionNoList... iLocalVersionNoList)
652 static_assert(
sizeof...(tLocalVersionNoList) == uLastGlobalVersionNo,
653 "GlobalVersionNoTable::add() illegal number of parameters.");
655 std::size_t aTypeIndex=mLocalVersionNoList.size();
656 mLocalVersionNoList.push_back(LocalVersionNo{iLocalVersionNoList...});
657 addGlobalVersionKey(GlobalVersionKey(iTypeInfo, aTypeIndex), mKeyList);
662 unsigned getLocalVersionNo(
unsigned iGlobalVersionNo, std::type_index iStdTypeIndex)
const 664 if (iGlobalVersionNo == 0 )
666 THEOLIZER_INTERNAL_VERSION_ERROR(
"GlobalVersionNo(%1%) is illegal.", iGlobalVersionNo);
668 if (uLastGlobalVersionNo < iGlobalVersionNo)
670 THEOLIZER_INTERNAL_VERSION_ERROR(
"GlobalVersionNo(%1%) is too big.", iGlobalVersionNo);
673 std::size_t aListIndex;
674 if (!findGlobalVersionKey(mKeyList, iStdTypeIndex, aListIndex))
677 unsigned ret = mLocalVersionNoList[aListIndex].mLocalVersionNo[iGlobalVersionNo-1];
682 THEOLIZER_INTERNAL_DATA_ERROR(
683 u8
"Can not process <%1%> for Global VersionNo.%2%",
684 getNameByTypeInfo(iStdTypeIndex),
693 unsigned getGlobalVersionNo(
unsigned iLocalVersionNo, std::type_index iStdTypeIndex)
const 695 THEOLIZER_INTERNAL_ASSERT(iLocalVersionNo != 0,
696 "GlobalVersionNoTable::getGlobalVersionNo() : iLocalVersionNo is illegal(0).");
698 std::size_t aListIndex;
699 if (!findGlobalVersionKey(mKeyList, iStdTypeIndex, aListIndex))
700 return uLastGlobalVersionNo;
703 for (ret=uLastGlobalVersionNo; 0 < ret; --ret)
705 if (mLocalVersionNoList[aListIndex].mLocalVersionNo[ret-1] == iLocalVersionNo)
711 return uLastGlobalVersionNo;
722 extern GlobalVersionNoTableBase
const*
const sGlobalVersionNoTable;
734 extern unsigned const kLastGlobalVersionNo;
744 #define THEOLIZER_GENERATED_GLOBAL_TABLE() \ 745 namespace theolizer{namespace internal{namespace{ \ 746 GlobalVersionNoTableBase const*const sGlobalVersionNoTable= \ 747 GlobalVersionNoTable<1>::getInstance(); \ 750 unsigned const kLastGlobalVersionNo=1; \ 762 #endif // THEOLIZER_INTERNAL_DOXYGEN 768 #ifndef THEOLIZER_INTERNAL_DOXYGEN 770 template<
class tClassType>
771 struct TheolizerNonIntrusive {};
775 template<
class tClassType>
776 class TheolizerBase {};
781 template<
class tClassType,
class tEnable>
782 struct TheolizerNonKeepStep;
795 struct tTheolizerVersion
797 template<
class tTypeFunc>
798 static void addElement(tTypeFunc iTypeFunc)
802 #endif // THEOLIZER_INTERNAL_DOXYGEN 831 THEOLIZER_INTERNAL_DLL std::ostream&
operator<<(std::ostream& iOStream,
CheckMode iCheckMode);
849 THEOLIZER_INTERNAL_DLL std::ostream&
operator<<(std::ostream& iOStream,
Property iProperty);
853 #ifndef THEOLIZER_INTERNAL_DOXYGEN 859 THEOLIZER_INTERNAL_DLL
extern const std::size_t kInvalidSize;
869 template<
class tClass,
class tEnable=
void>
870 struct IsStringImpl :
public std::false_type
873 template<
class tClass>
879 std::is_same<tClass, std::string>::value
880 || std::is_same<tClass, std::wstring>::value
881 || std::is_same<tClass, std::u16string>::value
882 || std::is_same<tClass, std::u32string>::value
884 > :
public std::true_type
887 template<
class tClass>
890 static const bool value=IsStringImpl<tClass>::value;
897 template<
typename tType,
class tEnable=
void>
898 struct IsPrimitiveImpl :
public std::false_type
901 template<
typename tType>
902 struct IsPrimitiveImpl
907 std::is_arithmetic<tType>::value
908 || IsString<tType>::value
910 > :
public std::true_type
913 template<
typename tType>
916 static const bool value=IsPrimitiveImpl<tType>::value;
923 template<
class tClass,
class tEnable=
void>
924 struct IsTheolizerVersionImpl :
public std::false_type
927 template<
class tClass>
928 struct IsTheolizerVersionImpl
933 tClass::Theolizer::kIsVersion
935 > :
public std::true_type
938 template<
class tClass>
939 struct IsTheolizerVersion
941 static const bool value=IsTheolizerVersionImpl<tClass>::value;
948 template<
class tClass,
class tEnable=
void>
949 struct IsTheolizerBase :
public std::false_type
952 template<
class tClass>
953 struct IsTheolizerBase
956 EnableIf<tClass::kIsTheolizerBase && !IsTheolizerVersion<tClass>::value>
957 > :
public std::true_type
964 template<
class tClass,
class tEnable=
void>
965 struct IsTheolizerNonKeepStepImpl :
public std::false_type
968 template<
class tClass>
969 struct IsTheolizerNonKeepStepImpl
972 EnableIf<tClass::kIsTheolizerNonKeepStep>
973 > :
public std::true_type
976 template<
class tClass>
977 struct IsTheolizerNonKeepStep
979 static const bool value=IsTheolizerNonKeepStepImpl<tClass>::value;
986 template<
class tClass,
class tEnable=
void>
987 struct IsNonIntrusiveImpl :
public std::false_type
990 template<
class tClass>
991 struct IsNonIntrusiveImpl
996 TheolizerNonIntrusive<typename std::remove_const<tClass>::type>::kIsTheolizer
998 > :
public std::true_type
1001 template<
class tClass>
1002 struct IsNonIntrusive
1004 static const bool value=IsNonIntrusiveImpl<tClass>::value;
1011 template<
class tClass,
class tEnable=
void>
1012 struct IsIntrusiveImpl :
public std::false_type
1015 template<
class tClass>
1016 struct IsIntrusiveImpl
1021 std::is_class<tClass>::value
1022 && !IsString<tClass>::value
1023 && !IsNonIntrusive<tClass>::value
1024 && !IsTheolizerBase<tClass>::value
1025 && !IsTheolizerNonKeepStep<tClass>::value
1027 > :
public std::true_type
1030 template<
class tClass>
1033 static const bool value=IsIntrusiveImpl<tClass>::value;
1048 template<
typename tType,
class tEnable=
void>
1051 static void deleteMember(tType* iData)
1057 template<
typename tType>
1058 struct Deleter<tType, EnableIf<std::is_array<tType>::value> >
1060 static void deleteMember(tType* iData)
1068 template<
typename tType>
1069 class DeferredGeneration
1072 typedef typename std::remove_reference<tType>::type Type;
1077 DeferredGeneration() : mData(
nullptr) { }
1078 ~DeferredGeneration()
1080 Deleter<Type>::deleteMember(mData);
1089 mData=
reinterpret_cast<tType*
>(
new Type());
1095 DeferredGeneration(DeferredGeneration&& ioDeferredGeneration) noexcept :
1096 mData(ioDeferredGeneration.mData)
1098 ioDeferredGeneration.mData=
nullptr;
1100 DeferredGeneration& operator=(DeferredGeneration&& ioDeferredGeneration)
1102 mData=ioDeferredGeneration.mData;
1103 ioDeferredGeneration.mData=
nullptr;
1107 DeferredGeneration(DeferredGeneration
const& iRhs)
1111 DeferredGeneration& operator=(DeferredGeneration
const& iRhs)
1118 #define THEOLIZER_INTERNAL_DEFERRED_GENERATION(dType) \ 1119 theolizer::internal::DeferredGeneration<THEOLIZER_INTERNAL_UNPAREN dType> 1129 class BaseTypeFunctions;
1130 THEOLIZER_INTERNAL_DLL BaseTypeFunctions* getTypeFunctions();
1131 THEOLIZER_INTERNAL_DLL
void setTypeFunctions(BaseTypeFunctions* iTypeFunctions);
1133 class BaseTypeFunctions
1136 static BaseTypeFunctions
const& getInstance()
1138 BaseTypeFunctions* ret=getTypeFunctions();
1141 THEOLIZER_INTERNAL_ERROR(u8
"BaseTypeFunctions is null.");
1146 #define THEOLIZER_INTERNAL_DEF_PRIMITIVE(dType, dSimbol) \ 1147 virtual char const* getPrimitiveName(unsigned iSerializerVersionNo, dType) const=0; 1149 #define THEOLIZER_INTERNAL_DEF_STRING(dType, dSimbol) \ 1150 virtual char const* getPrimitiveName(unsigned iSerializerVersionNo, dType const&) const=0; 1152 #include "primitive.inc" 1154 virtual std::type_index getStdTypeIndex()
const=0;
1155 virtual unsigned getLastVersionNo()
const=0;
1156 virtual char const* getSerializerName()
const=0;
1158 #ifdef THEOLIZER_INTERNAL_ENABLE_META_SERIALIZER 1159 virtual char const* getCppName
1161 std::string
const& iPrimitiveName,
1162 unsigned iSerializerVersionNo
1164 #endif // THEOLIZER_INTERNAL_ENABLE_META_SERIALIZER 1171 template<
class tM
idSerializer>
1172 class TypeFunctions :
public BaseTypeFunctions
1174 BaseTypeFunctions* mBackup;
1179 mBackup=getTypeFunctions();
1180 setTypeFunctions(
this);
1185 setTypeFunctions(mBackup);
1188 #define THEOLIZER_INTERNAL_DEF_PRIMITIVE(dType, dSimbol) \ 1189 char const* getPrimitiveName(unsigned iSerializerVersionNo, dType) const\ 1191 return tMidSerializer::template getPrimitiveName<dType>(iSerializerVersionNo);\ 1193 #define THEOLIZER_INTERNAL_DEF_STRING(dType, dSimbol) \ 1194 char const* getPrimitiveName(unsigned iSerializerVersionNo, dType const&) const\ 1196 return tMidSerializer::template getPrimitiveName<dType>(iSerializerVersionNo);\ 1199 #include "primitive.inc" 1201 std::type_index getStdTypeIndex()
const {
return std::type_index(
typeid(tMidSerializer));}
1202 unsigned getLastVersionNo()
const {
return tMidSerializer::kLastVersionNo;}
1203 char const* getSerializerName()
const {
return tMidSerializer::kSerializerName;}
1205 #ifdef THEOLIZER_INTERNAL_ENABLE_META_SERIALIZER 1206 char const* getCppName
1208 std::string
const& iPrimitiveName,
1209 unsigned iSerializerVersionNo
1212 return tMidSerializer::getCppName(iPrimitiveName, iSerializerVersionNo);
1214 #endif // THEOLIZER_INTERNAL_ENABLE_META_SERIALIZER 1217 #endif // THEOLIZER_INTERNAL_DOXYGEN 1231 #pragma warning(pop) 1234 #endif // THEOLIZER_INTERNAL_CORE_ASSORTED_H
auto getRBForIndexer(tContainer &&iContainer, tNextFunc &&iNextFunc=internal::NopFunctor()) -> typename internal::MakeRBForAdaptor< internal::Indexer, tContainer, tNextFunc >::Type
範囲ベースforを分割できるようにし、かつ、インデックス番号用レンジ生成
Destination
保存先シンボルを定義するscoped enum型
THEOLIZER_INTERNAL_DLL std::ostream & operator<<(std::ostream &iOStream, CheckMode iCheckMode)
CheckModeの表示用オーバーロード
Property
シリアライザが提供する機能(プロパティ)のリスト