-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunion.hpp
3861 lines (3453 loc) · 157 KB
/
union.hpp
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
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifndef ___FCF__UNION__UNION_HPP___
#define ___FCF__UNION__UNION_HPP___
#pragma warning(push)
#pragma warning(disable: 5045)
#include <stdexcept>
#include <algorithm>
#include <memory>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <iostream>
#ifdef FCF_IMPLEMENTATION
#define FCF_UNION_IMPLEMENTATION
#endif
#ifndef FCF_UNION_DELC_EXTERN
#ifdef FCF_UNION_IMPLEMENTATION
#define FCF_UNION_DELC_EXTERN
#else
#define FCF_UNION_DELC_EXTERN extern
#endif
#endif
#ifndef FCF_UNION_DECL_TEMPLATE_EXTERN
#ifdef _MSC_VER
#define FCF_UNION_DECL_TEMPLATE_EXTERN
#else
#ifdef FCF_UNION_IMPLEMENTATION
#define FCF_UNION_DECL_TEMPLATE_EXTERN
#else
#define FCF_UNION_DECL_TEMPLATE_EXTERN extern
#endif
#endif
#endif
#ifndef FCF_UNION_DECL_EXPORT
#ifdef WIN32
#if defined(FCF_UNION_EXPORT)
#define FCF_UNION_DECL_EXPORT __declspec(dllexport)
#elif defined(FCF_UNION_IMPORT)
#define FCF_UNION_DECL_EXPORT __declspec(dllimport)
#else
#define FCF_UNION_DECL_EXPORT
#endif
#else
#define FCF_UNION_DECL_EXPORT
#endif
#endif
#ifndef WIN32
#define FCF_UNION_DECL_VISIBILITY_HIDDEN __attribute__((visibility("hidden")))
#else
#define FCF_UNION_DECL_VISIBILITY_HIDDEN
#endif
namespace fcf {
#ifndef FCF_THROW_OR_RESULT_ERROR
#define FCF_THROW_OR_RESULT_ERROR(a_dstError, a_errorMessage, a_resolver, a_ignoreFirst) \
if (a_dstError) { \
*a_dstError = a_errorMessage; \
} else { \
throw UnionException(a_errorMessage, a_resolver.line(), a_resolver.column(), a_ignoreFirst); \
}
#endif
#ifndef FCF_CONST_CHAR_PTR_DEFINED
#define FCF_CONST_CHAR_PTR_DEFINED
typedef const char* ConstCharPtr;
#endif
#ifndef FCF_CHAR_PTR_DEFINED
#define FCF_CHAR_PTR_DEFINED
typedef char* CharPtr;
#endif
#ifndef FCF_JSON_FORMAT_STRUCT_DEFINED
#define FCF_JSON_FORMAT_STRUCT_DEFINED
struct JSONFormat {};
#endif
#ifndef FCF_TNOP_STRUCT_DEFINED
#define FCF_TNOP_STRUCT_DEFINED
struct TNOP {};
#endif
#ifndef FCF_UNDEFINED_STRUCT_DEFINED
#define FCF_UNDEFINED_STRUCT_DEFINED
struct Undefined {
bool operator < (const Undefined& a_value) const { return false; }
bool operator == (const Undefined& a_value) const { return true; }
bool operator != (const Undefined& a_value) const { return false; }
};
FCF_UNION_DELC_EXTERN FCF_UNION_DECL_EXPORT Undefined undefined;
#endif
#ifndef FCF_NULL_STRUCT_DEFINED
#define FCF_NULL_STRUCT_DEFINED
struct Null {
bool operator < (const Null& a_value) const { return false; }
bool operator == (const Null& a_value) const { return true; }
bool operator != (const Null& a_value) const { return false; }
};
FCF_UNION_DELC_EXTERN FCF_UNION_DECL_EXPORT Null null;
#endif
enum UnionFormat {
SF_VALUE = 0,
SF_JSON = 1
};
struct UnionStringifyOptions {
bool friendly;
const char* tab;
UnionFormat mode;
UnionStringifyOptions()
: friendly(false)
, tab(" ")
, mode(SF_JSON) {
}
};
namespace Details {
namespace NUnion {
template <typename Ty>
struct TypeHelper;
}
}
struct Union;
struct UnionMapLess{
template <typename Ty>
inline bool operator()(const Ty& a_left, const Ty& a_right) const{
return a_left.lessStr(a_right);
}
};
typedef std::vector<Union> UnionVector;
typedef std::map<Union, Union, UnionMapLess> UnionMap;
enum UnionType{
UT_UNDEFINED,
UT_NULL,
UT_INT,
UT_UINT,
UT_LONGLONG,
UT_ULONGLONG,
UT_DOUBLE,
UT_BOOL,
UT_STRING,
UT_VECTOR,
UT_MAP,
};
enum { FIRST_NUMBER_TYPE = UT_INT };
enum { LAST_NUMBER_TYPE = UT_DOUBLE };
union UnionValue{
Undefined vundefined;
Null vnull;
int vint;
long long vlonglong;
double vdouble;
bool vbool;
char vstring[sizeof(std::string)];
char vvector[sizeof(UnionVector)];
char vmap[sizeof(UnionMap)];
};
class UnionException : public std::runtime_error {
public:
inline UnionException(const char* a_message)
: runtime_error(a_message)
, _line(SIZE_MAX)
, _column(SIZE_MAX) {
}
inline UnionException(const char* a_message, size_t a_line, size_t a_col)
: runtime_error(_tostr(a_message, a_line, a_col))
, _line(a_line)
, _column(a_col) {
}
inline UnionException(const char* a_message, size_t a_line, size_t a_col, bool a_ignoreFirst)
: runtime_error(_tostr(a_message, a_ignoreFirst && a_line == 1 && a_col == 1 ? SIZE_MAX : a_line, a_ignoreFirst && a_line == 1 && a_col == 1 ? SIZE_MAX : a_col))
, _line(a_ignoreFirst && a_line == 1 && a_col == 1 ? SIZE_MAX: a_line)
, _column(a_ignoreFirst && a_line == 1 && a_col == 1 ? SIZE_MAX: a_col) {
}
inline size_t line() const{
return _line;
}
inline size_t column() const {
return _column;
}
inline std::string swhat() const {
std::string w = what();
const char* p = strstr(w.c_str(), " [");
return std::string(p ? w.substr(0, p - w.c_str()) : w);
}
protected:
FCF_UNION_DECL_EXPORT static std::string _tostr(const char* a_message, size_t a_line, size_t a_col);
size_t _line;
size_t _column;
};
struct Union {
UnionValue value;
UnionType type;
size_t orderc;
size_t order;
struct FCF_UNION_DECL_EXPORT base_iterator {
friend struct Union;
typedef std::shared_ptr< std::vector< UnionMap::iterator > > oiterators_type;
struct oiterator_type {
oiterators_type iterators;
std::vector< UnionMap::iterator >::iterator iterator;
};
enum IteratorType{
IT_UNDEFINED,
IT_VECTOR,
IT_MAP,
IT_OMAP
};
union value_iterator{
char vivector[sizeof(UnionVector::iterator)];
char vcivector[sizeof(UnionVector::const_iterator)];
char vimap[sizeof(UnionMap::iterator)];
char vcimap[sizeof(UnionMap::const_iterator)];
char voiterators[sizeof(oiterator_type)];
};
base_iterator();
base_iterator(oiterators_type a_iterators, std::vector< UnionMap::iterator >::iterator a_iterator, const UnionMap* a_owner);
base_iterator(const base_iterator& a_iterator);
~base_iterator();
base_iterator& operator=(const base_iterator& a_iterator);
bool operator ==(const base_iterator& a_it) const;
bool operator !=(const base_iterator& a_it) const;
base_iterator& operator++();
base_iterator operator++(int);
Union key() const;
protected:
bool _isend() const;
value_iterator _viiterator;
IteratorType _vitype;
void* _owner;
};
template <typename TPointer, typename TRef, typename TMapIterator, typename TVectorIterator>
struct FCF_UNION_DECL_EXPORT basic_iterator : public base_iterator {
using base_iterator::base_iterator;
inline basic_iterator() : base_iterator(){};
basic_iterator(TVectorIterator a_iterator, const UnionVector* a_owner);
basic_iterator(TMapIterator a_iterator, const UnionMap* a_owner);
TPointer operator->();
inline TRef operator*() { return *(operator->()); }
inline TRef value() { return *(operator->()); }
};
typedef Union& TRef;
typedef const Union& TConstRef;
typedef Union* TPointer;
typedef const Union* TConstPointer;
typedef basic_iterator<TPointer, TRef, UnionMap::iterator, UnionVector::iterator> iterator;
typedef basic_iterator<TConstPointer, TConstRef, UnionMap::const_iterator, UnionVector::const_iterator> const_iterator;
FCF_UNION_DECL_EXPORT Union();
FCF_UNION_DECL_EXPORT Union(const Union& a_union);
FCF_UNION_DECL_EXPORT Union(UnionType a_type);
template <typename Ty>
FCF_UNION_DECL_EXPORT Union(const Ty& a_value);
FCF_UNION_DECL_EXPORT Union(const char* a_value);
FCF_UNION_DECL_EXPORT ~Union();
FCF_UNION_DECL_EXPORT iterator obegin();
FCF_UNION_DECL_EXPORT iterator oend();
FCF_UNION_DECL_EXPORT const_iterator cobegin() const;
FCF_UNION_DECL_EXPORT const_iterator coend() const;
FCF_UNION_DECL_EXPORT iterator begin();
FCF_UNION_DECL_EXPORT iterator end();
FCF_UNION_DECL_EXPORT const_iterator cbegin() const;
FCF_UNION_DECL_EXPORT const_iterator cend() const;
FCF_UNION_DECL_EXPORT size_t size() const;
FCF_UNION_DECL_EXPORT iterator find(Union a_key);
FCF_UNION_DECL_EXPORT const Union& cat(Union a_key) const;
FCF_UNION_DECL_EXPORT Union& at(Union a_key);
FCF_UNION_DECL_EXPORT Union& operator[](Union a_key);
FCF_UNION_DECL_EXPORT iterator insert(Union a_value);
FCF_UNION_DECL_EXPORT iterator insert(Union a_key, Union a_value);
FCF_UNION_DECL_EXPORT iterator erase(const Union& a_key);
FCF_UNION_DECL_EXPORT iterator erase(const iterator& a_iterator);
FCF_UNION_DECL_EXPORT void swap(Union& a_union);
template <typename Ty>
FCF_UNION_DECL_EXPORT bool is() const;
inline bool is(UnionType a_type) const
{ return type == a_type; }
template <typename Ty>
inline bool isCompatible(bool a_stringifyMode = false) const
{ return isCompatible((UnionType)fcf::Details::NUnion::TypeHelper<Ty>::type_index, a_stringifyMode); }
FCF_UNION_DECL_EXPORT bool isCompatible(UnionType a_type, bool a_stringifyMode = false) const;
FCF_UNION_DECL_EXPORT void parse(const std::string& a_source);
FCF_UNION_DECL_EXPORT void parse(std::basic_istream<char>& a_source);
FCF_UNION_DECL_EXPORT void stringify(std::string& a_dest, const UnionStringifyOptions& a_options = UnionStringifyOptions{}) const;
FCF_UNION_DECL_EXPORT void stringify(std::basic_ostream<char>& a_dest, const UnionStringifyOptions& a_options = UnionStringifyOptions{}) const;
template <typename Ty>
FCF_UNION_DECL_EXPORT Ty get() const;
template <typename Ty>
FCF_UNION_DECL_EXPORT typename Details::NUnion::TypeHelper<Ty>::far_type& ref();
template <typename Ty>
FCF_UNION_DECL_EXPORT void set(const Ty& a_value);
inline void set(const char* a_value)
{ set<const char*>(a_value); }
FCF_UNION_DECL_EXPORT void set(const Union& a_value);
template <typename Ty>
inline void set()
{ set((UnionType)fcf::Details::NUnion::TypeHelper<Ty>::type_index); }
FCF_UNION_DECL_EXPORT void set(UnionType a_type);
template <typename Ty>
inline Union& operator=(const Ty& a_value)
{ set(a_value); return *this; }
inline Union& operator=(const Union& a_union)
{ set(a_union); return *this; }
template <typename Ty>
FCF_UNION_DECL_EXPORT bool equal(const Ty& a_value, bool a_strict = false, bool a_deep = false) const;
inline bool equal(const char* a_value, bool a_strict = false, bool a_deep = false) const
{ return equal<const char*>(a_value, a_strict, a_deep); }
FCF_UNION_DECL_EXPORT bool equal(const Union& a_value, bool a_strict = false, bool a_deep = false) const;
template <typename Ty>
FCF_UNION_DECL_EXPORT bool lessStr(const Ty& a_value) const;
inline bool lessStr(const char* a_value) const
{ return lessStr<const char*>(a_value); }
FCF_UNION_DECL_EXPORT bool lessStr(Union& a_value) const;
FCF_UNION_DECL_EXPORT bool lessStr(const Union& a_value) const;
template <typename Ty>
bool operator <(const Ty& a_value) const { return lessStr(a_value); }
template <typename Ty>
inline bool operator==(const Ty& a_value) const
{ return equal(a_value, false, false); }
template <typename Ty>
inline bool operator!=(const Ty& a_value) const
{ return !equal(a_value, false, false); }
template <typename Ty>
inline explicit operator Ty() const
{ return get<Ty>(); }
};
#ifdef FCF_UNION_IMPLEMENTATION
namespace Details {
namespace NConvert {
FCF_UNION_DECL_VISIBILITY_HIDDEN bool isDouble(const std::string& a_str, bool a_unsigned);
template <typename TFrom, typename TTo, typename TFormat = TNOP>
struct FCF_UNION_DECL_VISIBILITY_HIDDEN Converter{
template <typename TResolver, typename TReceiver>
inline void operator()(TResolver& a_resolver, TReceiver& a_receiver, bool a_inner, const char** a_dstErrorMessage) {
a_receiver((const TTo&)a_resolver());
}
};
template <typename Ty>
struct FCF_UNION_DECL_VISIBILITY_HIDDEN ConstResolver {
typedef Ty item_type;
typedef Ty value_type;
ConstResolver(const value_type& a_ref, bool a_enableLineCounter = false)
: _ref(a_ref) {
}
inline value_type& operator()(){
return (value_type&)_ref;
}
size_t line() {
return SIZE_MAX;
}
size_t column() {
return SIZE_MAX;
}
const Ty& _ref;
};
template <typename TString>
struct FCF_UNION_DECL_VISIBILITY_HIDDEN SimpleConstResolver {
typedef char item_type;
typedef TString value_type;
template <typename Ty>
SimpleConstResolver(Ty& a_ref, bool a_enableLineCounter = false)
: _ref((TString&)a_ref)
, _index(0){
}
inline TString& operator()(){
return _ref;
}
inline item_type read() {
return _ref[_index];
}
inline void next() {
++_index;
}
inline bool end() {
return !_ref[_index];
}
size_t line() {
return SIZE_MAX;
}
size_t column() {
return SIZE_MAX;
}
TString& _ref;
size_t _index;
};
template <>
struct FCF_UNION_DECL_VISIBILITY_HIDDEN SimpleConstResolver< std::basic_istream<char> > {
typedef char item_type;
typedef std::basic_istream<char> value_type;
SimpleConstResolver(std::basic_istream<char>& a_ref, bool a_enableLineCounter = false)
: _ref(a_ref) {
_ch = _ref.get();
}
inline std::basic_istream<char>& operator()(){
return _ref;
}
inline item_type read() {
return _ch;
}
inline void next() {
_ch = _ref.get();
}
inline bool end() {
return _ref.eof() || _ref.fail();
}
size_t line() {
return SIZE_MAX;
}
size_t column() {
return SIZE_MAX;
}
std::basic_istream<char>& _ref;
item_type _ch;
};
template <typename Ty>
struct FCF_UNION_DECL_VISIBILITY_HIDDEN ConstUncommentResolver {
public:
typedef Ty resolver_type;
typedef typename resolver_type::item_type item_type;
typedef typename resolver_type::value_type value_type;
template <typename TRef>
ConstUncommentResolver(TRef& a_ref, bool a_enableLineCounter = false)
: _resolver((TRef&)a_ref), _q(0), _n1(-1), _n2(-1), _nb1(-1), _s(0), _l(a_enableLineCounter ? 1 : SIZE_MAX), _c(a_enableLineCounter ? 1: SIZE_MAX) {
}
inline value_type& operator()(){
return _resolver.operator()();
}
inline item_type read() {
if (_n1 != -1) {
return _n1;
}
return _resolver.read();
}
void next() {
if (_n1 != -1){
_n1 = -1;
return;
}
char c = 0;
while(!_resolver.end()) {
_next();
if (_resolver.end()){
break;
}
c = _resolver.read();
if (!_q) {
if (_n1 == '/' && _n2 == '/') {
if (c == '\n') {
_n1 = -1;
_n2 = -1;
_nb1 = -1;
continue;
} else {
continue;
}
}
if (_n1 == '/' && _n2 == '*') {
if (_nb1 == '*' && c == '/' ) {
_n1 = -1;
_n2 = -1;
_nb1 = -1;
continue;
} else if (c == '*') {
_nb1 = c;
continue;
} else {
_nb1 = -1;
continue;
}
}
if (c == '/' && _n1 == '/'){
_n2 = c;
continue;
}
if (c == '*' && _n1 == '/'){
_n2 = c;
continue;
}
if (c == '/' && _n1 == -1){
_n1 = c;
continue;
}
break;
} else {
break;
}
}
if (_resolver.end() && _n1 != -1){
_n1 = -1;
_n2 = -1;
_nb1 = -1;
}
if (!_resolver.end()) {
if (_q) {
if (c == '\\') {
++_s;
}
if (c == _q && (_s % 2) == 0) {
_q = 0;
}
if (c != '\\') {
_s = 0;
}
} else {
if (c == '\'' || c == '\"') {
_q = c;
}
}
}
}
inline bool end() {
if (_n1 != -1){
return false;
}
return _resolver.end();
}
size_t line() {
return _l;
}
size_t column() {
return _c;
}
protected:
void _next() {
if (_l != SIZE_MAX) {
const char c = _resolver.read();
if (c == '\n'){
++_l;
_c = 1;
} else {
++_c;
}
}
_resolver.next();
}
resolver_type _resolver;
char _q;
int _n1;
int _n2;
int _nb1;
size_t _s;
size_t _l;
size_t _c;
};
template <>
struct FCF_UNION_DECL_VISIBILITY_HIDDEN ConstResolver< std::string > : public ConstUncommentResolver< SimpleConstResolver<std::string> >{
typedef ConstUncommentResolver< SimpleConstResolver<std::string> > base_type;
using ConstUncommentResolver< SimpleConstResolver<std::string> >::ConstUncommentResolver;
};
template <>
struct FCF_UNION_DECL_VISIBILITY_HIDDEN ConstResolver< const char* > : public ConstUncommentResolver< SimpleConstResolver<const char*> >{
typedef ConstUncommentResolver< SimpleConstResolver<const char*> > base_type;
using ConstUncommentResolver< SimpleConstResolver<const char*> >::ConstUncommentResolver;
};
template <>
struct FCF_UNION_DECL_VISIBILITY_HIDDEN ConstResolver< std::basic_istream<char> > : public ConstUncommentResolver< SimpleConstResolver< std::basic_istream<char> > >{
typedef ConstUncommentResolver< SimpleConstResolver< std::basic_istream<char> > > base_type;
using ConstUncommentResolver< SimpleConstResolver< std::basic_istream<char> > >::ConstUncommentResolver;
};
template <typename Ty, typename TOptions>
struct FCF_UNION_DECL_VISIBILITY_HIDDEN Receiver {
typedef Ty value_type;
inline void operator()(const Ty& a_value){
_ref = a_value;
}
inline Ty& get(){
return _ref;
}
Ty& _ref;
const TOptions& options;
};
template <typename TOptions>
struct FCF_UNION_DECL_VISIBILITY_HIDDEN Receiver<std::string, TOptions> {
typedef std::string value_type;
Receiver(std::string& a_ref, const TOptions& a_options)
: ref(a_ref)
, options(a_options)
, level (0) {
}
template <typename TOperand>
void operator()(const TOperand& a_value){
ref += a_value;
}
std::string& get(){
return ref;
}
std::string& ref;
const TOptions& options;
int level;
};
template <typename TOptions>
struct FCF_UNION_DECL_VISIBILITY_HIDDEN Receiver<std::basic_ostream<char>, TOptions> {
typedef std::basic_ostream<char> destination_type;
typedef std::string value_type;
Receiver(destination_type& a_ref, const TOptions& a_options)
: ref(a_ref)
, options(a_options)
, level (0) {
}
template <typename TOperand>
void operator()(const TOperand& a_value){
ref << std::string(a_value);
}
void operator()(const destination_type& a_value){
}
destination_type& get(){
return ref;
}
destination_type& ref;
const TOptions& options;
int level;
};
template <typename TOptions>
struct FCF_UNION_DECL_VISIBILITY_HIDDEN Receiver<UnionVector, TOptions> {
typedef UnionVector value_type;
template <typename TOperand>
inline void operator()(const TOperand& a_value){
_ref.push_back(a_value);
}
inline value_type& get(){
return _ref;
}
value_type& _ref;
const TOptions& options;
};
template <typename TOptions>
struct FCF_UNION_DECL_VISIBILITY_HIDDEN Receiver<UnionMap, TOptions> {
typedef UnionMap value_type;
inline void operator()(const UnionMap& a_value){
_ref = a_value;
};
template <typename TOperand>
inline void operator()(const TOperand& a_value){
UnionMap::iterator it = _ref.insert(a_value).first;
it->second.order = _ref.size();
}
inline value_type& get(){
return _ref;
}
value_type& _ref;
const TOptions& options;
};
///////////////////////////////////////
// Convertion from int
///////////////////////////////////////
template <>
struct FCF_UNION_DECL_VISIBILITY_HIDDEN Converter<int, std::string, TNOP>{
template <typename TResolver, typename TReceiver>
inline void operator()(TResolver& a_resolver, TReceiver& a_receiver, bool a_inner, const char** a_dstErrorMessage) {
return a_receiver(std::to_string(a_resolver()));
}
};
template <>
struct FCF_UNION_DECL_VISIBILITY_HIDDEN Converter<int, UnionVector, TNOP>{
template <typename TResolver, typename TReceiver>
inline void operator()(TResolver& a_resolver, TReceiver& a_receiver, bool a_inner, const char** a_dstErrorMessage) {
FCF_THROW_OR_RESULT_ERROR(a_dstErrorMessage, "Incorrect vector value", a_resolver, false);
}
};
template <>
struct FCF_UNION_DECL_VISIBILITY_HIDDEN Converter<int, UnionMap, TNOP>{
template <typename TResolver, typename TReceiver>
inline void operator()(TResolver& a_resolver, TReceiver& a_receiver, bool a_inner, const char** a_dstErrorMessage) {
FCF_THROW_OR_RESULT_ERROR(a_dstErrorMessage, "Incorrect map value", a_resolver, false);
}
};
///////////////////////////////////////
// Convertion from unsigned int
///////////////////////////////////////
template <>
struct FCF_UNION_DECL_VISIBILITY_HIDDEN Converter<unsigned int, std::string, TNOP>{
template <typename TResolver, typename TReceiver>
inline void operator()(TResolver& a_resolver, TReceiver& a_receiver, bool a_inner, const char** a_dstErrorMessage) {
return a_receiver(std::to_string(a_resolver()));
}
};
template <>
struct FCF_UNION_DECL_VISIBILITY_HIDDEN Converter<unsigned int, UnionVector, TNOP>{
template <typename TResolver, typename TReceiver>
inline void operator()(TResolver& a_resolver, TReceiver& a_receiver, bool a_inner, const char** a_dstErrorMessage) {
FCF_THROW_OR_RESULT_ERROR(a_dstErrorMessage, "Incorrect vector value", a_resolver, false);
}
};
template <>
struct FCF_UNION_DECL_VISIBILITY_HIDDEN Converter<unsigned int, UnionMap, TNOP>{
template <typename TResolver, typename TReceiver>
inline void operator()(TResolver& a_resolver, TReceiver& a_receiver, bool a_inner, const char** a_dstErrorMessage) {
FCF_THROW_OR_RESULT_ERROR(a_dstErrorMessage, "Incorrect map value", a_resolver, false);
}
};
///////////////////////////////////////
// Convertion from long long
///////////////////////////////////////
template <>
struct FCF_UNION_DECL_VISIBILITY_HIDDEN Converter<long long, std::string, TNOP>{
template <typename TResolver, typename TReceiver>
inline void operator()(TResolver& a_resolver, TReceiver& a_receiver, bool a_inner, const char** a_dstErrorMessage) {
return a_receiver(std::to_string(a_resolver()));
}
};
template <>
struct FCF_UNION_DECL_VISIBILITY_HIDDEN Converter<long long, UnionVector, TNOP>{
template <typename TResolver, typename TReceiver>
inline void operator()(TResolver& a_resolver, TReceiver& a_receiver, bool a_inner, const char** a_dstErrorMessage) {
FCF_THROW_OR_RESULT_ERROR(a_dstErrorMessage, "Incorrect vector value", a_resolver, false);
}
};
template <>
struct FCF_UNION_DECL_VISIBILITY_HIDDEN Converter<long long, UnionMap, TNOP>{
template <typename TResolver, typename TReceiver>
inline void operator()(TResolver& a_resolver, TReceiver& a_receiver, bool a_inner, const char** a_dstErrorMessage) {
FCF_THROW_OR_RESULT_ERROR(a_dstErrorMessage, "Incorrect map value", a_resolver, false);
}
};
///////////////////////////////////////
// Convertion from long int
///////////////////////////////////////
template <>
struct FCF_UNION_DECL_VISIBILITY_HIDDEN Converter<long int, std::string, TNOP>{
template <typename TResolver, typename TReceiver>
inline void operator()(TResolver& a_resolver, TReceiver& a_receiver, bool a_inner, const char** a_dstErrorMessage) {
return a_receiver(std::to_string(a_resolver()));
}
};
template <>
struct FCF_UNION_DECL_VISIBILITY_HIDDEN Converter<long int, UnionVector, TNOP>{
template <typename TResolver, typename TReceiver>
inline void operator()(TResolver& a_resolver, TReceiver& a_receiver, bool a_inner, const char** a_dstErrorMessage) {
FCF_THROW_OR_RESULT_ERROR(a_dstErrorMessage, "Incorrect vector value", a_resolver, false);
}
};
template <>
struct FCF_UNION_DECL_VISIBILITY_HIDDEN Converter<long int, UnionMap, TNOP>{
template <typename TResolver, typename TReceiver>
inline void operator()(TResolver& a_resolver, TReceiver& a_receiver, bool a_inner, const char** a_dstErrorMessage) {
FCF_THROW_OR_RESULT_ERROR(a_dstErrorMessage, "Incorrect map value", a_resolver, false);
}
};
///////////////////////////////////////
// Convertion from unsigned long int
///////////////////////////////////////
template <>
struct FCF_UNION_DECL_VISIBILITY_HIDDEN Converter<unsigned long int, std::string, TNOP>{
template <typename TResolver, typename TReceiver>
inline void operator()(TResolver& a_resolver, TReceiver& a_receiver, bool a_inner, const char** a_dstErrorMessage) {
return a_receiver(std::to_string(a_resolver()));
}
};
template <>
struct FCF_UNION_DECL_VISIBILITY_HIDDEN Converter<unsigned long int, UnionVector, TNOP>{
template <typename TResolver, typename TReceiver>
inline void operator()(TResolver& a_resolver, TReceiver& a_receiver, bool a_inner, const char** a_dstErrorMessage) {
FCF_THROW_OR_RESULT_ERROR(a_dstErrorMessage, "Incorrect vector value", a_resolver, false);
}
};
template <>
struct FCF_UNION_DECL_VISIBILITY_HIDDEN Converter<unsigned long int, UnionMap, TNOP>{
template <typename TResolver, typename TReceiver>
inline void operator()(TResolver& a_resolver, TReceiver& a_receiver, bool a_inner, const char** a_dstErrorMessage) {
FCF_THROW_OR_RESULT_ERROR(a_dstErrorMessage, "Incorrect map value", a_resolver, false);
}
};
///////////////////////////////////////
// Convertion from unsigned long long
///////////////////////////////////////
template <>
struct FCF_UNION_DECL_VISIBILITY_HIDDEN Converter<unsigned long long, std::string, TNOP>{
template <typename TResolver, typename TReceiver>
inline void operator()(TResolver& a_resolver, TReceiver& a_receiver, bool a_inner, const char** a_dstErrorMessage) {
return a_receiver(std::to_string(a_resolver()));
}
};
template <>
struct FCF_UNION_DECL_VISIBILITY_HIDDEN Converter<unsigned long long, UnionVector, TNOP>{
template <typename TResolver, typename TReceiver>
inline void operator()(TResolver& a_resolver, TReceiver& a_receiver, bool a_inner, const char** a_dstErrorMessage) {
FCF_THROW_OR_RESULT_ERROR(a_dstErrorMessage, "Incorrect vector value", a_resolver, false);
}
};
template <>
struct FCF_UNION_DECL_VISIBILITY_HIDDEN Converter<unsigned long long, UnionMap, TNOP>{
template <typename TResolver, typename TReceiver>
inline void operator()(TResolver& a_resolver, TReceiver& a_receiver, bool a_inner, const char** a_dstErrorMessage) {
FCF_THROW_OR_RESULT_ERROR(a_dstErrorMessage, "Incorrect map value", a_resolver, false);
}
};
///////////////////////////////////////
// Convertion from double
///////////////////////////////////////
template <>
struct FCF_UNION_DECL_VISIBILITY_HIDDEN Converter<double, std::string, TNOP>{
template <typename TResolver, typename TReceiver>
inline void operator()(TResolver& a_resolver, TReceiver& a_receiver, bool a_inner, const char** a_dstErrorMessage) {
return a_receiver(std::to_string(a_resolver()));
}
};
template <>
struct FCF_UNION_DECL_VISIBILITY_HIDDEN Converter<double, UnionVector, TNOP>{
template <typename TResolver, typename TReceiver>
inline void operator()(TResolver& a_resolver, TReceiver& a_receiver, bool a_inner, const char** a_dstErrorMessage) {
FCF_THROW_OR_RESULT_ERROR(a_dstErrorMessage, "Incorrect vector value", a_resolver, false);
}
};
template <>
struct FCF_UNION_DECL_VISIBILITY_HIDDEN Converter<double, UnionMap, TNOP>{
template <typename TResolver, typename TReceiver>
inline void operator()(TResolver& a_resolver, TReceiver& a_receiver, bool a_inner, const char** a_dstErrorMessage) {
FCF_THROW_OR_RESULT_ERROR(a_dstErrorMessage, "Incorrect map value", a_resolver, false);
}
};
///////////////////////////////////////
// Convertion from bool
///////////////////////////////////////
template <>
struct FCF_UNION_DECL_VISIBILITY_HIDDEN Converter<bool, int, TNOP>{
template <typename TResolver, typename TReceiver>
inline void operator()(TResolver& a_resolver, TReceiver& a_receiver, bool a_inner, const char** a_dstErrorMessage) {
return a_receiver(a_resolver() ? 1 : 0 );
}
};
template <>
struct FCF_UNION_DECL_VISIBILITY_HIDDEN Converter<bool, unsigned int, TNOP>{
template <typename TResolver, typename TReceiver>
inline void operator()(TResolver& a_resolver, TReceiver& a_receiver, bool a_inner, const char** a_dstErrorMessage) {
return a_receiver(a_resolver() ? 1 : 0 );
}
};
template <>
struct FCF_UNION_DECL_VISIBILITY_HIDDEN Converter<bool, long long, TNOP>{
template <typename TResolver, typename TReceiver>
inline void operator()(TResolver& a_resolver, TReceiver& a_receiver, bool a_inner, const char** a_dstErrorMessage) {
return a_receiver(a_resolver() ? 1 : 0 );
}
};