Warning, /include/Geant4/tools/value is written in an unsupported language. File is not indexed.
0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003
0004 #ifndef tools_value
0005 #define tools_value
0006
0007 #include "array"
0008 #include "typedefs"
0009 #include "num2s"
0010 #include "b2s"
0011
0012 namespace tools {
0013
0014 class value {
0015 static const std::string& s_class() {
0016 static const std::string s_v("tools::value");
0017 return s_v;
0018 }
0019 public:
0020 enum e_type {
0021 NONE = 0,
0022 UNSIGNED_SHORT = 12,
0023 SHORT = 13,
0024 UNSIGNED_INT = 14,
0025 INT = 15,
0026 UNSIGNED_INT64 = 16,
0027 INT64 = 17,
0028 // reals :
0029 FLOAT = 30,
0030 DOUBLE = 31,
0031 // else :
0032 BOOL = 50,
0033 STRING = 51,
0034 // pointers :
0035 VOID_STAR = 100,
0036 DOUBLE_STAR = 101,
0037 FLOAT_STAR = 102,
0038 INT_STAR = 103,
0039
0040 // multidimensional vectors (1000+base type) :
0041 ARRAY_UNSIGNED_SHORT = 1012,
0042 ARRAY_SHORT = 1013,
0043 ARRAY_UNSIGNED_INT = 1014,
0044 ARRAY_INT = 1015,
0045 ARRAY_UNSIGNED_INT64 = 1016,
0046 ARRAY_INT64 = 1017,
0047 ARRAY_FLOAT = 1030,
0048 ARRAY_DOUBLE = 1031,
0049 ARRAY_BOOL = 1050,
0050 ARRAY_STRING = 1051
0051 };
0052
0053 public:
0054 value():m_label(0) {
0055 m_type = NONE;
0056 u.m_unsigned_int64 = 0;
0057 }
0058
0059 value(bool a_value):m_label(0) {
0060 m_type = BOOL;
0061 u.m_bool = a_value;
0062 }
0063 value(short a_value):m_label(0) {
0064 m_type = SHORT;
0065 u.m_short = a_value;
0066 }
0067 value(int a_value):m_label(0) {
0068 m_type = INT;
0069 u.m_int = a_value;
0070 }
0071 value(int64 a_value):m_label(0) {
0072 m_type = INT64;
0073 u.m_int64 = a_value;
0074 }
0075 value(uint64 a_value):m_label(0) {
0076 m_type = UNSIGNED_INT64;
0077 u.m_unsigned_int64 = a_value;
0078 }
0079 value(float a_value):m_label(0) {
0080 m_type = FLOAT;
0081 u.m_float = a_value;
0082 }
0083 value(double a_value):m_label(0) {
0084 m_type = DOUBLE;
0085 u.m_double = a_value;
0086 }
0087
0088 value(unsigned short a_value):m_label(0) {
0089 m_type = UNSIGNED_SHORT;
0090 u.m_unsigned_short = a_value;
0091 }
0092 value(unsigned int a_value):m_label(0) {
0093 m_type = UNSIGNED_INT;
0094 u.m_unsigned_int = a_value;
0095 }
0096 value(void* a_value):m_label(0) {
0097 m_type = VOID_STAR;
0098 u.m_void_star = a_value;
0099 }
0100 value(double* a_value):m_label(0) {
0101 m_type = DOUBLE_STAR;
0102 u.m_double_star = a_value;
0103 }
0104 value(float* a_value):m_label(0) {
0105 m_type = FLOAT_STAR;
0106 u.m_float_star = a_value;
0107 }
0108 value(int* a_value):m_label(0) {
0109 m_type = INT_STAR;
0110 u.m_int_star = a_value;
0111 }
0112
0113 value(const char* a_value):m_label(0) {
0114 m_type = STRING;
0115 u.m_string = new std::string(a_value?a_value:"");
0116 }
0117 value(const std::string& a_value):m_label(0) {
0118 m_type = STRING;
0119 u.m_string = new std::string(a_value);
0120 }
0121
0122 #define TOOLS_VALUE_CSTOR(a_what,a_m_what,a_type) \
0123 value(const std::vector<a_what>& a_v):m_label(0){\
0124 m_type = a_type;\
0125 std::vector<unsigned int> is(1);\
0126 is[0] = (unsigned int)a_v.size();\
0127 u.a_m_what = new array<a_what>(is);\
0128 u.a_m_what->fill(a_v);\
0129 }
0130
0131 TOOLS_VALUE_CSTOR(unsigned short,m_array_unsigned_short,ARRAY_UNSIGNED_SHORT)
0132 TOOLS_VALUE_CSTOR(short,m_array_short,ARRAY_SHORT)
0133 TOOLS_VALUE_CSTOR(unsigned int,m_array_unsigned_int,ARRAY_UNSIGNED_INT)
0134 TOOLS_VALUE_CSTOR(int,m_array_int,ARRAY_INT)
0135 TOOLS_VALUE_CSTOR(uint64,m_array_unsigned_int64,ARRAY_UNSIGNED_INT64)
0136 TOOLS_VALUE_CSTOR(int64,m_array_int64,ARRAY_INT64)
0137 TOOLS_VALUE_CSTOR(float,m_array_float,ARRAY_FLOAT)
0138 TOOLS_VALUE_CSTOR(double,m_array_double,ARRAY_DOUBLE)
0139 TOOLS_VALUE_CSTOR(bool,m_array_bool,ARRAY_BOOL)
0140 TOOLS_VALUE_CSTOR(std::string,m_array_string,ARRAY_STRING)
0141
0142 #undef TOOLS_VALUE_CSTOR
0143
0144 #define TOOLS_VALUE_CSTORA(a_what,a_m_what,a_type) \
0145 value(const array<a_what>& a_a):m_label(0){\
0146 m_type = a_type;\
0147 u.a_m_what = new array<a_what>(a_a);\
0148 }
0149
0150 TOOLS_VALUE_CSTORA(unsigned short,m_array_unsigned_short,ARRAY_UNSIGNED_SHORT)
0151 TOOLS_VALUE_CSTORA(short,m_array_short,ARRAY_SHORT)
0152 TOOLS_VALUE_CSTORA(unsigned int,m_array_unsigned_int,ARRAY_UNSIGNED_INT)
0153 TOOLS_VALUE_CSTORA(int,m_array_int,ARRAY_INT)
0154 TOOLS_VALUE_CSTORA(uint64,m_array_unsigned_int64,ARRAY_UNSIGNED_INT64)
0155 TOOLS_VALUE_CSTORA(int64,m_array_int64,ARRAY_INT64)
0156 TOOLS_VALUE_CSTORA(float,m_array_float,ARRAY_FLOAT)
0157 TOOLS_VALUE_CSTORA(double,m_array_double,ARRAY_DOUBLE)
0158 TOOLS_VALUE_CSTORA(bool,m_array_bool,ARRAY_BOOL)
0159 TOOLS_VALUE_CSTORA(std::string,m_array_string,ARRAY_STRING)
0160
0161 #undef TOOLS_VALUE_CSTORA
0162
0163 virtual ~value() {
0164 delete m_label;
0165 reset();
0166 }
0167 public:
0168 value(const value& a_from):m_label(0){
0169 if(a_from.m_label) m_label = new std::string(*a_from.m_label);
0170 m_type = a_from.m_type;
0171
0172 if(a_from.m_type==STRING) {
0173 u.m_string = new std::string(*a_from.u.m_string);
0174
0175 } else if(a_from.m_type==ARRAY_UNSIGNED_SHORT) {
0176 u.m_array_unsigned_short =
0177 new array<unsigned short>(*a_from.u.m_array_unsigned_short);
0178
0179 } else if(a_from.m_type==ARRAY_SHORT) {
0180 u.m_array_short = new array<short>(*a_from.u.m_array_short);
0181
0182 } else if(a_from.m_type==ARRAY_UNSIGNED_INT) {
0183 u.m_array_unsigned_int = new array<unsigned int>(*a_from.u.m_array_unsigned_int);
0184
0185 } else if(a_from.m_type==ARRAY_INT) {
0186 u.m_array_int = new array<int>(*a_from.u.m_array_int);
0187
0188 } else if(a_from.m_type==ARRAY_UNSIGNED_INT64) {
0189 u.m_array_unsigned_int64 = new array<uint64>(*a_from.u.m_array_unsigned_int64);
0190
0191 } else if(a_from.m_type==ARRAY_INT64) {
0192 u.m_array_int64 = new array<int64>(*a_from.u.m_array_int64);
0193
0194 } else if(a_from.m_type==ARRAY_FLOAT) {
0195 u.m_array_float = new array<float>(*a_from.u.m_array_float);
0196
0197 } else if(a_from.m_type==ARRAY_DOUBLE) {
0198 u.m_array_double = new array<double>(*a_from.u.m_array_double);
0199
0200 } else if(a_from.m_type==ARRAY_BOOL) {
0201 u.m_array_bool = new array<bool>(*a_from.u.m_array_bool);
0202
0203 } else if(a_from.m_type==ARRAY_STRING) {
0204 u.m_array_string = new array<std::string>(*a_from.u.m_array_string);
0205
0206 } else {
0207 u = a_from.u;
0208 }
0209 }
0210
0211 value& operator=(const value& a_from) {
0212 if(&a_from==this) return *this;
0213
0214 delete m_label;m_label = 0;
0215 if(a_from.m_label) m_label = new std::string(*a_from.m_label);
0216
0217 reset();
0218
0219 m_type = a_from.m_type;
0220
0221 if(a_from.m_type==STRING) {
0222 u.m_string = new std::string(*a_from.u.m_string);
0223
0224 } else if(a_from.m_type==ARRAY_UNSIGNED_SHORT) {
0225 u.m_array_unsigned_short = new array<unsigned short>(*a_from.u.m_array_unsigned_short);
0226
0227 } else if(a_from.m_type==ARRAY_SHORT) {
0228 u.m_array_short = new array<short>(*a_from.u.m_array_short);
0229
0230 } else if(a_from.m_type==ARRAY_UNSIGNED_INT) {
0231 u.m_array_unsigned_int = new array<unsigned int>(*a_from.u.m_array_unsigned_int);
0232
0233 } else if(a_from.m_type==ARRAY_INT) {
0234 u.m_array_int = new array<int>(*a_from.u.m_array_int);
0235
0236 } else if(a_from.m_type==ARRAY_UNSIGNED_INT64) {
0237 u.m_array_unsigned_int64 = new array<uint64>(*a_from.u.m_array_unsigned_int64);
0238
0239 } else if(a_from.m_type==ARRAY_INT64) {
0240 u.m_array_int64 = new array<int64>(*a_from.u.m_array_int64);
0241
0242 } else if(a_from.m_type==ARRAY_FLOAT) {
0243 u.m_array_float = new array<float>(*a_from.u.m_array_float);
0244
0245 } else if(a_from.m_type==ARRAY_DOUBLE) {
0246 u.m_array_double = new array<double>(*a_from.u.m_array_double);
0247
0248 } else if(a_from.m_type==ARRAY_BOOL) {
0249 u.m_array_bool = new array<bool>(*a_from.u.m_array_bool);
0250
0251 } else if(a_from.m_type==ARRAY_STRING) {
0252 u.m_array_string = new array<std::string>(*a_from.u.m_array_string);
0253
0254 } else {
0255 u = a_from.u;
0256 }
0257
0258 return *this;
0259 }
0260
0261 private:
0262 static const std::string& s_empty() {
0263 static const std::string s_v("");
0264 return s_v;
0265 }
0266 public:
0267 void set_label(const std::string& a_s) {
0268 delete m_label;
0269 m_label = new std::string(a_s);
0270 }
0271 const std::string& label() const {return m_label?(*m_label):s_empty();}
0272
0273 e_type type() const {return m_type;}
0274 void set_type(e_type a_type) {
0275 reset();
0276 m_type = a_type;
0277 switch(a_type) {
0278 case NONE: u.m_unsigned_int64 = 0;break;
0279 case UNSIGNED_SHORT: u.m_unsigned_short = 0;break;
0280 case SHORT: u.m_short = 0;break;
0281 case UNSIGNED_INT: u.m_unsigned_int = 0;break;
0282 case INT: u.m_int = 0;break;
0283 case UNSIGNED_INT64: u.m_unsigned_int64 =0;break;
0284 case INT64: u.m_int64 = 0;break;
0285 case FLOAT: u.m_float = 0;break;
0286 case DOUBLE: u.m_double = 0;break;
0287 case BOOL: u.m_bool = false;break;
0288 case VOID_STAR: u.m_void_star = 0;break;
0289 case DOUBLE_STAR: u.m_double_star = 0;break;
0290 case FLOAT_STAR: u.m_float_star = 0;break;
0291 case INT_STAR: u.m_int_star = 0;break;
0292 case STRING: u.m_string = new std::string("");break;
0293
0294 case ARRAY_UNSIGNED_SHORT:
0295 u.m_array_unsigned_short = new array<unsigned short>();break;
0296 case ARRAY_SHORT:u.m_array_short = new array<short>();break;
0297
0298 case ARRAY_UNSIGNED_INT:
0299 u.m_array_unsigned_int = new array<unsigned int>();break;
0300 case ARRAY_INT:u.m_array_int = new array<int>();break;
0301 case ARRAY_UNSIGNED_INT64:
0302 u.m_array_unsigned_int64 = new array<uint64>();break;
0303 case ARRAY_INT64:u.m_array_int64 = new array<int64>();break;
0304
0305 case ARRAY_FLOAT:u.m_array_float = new array<float>();break;
0306 case ARRAY_DOUBLE:u.m_array_double = new array<double>();break;
0307 case ARRAY_BOOL:u.m_array_bool = new array<bool>();break;
0308 case ARRAY_STRING:u.m_array_string = new array<std::string>();break;
0309 }
0310 }
0311
0312 void set_none() {
0313 reset();
0314 m_type = NONE;
0315 u.m_unsigned_int64 = 0;
0316 }
0317
0318 void set(short a_value) {
0319 reset();
0320 m_type = SHORT;
0321 u.m_short = a_value;
0322 }
0323 void set(unsigned short a_value) {
0324 reset();
0325 m_type = UNSIGNED_SHORT;
0326 u.m_unsigned_short = a_value;
0327 }
0328 void set(int a_value) {
0329 reset();
0330 m_type = INT;
0331 u.m_int = a_value;
0332 }
0333 void set(unsigned int a_value) {
0334 reset();
0335 m_type = UNSIGNED_INT;
0336 u.m_unsigned_int = a_value;
0337 }
0338 void set(int64 a_value) {
0339 reset();
0340 m_type = INT64;
0341 u.m_int64 = a_value;
0342 }
0343 void set(uint64 a_value) {
0344 reset();
0345 m_type = UNSIGNED_INT64;
0346 u.m_unsigned_int64 = a_value;
0347 }
0348 void set(float a_value) {
0349 reset();
0350 m_type = FLOAT;
0351 u.m_float = a_value;
0352 }
0353 void set(double a_value) {
0354 reset();
0355 m_type = DOUBLE;
0356 u.m_double = a_value;
0357 }
0358 void set(bool a_value) {
0359 reset();
0360 m_type = BOOL;
0361 u.m_bool = a_value;
0362 }
0363
0364 void set(const std::string& a_value) {
0365 reset();
0366 m_type = STRING;
0367 u.m_string = new std::string(a_value);
0368 }
0369 void set(const char* a_value) {
0370 // To avoid the bool, const std::string& and passing "text" problem.
0371 reset();
0372 m_type = STRING;
0373 u.m_string = new std::string(a_value);
0374 }
0375
0376 void set(void* a_value) {
0377 reset();
0378 m_type = VOID_STAR;
0379 u.m_void_star = a_value;
0380 }
0381
0382 void set(double* a_value) {
0383 reset();
0384 m_type = DOUBLE_STAR;
0385 u.m_double_star = a_value;
0386 }
0387 void set(float* a_value) {
0388 reset();
0389 m_type = FLOAT_STAR;
0390 u.m_float_star = a_value;
0391 }
0392 void set(int* a_value) {
0393 reset();
0394 m_type = INT_STAR;
0395 u.m_int_star = a_value;
0396 }
0397
0398 unsigned int get_unsigned_int() const {return u.m_unsigned_int;}
0399 int get_int() const {return u.m_int;}
0400
0401 int64 get_int64() const {return u.m_int64;}
0402 uint64 get_unsigned_int64() const {return u.m_unsigned_int64;}
0403
0404 unsigned short get_unsigned_short() const{return u.m_unsigned_short;}
0405 short get_short() const {return u.m_short;}
0406 float get_float() const {return u.m_float;}
0407 double get_double() const {return u.m_double;}
0408 void* get_void_star() const {return u.m_void_star;}
0409 double* get_double_star() const {return u.m_double_star;}
0410 float* get_float_star() const {return u.m_float_star;}
0411 int* get_int_star() const {return u.m_int_star;}
0412 bool get_bool() const {return u.m_bool;}
0413
0414 const std::string& get_string() const {return *u.m_string;}
0415
0416 #define TOOLS_VALUE_SET(a_what,a_m_what,a_type) \
0417 void set(const std::vector<unsigned int>& a_orders,const std::vector<a_what>& a_v){\
0418 reset();\
0419 m_type = a_type;\
0420 u.a_m_what = new array<a_what>(a_orders);\
0421 u.a_m_what->fill(a_v);\
0422 }
0423
0424 TOOLS_VALUE_SET(unsigned short,m_array_unsigned_short,ARRAY_UNSIGNED_SHORT)
0425 TOOLS_VALUE_SET(short,m_array_short,ARRAY_SHORT)
0426 TOOLS_VALUE_SET(unsigned int,m_array_unsigned_int,ARRAY_UNSIGNED_INT)
0427 TOOLS_VALUE_SET(int,m_array_int,ARRAY_INT)
0428 TOOLS_VALUE_SET(uint64,m_array_unsigned_int64,ARRAY_UNSIGNED_INT64)
0429 TOOLS_VALUE_SET(int64,m_array_int64,ARRAY_INT64)
0430 TOOLS_VALUE_SET(float,m_array_float,ARRAY_FLOAT)
0431 TOOLS_VALUE_SET(double,m_array_double,ARRAY_DOUBLE)
0432 TOOLS_VALUE_SET(bool,m_array_bool,ARRAY_BOOL)
0433 TOOLS_VALUE_SET(std::string,m_array_string,ARRAY_STRING)
0434
0435 #undef TOOLS_VALUE_SET
0436
0437 #define TOOLS_VALUE_SET2(a_what,a_m_what,a_type) \
0438 void set(const std::vector<a_what>& a_v){\
0439 reset();\
0440 m_type = a_type;\
0441 std::vector<unsigned int> is(1);\
0442 is[0] = (unsigned int)a_v.size();\
0443 u.a_m_what = new array<a_what>(is);\
0444 u.a_m_what->fill(a_v);\
0445 }
0446
0447 TOOLS_VALUE_SET2(unsigned short,m_array_unsigned_short,ARRAY_UNSIGNED_SHORT)
0448 TOOLS_VALUE_SET2(short,m_array_short,ARRAY_SHORT)
0449 TOOLS_VALUE_SET2(unsigned int,m_array_unsigned_int,ARRAY_UNSIGNED_INT)
0450 TOOLS_VALUE_SET2(int,m_array_int,ARRAY_INT)
0451 TOOLS_VALUE_SET2(uint64,m_array_unsigned_int64,ARRAY_UNSIGNED_INT64)
0452 TOOLS_VALUE_SET2(int64,m_array_int64,ARRAY_INT64)
0453 TOOLS_VALUE_SET2(float,m_array_float,ARRAY_FLOAT)
0454 TOOLS_VALUE_SET2(double,m_array_double,ARRAY_DOUBLE)
0455 TOOLS_VALUE_SET2(bool,m_array_bool,ARRAY_BOOL)
0456 TOOLS_VALUE_SET2(std::string,m_array_string,ARRAY_STRING)
0457
0458 #undef TOOLS_VALUE_SET2
0459
0460 public:
0461 bool s_type(std::string& a_s) const {return s_type(m_type,a_s);}
0462
0463 static bool s_type(value::e_type a_type,std::string& a_s){
0464 switch(a_type) {
0465 case NONE:a_s = "NONE";return true;
0466 case INT:a_s = "INT";return true;
0467 case INT64:a_s = "INT64";return true;
0468 case DOUBLE:a_s = "DOUBLE";return true;
0469 case STRING:a_s = "STRING";return true;
0470 case VOID_STAR:a_s = "VOID_STAR";return true;
0471 case DOUBLE_STAR:a_s = "DOUBLE_STAR";return true;
0472 case FLOAT_STAR:a_s = "FLOAT_STAR";return true;
0473 case INT_STAR:a_s = "INT_STAR";return true;
0474 case BOOL:a_s = "BOOL";return true;
0475 case SHORT:a_s = "SHORT";return true;
0476 case FLOAT:a_s = "FLOAT";return true;
0477 case UNSIGNED_SHORT:a_s = "UNSIGNED_SHORT";return true;
0478 case UNSIGNED_INT:a_s = "UNSIGNED_INT";return true;
0479 case UNSIGNED_INT64:a_s = "UNSIGNED_INT64";return true;
0480 case ARRAY_UNSIGNED_SHORT:a_s = "ARRAY_UNSIGNED_SHORT";return true;
0481 case ARRAY_SHORT:a_s = "ARRAY_SHORT";return true;
0482 case ARRAY_UNSIGNED_INT:a_s = "ARRAY_UNSIGNED_INT";return true;
0483 case ARRAY_INT:a_s = "ARRAY_INT";return true;
0484 case ARRAY_UNSIGNED_INT64:a_s = "ARRAY_UNSIGNED_INT64";return true;
0485 case ARRAY_INT64:a_s = "ARRAY_INT64";return true;
0486 case ARRAY_FLOAT:a_s = "ARRAY_FLOAT";return true;
0487 case ARRAY_DOUBLE:a_s = "ARRAY_DOUBLE";return true;
0488 case ARRAY_BOOL:a_s = "ARRAY_BOOL";return true;
0489 case ARRAY_STRING:a_s = "ARRAY_STRING";return true;
0490 default:a_s.clear();return false;
0491 }
0492
0493 }
0494 bool tos(std::string& a_s) const {return tos(*this,a_s);}
0495
0496 static bool tos(const value& a_v,std::string& a_s){
0497 switch(a_v.m_type) {
0498 case NONE:
0499 sprintf(a_s,5,"(nil)");
0500 return true;
0501 case BOOL:
0502 sprintf(a_s,5,"%s",a_v.u.m_bool?"true":"false");
0503 return true;
0504 case UNSIGNED_SHORT:
0505 sprintf(a_s,32,"%u",a_v.u.m_unsigned_short);
0506 return true;
0507 case SHORT:
0508 sprintf(a_s,32,"%d",a_v.u.m_short);
0509 return true;
0510 case UNSIGNED_INT:
0511 sprintf(a_s,32,"%u",a_v.u.m_unsigned_int);
0512 return true;
0513 case INT:
0514 sprintf(a_s,32,"%d",a_v.u.m_int);
0515 return true;
0516 case UNSIGNED_INT64:
0517 sprintf(a_s,32,int64_format(),a_v.u.m_unsigned_int64);
0518 return true;
0519 case INT64:
0520 sprintf(a_s,32,int64_format(),a_v.u.m_int64);
0521 return true;
0522 case FLOAT:
0523 sprintf(a_s,32,"%g",a_v.u.m_float);
0524 return true;
0525 case DOUBLE:
0526 sprintf(a_s,32,"%g",a_v.u.m_double);
0527 return true;
0528 case VOID_STAR:
0529 sprintf(a_s,32,upointer_format_x(),(upointer)a_v.u.m_void_star);
0530 return true;
0531 case DOUBLE_STAR:
0532 sprintf(a_s,32,upointer_format_x(),(upointer)a_v.u.m_double_star);
0533 return true;
0534 case FLOAT_STAR:
0535 sprintf(a_s,32,upointer_format_x(),(upointer)a_v.u.m_float_star);
0536 return true;
0537 case INT_STAR:
0538 sprintf(a_s,32,upointer_format_x(),(upointer)a_v.u.m_int_star);
0539 return true;
0540 case STRING:
0541 a_s = *a_v.u.m_string;
0542 return true;
0543
0544 case ARRAY_UNSIGNED_SHORT:
0545 return nums2s<unsigned short>(a_v.u.m_array_unsigned_short->vector(),a_s);
0546 case ARRAY_SHORT:
0547 return nums2s<short>(a_v.u.m_array_short->vector(),a_s);
0548
0549 case ARRAY_UNSIGNED_INT:
0550 return nums2s<unsigned int>(a_v.u.m_array_unsigned_int->vector(),a_s);
0551 case ARRAY_INT:
0552 return nums2s<int>(a_v.u.m_array_int->vector(),a_s);
0553
0554 case ARRAY_UNSIGNED_INT64:
0555 return nums2s<uint64>(a_v.u.m_array_unsigned_int64->vector(),a_s);
0556 case ARRAY_INT64:
0557 return nums2s<int64>(a_v.u.m_array_int64->vector(),a_s);
0558
0559 case ARRAY_FLOAT:
0560 return nums2s<float>(a_v.u.m_array_float->vector(),a_s);
0561 case ARRAY_DOUBLE:
0562 return nums2s<double>(a_v.u.m_array_double->vector(),a_s);
0563 case ARRAY_BOOL:
0564 b2s(a_v.u.m_array_bool->vector(),a_s);
0565 return true;
0566 case ARRAY_STRING:
0567 return nums2s<std::string>(a_v.u.m_array_string->vector(),a_s);
0568 default:
0569 a_s.clear();
0570 return false;
0571 }
0572 }
0573
0574 public: // for valop :
0575
0576 std::string stype() const {
0577 std::string _s;
0578 if(!s_type(_s)) return "unknown";
0579 return _s;
0580 }
0581
0582 static std::string stype(e_type a_type) {
0583 std::string _s;
0584 if(!s_type(a_type,_s)) return "unknown";
0585 return _s;
0586 }
0587
0588 static std::string to_string(const value&);
0589
0590 protected:
0591 void reset() {
0592 if(m_type==STRING) {
0593 delete u.m_string;
0594 u.m_string = 0;
0595 } else if(m_type==ARRAY_UNSIGNED_SHORT) {
0596 delete u.m_array_unsigned_short;u.m_array_unsigned_short = 0;
0597
0598 } else if(m_type==ARRAY_SHORT) {
0599 delete u.m_array_short;u.m_array_short = 0;
0600
0601 } else if(m_type==ARRAY_UNSIGNED_INT) {
0602 delete u.m_array_unsigned_int;u.m_array_unsigned_int = 0;
0603
0604 } else if(m_type==ARRAY_INT) {
0605 delete u.m_array_int;u.m_array_int = 0;
0606
0607 } else if(m_type==ARRAY_UNSIGNED_INT64) {
0608 delete u.m_array_unsigned_int64;u.m_array_unsigned_int64 = 0;
0609
0610 } else if(m_type==ARRAY_INT64) {
0611 delete u.m_array_int64;u.m_array_int64 = 0;
0612
0613 } else if(m_type==ARRAY_FLOAT) {
0614 delete u.m_array_float;u.m_array_float = 0;
0615
0616 } else if(m_type==ARRAY_DOUBLE) {
0617 delete u.m_array_double;u.m_array_double = 0;
0618
0619 } else if(m_type==ARRAY_BOOL) {
0620 delete u.m_array_bool;u.m_array_bool = 0;
0621
0622 } else if(m_type==ARRAY_STRING) {
0623 delete u.m_array_string;u.m_array_string = 0;
0624
0625 } else {
0626 u.m_unsigned_int64 = 0;
0627 }
0628 }
0629 protected:
0630 std::string* m_label;
0631 protected:
0632 e_type m_type;
0633 union {
0634 bool m_bool;
0635 int m_int;
0636 short m_short;
0637 int64 m_int64;
0638 float m_float;
0639 double m_double;
0640 unsigned short m_unsigned_short;
0641 unsigned int m_unsigned_int;
0642 uint64 m_unsigned_int64;
0643 void* m_void_star;
0644 double* m_double_star;
0645 float* m_float_star;
0646 int* m_int_star;
0647 std::string* m_string;
0648
0649 array<unsigned char>* m_array_unsigned_char;
0650 array<char>* m_array_char;
0651 array<unsigned short>* m_array_unsigned_short;
0652 array<short>* m_array_short;
0653 array<uint64>* m_array_unsigned_int64;
0654 array<int64>* m_array_int64;
0655 array<unsigned int>* m_array_unsigned_int;
0656 array<int>* m_array_int;
0657 array<float>* m_array_float;
0658 array<double>* m_array_double;
0659 array<bool>* m_array_bool;
0660 array<std::string>* m_array_string;
0661 } u;
0662 };
0663
0664 }
0665
0666 #include "value.icc"
0667
0668 #endif