Skip to content

Commit

Permalink
fixed #97
Browse files Browse the repository at this point in the history
- added functions is_structured() and is_primitive()
- updated documentation
- updated test cases
  • Loading branch information
nlohmann committed Jun 27, 2015
1 parent 3ffedea commit c58c5aa
Show file tree
Hide file tree
Showing 11 changed files with 396 additions and 98 deletions.
25 changes: 25 additions & 0 deletions doc/examples/is_primitive.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <json.hpp>

using namespace nlohmann;

int main()
{
// create JSON values
json j_null;
json j_boolean = true;
json j_number_integer = 17;
json j_number_float = 23.42;
json j_object = {{"one", 1}, {"two", 2}};
json j_array = {1, 2, 4, 8, 16};
json j_string = "Hello, world";

// call is_primitive()
std::cout << std::boolalpha;
std::cout << j_null.is_primitive() << '\n';
std::cout << j_boolean.is_primitive() << '\n';
std::cout << j_number_integer.is_primitive() << '\n';
std::cout << j_number_float.is_primitive() << '\n';
std::cout << j_object.is_primitive() << '\n';
std::cout << j_array.is_primitive() << '\n';
std::cout << j_string.is_primitive() << '\n';
}
7 changes: 7 additions & 0 deletions doc/examples/is_primitive.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
true
true
true
true
false
false
true
25 changes: 25 additions & 0 deletions doc/examples/is_structured.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <json.hpp>

using namespace nlohmann;

int main()
{
// create JSON values
json j_null;
json j_boolean = true;
json j_number_integer = 17;
json j_number_float = 23.42;
json j_object = {{"one", 1}, {"two", 2}};
json j_array = {1, 2, 4, 8, 16};
json j_string = "Hello, world";

// call is_structured()
std::cout << std::boolalpha;
std::cout << j_null.is_structured() << '\n';
std::cout << j_boolean.is_structured() << '\n';
std::cout << j_number_integer.is_structured() << '\n';
std::cout << j_number_float.is_structured() << '\n';
std::cout << j_object.is_structured() << '\n';
std::cout << j_array.is_structured() << '\n';
std::cout << j_string.is_structured() << '\n';
}
7 changes: 7 additions & 0 deletions doc/examples/is_structured.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
false
false
false
false
true
true
false
34 changes: 34 additions & 0 deletions doc/examples/operator__value_t.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <json.hpp>

using namespace nlohmann;

int main()
{
// create JSON values
json j_null;
json j_boolean = true;
json j_number_integer = 17;
json j_number_float = 23.42;
json j_object = {{"one", 1}, {"two", 2}};
json j_array = {1, 2, 4, 8, 16};
json j_string = "Hello, world";

// call operator value_t()
json::value_t t_null = j_null;
json::value_t t_boolean = j_boolean;
json::value_t t_number_integer = j_number_integer;
json::value_t t_number_float = j_number_float;
json::value_t t_object = j_object;
json::value_t t_array = j_array;
json::value_t t_string = j_string;

// print types
std::cout << std::boolalpha;
std::cout << (t_null == json::value_t::null) << '\n';
std::cout << (t_boolean == json::value_t::boolean) << '\n';
std::cout << (t_number_integer == json::value_t::number_integer) << '\n';
std::cout << (t_number_float == json::value_t::number_float) << '\n';
std::cout << (t_object == json::value_t::object) << '\n';
std::cout << (t_array == json::value_t::array) << '\n';
std::cout << (t_string == json::value_t::string) << '\n';
}
7 changes: 7 additions & 0 deletions doc/examples/operator__value_t.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
true
true
true
true
true
true
true
25 changes: 25 additions & 0 deletions doc/examples/type.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <json.hpp>

using namespace nlohmann;

int main()
{
// create JSON values
json j_null;
json j_boolean = true;
json j_number_integer = 17;
json j_number_float = 23.42;
json j_object = {{"one", 1}, {"two", 2}};
json j_array = {1, 2, 4, 8, 16};
json j_string = "Hello, world";

// call type()
std::cout << std::boolalpha;
std::cout << (j_null.type() == json::value_t::null) << '\n';
std::cout << (j_boolean.type() == json::value_t::boolean) << '\n';
std::cout << (j_number_integer.type() == json::value_t::number_integer) << '\n';
std::cout << (j_number_float.type() == json::value_t::number_float) << '\n';
std::cout << (j_object.type() == json::value_t::object) << '\n';
std::cout << (j_array.type() == json::value_t::array) << '\n';
std::cout << (j_string.type() == json::value_t::string) << '\n';
}
7 changes: 7 additions & 0 deletions doc/examples/type.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
true
true
true
true
true
true
true
Loading

0 comments on commit c58c5aa

Please sign in to comment.