From 208a781e476a962b4c0120827586c379274f2dc0 Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Fri, 23 Mar 2007 08:55:25 +0000 Subject: [PATCH] Added empty() operator-bang and isNull() --- include/json/value.h | 10 +++++++++- src/lib_json/json_value.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/include/json/value.h b/include/json/value.h index 2453cb1..de09d5f 100644 --- a/include/json/value.h +++ b/include/json/value.h @@ -233,6 +233,7 @@ namespace Json { double asDouble() const; bool asBool() const; + bool isNull() const; bool isBool() const; bool isInt() const; bool isUInt() const; @@ -248,7 +249,14 @@ namespace Json { /// Number of values in array or object UInt size() const; - /// Removes all object members and array elements. + /// \brief Return true if empty array, empty object, or null; + /// otherwise, false. + bool empty() const; + + /// Return isNull() + bool operator!() const; + + /// Remove all object members and array elements. /// \pre type() is arrayValue, objectValue, or nullValue /// \post type() is unchanged void clear(); diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index 5fbbe13..329b634 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -888,6 +888,23 @@ Value::size() const } +bool +Value::empty() const +{ + if ( isNull() || isArray() || isObject() ) + return size() == 0u; + else + return false; +} + + +bool +Value::operator!() const +{ + return isNull(); +} + + void Value::clear() { @@ -1217,6 +1234,13 @@ Value::getMemberNames() const //# endif +bool +Value::isNull() const +{ + return type_ == nullValue; +} + + bool Value::isBool() const {