views:

24

answers:

1

You can display a Value's type like this:

cout << val.type() << end;

and it print a number.

How can I map this number back to the actual type?

besides peeking in the header file, of course, which reveals all...

enum Value_type {
    obj_type,array_type,str_type,bool_type,int_type,real_type,null_type
};
A: 

Nope, that seems to be the canonical way:

    switch(v.type()) {
        case obj_type:    pp_obj(v, lev+1);   break;
        case array_type:  pp_array(v, lev+1); break;
        case str_type:    pp<string>(v, lev+1);   break;
        case bool_type:   pp<bool>(v, lev+1);  break;
        case int_type:    pp<int>(v, lev+1);   break;
        case real_type:   pp<double>(v, lev+1);  break;
        case null_type:   pp_null(v, lev+1);  break;
    }
Mark Harrison