-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsr_param_native.h
More file actions
1418 lines (1185 loc) · 48.8 KB
/
sr_param_native.h
File metadata and controls
1418 lines (1185 loc) · 48.8 KB
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
// GreenControl framework
//
// LICENSETEXT
//
// Copyright (C) 2007 : GreenSocs Ltd
// http://www.greensocs.com/ , email: info@greensocs.com
//
// Developed by :
//
// Christian Schroeder <schroeder@eis.cs.tu-bs.de>,
// Wolfgang Klingauf <klingauf@eis.cs.tu-bs.de>
// Technical University of Braunschweig, Dept. E.I.S.
// http://www.eis.cs.tu-bs.de
//
//
// The contents of this file are subject to the licensing terms specified
// in the file LICENSE. Please consult this file for restrictions and
// limitations that may apply.
//
// ENDLICENSETEXT
using std::istringstream;
// /////////////////////////////////////////////////////////////////////////////// //
// /////////////////// sr_param< INT > /////////////////////////////////////////// //
// /////////////////////////////////////////////////////////////////////////////// //
/// Template specialization for sr_param<int>.
/**
* Default value = 0.
*/
template<>
class sr_param<int>
: public sr_param_t<int>
{
/// Typedef for the value.
typedef int val_type;
public:
SR_PARAM_HEAD;
// ///////////////////////
// operators
GC_SPECIALISATIONS_ARITHMETIC_OPERATORS;
GC_SPECIALISATIONS_BINARY_OPERATORS;
GC_SPECIALISATIONS_INCREMENT_OPERATORS;
GC_SPECIALISATIONS_DECREMENT_OPERATORS;
SR_PARAM_DELEGATE;
/// Overloads sr_param::getTypeString
const std::string getTypeString() const {
return std::string("int");
}
/// Overloads sr_param::getType
gs::cnf::Param_type getType() const {
return gs::cnf::PARTYPE_INT;
}
/// Overloads gs_param_t<T>::convertValueToString
std::string convertValueToString(const val_type &val) const{
return static_convertValueToString(val);;
}
inline static std::string static_convertValueToString(const val_type &val) {
std::ostringstream ss;
ss << val;
return ss.str();
}
/// Static convertion function called by virtual deserialize and others (e.g. GCnf_API)
inline static bool static_deserialize(val_type &target_val, const std::string& str) {
std::istringstream ss(str);
GS_PARAM_DUMP_WITHNAME("gs_param", "deserialize: string='"<< ss.str().c_str() << "'");
if (ss.str().length() == 0) {
target_val = 0;
GS_PARAM_DUMP_WITHNAME("gs_param", "deserialize: set default value");
return true;
}
val_type tmp;
ss >> tmp;
// if next char is a decimal point, ignore
if (!ss.eof() && ss.peek() == '.') {
target_val = tmp;
GS_PARAM_DUMP_WITHNAME("gs_param", "(int) ignored decimal point");
return true;
}
// if error try hex
if (!ss.eof() || ss.fail() || ss.bad()) {
GS_PARAM_DUMP_WITHNAME("gs_param", "stream fail or not eof, try hex");
ss.~istringstream();
new ( (void *) &ss ) std::istringstream(str); /// @TODO: changed m_api->getParam(m_par_name) to str; correct??
ss >> (std::hex) >> tmp;
}
// no conversion error
if (ss.eof() && !ss.fail() && !ss.bad()) {
target_val = tmp;
GS_PARAM_DUMP_WITHNAME("gs_param", "(int) stream eof and not fail");
}
else {
std::stringstream ess;
ess << "Conversion error: '" << str << "'";
SC_REPORT_WARNING("deserialize", ess.str().c_str());
return false;
}
return true;
}
};
// /////////////////////////////////////////////////////////////////////////////// //
// /////////////////// sr_param< UNSIGNED INT > ////////////////////////////////// //
// /////////////////////////////////////////////////////////////////////////////// //
/// Template specialization for sr_param<unsigned int>.
/**
* Default value = 0.
*/
template<>
class sr_param<unsigned int>
: public sr_param_t<unsigned int>
{
/// Typedef for the value.
typedef unsigned int val_type;
public:
SR_PARAM_HEAD;
explicit sr_param(const std::string &nam, const int &val) : sr_param_t<val_type>(nam ) { sr_param_t<unsigned int>::init((unsigned int)val); }
explicit sr_param(const char *nam, const int &val) : sr_param_t<val_type>(std::string(nam)) { sr_param_t<unsigned int>::init((unsigned int)val); }
// ///////////////////////
// operators
GC_SPECIALISATIONS_ARITHMETIC_OPERATORS;
GC_SPECIALISATIONS_BINARY_OPERATORS;
GC_SPECIALISATIONS_INCREMENT_OPERATORS;
GC_SPECIALISATIONS_DECREMENT_OPERATORS;
SR_PARAM_DELEGATE;
/// Overloads sr_param::getTypeString
const std::string getTypeString() const {
return std::string("unsigned int");
}
/// Overloads sr_param::getType
gs::cnf::Param_type getType() const {
return gs::cnf::PARTYPE_UINT;
}
/// Overloads gs_param_t<T>::convertValueToString
std::string convertValueToString(const val_type &val) const {
return static_convertValueToString(val);;
}
inline static std::string static_convertValueToString(const val_type &val) {
std::ostringstream ss;
ss << val;
return ss.str();
}
/// Static convertion function called by virtual deserialize and others (e.g. GCnf_API)
inline static bool static_deserialize(val_type &target_val, const std::string& str) {
std::istringstream ss(str);
GS_PARAM_DUMP_WITHNAME("gs_param", "deserialize: string='" << ss.str().c_str() <<"'");
if (ss.str().length() == 0) {
target_val = 0;
GS_PARAM_DUMP_WITHNAME("gs_param", "deserialize: set default value");
return true;
}
val_type tmp;
ss >> tmp;
// if next char is a decimal point, ignore
if (!ss.eof() && ss.peek() == '.') {
target_val = tmp;
GS_PARAM_DUMP_WITHNAME("gs_param", "(unsigned int) ignored decimal point");
return true;
}
// if error try hex
if (!ss.eof() || ss.fail() || ss.bad()) {
ss.~istringstream();
new ( (void *) &ss ) std::istringstream(str); /// @TODO(all): changed m_api->getParam(m_par_name) to str; correct??
ss >> (std::hex) >> tmp;
}
// no conversion error
if (ss.eof() && !ss.fail() && !ss.bad()) {
target_val = tmp;
GS_PARAM_DUMP_WITHNAME("gs_param", "(unsigned int) stream eof and not fail");
}
else {
std::stringstream ess;
ess << "Conversion error: '" << str << "'";
SC_REPORT_WARNING("deserialize", ess.str().c_str());
return false;
}
return true;
}
};
// /////////////////////////////////////////////////////////////////////////////// //
// /////////////////// sr_param< BOOL > ////////////////////////////////////////// //
// /////////////////////////////////////////////////////////////////////////////// //
/// Template specialization for sr_param<bool>.
/**
* Default value = false.
*/
template<>
class sr_param<bool>
: public sr_param_t<bool>
{
/// Typedef for the value.
typedef bool val_type;
public:
SR_PARAM_HEAD;
// ///////////////////////
// operators
// unsafe for bool: (according to MSVS)
//GC_SPECIALISATIONS_ARITHMETIC_OPERATORS;
// unsafe for bool: (according to MSVS)
//GC_SPECIALISATIONS_BINARY_OPERATORS;
GC_SPECIALISATIONS_INCREMENT_OPERATORS;
// not allowed for bool:
// GC_SPECIALISATIONS_DECREMENT_OPERATORS;
SR_PARAM_DELEGATE;
/// Overloads sr_param::getTypeString
const std::string getTypeString() const {
return std::string("bool");
}
/// Overloads sr_param::getType
gs::cnf::Param_type getType() const {
return gs::cnf::PARTYPE_BOOL;
}
/// Overloads gs_param_t<T>::convertValueToString
std::string convertValueToString(const val_type &val) const {
return static_convertValueToString(val);;
}
inline static std::string static_convertValueToString(const val_type &val) {
std::ostringstream ss;
ss << val;
return ss.str();
}
/// Static convertion function called by virtual deserialize and others (e.g. GCnf_API)
inline static bool static_deserialize(val_type &target_val, const std::string& str) {
GS_PARAM_DUMP_WITHNAME("gs_param", "deserialize: string='"<<str.c_str()<<"'");
if (str.length() == 0) {
GS_PARAM_DUMP_WITHNAME("gs_param", "getValue: set default value (false)");
target_val = false;
}
else if (strcmp( str.c_str(), "true" ) == 0) {
GS_PARAM_DUMP_WITHNAME("gs_param", "getValue: set value true");
target_val = true;
}
else if (strcmp( str.c_str(), "True" ) == 0) {
GS_PARAM_DUMP_WITHNAME("gs_param", "getValue: set value true");
target_val = true;
}
else if (strcmp( str.c_str(), "false" ) == 0) {
GS_PARAM_DUMP_WITHNAME("gs_param", "getValue: set value false");
target_val = false;
}
else if (strcmp( str.c_str(), "False" ) == 0) {
GS_PARAM_DUMP_WITHNAME("gs_param", "getValue: set value false");
target_val = false;
}
else {
std::istringstream ss(str);
//ss.setf(ios::boolalpha);
val_type tmp;
ss >> tmp;
// no conversion error
if (ss.eof() && !ss.fail() && !ss.bad()) {
target_val = tmp;
GS_PARAM_DUMP_WITHNAME("gs_param", "(bool) stream eof and not fail");
}
else {
std::stringstream ess;
ess << "Conversion error: '" << str << "'";
SC_REPORT_WARNING("deserialize", ess.str().c_str());
return false;
}
}
return true;
}
};
// /////////////////////////////////////////////////////////////////////////////// //
// /////////////////// sr_param< DOUBLE > //////////////////////////////////////// //
// /////////////////////////////////////////////////////////////////////////////// //
/// Template specialization for sr_param<double>.
/**
* Default value = 0.
*/
template<>
class sr_param<double>
: public sr_param_t<double>
{
/// Typedef for the value.
typedef double val_type;
public:
SR_PARAM_HEAD;
// ///////////////////////
// operators
GC_SPECIALISATIONS_ARITHMETIC_OPERATORS;
// not allowed for double:
// GC_SPECIALISATIONS_BINARY_OPERATORS;
GC_SPECIALISATIONS_INCREMENT_OPERATORS;
GC_SPECIALISATIONS_DECREMENT_OPERATORS;
SR_PARAM_DELEGATE;
/// Overloads sr_param::getTypeString
const std::string getTypeString() const {
return std::string("double");
}
/// Overloads sr_param::getType
gs::cnf::Param_type getType() const {
return gs::cnf::PARTYPE_DOUBLE;
}
/// Overloads gs_param_t<T>::convertValueToString
std::string convertValueToString(const val_type &val) const {
return static_convertValueToString(val);;
}
inline static std::string static_convertValueToString(const val_type &val) {
std::ostringstream ss;
ss << val;
return ss.str();
}
/// Static convertion function called by virtual deserialize and others (e.g. GCnf_API)
inline static bool static_deserialize(val_type &target_val, const std::string& str) {
std::istringstream ss(str);
if (ss.str().length() == 0) {
target_val = 0;
return true;
}
val_type tmp;
ss >> tmp;
// no conversion error
if (ss.eof() && !ss.fail() && !ss.bad()) {
target_val = tmp;
}
else {
std::stringstream ess;
ess << "Conversion error: '" << str << "'";
SC_REPORT_WARNING("deserialize", ess.str().c_str());
return false;
}
return true;
}
};
// /////////////////////////////////////////////////////////////////////////////// //
// ////////////////// sr_param< FLOAT > //////////////////////////////////////// //
// /////////////////////////////////////////////////////////////////////////////// //
/// Template specialization for sr_param<float>.
/**
* Default value = 0.
*/
template<>
class sr_param<float>
: public sr_param_t<float>
{
/// Typedef for the value.
typedef float val_type;
public:
SR_PARAM_HEAD;
// ///////////////////////
// operators
GC_SPECIALISATIONS_ARITHMETIC_OPERATORS;
// not allowed for float:
// GC_SPECIALISATIONS_BINARY_OPERATORS;
GC_SPECIALISATIONS_INCREMENT_OPERATORS;
GC_SPECIALISATIONS_DECREMENT_OPERATORS;
SR_PARAM_DELEGATE;
/// Overloads sr_param::getTypeString
const std::string getTypeString() const {
return std::string("float");
}
/// Overloads sr_param::getType
gs::cnf::Param_type getType() const {
return gs::cnf::PARTYPE_FLOAT;
}
/// Overloads gs_param_t<T>::convertValueToString
std::string convertValueToString(const val_type &val) const {
return static_convertValueToString(val);;
}
inline static std::string static_convertValueToString(const val_type &val) {
std::ostringstream ss;
ss << val;
return ss.str();
}
/// Static convertion function called by virtual deserialize and others (e.g. GCnf_API)
inline static bool static_deserialize(val_type &target_val, const std::string& str) {
std::istringstream ss(str);
if (ss.str().length() == 0) {
target_val = 0;
return true;
}
val_type tmp;
ss >> tmp;
// no conversion error
if (ss.eof() && !ss.fail() && !ss.bad()) {
target_val = tmp;
}
else {
std::stringstream ess;
ess << "Conversion error: '" << str << "'";
SC_REPORT_WARNING("deserialize", ess.str().c_str());
return false;
}
return true;
}
};
// /////////////////////////////////////////////////////////////////////////////// //
// /////////////////// sr_param< STRING > //////////////////////////////////////// //
// /////////////////////////////////////////////////////////////////////////////// //
/// Template specialization for sr_param<std::string>.
/**
*
*/
template<>
class sr_param<std::string>
: public sr_param_t<std::string>
{
protected:
/// Typedef for this specialized class.
typedef sr_param<std::string> my_type;
/// Typedef for the value.
typedef std::string val_type;
using sr_param_t<val_type>::my_value;
using sr_param_t<val_type>::m_api;
using sr_param_t<val_type>::m_par_name;
using sr_param_t<val_type>::convertStringToValue;
private:
// String constructor is allowed for string parameter
public:
// Explicit constructors to avoid implicit construction of parameters.
/// Empty constructor. Name will be set in base
explicit sr_param() : sr_param_t<val_type>() { sr_param_t<val_type>::init(); }
/// Constructor with (local/hierarchical) name.
explicit sr_param(const std::string &nam) : sr_param_t<val_type>(nam ) { sr_param_t<val_type>::init(); }
explicit sr_param(const char *nam ) : sr_param_t<val_type>(std::string(nam)) { sr_param_t<val_type>::init(); }
/// Constructor with (local/hierarchical) name and string representation of initial value.
explicit sr_param(const std::string &nam, const std::string &val, const bool force_top_level_name = false) : sr_param_t<val_type>(nam , force_top_level_name, NULL, true ) { sr_param_t<val_type>::init(convertStringToValue(val)); }
explicit sr_param(const char *nam, const char *val , const bool force_top_level_name = false) : sr_param_t<val_type>(std::string(nam), force_top_level_name, NULL, true ) { sr_param_t<val_type>::init(convertStringToValue(std::string(val))); }
explicit sr_param(const std::string &nam, const char *val , const bool force_top_level_name = false) : sr_param_t<val_type>(nam , force_top_level_name, NULL, true ) { sr_param_t<val_type>::init(convertStringToValue(std::string(val))); }
explicit sr_param(const char *nam, const std::string &val, const bool force_top_level_name = false) : sr_param_t<val_type>(std::string(nam), force_top_level_name, NULL, true ) { sr_param_t<val_type>::init(convertStringToValue(val)); }
// Constructors with parent array
explicit sr_param( gs_param_array* parent_array) : sr_param_t<val_type>( false, parent_array, true) { sr_param_t<val_type>::init(); }
explicit sr_param(const std::string &nam , gs_param_array* parent_array) : sr_param_t<val_type>(nam , false, parent_array, true) { sr_param_t<val_type>::init(); }
explicit sr_param(const char *nam , gs_param_array* parent_array) : sr_param_t<val_type>(std::string(nam), false, parent_array, true) { sr_param_t<val_type>::init(); }
explicit sr_param(const std::string &nam, const std::string &val, gs_param_array* parent_array) : sr_param_t<val_type>(nam , false, parent_array, true) { sr_param_t<val_type>::init(convertStringToValue(val)); }
explicit sr_param(const char *nam, const char *val , gs_param_array* parent_array) : sr_param_t<val_type>(std::string(nam), false, parent_array, true) { sr_param_t<val_type>::init(convertStringToValue(std::string(val))); }
explicit sr_param(const std::string &nam, const char *val , gs_param_array* parent_array) : sr_param_t<val_type>(nam , false, parent_array, true) { sr_param_t<val_type>::init(convertStringToValue(std::string(val))); }
explicit sr_param(const char *nam, const std::string &val, gs_param_array* parent_array) : sr_param_t<val_type>(std::string(nam), false, parent_array, true) { sr_param_t<val_type>::init(convertStringToValue(val)); }
explicit sr_param( gs_param_array& parent_array) : sr_param_t<val_type>( false, &parent_array, true) { sr_param_t<val_type>::init(); }
explicit sr_param(const std::string &nam , gs_param_array& parent_array) : sr_param_t<val_type>(nam , false, &parent_array, true) { sr_param_t<val_type>::init(); }
explicit sr_param(const char *nam , gs_param_array& parent_array) : sr_param_t<val_type>(std::string(nam), false, &parent_array, true) { sr_param_t<val_type>::init(); }
explicit sr_param(const std::string &nam, const std::string &val, gs_param_array& parent_array) : sr_param_t<val_type>(nam , false, &parent_array, true) { sr_param_t<val_type>::init(convertStringToValue(val)); }
explicit sr_param(const char *nam, const char *val , gs_param_array& parent_array) : sr_param_t<val_type>(std::string(nam), false, &parent_array, true) { sr_param_t<val_type>::init(convertStringToValue(std::string(val))); }
explicit sr_param(const std::string &nam, const char *val , gs_param_array& parent_array) : sr_param_t<val_type>(nam , false, &parent_array, true) { sr_param_t<val_type>::init(convertStringToValue(std::string(val))); }
explicit sr_param(const char *nam, const std::string &val, gs_param_array& parent_array) : sr_param_t<val_type>(std::string(nam), false, &parent_array, true) { sr_param_t<val_type>::init(convertStringToValue(val)); }
// Constructors with register_at_db bool
explicit sr_param(const std::string &nam, const std::string &val, gs_param_array* parent_array, const bool force_top_level_name, const bool register_at_db) : sr_param_t<val_type>(nam, force_top_level_name, parent_array, register_at_db) { sr_param_t<val_type>::init(convertStringToValue(val)); }
explicit sr_param(const std::string &nam, const std::string &val, gs_param_array& parent_array, const bool force_top_level_name, const bool register_at_db) : sr_param_t<val_type>(nam, force_top_level_name, &parent_array, register_at_db) { sr_param_t<val_type>::init(convertStringToValue(val)); }
SR_PARAM_DELEGATE;
const val_type convertStringToValue(const std::string& str) {
return str;
}
void serialize(const val_type &val) {
my_value = val;
}
/// Overloads sr_param_t<T>::deserialize in sr_param_t<T>
const bool deserialize(val_type &target_val, const std::string& str) {
return static_deserialize(target_val, str);
}
/// To resolve the correct = operator
using sr_param_t<val_type>::operator =;
/// @TODO(all): other operators??
//using sr_param::name;
using sr_param_t<val_type>::setString;
using sr_param_t<val_type>::getString;
using sr_param_t<val_type>::setValue;
using sr_param_t<val_type>::getValue;
/// Set the value of this parameter with char.
/**
* @param v Char value which has to be set.
* @return Pointer to this.
*/
my_type& operator = (const char *v) {
setValue(gs::cnf::envvar_subst(v, m_par_name));
return *this;
}
/// Desctructor
~sr_param() { sr_param_t<val_type>::destruct_gs_param(); }
// ///////////////////////
// operators
// see outside the class definition
/// Overloads sr_param::getTypeString
const std::string getTypeString() const {
return std::string("string");
}
/// Overloads sr_param::getType
gs::cnf::Param_type getType() const {
return gs::cnf::PARTYPE_STRING;
}
/// Overloads sr_param_t<T>::convertValueToString
std::string convertValueToString(const val_type &val) const {
return val;
}
inline static std::string static_convertValueToString(const val_type &val) {
return val;//m_api->setParam(m_par_name, val);
}
/// Static convertion function called by virtual deserialize and others (e.g. GCnf_API)
inline static bool static_deserialize(val_type &target_val, const std::string& str) {
target_val = str;
return true;
}
};
#define CNSC_STRING_OPERATOR_IMPLEMENTATIONS(otype) \
inline bool operator otype (const sr_param<std::string>& lhs, \
const sr_param<std::string>& rhs) \
{ \
return const_cast<sr_param<std::string>& >(lhs).getValue() otype \
const_cast<sr_param<std::string>& >(rhs).getValue(); \
} \
\
inline bool operator otype (const std::string& lhs, const sr_param<std::string>& rhs) \
{ \
return lhs otype const_cast<sr_param<std::string>& >(rhs).getValue(); \
} \
\
inline bool operator otype (const sr_param<std::string>& lhs, const std::string& rhs) \
{ \
return const_cast<sr_param<std::string>& >(lhs).getValue() otype rhs; \
} \
\
\
\
inline bool operator otype (const char *lhs, const sr_param<std::string>& rhs) \
{ \
return std::string(lhs) otype const_cast<sr_param<std::string>& >(rhs).getValue(); \
} \
\
inline bool operator otype (const sr_param<std::string>& lhs, const char *rhs) \
{ \
return const_cast<sr_param<std::string>& >(lhs).getValue() otype std::string(rhs); \
} \
CNSC_STRING_OPERATOR_IMPLEMENTATIONS(==)
CNSC_STRING_OPERATOR_IMPLEMENTATIONS(!=)
CNSC_STRING_OPERATOR_IMPLEMENTATIONS(<)
CNSC_STRING_OPERATOR_IMPLEMENTATIONS(<=)
CNSC_STRING_OPERATOR_IMPLEMENTATIONS(>)
CNSC_STRING_OPERATOR_IMPLEMENTATIONS(>=)
#undef CNSC_STRING_OPERATOR_IMPLEMENTATIONS
inline std::ostream& operator << (std::ostream& os, const sr_param<std::string>& str)
{
os << const_cast<sr_param<std::string>& >(str).getValue();
return os;
}
/// @TODO(all): check if works!
inline std::istream& operator>>(std::istream& is, sr_param<std::string>& str)
{
std::string ret_str(const_cast<sr_param<std::string>& >(str).getValue());
is >> ret_str;
const_cast<sr_param<std::string>& >(str).setString(ret_str);
return is;
}
inline std::string operator+ (const sr_param<std::string>& lhs, const sr_param<std::string>& rhs)
{
return const_cast<sr_param<std::string>& >(lhs).getValue() + const_cast<sr_param<std::string>& >(rhs).getValue();
}
inline std::string operator+ (const sr_param<std::string>& lhs, const std::string& rhs)
{
return const_cast<sr_param<std::string>& >(lhs).getValue() + rhs;
}
inline std::string operator+ (const std::string& lhs, const sr_param<std::string>& rhs)
{
return lhs + const_cast<sr_param<std::string>& >(rhs).getValue();
}
inline std::string operator+ (const sr_param<std::string>& lhs, const char *rhs)
{
return const_cast<sr_param<std::string>& >(lhs).getValue() + std::string(rhs);
}
inline std::string operator+ (const char *lhs, const sr_param<std::string>& rhs)
{
return std::string(lhs) + const_cast<sr_param<std::string>& >(rhs).getValue();
}
///////////////////////////////////////////////////////////////////////////////// //
///////////////////// gs_param< std::vector<std::string> > ////////////////////// //
///////////////////////////////////////////////////////////////////////////////// //
/// Template specialization for gs_param< std::vector<std::string> >.
/// Default value = empty vector.
/// @TODO(all): maybe template<typename T>
// class gs_param< std::vector<T> >
// issue: (de)serialization of T
template<>
class sr_param<std::vector<std::string> >
: public sr_param_t<std::vector<std::string> > {
/// Typedef for the value.
typedef std::vector<std::string> val_type;
public:
SR_PARAM_HEAD;
/////////////////////////
// additional functions
bool empty() const {return my_value.empty(); }
/// @TODO(all) optional: More of the vector functions
/////////////////////////
// overloaded functions
/// Overloads gs_param_base::getTypeString
const std::string getTypeString() const {
return std::string("std::vector<std::string>");
}
/// Overloads gs_param_base::getType
gs::cnf::Param_type getType() const {
return gs::cnf::PARTYPE_NOT_AVAILABLE;
}
const std::string& operator [] (const int index) {
return my_value[index];
}
size_t size() {
return my_value.size();
}
/// Overloads gs_param_t<T>::serialize
/**
* Serializes the vector to a single line comma separated list
* of the members.<br>
* Members surrounded by quotes (").
* The whole string surrounded by { }
*/
std::string convertValueToString(const val_type &val) const {
return static_convertValueToString(val);
}
inline static std::string static_convertValueToString(const val_type &val) {
std::ostringstream ss;
ss << "{";
bool first = true;
val_type::const_iterator iter;
for (iter = val.begin(); iter != val.end(); iter++) {
if (!first) {ss << ','; }
first = false;
// make sure included "s are handled
std::string::size_type loc = iter->find('"');
std::string aux = *iter;
while (loc != std::string::npos) {
if (aux[loc - 1] != '\\') {
aux = aux.substr(0, loc) + "\\" + aux.substr(loc, aux.npos);
}
loc = aux.find('"', loc + 1);
}
ss << '"' << aux << '"'; // not nescessarily quotes
}
ss << "}";
return ss.str();
}
/// Static convertion function called by virtual deserialize and others (e.g. GCnf_API)
/**
* Deserializes a single-line string into a vector.
* - The string has to look like: "{"value1","value 2","value 3"}"
* - Optionally there may be spaces between the values and the comma.
* - so far the value must not contain quotes: TODO!!
*/
inline static bool static_deserialize(val_type &target_val, const std::string &str) {
std::istringstream ss(str);
GS_PARAM_DUMP_WITHNAME("gs_param", "deserialize: string='" << ss.str().c_str() << "'");
if (ss.str().length() == 0) {
target_val.clear();
GS_PARAM_DUMP_WITHNAME("gs_param", "vector<std::string> deserialize: set default value");
return true;
} else {
target_val.clear();
std::string::size_type index = str.find("{");
if (index == str.npos) {
SC_REPORT_ERROR("gs_param", "vector<std::string> deserialize error!");
}
std::string my_string = str;
std::string value;
std::string word;
std::string::size_type indexB, indexC;
do {
if (my_string == "}") {break; }
index = 0;
do {
index = my_string.find("\"", index);
} while (my_string[index - 1] == '\\' && index != std::string::npos);
indexB = index;
do {
indexB = my_string.find("\"", indexB + 1);
} while (my_string[indexB - 1] == '\\' && indexB != std::string::npos);
if ((index == std::string::npos) || (indexB == std::string::npos)) {break; }
value = my_string.substr(index + 1, indexB - index - 1);
// now we must handle \" that can be inside the string, and transform them to single "
indexC = value.find("\\\"");
while (indexC != std::string::npos) {
value = value.substr(0, indexC) + value.substr(indexC + 1, value.npos);
indexC = value.find("\\\"", indexC);
}
target_val.push_back(value);
my_string = my_string.substr(indexB + 1, word.npos);
} while (index != std::string::npos);
return true;
}
return true;
}
};
// /////////////////////////////////////////////////////////////////////////////// //
// /////////////////// sr_param< UNSIGNED LONG LONG > //////////////////////////// //
// /////////////////////////////////////////////////////////////////////////////// //
/// Template specialization for sr_param<unsigned long long int>.
/**
* Default value = 0.
*/
template<>
class sr_param<unsigned long long>
: public sr_param_t<unsigned long long>
{
/// Typedef for the value.
typedef unsigned long long val_type;
public:
SR_PARAM_HEAD;
/// Constructor with unsigned int value
//explicit sr_param(const std::string &nam, const unsigned long &val) : sr_param_t<val_type>(nam ) { sr_param_t<val_type>::init((val_type)val); }
//explicit sr_param(const char *nam, const unsigned long &val) : sr_param_t<val_type>(std::string(nam) ) { sr_param_t<val_type>::init((val_type)val); }
/// Constructor with int value
//explicit sr_param(const std::string &nam, const long &val) : sr_param_t<val_type>(nam ) { sr_param_t<val_type>::init((val_type)val); }
//explicit sr_param(const char *nam, const long &val) : sr_param_t<val_type>(std::string(nam) ) { sr_param_t<val_type>::init((val_type)val); }
// ///////////////////////
// operators
GC_SPECIALISATIONS_ARITHMETIC_OPERATORS;
GC_SPECIALISATIONS_BINARY_OPERATORS;
GC_SPECIALISATIONS_INCREMENT_OPERATORS;
GC_SPECIALISATIONS_DECREMENT_OPERATORS;
SR_PARAM_DELEGATE;
/// Overloads sr_param::getTypeString
const std::string getTypeString() const {
return std::string("unsigned long long");
}
/// Overloads sr_param::getType
gs::cnf::Param_type getType() const {
return gs::cnf::PARTYPE_ULONGLONG;
}
/// Overloads sr_param_t<T>::convertValueToString
std::string convertValueToString(const val_type &val) const {
return static_convertValueToString(val);;
}
inline static std::string static_convertValueToString(const val_type &val) {
std::ostringstream ss;
ss << val;
return ss.str();
}
/// Static convertion function called by virtual deserialize and others (e.g. GCnf_API)
inline static bool static_deserialize(val_type &target_val, const std::string& str) {
std::istringstream ss(str);
if (ss.str().length() == 0) {
target_val = 0;
return true;
}
val_type tmp;
ss >> tmp;
// if next char is a decimal point, ignore
if (!ss.eof() && ss.peek() == '.') {
target_val = tmp;
GS_PARAM_DUMP_WITHNAME("sr_param", "(unsigned long long) ignored decimal point");
return true;
}
// if error try hex
if (!ss.eof() || ss.fail() || ss.bad()) {
ss.clear(); ss.str(str);
ss >> (std::hex) >> tmp;
}
// no conversion error
if (ss.eof() && !ss.fail() && !ss.bad()) {
target_val = tmp;
}
else {
std::stringstream ess;
ess << "Conversion error: '" << str << "'";
SC_REPORT_WARNING("deserialize", ess.str().c_str());
return false;
}
return true;
}
};
// /////////////////////////////////////////////////////////////////////////////// //
// /////////////////// sr_param< LONG LONG > //////////////////////////// //
// /////////////////////////////////////////////////////////////////////////////// //
/// Template specialization for sr_param<long long int>.
/**
* Default value = 0.
*/
template<>
class sr_param<long long>
: public sr_param_t<long long>
{
/// Typedef for the value.
typedef long long val_type;
public:
SR_PARAM_HEAD;
/// Constructor with int value
explicit sr_param(const std::string &nam, const int &val) : sr_param_t<val_type>(nam ) { sr_param_t<val_type>::init(val); }
explicit sr_param(const char *nam, const int &val) : sr_param_t<val_type>(std::string(nam) ) { sr_param_t<val_type>::init(val); }
// ///////////////////////
// operators
GC_SPECIALISATIONS_ARITHMETIC_OPERATORS;
GC_SPECIALISATIONS_BINARY_OPERATORS;
GC_SPECIALISATIONS_INCREMENT_OPERATORS;
GC_SPECIALISATIONS_DECREMENT_OPERATORS;
SR_PARAM_DELEGATE;
/// Overloads sr_param::getTypeString
const std::string getTypeString() const {
return std::string("long long");
}
/// Overloads sr_param::getType
gs::cnf::Param_type getType() const {
return gs::cnf::PARTYPE_LONGLONG;
}
/// Overloads sr_param_t<T>::convertValueToString
std::string convertValueToString(const val_type &val) const {
return static_convertValueToString(val);;
}
inline static std::string static_convertValueToString(const val_type &val) {
std::ostringstream ss;
ss << val;
return ss.str();
}
/// Static convertion function called by virtual deserialize and others (e.g. GCnf_API)
inline static bool static_deserialize(val_type &target_val, const std::string& str) {
std::istringstream ss(str);
if (ss.str().length() == 0) {
target_val = 0;
return true;
}
val_type tmp;
ss >> tmp;
// if next char is a decimal point, ignore
if (!ss.eof() && ss.peek() == '.') {
target_val = tmp;
GS_PARAM_DUMP_WITHNAME("sr_param", "(long long) ignored decimal point");
return true;
}
// if error try hex
if (!ss.eof() || ss.fail() || ss.bad()) {
ss.clear(); ss.str(str);
ss >> (std::hex) >> tmp;
}
// if still error try deserialize to unsigned long long
if (!ss.eof() || ss.fail() || ss.bad()) {
ss.clear(); ss.str(str);
unsigned long long ulltmp;
ss >> ulltmp;
if (!ss.eof() || ss.fail() || ss.bad()) {
ss.clear(); ss.str(str);
ss >> (std::hex) >> ulltmp;
}
if (ss.eof() && !ss.fail() && !ss.bad()) {
tmp = ulltmp;
}
}
// no conversion error
if (ss.eof() && !ss.fail() && !ss.bad()) {
target_val = tmp;
}
else {