From 611748a1e815e9e9bc9944a8b73f7d6505e77216 Mon Sep 17 00:00:00 2001 From: Mike Anchor Date: Wed, 6 Jul 2016 09:10:02 +0100 Subject: Allow a JSONValue to be created from an int --- src/JSONValue.cpp | 13 +++++++++++++ src/JSONValue.h | 1 + src/demo/testcases.cpp | 13 +++++++++++++ 3 files changed, 27 insertions(+) diff --git a/src/JSONValue.cpp b/src/JSONValue.cpp index 376059e..6aa79bf 100644 --- a/src/JSONValue.cpp +++ b/src/JSONValue.cpp @@ -367,6 +367,19 @@ JSONValue::JSONValue(double m_number_value) number_value = m_number_value; } +/** + * Basic constructor for creating a JSON Value of type Number + * + * @access public + * + * @param int m_integer_value The number to use as the value + */ +JSONValue::JSONValue(int m_integer_value) +{ + type = JSONType_Number; + number_value = (double) m_integer_value; +} + /** * Basic constructor for creating a JSON Value of type Array * diff --git a/src/JSONValue.h b/src/JSONValue.h index e7024f9..1e38228 100644 --- a/src/JSONValue.h +++ b/src/JSONValue.h @@ -44,6 +44,7 @@ class JSONValue JSONValue(const std::wstring &m_string_value); JSONValue(bool m_bool_value); JSONValue(double m_number_value); + JSONValue(int m_integer_value); JSONValue(const JSONArray &m_array_value); JSONValue(const JSONObject &m_object_value); JSONValue(const JSONValue &m_source); diff --git a/src/demo/testcases.cpp b/src/demo/testcases.cpp index 5fe28a5..a73c20b 100644 --- a/src/demo/testcases.cpp +++ b/src/demo/testcases.cpp @@ -177,5 +177,18 @@ void run_tests() } print_out(test_output.c_str()); + // Test case for int initialisation of JSONValue. + test_output = wstring(L"| Testing JSONValue int initialisation") + wstring(DESC_LENGTH - 36, L' ') + wstring(L" | "); + JSONValue int_test = JSONValue(42); + if (int_test.Stringify() == L"42") + { + test_output += wstring(L"passed |\r\n"); + } + else + { + test_output += wstring(L"failed |\r\n"); + } + print_out(test_output.c_str()); + print_out(vert_sep.c_str()); } -- cgit v1.2.3