Theolizer  Version.1.2.0
serializer for C++ / Do you want to update your classes easily ?
core_type_info.h
1 //############################################################################
2 // Theolizerライブラリのコア部(型情報リスト)
3 /*
4  © 2016 Theoride Technology (http://theolizer.com/) All Rights Reserved.
5  "Theolizer" is a registered trademark of Theoride Technology.
6 
7  "Theolizer" License
8  In the case where you are in possession of a valid “Theolizer” License,
9  you may use this file in accordance with the terms and conditions of
10  the use license determined by Theoride Technology.
11 
12  General Public License Version 3 ("GPLv3")
13  You may use this file in accordance with the terms and conditions of
14  GPLv3 published by Free Software Foundation.
15  Please confirm the contents of GPLv3 at https://www.gnu.org/licenses/gpl.txt .
16  A copy of GPLv3 is also saved in a LICENSE.TXT file.
17 
18  商用ライセンス
19  あなたが有効なTheolizer商用ライセンスを保持している場合、
20  セオライド テクノロジーの定める使用許諾書の条件に従って、
21  このファイルを取り扱うことができます。
22 
23  General Public License Version 3(以下GPLv3)
24  Free Software Foundationが公表するGPLv3の使用条件に従って、
25  あなたはこのファイルを取り扱うことができます。
26  GPLv3の内容を https://www.gnu.org/licenses/gpl.txt にて確認して下さい。
27  またGPLv3のコピーをLICENSE.TXTファイルにおいてます。
28 */
29 //############################################################################
30 
31 #if !defined(THEOLIZER_INTERNAL_CORE_TYPE_INFO_H)
32 #define THEOLIZER_INTERNAL_CORE_TYPE_INFO_H
33 
34 #include "core_assorted.h"
35 
36 //############################################################################
37 // Begin
38 //############################################################################
39 
40 // ***************************************************************************
41 // 警告抑止
42 // ***************************************************************************
43 
44 #ifdef _MSC_VER
45  #pragma warning(push)
46  #pragma warning(disable:4100 4127 4251)
47 #endif
48 
49 namespace theolizer
50 {
51 namespace internal
52 {
53 #ifndef THEOLIZER_INTERNAL_DOXYGEN
54 
55 //############################################################################
56 // 各種シンボル定義
57 //############################################################################
58 
59 // ***************************************************************************
60 // フィールド対応方法指定
61 // ***************************************************************************
62 
63 enum ElementsMapping
64 {
65  emName, // フィールド名(=0:完全自動時)
66  emOrder // 順序
67 };
68 
69 // ***************************************************************************
70 // シリアライズ・データ読出状態
71 // ***************************************************************************
72 
73 enum ReadStat {Terminated=0, Continue, DontCare};
74 
75 // ***************************************************************************
76 // オブジェクト追跡指定
77 // 動的生成領域:newで獲得したエリア/デシリアライズ時newが必要になる
78 // 複数のポインタが同じ動的生成領域をポイントし、かつ、
79 // それぞれのポインタが獲得/開放するケースがある。(shared_ptr<>等)
80 // 仮想基底クラスは同じ領域を複数からポイントされるため、
81 // 動的生成領域と同じ追跡処理を行う。
82 // 静的定義領域:グローバル変数、ローカル変数、メンバー変数等、
83 // 明示的解放が不要な領域
84 // 参照はある種のポインタであるが、別名として運用するので
85 // 静的定義領域として処理する。
86 // ***************************************************************************
87 
88 enum TrackingMode
89 {
90  etmDefault, // デフォルト:ポインタならアドレスのみ回復、その他はオブジェクト追跡無し
91  etmPointee, // ポイントすることはないオブジェクト追跡対象(静的領域と参照)
92  etmOwner // ポイントすることもあるオブジェクト追跡対象(動的生成領域と仮想基底クラス)
93 };
94 
95 //############################################################################
96 // internal化のための前方宣言
97 //############################################################################
98 
99 template<class tBaseSerializer, typename tType, bool tIsRegister=false,
100  TrackingMode tTrackingMode=etmDefault, class tEnable=void>
101 struct Switcher;
102 
103 template
104 <
105  TrackingMode tTrackingMode,
106  class tTheolizerVersion,
107  class tSerializer,
108  typename tType,
109  class tEnable=void
110 >
111 struct BranchedProcess;
112 
113 template
114 <
115  TrackingMode tTrackingMode,
116  class tTheolizerVersion,
117  class tSerializer,
118  typename tType
119 >
120 void process
121 (
122  tSerializer& iSerializer,
123  tType const& iInstance,
124  char const* iName,
125  char const* iFileName,
126  size_t iLineNo
127 );
128 
129 template
130 <
131  TrackingMode tTrackingMode,
132  class tTheolizerVersion,
133  class tSerializer,
134  typename tType
135 >
136 void process
137 (
138  tSerializer& iSerializer,
139  tType& ioInstance,
140  char const* iName,
141  char const* iFileName,
142  size_t iLineNo
143 );
144 
145 //############################################################################
146 // 型管理
147 //############################################################################
148 
149 // ***************************************************************************
150 // 型チェック用定義
151 // ***************************************************************************
152 
153 //----------------------------------------------------------------------------
154 // シリアライズ・データ上のTypeIndexリストの要素
155 //----------------------------------------------------------------------------
156 
157 struct SerializedTypeIndex;
158 
159 //----------------------------------------------------------------------------
160 // シリアライズ・データ上の型名リストの要素
161 //----------------------------------------------------------------------------
162 
163 struct SerializedTypeName;
164 
165 // ***************************************************************************
166 // 型リスト(シングルトン)
167 // 派生シリアライザー毎に型リストを生成し、型IDを決定する。
168 // ***************************************************************************
169 
170 class THEOLIZER_INTERNAL_DLL BaseTypeInfo;
171 
172 //----------------------------------------------------------------------------
173 // 型種別
174 //----------------------------------------------------------------------------
175 
176 enum TypeCategory
177 {
178  etcPointerType, // ポインタ型と参照型の両方
179  etcArrayType,
180  etcClassType,
181  etcEnumType,
182  etcPrimitiveType
183 };
184 
185 //----------------------------------------------------------------------------
186 // 型名リストの要素(型名→TypeIndex)
187 //----------------------------------------------------------------------------
188 
189 struct TypeName
190 {
191  char const* mTypeName;
192  std::size_t mTypeIndex;
193 
194  TypeName(char const* iTypeName, std::size_t iTypeIndex) :
195  mTypeName(iTypeName),
196  mTypeIndex(iTypeIndex)
197  { }
198 };
199 typedef std::vector<TypeName> TypeNameList;
200 
201 TypeNameList::const_iterator findTypeName(TypeNameList const& iTypeNameList,
202  char const* iTypeName);
203 
204 //----------------------------------------------------------------------------
205 // リスト型
206 //----------------------------------------------------------------------------
207 
208 typedef std::vector<std::size_t> TypeIndexList;
209 
210 using TypeInfoListImpl=std::vector<BaseTypeInfo*>;
211 
212 //----------------------------------------------------------------------------
213 // 型リスト本体
214 //----------------------------------------------------------------------------
215 
216 class BaseGlobalVersions;
217 
218 class THEOLIZER_INTERNAL_DLL TypeInfoList
219 {
220 private:
221  template<class, class, class, bool, bool> friend class RegisterType;
222 
223  TypeInfoList() : mPrimitiveTypeIndex(kInvalidSize) // 無効値
224  { }
225 
226  // 型のリスト
227  TypeInfoListImpl mList;
228 
229  // プリミティブのTypeIndex
230  std::size_t mPrimitiveTypeIndex;
231 
232 public:
233  static TypeInfoList& getInstance();
234 
235  // コピー/ムーブ禁止(std::vector<>を使っているのでis_trivially_copyableにならない)
236  TypeInfoList(const TypeInfoList&) = delete;
237  TypeInfoList( TypeInfoList&&) = delete;
238  TypeInfoList& operator=(const TypeInfoList&) = delete;
239  TypeInfoList& operator=( TypeInfoList&&) = delete;
240 
241  // 型登録(TypeIndex返却)
242  std::size_t registerType(BaseTypeInfo* iTypeInfo);
243 
244  // リスト返却
245  TypeInfoListImpl& getList() {return mList;}
246 
247  // プリミティブのTypeIndex返却
248  std::size_t getPrimitiveTypeIndex() {return mPrimitiveTypeIndex;}
249 };
250 
251 //----------------------------------------------------------------------------
252 // 現在のグローバル・バージョン番号に対応したローカル・バージョン番号
253 // 下記パラメータをハンドリングする
254 // 特定のグローバル・バージョン番号に対する
255 // 各TypeIndexのローカル・バージョン番号表
256 // メタ・シリアライズ/デシリアライズ・モード・フラグ
257 //----------------------------------------------------------------------------
258 
259 class THEOLIZER_INTERNAL_DLL VersionNoList : public std::vector<unsigned>
260 {
261  bool mIsMetaMode;
262 public:
263  VersionNoList(bool iIsMetaMode=false) : mIsMetaMode(iIsMetaMode) { }
264  bool isMetaMode() const {return mIsMetaMode;}
265  unsigned at(std::size_t iTypeIndex) const;
266 };
267 
268 // ***************************************************************************
269 // 型情報管理用基底クラス
270 // ***************************************************************************
271 
272 //----------------------------------------------------------------------------
273 // ポリモーフィズム対応用
274 //----------------------------------------------------------------------------
275 
276 // ---<<< ヘッダ・シリアライズ中の各型の出力状態 >>>---
277 
278 enum SaveStat
279 {
280  essIdle,
281  essSaving,
282  essSaved
283 };
284 
285 //----------------------------------------------------------------------------
286 // enum型の保存方法指定
287 // 名前、もしくは、値を保存するので、その指定
288 //----------------------------------------------------------------------------
289 
290 enum EnumSaveType
291 {
292  estName, // enumシンボル名(=0:完全自動時)
293  estValue // enum値
294 };
295 
296 //----------------------------------------------------------------------------
297 // クラス要素/Enumシンボル枚挙用Range
298 //----------------------------------------------------------------------------
299 
300 struct ElementBase;
301 using ElementRange = PolyRange<ElementBase const>;
302 
303 //----------------------------------------------------------------------------
304 // 型種別(メタ・シリアライズ用)
305 //----------------------------------------------------------------------------
306 
307 enum TypeKind
308 {
309  // フラグ
310  etkPrimitiveFlag =1, // Primitive型
311  etkEnumFlag =2, // enum型
312  etkClassFlag =4, // クラス型
313  etkNonIntrusiveFlag =8, // 非侵入型
314  etkManualFlag =16, // 手動型
315  etkTemplateFlag =32, // テンプレート
316 
317  // 値
318  etkGlobalTable =0, // グローバルバージョン番号テーブル名
319  etkPrimitive =etkPrimitiveFlag, // プリミティブ(派生Serialzier)
320  etkEnum =etkEnumFlag | etkNonIntrusiveFlag,
321  etkIntrusiveAuto =etkClassFlag,
322  etkNonIntrusiveAuto =etkClassFlag | etkNonIntrusiveFlag,
323  etkIntrusiveManual =etkClassFlag | etkManualFlag,
324  etkNonIntrusiveManual =etkClassFlag | etkNonIntrusiveFlag | etkManualFlag
325 };
326 
327 // ---<<< クラス種別 >>>---
328 
329 enum ClassFlag
330 {
331  ecfFullAuto =1, // 0:Normal 1:完全自動
332  ecfOrder =2 // 0:Name 1:Order (要素対応方式)
333 };
334 
335 // ---<<< enum種別 >>>---
336 
337 enum EnumFlag
338 {
339  eefUnsigned =1, // 0:符号付き 1:符号無し
340  eefScoped =2, // 0:Unscoped 1:Scoped
341  eefValue =4 // 0:名前保存 1:値保存
342 };
343 
344 //----------------------------------------------------------------------------
345 // 基底クラス本体
346 //----------------------------------------------------------------------------
347 
348 class BaseSerializer;
349 
350 class BaseTypeInfo
351 {
352 private:
353  template<class, class, class, bool, bool> friend class RegisterType;
354  friend class BaseSerializer;
355  friend class TypeInfoList;
356  template<class> friend class PointerTypeInfo;
357  template<class> friend class ArrayTypeInfo;
358  template<class> friend class ClassTypeInfo;
359  template<class, typename, bool, TrackingMode, class> friend struct Switcher;
360  template<typename, bool, class> friend struct Switcher2;
361  template<typename...> friend struct ParameterName;
362  template<class> friend class Element;
363 
364  // TypeIndexを記録する
365  void registerTypeIndex(std::size_t iTypeIndex)
366  {
367  mTypeIndex=iTypeIndex;
368  mIsRegistered=true;
369  }
370 
371  // トップ・レベルの保存先
372  bool mIsTopLevel;
373  Destinations mTopDestinations;
374 
375  // 手動型からの保存
376  bool mIsManual;
377 
378  // 被ポインタ
379  bool mIsPointee;
380 
381  // 型種別
382  TypeCategory mTypeCategory;
383 
384 protected:
385  BaseTypeInfo(TypeCategory iTypeCategory) :
386  mIsTopLevel(false),
387  mIsManual(false),
388  mIsPointee(false),
389  mTypeCategory(iTypeCategory),
390  mTypeIndex(kInvalidSize), // 無効値設定
391  mIsRegistered(false)
392  { }
393 
394  // TypeInfoList<>::mListへの登録先インデックス
395 protected:
396  std::size_t mTypeIndex;
397 private:
398  bool mIsRegistered;
399 
400 public:
401 
402 // ---<<< トップ・レベルの保存先関連 >>>---
403 
404  void addDestination
405  (
406  Destinations const& iDestinations
407  )
408  {
409  mIsTopLevel=true;
410  mTopDestinations.add(iDestinations);
411  }
412 
413  // トップ・レベルの保存先一致判定
414  bool isTopMatch
415  (
416  Destinations const& iSerializerDestinations
417  )
418  {
419  // トップ・レベルでないならfalse
420  if (!mIsTopLevel)
421  return false;
422 
423  // 保存先がAllも含めて一致するなら保存する
424  return iSerializerDestinations.isMatch(mTopDestinations, true);
425  }
426 
427 // ---<<< 手動型からの保存 >>>---
428 
429  bool isManual() {return mIsManual;}
430 
431 // ---<<< 型チェック用 >>>---
432 
433 public:
434 
435  // 下記は各TypeInfoで定義する
436  virtual std::type_index getStdTypeIndex(bool iRaw=false) const = 0;
437  virtual unsigned getLastVersionNoV() const = 0;
438  virtual std::string getTypeName(VersionNoList const& iVersionNoList) = 0;
439 
440  // 下記はClassTypeInfoのみ有効
441  virtual char const* getUniqueName()
442  {THEOLIZER_INTERNAL_ABORT("BaseTypeInfo::getUniqueName()");}
443  virtual ElementsMapping getElementsMapping(unsigned iVersionNo)
444  {THEOLIZER_INTERNAL_ABORT("BaseTypeInfo::getElementsMapping()");}
445 
446  // 下記はClassTypeInfoとEnumTypeInfoのみ有効
447  virtual ElementRange getElementRange(unsigned iVersionNo)
448  {return ElementRange();}
449 
450  // デバッグ用
451  virtual char const* getCName() const = 0;
452  bool isTopLovel() {return mIsTopLevel;}
453 
454 // ---<<< 被ポインタ・チェック用 >>>---
455 
456  bool isPointee() { return mIsPointee; }
457 
458 // ---<<< ポリモーフィズム対応 >>>---
459 
460 private:
461  // 当クラスから派生したクラスについてヘッダへ型情報記録するよう指示する
462  // 自分より前にあるクラスについて保存要求したら、true返却
463  virtual bool setSaving(BaseSerializer& iSerializer, std::vector<SaveStat>& ioSaveStatList)
464  {return false;}
465 
466  // 被ポインタのBaseTypeInfo*獲得
467  virtual BaseTypeInfo* getPointeeTypeInfo() {return nullptr;}
468 
469  // 配列の基本型のTypeIndex獲得
470  virtual std::size_t getUnderlyingTypeIndex()
471  {THEOLIZER_INTERNAL_ABORT("BaseTypeInfo::getUnderlyingTypeIndex()");}
472 
473 // ---<<< メタ・シリアライズ用 >>>---
474 
475  // enum型の時、iVersionNoは有効。その他はDon't care
476  virtual unsigned getTypeFlags(unsigned iVersionNo) {return 0;}
477 
478  virtual TypeKind getTypeKind() = 0;
479 };
480 
481 // ***************************************************************************
482 // グローバル・バージョン・テーブル検索用type_index返却
483 // ポインタ、参照、配列の大元の型によりtype_indexを求める
484 // ***************************************************************************
485 
486 // 大元の型
487 template<typename tType, class tEnable=void>
488 class StdTypeIndex
489 {
490  typedef typename std::remove_cv<tType>::type Type;
491 public:
492  static std::type_index getStdTypeIndex()
493  {
494  return std::type_index(typeid(Type));
495  }
496 };
497 
498 // ポインタ解除
499 template<typename tType>
500 class StdTypeIndex<tType, EnableIf<std::is_pointer<tType>::value>>
501 {
502  typedef typename std::remove_pointer<tType>::type Type;
503 public:
504  static std::type_index getStdTypeIndex()
505  {
506  return StdTypeIndex<Type>::getStdTypeIndex();
507  }
508 };
509 // 参照解除
510 template<typename tType>
511 class StdTypeIndex<tType, EnableIf<std::is_lvalue_reference<tType>::value>>
512 {
513  typedef typename std::remove_reference<tType>::type Type;
514 public:
515  static std::type_index getStdTypeIndex()
516  {
517  return StdTypeIndex<Type>::getStdTypeIndex();
518  }
519 };
520 // 配列解除
521 template<typename tType>
522 class StdTypeIndex<tType, EnableIf<std::is_array<tType>::value>>
523 {
524  typedef typename std::remove_extent<tType>::type Type;
525 public:
526  static std::type_index getStdTypeIndex()
527  {
528  return StdTypeIndex<Type>::getStdTypeIndex();
529  }
530 };
531 
532 // ***************************************************************************
533 // ポインタ型管理クラス(シングルトン)
534 // ポインタ型を型リストへ登録する
535 // ***************************************************************************
536 
537 template<typename tPointerType>
538 class PointerTypeInfo : public BaseTypeInfo
539 {
540 private:
541  // コンストラクタ/デストラクタ
542  PointerTypeInfo() : BaseTypeInfo(etcPointerType) { }
543 public:
544  static PointerTypeInfo& getInstance()
545  {
546  static PointerTypeInfo instance;
547  return instance;
548  }
549 
550  // コピー/ムーブ禁止(仮想関数があるのでis_trivially_copyableにならない)
551  PointerTypeInfo(const PointerTypeInfo&) = delete;
552  PointerTypeInfo( PointerTypeInfo&&) = delete;
553  PointerTypeInfo& operator=(const PointerTypeInfo&) = delete;
554  PointerTypeInfo& operator=( PointerTypeInfo&&) = delete;
555 
556 // ---<<< 型チェック用 >>>---
557 
558  // type_index返却
559  std::type_index getStdTypeIndex(bool iRaw) const
560  {
561  return StdTypeIndex<tPointerType>::getStdTypeIndex();
562  }
563  // 最新版のバージョン番号返却
564  static unsigned getLastVersionNo();
565  unsigned getLastVersionNoV() const {return getLastVersionNo();}
566  // 型名返却
567  std::string getTypeName(VersionNoList const& iVersionNoList);
568  // C言語名返却(デバッグ用)
569  char const* getCName() const
570  {
571  return THEOLIZER_INTERNAL_TYPE_NAME(tPointerType);
572  }
573 
574  // 被ポインタのBaseTypeInfo*獲得
575  BaseTypeInfo* getPointeeTypeInfo();
576 
577 // ---<<< メタ・シリアライズ用 >>>---
578 
579  TypeKind getTypeKind()
580  {
581  return getPointeeTypeInfo()->getTypeKind();
582  }
583 };
584 
585 // ***************************************************************************
586 // 生配列管理クラス(シングルトン)
587 // 生配列型を型リストへ登録する
588 // 型名は"型名[]"とし、型名に要素数は含まない。
589 // 要素数が異なっても同じ型として認識する。
590 // これはClassTypeの要素が変化しても同じ型と認識することと同じ。
591 // ***************************************************************************
592 
593 //----------------------------------------------------------------------------
594 // ArrayType管理クラス本体
595 //----------------------------------------------------------------------------
596 
597 template<typename tArrayType>
598 class ArrayTypeInfo : public BaseTypeInfo
599 {
600 private:
601  // コンストラクタ/デストラクタ
602  ArrayTypeInfo() : BaseTypeInfo(etcArrayType) { }
603 public:
604  static ArrayTypeInfo& getInstance()
605  {
606  static ArrayTypeInfo instance;
607  return instance;
608  }
609 
610  // コピー/ムーブ禁止(仮想関数があるのでis_trivially_copyableにならない)
611  ArrayTypeInfo(const ArrayTypeInfo&) = delete;
612  ArrayTypeInfo( ArrayTypeInfo&&) = delete;
613  ArrayTypeInfo& operator= (const ArrayTypeInfo&) = delete;
614  ArrayTypeInfo& operator= ( ArrayTypeInfo&&) = delete;
615 
616 // ---<<< 型チェック用 >>>---
617 
618  // type_index返却
619  std::type_index getStdTypeIndex(bool iRaw) const
620  {return StdTypeIndex<tArrayType>::getStdTypeIndex();}
621  // 最新版のバージョン番号返却
622  static unsigned getLastVersionNo();
623  unsigned getLastVersionNoV() const {return getLastVersionNo();}
624  // 型名返却
625  std::string getTypeName(VersionNoList const& iVersionNoList);
626  // C言語名返却(デバッグ用)
627  char const* getCName() const
628  {
629  return THEOLIZER_INTERNAL_TYPE_NAME(tArrayType);
630  }
631  // 配列の基本型のTypeIndex獲得
632  std::size_t getUnderlyingTypeIndex();
633 
634 // ---<<< メタ・シリアライズ用 >>>---
635 
636  TypeKind getTypeKind()
637  {
638  BaseTypeInfo* aTypeInfo =
639  TypeInfoList::getInstance().getList().at(getUnderlyingTypeIndex());
640  return aTypeInfo->getTypeKind();
641  }
642 };
643 
644 // ***************************************************************************
645 // ClassType管理クラス(シングルトン)
646 // struct/class型を型リストへ登録する
647 // tClassType
648 // 侵入型 ターゲット・クラス
649 // 非侵入型 TheolizerNonIntrusive<ターゲット・クラス>
650 //
651 // 注意事項(http://jumble-note.blogspot.jp/2015/01/c.html)
652 // クラス・テンプレートの名前探索はテンプレート・パラメータが
653 // 全て確定後に行われるとC++規格にて定められている。
654 // →部分特殊化や特殊化を考慮?
655 // そのため、クラス・テンプレートを継承した場合、そのままでは、
656 // 基底クラスのメンバは名前探索対象にならない。
657 // しかし、明示的に基底クラスのメンバであることを指定すればよい。
658 // →部分特殊化や特殊化で無くなっていたら、その時エラーか?
659 // 注意深くやれと言うことかも。
660 // ***************************************************************************
661 
662 template<class tClassType>
663 class ClassTypeInfo : public BaseTypeInfo
664 {
665  template<class, typename, class> friend struct SavePointer;
666  template<class, typename, class> friend struct LoadPointer;
667 
668  typedef typename tClassType::TheolizerTarget TheolizerTarget;
669 public:
670  typedef typename tClassType::TheolizerClass TheolizerClass;
671 
672 private:
673  // コンストラクタ/デストラクタ
674  ClassTypeInfo() : BaseTypeInfo(etcClassType) { }
675 public:
676  static ClassTypeInfo& getInstance()
677  {
678  static ClassTypeInfo instance;
679  return instance;
680  }
681 
682  // コピー/ムーブ禁止(仮想関数があるのでis_trivially_copyableにならない)
683  ClassTypeInfo(const ClassTypeInfo&) = delete;
684  ClassTypeInfo( ClassTypeInfo&&) = delete;
685  ClassTypeInfo& operator=(const ClassTypeInfo&) = delete;
686  ClassTypeInfo& operator=( ClassTypeInfo&&) = delete;
687 
688 // ---<<< 型チェック用 >>>---
689 
690  // type_index返却
691  // iRaw==true : ターゲット・クラスのもの
692  // iRaw==false : グローバル・バージョン番号テーブルに登録されているもの
693  std::type_index getStdTypeIndex(bool iRaw) const
694  {
695  if (iRaw)
696  {
697  return std::type_index(typeid(TheolizerTarget));
698  }
699 
700  typedef typename tClassType::Theolizer::DefineUniqueName::UniqueClass UniqueClass;
701  return std::type_index(typeid(UniqueClass));
702  }
703  // 最新版のバージョン番号返却
704  static unsigned getLastVersionNo() {return tClassType::Theolizer::kLastVersionNo;}
705  unsigned getLastVersionNoV() const {return getLastVersionNo();}
706  // 型名返却
707  std::string getTypeName(VersionNoList const& iVersionNoList)
708  {
709  THEOLIZER_INTERNAL_ASSERT(BaseTypeInfo::mTypeIndex != kInvalidSize,
710  "Not registered class %1%.", getCName());
711  return tClassType::Theolizer::getClassName
712  (
713  iVersionNoList,
714  iVersionNoList.at(BaseTypeInfo::mTypeIndex)
715  );
716  }
717  char const* getUniqueName()
718  {
719  return tClassType::Theolizer::getUniqueName();
720  }
721  // メンバ変数対応方法返却
722  ElementsMapping getElementsMapping(unsigned iVersionNo)
723  {
724  return tClassType::Theolizer::getElementsMapping(iVersionNo);
725  }
726 
727  // C言語名返却(デバッグ用)
728  char const* getCName() const
729  {
730  return THEOLIZER_INTERNAL_TYPE_NAME(typename tClassType::TheolizerTarget);
731  }
732 
733  // 要素枚挙用Range返却
734  ElementRange getElementRange(unsigned iVersionNo)
735  {
736  return tClassType::Theolizer::getElementRange(iVersionNo);
737  }
738 
739 // ---<<< ポリモーフィズム対応 >>>---
740 
741 private:
742  // 派生クラスのsaveTypeInstance/loadTypeInstance呼び出し登録用クラス
743  struct HolderBase
744  {
745  virtual bool saveTypeInstance
746  (
747  BaseSerializer& iSerializer,
748  tClassType*& iPointer,
749  std::type_index iStdTypeIndex
750  )=0;
751  virtual bool loadTypeInstance
752  (
753  BaseSerializer& iSerializer,
754  tClassType*& ioPointer,
755  TypeIndexList& iTypeIndexList
756  )=0;
757  virtual bool setSaving
758  (
759  BaseSerializer& iSerializer,
760  std::vector<SaveStat>& ioSaveStatList
761  )=0;
762  virtual void const* getDerivedPointer(TheolizerTarget* iBasePointer)=0;
763  virtual std::size_t getTypeIndex()=0;
764  virtual ~HolderBase() { }
765  };
766 
767  // 派生クラスのsaveTypeInstance/loadTypeInstance呼び出し用クラス
768  template<class tDrivedClassType>
769  struct Holder : public HolderBase
770  {
771  Holder() { }
772  ~Holder() = default;
773 
774  bool saveTypeInstance
775  (
776  BaseSerializer& iSerializer,
777  tClassType*& iPointer,
778  std::type_index iStdTypeIndex
779  )
780  {
781  typedef typename tClassType::TheolizerTarget TheolizerTarget;
782  tDrivedClassType* aPointer=
783  static_cast<tDrivedClassType*>(reinterpret_cast<TheolizerTarget*>(iPointer));
784  return ClassTypeInfo<tDrivedClassType>::getInstance().
785  saveTypeInstance
786  (
787  iSerializer,
788  aPointer,
789  iStdTypeIndex
790  );
791  }
792 
793  bool loadTypeInstance
794  (
795  BaseSerializer& iSerializer,
796  tClassType*& ioPointer,
797  TypeIndexList& iTypeIndexList
798  )
799  {
800  tDrivedClassType* aPointer=
801  static_cast<tDrivedClassType*>(reinterpret_cast<TheolizerTarget*>(ioPointer));
802  bool ret=ClassTypeInfo<tDrivedClassType>::getInstance().
803  loadTypeInstance
804  (
805  iSerializer,
806  aPointer,
807  iTypeIndexList
808  );
809  ioPointer=reinterpret_cast<tClassType*>(static_cast<TheolizerTarget*>(aPointer));
810  return ret;
811  }
812 
813  bool setSaving(BaseSerializer& iSerializer, std::vector<SaveStat>& ioSaveStatList)
814  {
815  return ClassTypeInfo<tDrivedClassType>::getInstance().
816  setSaving(iSerializer, ioSaveStatList);
817  }
818 
819  void const* getDerivedPointer(TheolizerTarget* iBasePointer)
820  {
821  void* aPointer=static_cast<tDrivedClassType*>(iBasePointer);
822  return aPointer;
823  }
824 
825  std::size_t getTypeIndex()
826  {
827  return ClassTypeInfo<tDrivedClassType>::getInstance().mTypeIndex;
828  }
829  };
830 
831  // 派生クラス・リスト
832  std::vector<std::unique_ptr<HolderBase> > mDrivedClassList;
833 
834 public:
835  // 派生クラスをmDrivedClassListへ登録する
836  template<class tDrivedClassType>
837  void registerDrivedClass()
838  {
839 //std::cout << "registerDrivedClass<" << THEOLIZER_INTERNAL_TYPE_NAME(tDrivedClassType)
840 // << " base=" << THEOLIZER_INTERNAL_TYPE_NAME(typename tClassType::TheolizerTarget)
841 // << "\n";
842  mDrivedClassList.emplace_back(new Holder<tDrivedClassType>);
843  }
844 
845  // 型、および、インスタンス保存(privateだとHolderからの呼び出しができない。friend化が難しい。)
846  bool saveTypeInstance
847  (
848  BaseSerializer& iSerializer,
849  tClassType*& iPointer,
850  std::type_index iStdTypeIndex
851  );
852 
853  // 型、および、インスタンス回復
854  bool loadTypeInstance
855  (
856  BaseSerializer& iSerializer,
857  tClassType*& ioPointer,
858  TypeIndexList& iTypeIndexList
859  );
860 
861  // 当クラスから派生したクラスについてヘッダへ型情報記録するよう指示する
862  // 自分より前にあるクラスについて保存要求したら、true返却
863  bool setSaving(BaseSerializer& iSerializer, std::vector<SaveStat>& ioSaveStatList)
864  {
865  // 派生クラスが登録されていないなら、NOP
866  if (!mDrivedClassList.size())
867  return false;
868 
869  bool ret=false;
870 //std::cout << "setSaving(" << getCName()
871 // << " mDrivedClassList.size()=" << mDrivedClassList.size() << "\n";
872  for (auto&& aDrivedClass : mDrivedClassList)
873  {
874  std::size_t aTypeIndex = aDrivedClass->getTypeIndex();
875  SaveStat& aSaveStat = ioSaveStatList.at(aTypeIndex);
876 //std::cout << " " << aDrivedClass->getCName() << "\n";
877  if (aSaveStat == essIdle)
878  {
879  aSaveStat=essSaving;
880  if (aTypeIndex < mTypeIndex) ret=true;
881  }
882  if (aDrivedClass->setSaving(iSerializer, ioSaveStatList)) ret=true;
883  }
884  return ret;
885  }
886 
887  // 現インスタンスの先頭アドレス返却
888  void const* getDerivedPointer(TheolizerTarget* iBasePointer);
889 
890 private:
891  // ターゲットクラスのstd::type_index返却
892  std::type_index getTargetStdTypeIndex() const
893  {
894  return std::type_index(typeid(typename tClassType::TheolizerTarget));
895  }
896 
897 // ---<<< メタ・シリアライズ用 >>>---
898 
899  unsigned getTypeFlags(unsigned iVersionNo)
900  {
901  // 自動型
902  if (tClassType::Theolizer::kIsAuto)
903  return tClassType::Theolizer::getTypeFlags(iVersionNo);
904 
905  // 手動型はここで求める(バージョン毎に異なる部分がない)
906  unsigned ret=0;
907  ret |= theolizer::internal::ecfOrder;
908  return ret;
909  }
910 
911  TypeKind getTypeKind()
912  {
913  std::underlying_type<TypeKind>::type ret = etkClassFlag;
914 
915  if (tClassType::Theolizer::kIsNonIntrusive)
916  {
917  ret |= etkNonIntrusiveFlag;
918  }
919 
920  if (!tClassType::Theolizer::kIsAuto)
921  {
922  ret |= etkManualFlag;
923  }
924 
925  if (!std::is_same
926  <
927  typename tClassType::Theolizer::DefineUniqueName::UniqueClass,
928  typename tClassType::TheolizerTarget
929  >::value)
930  {
931  ret |= etkTemplateFlag;
932  }
933 
934  return static_cast<TypeKind>(ret);
935  }
936 };
937 
938 // ***************************************************************************
939 // EnumType管理クラス(シングルトン)
940 // enum型を型リストへ登録する
941 // バージョン管理する。詳細T.B.D.
942 // ***************************************************************************
943 
944 template<typename tEnumType>
945 class EnumTypeInfo : public BaseTypeInfo
946 {
947 private:
948  typedef TheolizerNonIntrusive<tEnumType> EnumNonIntrusive;
949 
950  // コンストラクタ/デストラクタ
951  EnumTypeInfo() : BaseTypeInfo(etcEnumType) { }
952 public:
953  static EnumTypeInfo& getInstance()
954  {
955  static EnumTypeInfo instance;
956  return instance;
957  }
958 
959  // コピー/ムーブ禁止(仮想関数があるのでis_trivially_copyableにならない)
960  EnumTypeInfo(const EnumTypeInfo&) = delete;
961  EnumTypeInfo( EnumTypeInfo&&) = delete;
962  EnumTypeInfo& operator=(const EnumTypeInfo&) = delete;
963  EnumTypeInfo& operator=( EnumTypeInfo&&) = delete;
964 
965 // ---<<< 型チェック用 >>>---
966 
967  // type_index返却
968  std::type_index getStdTypeIndex(bool iRaw) const
969  {return std::type_index(typeid(tEnumType));}
970  // 最新版のバージョン番号返却
971  static unsigned getLastVersionNo()
972  {
973  return EnumNonIntrusive::Theolizer::kLastVersionNo;
974  }
975  unsigned getLastVersionNoV() const {return getLastVersionNo();}
976  // 型名返却
977  std::string getTypeName(VersionNoList const& iVersionNoList)
978  {
979  return EnumNonIntrusive::Theolizer::getEnumName
980  (
981  iVersionNoList.
982  at(BaseTypeInfo::mTypeIndex)
983  );
984  }
985  // C言語名返却(デバッグ用)
986  char const* getCName() const
987  {
988  return THEOLIZER_INTERNAL_TYPE_NAME(tEnumType);
989  }
990 
991  // 要素枚挙用Range返却
992  ElementRange getElementRange(unsigned iVersionNo)
993  {
994  return EnumNonIntrusive::Theolizer::getElementRange(iVersionNo);
995  }
996 
997 // ---<<< メタ・シリアライズ用 >>>---
998 
999  unsigned getTypeFlags(unsigned iVersionNo)
1000  {
1001  return EnumNonIntrusive::Theolizer::getTypeFlags(iVersionNo);
1002  }
1003 
1004 // ---<<< メタ・シリアライズ用 >>>---
1005 
1006  TypeKind getTypeKind() {return etkEnum;}
1007 };
1008 
1009 // ***************************************************************************
1010 // プリミティブ管理クラス(シングルトン)
1011 // プリミティブ型を型リストへ登録する
1012 // ***************************************************************************
1013 
1014 //----------------------------------------------------------------------------
1015 // PrimitiveType管理クラス本体
1016 //----------------------------------------------------------------------------
1017 
1018 template<typename tPrimitiveType>
1019 class THEOLIZER_INTERNAL_DLL PrimitiveTypeInfo : public BaseTypeInfo
1020 {
1021 private:
1022  // コンストラクタ/デストラクタ
1023  PrimitiveTypeInfo() : BaseTypeInfo(etcPrimitiveType) { }
1024 public:
1025  static PrimitiveTypeInfo& getInstance();
1026 
1027  // コピー/ムーブ禁止(仮想関数があるのでis_trivially_copyableにならない)
1028  PrimitiveTypeInfo(const PrimitiveTypeInfo&) = delete;
1029  PrimitiveTypeInfo( PrimitiveTypeInfo&&) = delete;
1030  PrimitiveTypeInfo& operator=(const PrimitiveTypeInfo&) = delete;
1031  PrimitiveTypeInfo& operator=( PrimitiveTypeInfo&&) = delete;
1032 
1033 // ---<<< 型チェック用 >>>---
1034 
1035  // type_index返却
1036  std::type_index getStdTypeIndex(bool iRaw) const
1037  {
1038  return BaseTypeFunctions::getInstance().getStdTypeIndex();
1039  }
1040  // 最新版のバージョン番号返却(シリアライザのバージョン番号を返却する)
1041  static unsigned getLastVersionNo()
1042  {
1043  return BaseTypeFunctions::getInstance().getLastVersionNo();
1044  }
1045  unsigned getLastVersionNoV() const {return getLastVersionNo();}
1046  // 型名返却
1047  std::string getTypeName(VersionNoList const& iVersionNoList)
1048  {
1049  unsigned aVersionNo = iVersionNoList.at(BaseTypeInfo::mTypeIndex);
1050  return BaseTypeFunctions::getInstance().getPrimitiveName(aVersionNo, tPrimitiveType());
1051  }
1052  // C言語名返却(デバッグ用)
1053  char const* getCName() const
1054  {
1055  return THEOLIZER_INTERNAL_TYPE_NAME(tPrimitiveType);
1056  }
1057 
1058 // ---<<< メタ・シリアライズ用 >>>---
1059 
1060  TypeKind getTypeKind() {return etkPrimitive;}
1061 };
1062 
1063 // ***************************************************************************
1064 // TypeをTypeInfoListへ登録する
1065 // ***************************************************************************
1066 
1067 template<typename tType>
1068 std::size_t getTypeIndex();
1069 
1070 //----------------------------------------------------------------------------
1071 // TypeInfoを求める
1072 //----------------------------------------------------------------------------
1073 
1074 // ---<<< プライマリ >>>---
1075 
1076 template<typename tType, class tEnable=void>
1077 struct GetTypeInfo
1078 {
1079  static_assert(Ignore<tType>::kFalse, "This is not supported type.");
1080 };
1081 
1082 // ---<<< ポインタ型 >>>---
1083 
1084 template<typename tType>
1085 struct GetTypeInfo<tType, EnableIf<std::is_pointer<tType>::value> >
1086 {
1087  typedef PointerTypeInfo<tType> Type;
1088 };
1089 
1090 // ---<<< 生配列 >>>---
1091 
1092 template<typename tType>
1093 struct GetTypeInfo<tType, EnableIf<std::is_array<tType>::value> >
1094 {
1095  typedef ArrayTypeInfo<tType> Type;
1096 };
1097 
1098 // ---<<< 侵入型 >>>---
1099 
1100 template<typename tType>
1101 struct GetTypeInfo<tType, EnableIf<IsIntrusive<tType>::value> >
1102 {
1103  typedef ClassTypeInfo<tType> Type;
1104 };
1105 
1106 // ---<<< 非侵入型 >>>---
1107 
1108 template<typename tType>
1109 struct GetTypeInfo<tType, EnableIf<IsNonIntrusive<tType>::value> >
1110 {
1111 private:
1112  typedef TheolizerNonIntrusive<tType> TheolizerClass;
1113 public:
1114  typedef ClassTypeInfo<TheolizerClass> Type;
1115 };
1116 
1117 // ---<<< enum型 >>>---
1118 
1119 template<typename tType>
1120 struct GetTypeInfo<tType, EnableIf<std::is_enum<tType>::value> >
1121 {
1122  typedef EnumTypeInfo<tType> Type;
1123 };
1124 
1125 // ---<<< プリミティブ型 >>>---
1126 
1127 template<typename tType>
1128 struct GetTypeInfo<tType, EnableIf<IsPrimitive<tType>::value> >
1129 {
1130  typedef PrimitiveTypeInfo<tType> Type;
1131 };
1132 
1133 // ---<<< 参照型 >>>---
1134 
1135 template<typename tType>
1136 struct GetTypeInfo<tType, EnableIf<std::is_lvalue_reference<tType>::value> >
1137 {
1138 private:
1139  typedef typename std::remove_reference<tType>::type RemovedType;
1140 public:
1141  typedef typename GetTypeInfo<RemovedType>::Type Type;
1142 };
1143 
1144 //----------------------------------------------------------------------------
1145 // ポインタか配列の場合、「ポイント先」/「配列の基本」の型を登録する
1146 //----------------------------------------------------------------------------
1147 
1148 // ---<<< プライマリ >>>---
1149 
1150 template
1151 <
1152  class tSerializer,
1153  typename tType,
1154  class tTheolizerVersion,
1155  bool uIsDerived,
1156  bool uIsManual=false,
1157  class tEnable=void
1158 >
1159 struct RegisterPointeeUnderlying
1160 {
1161  static void registerType() { }
1162 };
1163 
1164 // ---<<< ポインタ型 >>>---
1165 
1166 template<class tSerializer,typename tType,class tTheolizerVersion,bool uIsDerived,bool uIsManual>
1167 struct RegisterPointeeUnderlying
1168 <
1169  tSerializer,
1170  tType,
1171  tTheolizerVersion,
1172  uIsDerived,
1173  uIsManual,
1174  EnableIf<std::is_pointer<tType>::value>
1175 >
1176 {
1177  static void registerType();
1178 };
1179 
1180 // ---<<< 配列 >>>---
1181 
1182 template<class tSerializer,typename tType,class tTheolizerVersion,bool uIsDerived,bool uIsManual>
1183 struct RegisterPointeeUnderlying
1184 <
1185  tSerializer,
1186  tType,
1187  tTheolizerVersion,
1188  uIsDerived,
1189  uIsManual,
1190  EnableIf<std::is_array<tType>::value>
1191 >
1192 {
1193  static void registerType();
1194 };
1195 
1196 //----------------------------------------------------------------------------
1197 // 基底クラスへ登録する
1198 //----------------------------------------------------------------------------
1199 
1200 template<typename tType, bool uIsDerived>
1201 struct RegisterToBaseClassEntrance
1202 {
1203  void operator()(BaseTypeInfo*) { }
1204 };
1205 
1206 template<typename tType>
1207 struct RegisterToBaseClassEntrance<tType, true>
1208 {
1209  void operator()(BaseTypeInfo* iBaseTypeInfo)
1210  {
1211  typedef typename tType::TheolizerClass TheolizerClass;
1212  typedef typename TheolizerClass::Theolizer Theolizer;
1213  Theolizer::registerToBaseClass(iBaseTypeInfo);
1214  }
1215 };
1216 
1217 //----------------------------------------------------------------------------
1218 // 登録本体
1219 //----------------------------------------------------------------------------
1220 
1221 template
1222 <
1223  class tSerializer,
1224  typename tType,
1225  class tTheolizerVersion=::tTheolizerVersion,
1226  bool uIsDerived=false,
1227  bool uIsManual=false
1228 >
1229 class RegisterType
1230 {
1231 private:
1232  typedef typename RemoveCV<tType>::type RemovedCVType;
1233 
1234  static RegisterType& mInstance;
1235  static void use(const RegisterType&) {}
1236 
1237  // 登録した型情報
1238  BaseTypeInfo* mBaseTypeInfo;
1239 
1240  // コンストラクタ
1241  // 型リストへ登録し、型IDを入手する。
1242  RegisterType()
1243  {
1244  // XxxTypeInfo生成
1245  typedef typename GetTypeInfo<RemovedCVType>::Type TypeInfo;
1246  mBaseTypeInfo=&TypeInfo::getInstance();
1247 
1248 #if 0
1249 std::cout << "RegisterType<" << THEOLIZER_INTERNAL_TYPE_NAME(tSerializer) << ",\n"
1250  << " " << THEOLIZER_INTERNAL_TYPE_NAME(tType) << ",\n"
1251  << " " << THEOLIZER_INTERNAL_TYPE_NAME(TypeInfo) << ",\n"
1252  << " " << THEOLIZER_INTERNAL_TYPE_NAME(tTheolizerVersion) << ",\n"
1253  << " uIsDerived=" << uIsDerived << ">\n";
1254 #endif
1255 
1256  // 保存先があるTopLevelシリアライザなら、TypeInfoに保存先を登録する
1257  if (tSerializer::kHasDestination)
1258  {
1259 //std::cout << " addDestination(" << tSerializer::getDestinations() << ")\n";
1260  mBaseTypeInfo->addDestination(tSerializer::getDestinations());
1261  }
1262 
1263  // 未登録なら、TypeInfoListへBaseTypeInfoを登録する
1264  std::size_t aTypeIndex=0;
1265  if (mBaseTypeInfo->mIsRegistered)
1266  {
1267  aTypeIndex=mBaseTypeInfo->mTypeIndex;
1268 //std::cout << " aTypeIndex=" << aTypeIndex << " (Registered)\n";
1269  }
1270  else
1271  {
1272  aTypeIndex=TypeInfoList::getInstance().registerType(mBaseTypeInfo);
1273 //std::cout << " aTypeIndex=" << aTypeIndex << "\n";
1274 
1275  // TypeIndexをBaseTypeInfoへ設定する
1276  mBaseTypeInfo->registerTypeIndex(aTypeIndex);
1277  }
1278 
1279  // ポリモーフィズム用派生クラスの登録なら、基底クラスのリストへ追加する
1280  RegisterToBaseClassEntrance<TypeInfo, uIsDerived>()(mBaseTypeInfo);
1281 
1282  // ポインタなら、その先の型を登録する
1283  // 配列なら、基本型を登録する
1284  RegisterPointeeUnderlying
1285  <
1286  tSerializer,
1287  RemovedCVType,
1288  tTheolizerVersion,
1289  uIsDerived,
1290  uIsManual
1291  >::registerType();
1292 
1293  // 手動型のkElementListへ登録する
1294  tTheolizerVersion::addElement
1295  (
1296  []{return theolizer::internal::getTypeIndex<tType>();}
1297  );
1298  }
1299  // デストラクタ
1300  ~RegisterType() { }
1301 public:
1302  static RegisterType& getInstance()
1303  {
1304  static RegisterType instance;
1305  use(mInstance);
1306 
1307  // 手動型からの保存設定
1308  instance.mBaseTypeInfo->mIsManual=uIsManual;
1309 
1310  return instance;
1311  }
1312 
1313  // コピー/ムーブ禁止(デストラクタ定義がないとis_trivially_copyableになる)
1314  RegisterType(const RegisterType&) = delete;
1315  RegisterType( RegisterType&&) = delete;
1316  RegisterType& operator=(const RegisterType&) = delete;
1317  RegisterType& operator=( RegisterType&&) = delete;
1318 
1319  // 被ポインタ登録
1320  void setPointee() { mBaseTypeInfo->mIsPointee=true; }
1321 };
1322 
1323 // プロセス起動時にシングルトンを生成させる
1324 template<class tSerializer, class tType, class tTheolizerVersion, bool uIsDerived, bool uIsManual>
1325 RegisterType<tSerializer, tType, tTheolizerVersion, uIsDerived, uIsManual>&
1326  RegisterType<tSerializer, tType, tTheolizerVersion, uIsDerived, uIsManual>::mInstance
1327  = RegisterType<tSerializer, tType, tTheolizerVersion, uIsDerived, uIsManual>::getInstance();
1328 
1329 //----------------------------------------------------------------------------
1330 // ポインタの場合、ポイント先の型を登録する関数本体
1331 //----------------------------------------------------------------------------
1332 
1333 template<class tSerializer,typename tType,class tTheolizerVersion,bool uIsDerived,bool uIsManual>
1334 void RegisterPointeeUnderlying
1335 <
1336  tSerializer,
1337  tType,
1338  tTheolizerVersion,
1339  uIsDerived,
1340  uIsManual,
1341  EnableIf<std::is_pointer<tType>::value>
1342 >::registerType()
1343 {
1344  RegisterType
1345  <
1346  tSerializer,
1347  typename std::remove_pointer<tType>::type,
1348  tTheolizerVersion,
1349  uIsDerived,
1350  uIsManual
1351  >::getInstance().setPointee();
1352 }
1353 
1354 //----------------------------------------------------------------------------
1355 // 配列の場合、基本型を登録する関数本体
1356 //----------------------------------------------------------------------------
1357 
1358 // ---<<< 基本型を取り出すためのプライマリ・テンプレート >>>---
1359 
1360 template
1361 <
1362  class tSerializer,
1363  typename tType,
1364  class tTheolizerVersion,
1365  bool uIsDerived,
1366  bool uIsManual=false,
1367  class tEnable=void
1368 >
1369 struct RegisterUnderlying
1370 {
1371  static void registerType()
1372  {
1373  RegisterType
1374  <
1375  tSerializer,
1376  tType,
1377  tTheolizerVersion,
1378  uIsDerived,
1379  uIsManual
1380  >::getInstance();
1381  }
1382 };
1383 
1384 // ---<<< 基本型を取り出すための部分特殊化テンプレート >>>---
1385 
1386 template<class tSerializer,typename tType,class tTheolizerVersion,bool uIsDerived,bool uIsManual>
1387 struct RegisterUnderlying
1388 <
1389  tSerializer,
1390  tType,
1391  tTheolizerVersion,
1392  uIsDerived,
1393  uIsManual,
1394  EnableIf<std::is_array<tType>::value>
1395 >
1396 {
1397  static void registerType()
1398  {
1399  RegisterUnderlying
1400  <
1401  tSerializer,
1402  typename std::remove_extent<tType>::type,
1403  tTheolizerVersion,
1404  uIsDerived,
1405  uIsManual
1406  >::registerType();
1407  }
1408 };
1409 
1410 // ---<<< 本体 >>>---
1411 
1412 template<class tSerializer,typename tType,class tTheolizerVersion,bool uIsDerived,bool uIsManual>
1413 void RegisterPointeeUnderlying
1414 <
1415  tSerializer,
1416  tType,
1417  tTheolizerVersion,
1418  uIsDerived,
1419  uIsManual,
1420  EnableIf<std::is_array<tType>::value>
1421 >::registerType()
1422 {
1423  RegisterUnderlying
1424  <
1425  tSerializer,
1426  typename std::remove_extent<tType>::type,
1427  tTheolizerVersion,
1428  uIsDerived,
1429  uIsManual
1430  >::registerType();
1431 }
1432 
1433 // ***************************************************************************
1434 // Switcher2(管理する型毎に特殊化する)
1435 // 型管理における型毎の分岐を実現する
1436 // ***************************************************************************
1437 
1438 //----------------------------------------------------------------------------
1439 // デフォルトSwitcher(エラー)
1440 //----------------------------------------------------------------------------
1441 
1442 template<typename tType, bool tIsRegister=false, class tEnable=void>
1443 struct Switcher2
1444 {
1445  // 最新版のバージョン番号返却
1446  static unsigned getLastVersionNo()
1447  {
1448  static_assert(Ignore<tType>::kFalse, "This is not serializable class.");
1449  return 0;
1450  }
1451  // 型名返却
1452  static std::string getTypeName(VersionNoList const& iVersionNoList)
1453  {
1454  static_assert(Ignore<tType>::kFalse, "This is not serializable class.");
1455  return 0;
1456  }
1457  // TypeIndex返却
1458  static std::size_t getTypeIndex()
1459  {
1460  static_assert(Ignore<tType>::kFalse, "This is not serializable class.");
1461  return 0;
1462  }
1463  // そのまま返却
1464  static void const* getDerivedPointer(tType* iPointer)
1465  {
1466  static_assert(Ignore<tType>::kFalse, "This is not serializable class.");
1467  return iPointer;
1468  }
1469 };
1470 
1471 //----------------------------------------------------------------------------
1472 // ポインタ型(オブジェクト追跡)用Switcher2
1473 //----------------------------------------------------------------------------
1474 
1475 template<typename tPointerType, bool tIsRegister>
1476 struct Switcher2
1477 <
1478  tPointerType,
1479  tIsRegister,
1480  EnableIf<std::is_pointer<tPointerType>::value>
1481 >
1482 {
1483  typedef typename RemoveCV<tPointerType>::type PointerType;
1484 
1485  // 最新版のバージョン番号返却
1486  static unsigned getLastVersionNo()
1487  {
1488  return PointerTypeInfo<PointerType>::getLastVersionNo();
1489  }
1490  // 型名返却
1491  static std::string getTypeName(VersionNoList const& iVersionNoList)
1492  {
1493  return PointerTypeInfo<PointerType>::getInstance().getTypeName(iVersionNoList);
1494  }
1495  // TypeIndex返却
1496  static std::size_t getTypeIndex()
1497  {
1498  return PointerTypeInfo<PointerType>::getInstance().mTypeIndex;
1499  }
1500  // これは不要(多重ポインタは非サポート)
1501 // static void const* getDerivedPointer(tPointerType* iPointer)
1502 // {
1503 // return iPointer;
1504 // }
1505 };
1506 
1507 //----------------------------------------------------------------------------
1508 // 生配列型用Switcher2
1509 //----------------------------------------------------------------------------
1510 
1511 template<typename tArrayType, bool tIsRegister>
1512 struct Switcher2
1513 <
1514  tArrayType,
1515  tIsRegister,
1516  EnableIf<std::is_array<tArrayType>::value>
1517 >
1518 {
1519  typedef typename RemoveCV<tArrayType>::type ArrayType;
1520 
1521  // 最新版のバージョン番号返却
1522  static unsigned getLastVersionNo()
1523  {
1524  return ArrayTypeInfo<ArrayType>::getLastVersionNo();
1525  }
1526  // 型名返却
1527  static std::string getTypeName(VersionNoList const& iVersionNoList)
1528  {
1529  return ArrayTypeInfo<ArrayType>::getInstance().getTypeName(iVersionNoList);
1530  }
1531  // TypeIndex返却
1532  static std::size_t getTypeIndex()
1533  {
1534  return ArrayTypeInfo<ArrayType>::getInstance().mTypeIndex;
1535  }
1536  // そのまま返却
1537  static void const* getDerivedPointer(tArrayType* iPointer)
1538  {
1539  return iPointer;
1540  }
1541 };
1542 
1543 //----------------------------------------------------------------------------
1544 // ClassType用Switcher2
1545 //----------------------------------------------------------------------------
1546 
1547 // ---<<< 侵入型用Switcher2本体 >>>---
1548 
1549 template<class tClassType, bool tIsRegister>
1550 struct Switcher2
1551 <
1552  tClassType,
1553  tIsRegister,
1554  EnableIf<IsIntrusive<tClassType>::value>
1555 >
1556 {
1557  typedef typename std::remove_cv<tClassType>::type ClassType;
1558 
1559  // 最新版のバージョン番号返却
1560  static unsigned getLastVersionNo()
1561  {
1562  return ClassTypeInfo<ClassType>::getLastVersionNo();
1563  }
1564  // 型名返却
1565  static std::string getTypeName(VersionNoList const& iVersionNoList)
1566  {
1567  return ClassTypeInfo<ClassType>::getInstance().getTypeName(iVersionNoList);
1568  }
1569  // TypeIndex返却
1570  static std::size_t getTypeIndex()
1571  {
1572  return ClassTypeInfo<ClassType>::getInstance().mTypeIndex;
1573  }
1574  // 派生クラスのアドレスを返却
1575  static void const* getDerivedPointer(tClassType* iPointer)
1576  {
1577  return ClassTypeInfo<ClassType>::getInstance().getDerivedPointer(iPointer);
1578  }
1579 };
1580 
1581 // ---<<< 非侵入型用Switcher2本体 >>>---
1582 // 対象クラスがconstの場合、TheolizerNonIntrusive<>が別物になるので、
1583 // constを外したTheolizerNonIntrusive<>の有無をチェックする
1584 
1585 template<class tClassType, bool tIsRegister>
1586 struct Switcher2
1587 <
1588  tClassType,
1589  tIsRegister,
1590  EnableIf<IsNonIntrusive<tClassType>::value>
1591 >
1592 {
1593  typedef typename std::remove_cv<tClassType>::type ClassNoConst;
1594  typedef TheolizerNonIntrusive<ClassNoConst> ClassType;
1595 
1596  // 最新版のバージョン番号返却
1597  static unsigned getLastVersionNo()
1598  {
1599  return ClassTypeInfo<ClassType>::getLastVersionNo();
1600  }
1601  // 型名返却
1602  static std::string getTypeName(VersionNoList const& iVersionNoList)
1603  {
1604  return ClassTypeInfo<ClassType>::
1605  getInstance().getTypeName(iVersionNoList);
1606  }
1607  // TypeIndex返却
1608  static std::size_t getTypeIndex()
1609  {
1610  return ClassTypeInfo<ClassType>::getInstance().mTypeIndex;
1611  }
1612  // 派生クラスのアドレスを返却
1613  static void const* getDerivedPointer(tClassType* iPointer)
1614  {
1615  return ClassTypeInfo<ClassType>::getInstance().getDerivedPointer(iPointer);
1616  }
1617 };
1618 
1619 //----------------------------------------------------------------------------
1620 // EnumType用Switcher2
1621 //----------------------------------------------------------------------------
1622 
1623 template<typename tEnumType, bool tIsRegister>
1624 struct Switcher2
1625 <
1626  tEnumType,
1627  tIsRegister,
1628  EnableIf<std::is_enum<tEnumType>::value>
1629 >
1630 {
1631  typedef typename std::remove_cv<tEnumType>::type EnumType;
1632 
1633  // 最新版のバージョン番号返却
1634  static unsigned getLastVersionNo()
1635  {
1636  return EnumTypeInfo<EnumType>::getLastVersionNo();
1637  }
1638  // 型名返却
1639  static std::string getTypeName(VersionNoList const& iVersionNoList)
1640  {
1641  return EnumTypeInfo<EnumType>::getInstance().getTypeName(iVersionNoList);
1642  }
1643  // TypeIndex返却
1644  static std::size_t getTypeIndex()
1645  {
1646  return EnumTypeInfo<EnumType>::getInstance().mTypeIndex;
1647  }
1648  // そのまま返却
1649  static void const* getDerivedPointer(tEnumType* iPointer)
1650  {
1651  return iPointer;
1652  }
1653 };
1654 
1655 //----------------------------------------------------------------------------
1656 // プリミティブ型用Switcher2
1657 //----------------------------------------------------------------------------
1658 
1659 // ---<<< Primitive用Switcher2本体 >>>---
1660 // プリミティブへの参照の場合でも、save/loadPrimitiveにマッチする。
1661 // なので、参照の場合はここにマッチしないように条件を追加している。
1662 
1663 template<typename tPrimitiveType, bool tIsRegister>
1664 struct Switcher2
1665 <
1666  tPrimitiveType,
1667  tIsRegister,
1668  EnableIf<IsPrimitive<tPrimitiveType>::value>
1669 >
1670 {
1671  typedef typename std::remove_cv<tPrimitiveType>::type PrimitiveType;
1672 
1673  // 最新版のバージョン番号返却
1674  static unsigned getLastVersionNo()
1675  {
1676  return PrimitiveTypeInfo<PrimitiveType>::getLastVersionNo();
1677  }
1678  // 型名返却
1679  static std::string getTypeName(VersionNoList const& iVersionNoList)
1680  {
1681  return PrimitiveTypeInfo<PrimitiveType>::getInstance().getTypeName(iVersionNoList);
1682  }
1683  // TypeIndex返却
1684  static std::size_t getTypeIndex()
1685  {
1686  return PrimitiveTypeInfo<PrimitiveType>::getInstance().mTypeIndex;
1687  }
1688  // そのまま返却
1689  static void const* getDerivedPointer(tPrimitiveType* iPointer)
1690  {
1691  return iPointer;
1692  }
1693 };
1694 
1695 //----------------------------------------------------------------------------
1696 // TypeIndex取出し
1697 //----------------------------------------------------------------------------
1698 
1699 template<typename tType>
1700 std::size_t getTypeIndex()
1701 {
1702  typedef typename std::remove_reference<tType>::type Type;
1703  return Switcher2<Type>::getTypeIndex();
1704 }
1705 
1706 //----------------------------------------------------------------------------
1707 // 派生クラスの先頭アドレス返却
1708 // クラスでない場合は、そのまま返却
1709 //----------------------------------------------------------------------------
1710 
1711 template<typename tType>
1712 void const* getDerivedPointer(tType* iPointer)
1713 {
1714  return Switcher2<tType>::getDerivedPointer(iPointer);
1715 //return nullptr;
1716 }
1717 
1718 // ***************************************************************************
1719 // TypeInfoからのSwitcher2呼び出し
1720 // ***************************************************************************
1721 
1722 //----------------------------------------------------------------------------
1723 // PointerTypeInfo
1724 // aIndexについて
1725 // iVersionNoは
1726 // 型がClassTypeの場合、プリミティブ化されている時
1727 // iSerializerVersionNoが変化する
1728 // 型がプリミティブの場合、iSerializerVersionNoは0固定
1729 // 型がenumの場合、iSerializerVersionNoは0固定
1730 // tMidSerializerがiVersionNoとiSerializerVersionNoの組み合わせを
1731 // 決定する。
1732 // また、iVersionNoとiSerializerVersionNoは、両方共単調増加である。
1733 // 従って、同じaIndex値となるiVersionNoとiSerializerVersionNoの
1734 // 組み合わせはtMidSerializer毎に一意である。
1735 // 例:
1736 // プリミティブ化状況 ClassType 派生Serialzier GlobalVersionNo aIndex
1737 // ノーマル 0 0 0 0
1738 // プリミティブ化 0 1 1 1
1739 // クラスVersionUp 1 1 2 2
1740 // 他クラスVersionUp 1 1 3 2
1741 // Serializer VersionUp 1 2 4 3
1742 // 非プリミティブ化 1 3 5 4
1743 // クラスVersionUp 2 3 6 5
1744 //----------------------------------------------------------------------------
1745 
1746 // ---<<< 型名獲得 >>>---
1747 
1748 template<typename tPointerType>
1749 unsigned PointerTypeInfo<tPointerType>::getLastVersionNo()
1750 {
1751  typedef typename std::remove_pointer<tPointerType>::type ParentType;
1752  return Switcher2<ParentType>::getLastVersionNo();
1753 }
1754 
1755 template<typename tPointerType>
1756 std::string PointerTypeInfo<tPointerType>::
1757  getTypeName(VersionNoList const& iVersionNoList)
1758 {
1759  typedef typename std::remove_pointer<tPointerType>::type ParentType;
1760  return Switcher2<ParentType>::getTypeName(iVersionNoList)+"*";
1761 }
1762 
1763 // ---<<< ポイントされている型のBaseTypeInfo*獲得 >>>---
1764 
1765 template<typename tPointerType>
1766 BaseTypeInfo* PointerTypeInfo<tPointerType>::getPointeeTypeInfo()
1767 {
1768  typedef typename std::remove_pointer<tPointerType>::type ParentType;
1769  std::size_t aTypeIndex = Switcher2<ParentType>::getTypeIndex();
1770  return TypeInfoList::getInstance().getList().at(aTypeIndex);
1771 }
1772 
1773 //----------------------------------------------------------------------------
1774 // ArrayTypeInfo
1775 //----------------------------------------------------------------------------
1776 
1777 template<typename tArrayType>
1778 unsigned ArrayTypeInfo<tArrayType>::getLastVersionNo()
1779 {
1780  typedef typename std::remove_extent<tArrayType>::type ParentType;
1781  return Switcher2<ParentType>::getLastVersionNo();
1782 }
1783 
1784 template<typename tArrayType>
1785 std::string ArrayTypeInfo<tArrayType>::
1786  getTypeName(VersionNoList const& iVersionNoList)
1787 {
1788  typedef typename std::remove_extent<tArrayType>::type ParentType;
1789  std::string ret = Switcher2<ParentType>::getTypeName(iVersionNoList);
1790  if (iVersionNoList.isMetaMode())
1791  {
1792  // []の順序が逆になるのでひっくり返す
1793  std::size_t pos=ret.find('[');
1794  std::string aExtent;
1795  if (pos != std::string::npos)
1796  {
1797  aExtent = ret.substr(pos);
1798  ret = ret.substr(0, pos);
1799  }
1800  ret.push_back('[');
1801  ret.append(std::to_string(std::extent<tArrayType>::value));
1802  ret.push_back(']');
1803  ret.append(aExtent);
1804  }
1805  else
1806  { // []の順序は逆だが、中身がないのでひっくり返す必要無し
1807  ret.append("[]");
1808  }
1809  return ret;
1810 }
1811 
1812 // 基本型のTypeIndex返却
1813 template<typename tArrayType>
1814 std::size_t ArrayTypeInfo<tArrayType>::
1815  getUnderlyingTypeIndex()
1816 {
1817  typedef typename std::remove_all_extents<tArrayType>::type UnderlyingType;
1818  return getTypeIndex<UnderlyingType>();
1819 }
1820 
1821 //############################################################################
1822 // 型名生成補助ツール
1823 //############################################################################
1824 
1825 // ***************************************************************************
1826 // 派生Serializerが提供するプリミティブ名獲得用クラスのプライマリー定義
1827 // ***************************************************************************
1828 
1829 template<class tMidSerializer, typename tPrimitive, class tEnable=void>
1830 struct PrimitiveName { };
1831 
1832 // ***************************************************************************
1833 // クラス・テンプレート型名
1834 // ***************************************************************************
1835 
1836 //----------------------------------------------------------------------------
1837 // 非型パラメータ用補助テンプレート
1838 //----------------------------------------------------------------------------
1839 
1840 template<typename tType, tType tValue, class tEnable=void>
1841 struct NonType
1842 {
1843  static std::string get()
1844  {
1845  return std::to_string(tValue);
1846  }
1847 };
1848 
1849 template<typename tType, tType tValue>
1850 struct NonType<tType, tValue, EnableIf<std::is_enum<tType>::value> >
1851 {
1852  static std::string get()
1853  {
1854  typedef typename std::underlying_type<tType>::type Type;
1855  Type mValue=static_cast<Type>(tValue);
1856  return std::to_string(mValue);
1857  }
1858 };
1859 
1860 //----------------------------------------------------------------------------
1861 // テンプレート・パラメータ展開処理
1862 //----------------------------------------------------------------------------
1863 
1864 // ---<<< プライマリー >>>---
1865 
1866 template<typename... tRest>
1867 struct ParameterName
1868 {
1869  static std::string get(VersionNoList const& iVersionNoList)
1870  {
1871  return "";
1872  }
1873 };
1874 
1875 // ---<<< 非プリミティブ用特殊化 >>>---
1876 
1877 template<typename tClass, typename... tRest>
1878 struct ParameterName<tClass, tRest...>
1879 {
1880  static std::string get(VersionNoList const& iVersionNoList)
1881  {
1882  std::string aName=Switcher2<tClass>::getTypeName(iVersionNoList);
1883  if (sizeof...(tRest))
1884  {
1885  aName = aName+","+ParameterName<tRest...>::get(iVersionNoList);
1886  }
1887  return aName;
1888  }
1889 };
1890 
1891 // ---<<< 非型用特殊化 >>>---
1892 
1893 template<typename tType, tType tValue, typename... tRest>
1894 struct ParameterName<NonType<tType, tValue>, tRest...>
1895 {
1896  static std::string get(VersionNoList const& iVersionNoList)
1897  {
1898  std::string aName=NonType<tType, tValue>::get();
1899  if (sizeof...(tRest))
1900  {
1901  aName = aName+","+ParameterName<tRest...>::get(iVersionNoList);
1902  }
1903  return aName;
1904  }
1905 };
1906 
1907 // ---<<< プリミティブ用特殊化 >>>---
1908 
1909 #define THEOLIZER_INTERNAL_DEF_PRIMITIVE(dType, dSymbol) \
1910  template<typename... tRest> \
1911  struct ParameterName<dType, tRest...> \
1912  { \
1913  static std::string get(VersionNoList const& iVersionNoList) \
1914  { \
1915  std::size_t aTypeIndex=PrimitiveTypeInfo<dType>::getInstance().mTypeIndex;\
1916  unsigned aSerializerVersionNo=iVersionNoList.at(aTypeIndex); \
1917  static dType aType; \
1918  std::string aName=BaseTypeFunctions::getInstance(). \
1919  getPrimitiveName(aSerializerVersionNo, aType); \
1920  if (sizeof...(tRest)) { \
1921  aName = aName+","+ParameterName<tRest...>::get(iVersionNoList);\
1922  } \
1923  return aName; \
1924  } \
1925  };
1926 #include "primitive.inc"
1927 
1928 #define THEOLIZER_INTERNAL_DEF_PRIMITIVE(dType, dSymbol) \
1929  template<typename... tRest> \
1930  struct ParameterName<dType const, tRest...> \
1931  { \
1932  static std::string get(VersionNoList const& iVersionNoList) \
1933  { \
1934  std::size_t aTypeIndex=PrimitiveTypeInfo<dType>::getInstance().mTypeIndex;\
1935  unsigned aSerializerVersionNo=iVersionNoList.at(aTypeIndex); \
1936  static dType aType; \
1937  std::string aName=BaseTypeFunctions::getInstance(). \
1938  getPrimitiveName(aSerializerVersionNo, aType); \
1939  if (sizeof...(tRest)) { \
1940  aName = aName+","+ParameterName<tRest...>::get(iVersionNoList);\
1941  } \
1942  return aName; \
1943  } \
1944  };
1945 #include "primitive.inc"
1946 
1947 // ---<<< void用特殊化 >>>---
1948 
1949 /*!
1950  ... text ...
1951 */
1952 
1953 template<typename... tRest>
1954 struct ParameterName<void, tRest...>
1955 {
1956  static std::string get(BaseSerializer& iSerializer)
1957  {
1958  std::string aName;
1959  aName="void";
1960  if (sizeof...(tRest))
1961  {
1962  aName = aName+","+ParameterName<tRest...>::get(iSerializer);
1963  }
1964  return aName;
1965  }
1966 };
1967 
1968 //----------------------------------------------------------------------------
1969 // テンプレート・パラメータ展開入口
1970 //----------------------------------------------------------------------------
1971 
1972 template<typename... tArgs>
1973 char const* makeTemplateName(char const* iName, VersionNoList const& iVersionNoList)
1974 {
1975  static std::string gStaticString;
1976 
1977  if (iVersionNoList.isMetaMode())
1978  {
1979  gStaticString = std::string(iName) + "<"
1980  + ParameterName<tArgs...>::get(iVersionNoList)
1981  + ">";
1982 return gStaticString.c_str();
1983  }
1984  else
1985  {
1986  gStaticString = std::string(iName) + "<"
1987  + ParameterName<tArgs...>::get(iVersionNoList)
1988  + ">";
1989 return gStaticString.c_str();
1990  }
1991 }
1992 
1993 #define THEOLIZER_INTERNAL_MAKE_TEMPLATE_NAME(dName, ...) \
1994  theolizer::internal::makeTemplateName<__VA_ARGS__>(dName, iVersionNoList)
1995 
1996 //############################################################################
1997 // End
1998 //############################################################################
1999 
2000 #endif // THEOLIZER_INTERNAL_DOXYGEN
2001 } // namespace internal
2002 } // namespace theolizer
2003 
2004 // ***************************************************************************
2005 // 警告抑止解除
2006 // ***************************************************************************
2007 
2008 #ifdef _MSC_VER
2009  #pragma warning(pop)
2010 #endif
2011 
2012 #endif // THEOLIZER_INTERNAL_CORE_TYPE_INFO_H
theolizer名前空間
Definition: base.h:53
Theolizerライブラリのコア部(型情報リスト)