c++ - Parsing YAML !!timestamp (date time) with yaml-cpp -
i'm using yaml-cpp amazing library parse yaml files , need parse scalar of !!timestamp type. example:
- timespec: starttime: 2013-05-15t02:59:43.138z endtime: 2013-05-23t02:59:43.138z 1 - how that? should parse std::string , handle parsing of date time myself? need import boost library data type conversion straightforward?
2 - , in general, yaml basic data types supported library?
you'll have parse datetime yourself. if have structure datetime, skeleton, write:
namespace yaml { template<> struct convert<datetime> { static node encode(const datetime& rhs) { std::string str = yourcodetoconverttoastring(rhs); return node(str); } static bool decode(const node& node, datetime& rhs) { if(!node.isscalar()) return false; std::string str = node.as<std::string>(); // fill in datetime struct. return true; } }; } if can find library (maybe boost) that, that'd easier, it's possible yaml format datetime isn't other library expects.
in general, yaml-cpp doesn't support automatic type detection.
Comments
Post a Comment