diff C++/modules/Json/Json.cpp @ 406:d485d36a8de1

Json: - Add clear functions - Add erase functions - Add initializer_list constructors - Update the unit tests
author David Demelier <markand@malikania.fr>
date Mon, 05 Oct 2015 20:24:48 +0200
parents f81478065901
children f5e62f6c1475
line wrap: on
line diff
--- a/C++/modules/Json/Json.cpp	Mon Oct 05 17:04:40 2015 +0200
+++ b/C++/modules/Json/Json.cpp	Mon Oct 05 20:24:48 2015 +0200
@@ -35,9 +35,12 @@
 	if (json_is_string(v)) {
 		return Value{json_string_value(v)};
 	}
-	if (json_is_number(v)) {
+	if (json_is_real(v)) {
 		return Value{json_number_value(v)};
 	}
+	if (json_is_integer(v)) {
+		return Value{static_cast<int>(json_integer_value(v))};
+	}
 	if (json_is_boolean(v)) {
 		return Value{json_boolean_value(v)};
 	}
@@ -108,20 +111,31 @@
 
 bool Value::toBool() const noexcept
 {
-	if (m_type != Type::Boolean)
+	if (m_type != Type::Boolean) {
 		return false;
+	}
 
 	return m_boolean;
 }
 
-double Value::toNumber() const noexcept
+double Value::toReal() const noexcept
 {
-	if (m_type != Type::Number)
+	if (m_type != Type::Real) {
 		return 0;
+	}
 
 	return m_number;
 }
 
+int Value::toInt() const noexcept
+{
+	if (m_type != Type::Int) {
+		return 0;
+	}
+
+	return m_integer;
+}
+
 std::string Value::toString() const noexcept
 {
 	if (m_type != Type::String) {
@@ -159,4 +173,4 @@
 	m_value = convert(json_load_file, file.path.c_str(), 0);
 }
 
-} // !json
\ No newline at end of file
+} // !json