| 1 |
sf-pippijn |
1.1 |
struct value_t |
| 2 |
|
|
{ |
| 3 |
|
|
typedef void convert_fn (void const *data); typedef convert_fn *convert_fp; |
| 4 |
|
|
typedef std::string str_fn (void const *data); |
| 5 |
|
|
|
| 6 |
|
|
enum type_code_t |
| 7 |
|
|
{ |
| 8 |
|
|
VALUE, |
| 9 |
|
|
ARRAY, |
| 10 |
|
|
MAP |
| 11 |
|
|
}; |
| 12 |
|
|
|
| 13 |
|
|
void const *data; |
| 14 |
|
|
str_fn *to_str; |
| 15 |
|
|
std::type_info const *type; |
| 16 |
|
|
|
| 17 |
|
|
value_t (void const *data, str_fn *to_str, std::type_info const &type) |
| 18 |
|
|
: data (data) |
| 19 |
|
|
, to_str (to_str) |
| 20 |
|
|
, type (&type) |
| 21 |
|
|
{ |
| 22 |
|
|
} |
| 23 |
|
|
|
| 24 |
|
|
std::string str () const |
| 25 |
|
|
{ |
| 26 |
|
|
assert (type_code () == VALUE); |
| 27 |
|
|
assert (to_str != NULL); |
| 28 |
|
|
return to_str (data); |
| 29 |
|
|
} |
| 30 |
|
|
|
| 31 |
|
|
array_t const &array () const |
| 32 |
|
|
{ |
| 33 |
|
|
assert (type_code () == ARRAY); |
| 34 |
|
|
return *(array_t const *)data; |
| 35 |
|
|
} |
| 36 |
|
|
|
| 37 |
|
|
map_t const &map () const |
| 38 |
|
|
{ |
| 39 |
|
|
assert (type_code () == MAP); |
| 40 |
|
|
return *(map_t const *)data; |
| 41 |
|
|
} |
| 42 |
|
|
|
| 43 |
|
|
type_code_t type_code () const |
| 44 |
|
|
{ |
| 45 |
|
|
if (*type == typeid (map_t )) return MAP; |
| 46 |
|
|
if (*type == typeid (array_t)) return ARRAY; |
| 47 |
|
|
return VALUE; |
| 48 |
|
|
} |
| 49 |
|
|
}; |