Closed GoogleCodeExporter closed 8 years ago
So you'd like node.as<int>() to throw an exception? I've thought about this
too, but I'm not sure how I feel about it.
Original comment by jbe...@gmail.com
on 25 Oct 2014 at 4:44
I am not sure exactly. For my application I switched to jsoncpp which instead
of having a generic scalar type, has explicit types for uint, int, bool, and
string. This preserves all the type information in the parsed file so I can
handle it properly on my end.
Essentially yaml-cpp is preforming some type erasure which is not what I want
for my application where I want to be relative strict about the types.
Original comment by jli...@gmail.com
on 26 Oct 2014 at 2:03
jsoncpp is also performing type erasure. You can't write a library that parses
this stuff without representing each node internally as, well, a node. In
yaml-cpp, we *can* attempt to understand the type.
Looking at jsoncpp's source, it appears that they throw an exception if you
access an incorrect type, which we can do, but as I said, I'm not sure if I
want to. What they *also* do is give you an enum, which we *can't* do, since in
yaml-cpp, you can parse arbitrary (user-defined) types.
Original comment by jbe...@gmail.com
on 26 Oct 2014 at 2:23
Could you have something like:
enum {
Map,
Sequence,
Int, // Maybe ScalarInt
Bool, // Maybe ScalarBool
String, // Maybe ScalarString
Real, // Maybe ScalarReal
UserDefined, // Maybe Unknown?, ScalarUser?
}
In my exact use case I was feeding data from a yaml-cpp into a generic
boost::any based config store. With the cast and catch exceptions approach I
was treating "1000" and 1000 as an integer when the end user really wanted
their string back.
Original comment by jli...@gmail.com
on 26 Oct 2014 at 2:37
No, I don't think I'll extend enum to specific scalar types, because I like
that various user types are first-class.
I'll leave this issue open and think about whether the cast should throw an
exception.
Original comment by jbe...@gmail.com
on 26 Oct 2014 at 11:36
This issue has moved to github: https://github.com/jbeder/yaml-cpp/issues/261
Original comment by jbe...@gmail.com
on 1 Apr 2015 at 3:28
Original issue reported on code.google.com by
jli...@gmail.com
on 23 Oct 2014 at 7:33