0

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
};
Mark Harrison
  • 297,451
  • 125
  • 333
  • 465
  • Odd question - the return type of `value()` is the enum you mention. It only appears to be a number because you're implicitly casting it to an int when you attempt to write it to an ostream. – jon hanson Sep 14 '11 at 11:26

2 Answers2

0

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
  • 297,451
  • 125
  • 333
  • 465
0

Value val; read(is, val); Object o = val.get_obj();

Then create a Pair, assuming it's type 0. Pair pair = o[1];

where 1 is the iterated value. This took me forever to figure out, so I'm trying to save the time of anyone else who needs to look this up later. use sizeof(o)/sizeof(int) to iterate, along with the ++i instead of i++.

NazCodezz
  • 81
  • 1
  • 1