1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
|
/* { dg-do link } */
/* { dg-timeout-factor 2.0 } */
namespace Loki
{
class NullType {};
template <class T, class U>
struct Typelist
{
typedef T Head;
typedef U Tail;
};
namespace TL
{
template
<
typename T1 = NullType, typename T2 = NullType, typename T3 =
NullType,
typename T4 = NullType, typename T5 = NullType, typename T6 =
NullType,
typename T7 = NullType, typename T8 = NullType, typename T9 =
NullType,
typename T10 = NullType, typename T11 = NullType, typename T12
= NullType,
typename T13 = NullType, typename T14 = NullType, typename T15
= NullType,
typename T16 = NullType, typename T17 = NullType, typename T18
= NullType,
typename T19 = NullType, typename T20 = NullType, typename T21
= NullType,
typename T22 = NullType, typename T23 = NullType, typename T24
= NullType,
typename T25 = NullType, typename T26 = NullType, typename T27
= NullType,
typename T28 = NullType, typename T29 = NullType, typename T30
= NullType,
typename T31 = NullType, typename T32 = NullType, typename T33
= NullType,
typename T34 = NullType, typename T35 = NullType, typename T36
= NullType,
typename T37 = NullType, typename T38 = NullType, typename T39
= NullType,
typename T40 = NullType
>
struct MakeTypelist
{
private:
typedef typename MakeTypelist
<
T2 , T3 , T4 ,
T5 , T6 , T7 ,
T8 , T9 , T10,
T11, T12, T13,
T14, T15, T16,
T17, T18, T19,
T20, T21, T22,
T23, T24, T25,
T26, T27, T28,
T29, T30, T31,
T32, T33, T34,
T35, T36, T37,
T38, T39, T40
>
::Result TailResult;
public:
typedef Typelist<T1, TailResult> Result;
};
template<>
struct MakeTypelist<>
{
typedef NullType Result;
};
}
}
template <class Key>
class Factory;
template <class Key, bool iW>
struct Context
{
typedef Key KeyType;
enum
{
isWrite = iW
};
};
namespace detail
{
template <class Key, bool isWrite>
class CreatorUnitBaseImpl
{
public:
typedef Context<Key, isWrite> Context_;
private:
typedef void*(CreatorUnitBaseImpl::*CreateFun)(Context_&, unsigned&, const
Key&);
CreateFun createFun_;
protected:
virtual void* createUninitialized () = 0;
template <class Value>
void* createImpl (Context_& ctx, unsigned& ver, const Key& k)
{
return createUninitialized();
}
private:
CreatorUnitBaseImpl();
public:
template <class Value>
CreatorUnitBaseImpl (Value*) :
createFun_( &CreatorUnitBaseImpl::template createImpl<Value> )
{
}
virtual ~CreatorUnitBaseImpl () {}
CreatorUnitBaseImpl(const CreatorUnitBaseImpl& s)
: createFun_(s.createFun_)
{
}
CreatorUnitBaseImpl& operator=(const CreatorUnitBaseImpl& s)
{
createFun_ = s.createFun_;
return *this;
}
void* create (Context_& ctx, unsigned& ver, const Key& k)
{
return (this->*createFun_)(ctx, ver, k);
}
};
template <class Key>
class Creator : protected CreatorUnitBaseImpl<Key, true>, protected
CreatorUnitBaseImpl<Key, false>
{
public:
typedef void* (*CreatorFun) ();
private:
CreatorFun fun_;
protected:
virtual void* createUninitialized ()
{
if (fun_)
return (*fun_)();
return 0;
}
private:
Creator ();
public:
template <class Value>
Creator (CreatorFun f, Value*) :
CreatorUnitBaseImpl<Key, true>((Value*)0),
CreatorUnitBaseImpl<Key, false>((Value*)0),
fun_(f)
{
}
Creator(const Creator& s) :
CreatorUnitBaseImpl<Key, true>(s),
CreatorUnitBaseImpl<Key, false>(s),
fun_(s.fun_)
{
}
Creator& operator=(const Creator& s)
{
CreatorUnitBaseImpl<Key, true>::operator=(s);
CreatorUnitBaseImpl<Key, false>::operator=(s);
fun_ = s.fun_;
return *this;
}
virtual ~Creator ()
{
}
template <class Context>
void* createObject (Context& ctx, unsigned& ver, const Key& k)
{
void* r = CreatorUnitBaseImpl<Key, Context::isWrite>::create(ctx, ver,
k);
return r;
}
};
}
template <class Key>
class Factory
{
public:
typedef Key KeyType;
typedef void* (*CreatorFun) ();
typedef detail::Creator<Key> Creator;
public:
Factory () {}
~Factory () {}
template <class Value>
bool registerCreator (const Key& k, CreatorFun fun)
{
return true;
}
template <class Context>
void* createObject (const Key& k, Context& ctx, unsigned& ver)
{
return 0;
}
};
template <class Key, class Base, Key key>
struct ClassSpec
{
typedef Key KeyType;
typedef Base BaseType;
enum {KeyValue = key};
};
template <class Key, class T>
class Serializer;
template <class Key, class Base, Key key>
class Serializer<Key, ClassSpec <Key, Base, key> >
: public virtual Factory<Key>
{
typedef Key KeyType;
typedef Base BaseType;
enum {KeyValue = key};
typedef Factory<Key> Inherited;
typedef Serializer<Key, ClassSpec< Key, Base, key > > SelfType;
static void* create ()
{
return (void*) (new BaseType);
}
public:
Serializer()
{
Inherited::template registerCreator<BaseType>(
KeyValue,
&SelfType::create);
}
};
template <class Key, class Head>
class Serializer<Key, Loki::Typelist<Head, Loki::NullType> >:
public Serializer<Key, Head>
{
};
template <class Key, class Head, class Tail>
class Serializer<Key, Loki::Typelist<Head, Tail> >:
public virtual Serializer<Key, Head>,
public virtual Serializer<Key, Tail>
{
};
template <class Key>
class Serializer<Key, Loki::NullType> : public virtual Factory<Key>
{
};
typedef unsigned KeyType;
typedef Factory<KeyType> FactoryType;
typedef KeyType Key;
struct A001
{
template <class Context>
bool serialize(Context& ctx, unsigned& ver)
{
return true;
}
static Key classId() { return 1; }
static const char* className () {return "A001";}
};
struct A002
{
template <class Context>
bool serialize(Context& ctx, unsigned& ver)
{
return true;
}
static Key classId() { return 2; }
static const char* className () {return "A002";}
};
struct A003
{
template <class Context>
bool serialize(Context& ctx, unsigned& ver)
{
return true;
}
static Key classId() { return 3; }
static const char* className () {return "A003";}
};
struct A004
{
template <class Context>
bool serialize(Context& ctx, unsigned& ver)
{
return true;
}
static Key classId() { return 4; }
static const char* className () {return "A004";}
};
struct A005
{
template <class Context>
bool serialize(Context& ctx, unsigned& ver)
{
return true;
}
static Key classId() { return 5; }
static const char* className () {return "A005";}
};
struct A006
{
template <class Context>
bool serialize(Context& ctx, unsigned& ver)
{
return true;
}
static Key classId() { return 6; }
static const char* className () {return "A006";}
};
struct A007
{
template <class Context>
bool serialize(Context& ctx, unsigned& ver)
{
return true;
}
static Key classId() { return 7; }
static const char* className () {return "A007";}
};
struct A008
{
template <class Context>
bool serialize(Context& ctx, unsigned& ver)
{
return true;
}
static Key classId() { return 8; }
static const char* className () {return "A008";}
};
struct A009
{
template <class Context>
bool serialize(Context& ctx, unsigned& ver)
{
return true;
}
static Key classId() { return 9; }
static const char* className () {return "A009";}
};
struct A010
{
template <class Context>
bool serialize(Context& ctx, unsigned& ver)
{
return true;
}
static Key classId() { return 10; }
static const char* className () {return "A010";}
};
struct A011
{
template <class Context>
bool serialize(Context& ctx, unsigned& ver)
{
return true;
}
static Key classId() { return 11; }
static const char* className () {return "A011";}
};
struct A012
{
template <class Context>
bool serialize(Context& ctx, unsigned& ver)
{
return true;
}
static Key classId() { return 12; }
static const char* className () {return "A012";}
};
struct A013
{
template <class Context>
bool serialize(Context& ctx, unsigned& ver)
{
return true;
}
static Key classId() { return 13; }
static const char* className () {return "A013";}
};
struct A014
{
template <class Context>
bool serialize(Context& ctx, unsigned& ver)
{
return true;
}
static Key classId() { return 14; }
static const char* className () {return "A014";}
};
struct A015
{
template <class Context>
bool serialize(Context& ctx, unsigned& ver)
{
return true;
}
static Key classId() { return 15; }
static const char* className () {return "A015";}
};
struct A016
{
template <class Context>
bool serialize(Context& ctx, unsigned& ver)
{
return true;
}
static Key classId() { return 16; }
static const char* className () {return "A016";}
};
struct A017
{
template <class Context>
bool serialize(Context& ctx, unsigned& ver)
{
return true;
}
static Key classId() { return 17; }
static const char* className () {return "A017";}
};
struct A018
{
template <class Context>
bool serialize(Context& ctx, unsigned& ver)
{
return true;
}
static Key classId() { return 18; }
static const char* className () {return "A018";}
};
struct A019
{
template <class Context>
bool serialize(Context& ctx, unsigned& ver)
{
return true;
}
static Key classId() { return 19; }
static const char* className () {return "A019";}
};
struct A020
{
template <class Context>
bool serialize(Context& ctx, unsigned& ver)
{
return true;
}
static Key classId() { return 20; }
static const char* className () {return "A020";}
};
struct A021
{
template <class Context>
bool serialize(Context& ctx, unsigned& ver)
{
return true;
}
static Key classId() { return 21; }
static const char* className () {return "A021";}
};
struct A022
{
template <class Context>
bool serialize(Context& ctx, unsigned& ver)
{
return true;
}
static Key classId() { return 22; }
static const char* className () {return "A022";}
};
struct A023
{
template <class Context>
bool serialize(Context& ctx, unsigned& ver)
{
return true;
}
static Key classId() { return 23; }
static const char* className () {return "A023";}
};
struct A024
{
template <class Context>
bool serialize(Context& ctx, unsigned& ver)
{
return true;
}
static Key classId() { return 24; }
static const char* className () {return "A024";}
};
struct A025
{
template <class Context>
bool serialize(Context& ctx, unsigned& ver)
{
return true;
}
static Key classId() { return 25; }
static const char* className () {return "A025";}
};
struct A026
{
template <class Context>
bool serialize(Context& ctx, unsigned& ver)
{
return true;
}
static Key classId() { return 26; }
static const char* className () {return "A026";}
};
struct A027
{
template <class Context>
bool serialize(Context& ctx, unsigned& ver)
{
return true;
}
static Key classId() { return 27; }
static const char* className () {return "A027";}
};
struct A028
{
template <class Context>
bool serialize(Context& ctx, unsigned& ver)
{
return true;
}
static Key classId() { return 28; }
static const char* className () {return "A028";}
};
struct A029
{
template <class Context>
bool serialize(Context& ctx, unsigned& ver)
{
return true;
}
static Key classId() { return 29; }
static const char* className () {return "A029";}
};
struct A030
{
template <class Context>
bool serialize(Context& ctx, unsigned& ver)
{
return true;
}
static Key classId() { return 30; }
static const char* className () {return "A030";}
};
struct A031
{
template <class Context>
bool serialize(Context& ctx, unsigned& ver)
{
return true;
}
static Key classId() { return 31; }
static const char* className () {return "A031";}
};
struct A032
{
template <class Context>
bool serialize(Context& ctx, unsigned& ver)
{
return true;
}
static Key classId() { return 32; }
static const char* className () {return "A032";}
};
struct A033
{
template <class Context>
bool serialize(Context& ctx, unsigned& ver)
{
return true;
}
static Key classId() { return 33; }
static const char* className () {return "A033";}
};
struct A034
{
template <class Context>
bool serialize(Context& ctx, unsigned& ver)
{
return true;
}
static Key classId() { return 34; }
static const char* className () {return "A034";}
};
struct A035
{
template <class Context>
bool serialize(Context& ctx, unsigned& ver)
{
return true;
}
static Key classId() { return 35; }
static const char* className () {return "A035";}
};
struct A036
{
template <class Context>
bool serialize(Context& ctx, unsigned& ver)
{
return true;
}
static Key classId() { return 36; }
static const char* className () {return "A036";}
};
struct A037
{
template <class Context>
bool serialize(Context& ctx, unsigned& ver)
{
return true;
}
static Key classId() { return 37; }
static const char* className () {return "A037";}
};
struct A038
{
template <class Context>
bool serialize(Context& ctx, unsigned& ver)
{
return true;
}
static Key classId() { return 38; }
static const char* className () {return "A038";}
};
struct A039
{
template <class Context>
bool serialize(Context& ctx, unsigned& ver)
{
return true;
}
static Key classId() { return 39; }
static const char* className () {return "A039";}
};
struct A040
{
template <class Context>
bool serialize(Context& ctx, unsigned& ver)
{
return true;
}
static Key classId() { return 40; }
static const char* className () {return "A040";}
};
Factory<Key>& getInstance()
{
static Serializer<Key,
Loki::TL::MakeTypelist<
ClassSpec<Key, A001, 1>,
ClassSpec<Key, A002, 2>,
ClassSpec<Key, A003, 3>,
ClassSpec<Key, A004, 4>,
ClassSpec<Key, A005, 5>,
ClassSpec<Key, A006, 6>,
ClassSpec<Key, A007, 7>,
ClassSpec<Key, A008, 8>,
ClassSpec<Key, A009, 9>,
ClassSpec<Key, A010, 10>,
ClassSpec<Key, A011, 11>,
ClassSpec<Key, A012, 12>,
ClassSpec<Key, A013, 13>,
ClassSpec<Key, A014, 14>,
ClassSpec<Key, A015, 15>,
ClassSpec<Key, A016, 16>,
ClassSpec<Key, A017, 17>,
ClassSpec<Key, A018, 18>,
ClassSpec<Key, A019, 19>,
ClassSpec<Key, A020, 20>,
ClassSpec<Key, A021, 21>,
ClassSpec<Key, A022, 22>,
ClassSpec<Key, A023, 23>,
ClassSpec<Key, A024, 24>,
ClassSpec<Key, A025, 25>,
ClassSpec<Key, A026, 26>,
ClassSpec<Key, A027, 27>,
ClassSpec<Key, A028, 28>,
ClassSpec<Key, A029, 29>,
ClassSpec<Key, A030, 30>,
ClassSpec<Key, A031, 31>,
ClassSpec<Key, A032, 32>,
ClassSpec<Key, A033, 33>,
ClassSpec<Key, A034, 34>,
ClassSpec<Key, A035, 35>,
ClassSpec<Key, A036, 36>,
ClassSpec<Key, A037, 37>,
ClassSpec<Key, A038, 38>,
ClassSpec<Key, A039, 39>,
ClassSpec<Key, A040, 40>
>::Result
> instance;
return instance;
}
int main ()
{
return 0;
}
|