diff --git a/json/tree.cpp b/json/tree.cpp index d11b907a..76268ea8 100644 --- a/json/tree.cpp +++ b/json/tree.cpp @@ -321,6 +321,54 @@ json::tree::node::as_chars (void) const } +/////////////////////////////////////////////////////////////////////////////// +namespace json { namespace tree { + template <> + bool node::as (void) const + { + return as_bool (); + } +} } + + +//----------------------------------------------------------------------------- +namespace json { namespace tree { + template <> + float json::tree::node::as (void) const + { + return as_float (); + } +} } + + +//----------------------------------------------------------------------------- +namespace json { namespace tree { + template <> + double + json::tree::node::as (void) const + { + return as_double (); + } +} } + + +//----------------------------------------------------------------------------- +#define AS_INTEGRAL(T) \ +namespace json { namespace tree { \ + template <> \ + T \ + node::as (void) const \ + { \ + return static_cast (as_double ()); \ + } \ +} } + +AS_INTEGRAL(uint8_t) +AS_INTEGRAL(uint16_t) +AS_INTEGRAL(uint32_t) +AS_INTEGRAL(uint64_t) + + /////////////////////////////////////////////////////////////////////////////// // Global operatoers bool diff --git a/json/tree.hpp b/json/tree.hpp index dc4913e7..ab0030e6 100644 --- a/json/tree.hpp +++ b/json/tree.hpp @@ -75,6 +75,9 @@ namespace json { namespace tree { virtual size_t as_uint (void) const; virtual const char* as_chars (void) const; + template + T as (void) const; + virtual bool is_object (void) const { return false; } virtual bool is_array (void) const { return false; } virtual bool is_string (void) const { return false; }