Skip to content

Commit

Permalink
Release 1.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
arturl committed Nov 14, 2013
1 parent b5ccc39 commit 90402d1
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
26 changes: 26 additions & 0 deletions Release/include/cpprest/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,26 @@ namespace web { namespace json
/// <returns><c>true</c> if the value is a number value, <c>false</c> otherwise</returns>
bool is_number() const { return type() == Number; }

/// <summary>
/// Is the current value represented as an integer number value?
/// </summary>
/// <remarks>
/// Note that if a json value is a number but represented as a double it can still
/// be retrieved as a integer using as_integer(), however the value will be truncated.
/// </remarks>
/// <returns><c>true</c> if the value is an integer value, <c>false</c> otherwise.</returns>
_ASYNCRTIMP bool is_integer() const ;

/// <summary>
/// Is the current value represented as an double number value?
/// </summary>
/// <remarks>
/// Note that if a json value is a number but represented as a int it can still
/// be retrieved as a double using as_double().
/// </remarks>
/// <returns><c>true</c> if the value is an double value, <c>false</c> otherwise.</returns>
_ASYNCRTIMP bool is_double() const ;

/// <summary>
/// Is the current value a Boolean value?
/// </summary>
Expand Down Expand Up @@ -568,6 +588,9 @@ namespace web { namespace json

virtual json::value::value_type type() const { return json::value::Null; }

virtual bool is_integer() const { throw json_exception(_XPLATSTR("not a number")); }
virtual bool is_double() const { throw json_exception(_XPLATSTR("not a number")); }

virtual double as_double() const { throw json_exception(_XPLATSTR("not a number")); }
virtual int32_t as_integer() const { throw json_exception(_XPLATSTR("not a number")); }
virtual bool as_bool() const { throw json_exception(_XPLATSTR("not a boolean")); }
Expand Down Expand Up @@ -647,6 +670,9 @@ namespace web { namespace json

virtual json::value::value_type type() const { return json::value::Number; }

virtual bool is_integer() const { return m_was_int; }
virtual bool is_double() const { return !m_was_int; }

virtual double as_double() const { return m_was_int ? static_cast<double>(m_intval) : m_value; }
virtual int32_t as_integer() const { return m_was_int ? m_intval : static_cast<int32_t>(m_value); }

Expand Down
2 changes: 1 addition & 1 deletion Release/include/cpprest/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
* ==--==
*/
#define CPPREST_VERSION_REVISION 0
#define CPPREST_VERSION_REVISION 1
#define CPPREST_VERSION_MINOR 3
#define CPPREST_VERSION_MAJOR 1

Expand Down
18 changes: 18 additions & 0 deletions Release/src/json/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,24 @@ web::json::details::_Object::_Object(const _Object& other):web::json::details::_

web::json::value::value_type json::value::type() const { return m_value->type(); }

bool json::value::is_integer() const
{
if(!is_number())
{
return false;
}
return m_value->is_integer();
}

bool json::value::is_double() const
{
if(!is_number())
{
return false;
}
return m_value->is_double();
}

json::value& web::json::details::_Object::index(const utility::string_t &key)
{
map_fields();
Expand Down
4 changes: 4 additions & 0 deletions Release/tests/Functional/json/construction_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,12 @@ TEST(constructor_overloads)
VERIFY_IS_TRUE(v0.is_null());
VERIFY_ARE_EQUAL(v1.type(), json::value::Number);
VERIFY_IS_TRUE(v1.is_number());
VERIFY_IS_TRUE(v1.is_integer());
VERIFY_IS_FALSE(v1.is_double());
VERIFY_ARE_EQUAL(v2.type(), json::value::Number);
VERIFY_IS_TRUE(v2.is_number());
VERIFY_IS_TRUE(v2.is_double());
VERIFY_IS_FALSE(v2.is_integer());
VERIFY_ARE_EQUAL(v3.type(), json::value::Boolean);
VERIFY_IS_TRUE(v3.is_boolean());
VERIFY_ARE_EQUAL(v4.type(), json::value::String);
Expand Down

0 comments on commit 90402d1

Please sign in to comment.