diff --git a/json.cpp.rl b/json.cpp.rl index 6cc2ae58..b9896b4e 100644 --- a/json.cpp.rl +++ b/json.cpp.rl @@ -305,6 +305,11 @@ json::node::as_boolean (void) const { throw parse_error ("node is not a boolean"); } +const json::null& +json::node::as_null (void) const + { throw parse_error ("node is not a null"); } + + bool json::node::operator!=(const node &rhs) const { return !(*this == rhs); } diff --git a/json.hpp b/json.hpp index 54dec959..b7c2bf7a 100644 --- a/json.hpp +++ b/json.hpp @@ -55,6 +55,7 @@ namespace json { virtual const string& as_string (void) const; virtual const number& as_number (void) const; virtual const boolean& as_boolean (void) const; + virtual const null& as_null (void) const; virtual bool is_object (void) const { return false; } virtual bool is_array (void) const { return false; } @@ -206,11 +207,13 @@ namespace json { /// Represents a JSON null value. class null : public node { public: - virtual bool is_null (void) const { return true; } virtual bool operator==(const null&) const { return true; } virtual bool operator==(const node &rhs) const { return rhs == *this; } + virtual bool is_null (void) const { return true; } + virtual const null& as_null (void) const { return *this; } + virtual std::ostream& write (std::ostream &os) const; };