Skip to content

Commit

Permalink
worked on #102: more documentation and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
nlohmann committed Jul 8, 2015
1 parent 19d550c commit c012b29
Show file tree
Hide file tree
Showing 33 changed files with 538 additions and 86 deletions.
2 changes: 2 additions & 0 deletions doc/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
SRCDIR = ../src

all: doxygen

clean:
rm -fr me.nlohmann.json.docset html

Expand Down
23 changes: 23 additions & 0 deletions doc/examples/operator__equal.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <json.hpp>

using namespace nlohmann;

int main()
{
// create several JSON values
json array_1 = {1, 2, 3};
json array_2 = {1, 2, 4};
json object_1 = {{"A", "a"}, {"B", "b"}};
json object_2 = {{"B", "b"}, {"A", "a"}};
json number_1 = 17;
json number_2 = 17.000000000000001L;
json string_1 = "foo";
json string_2 = "bar";

// output values and comparisons
std::cout << std::boolalpha;
std::cout << array_1 << " == " << array_2 << " " << (array_1 == array_2) << '\n';
std::cout << object_1 << " == " << object_2 << " " << (object_1 == object_2) << '\n';
std::cout << number_1 << " == " << number_2 << " " << (number_1 == number_2) << '\n';
std::cout << string_1 << " == " << string_2 << " " << (string_1 == string_2) << '\n';
}
1 change: 1 addition & 0 deletions doc/examples/operator__equal.link
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<a target="_blank" href="http://melpon.org/wandbox/permlink/a74tSggkWP5Zo0Ee"><b>online</b></a>
4 changes: 4 additions & 0 deletions doc/examples/operator__equal.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[1,2,3] == [1,2,4] false
{"A":"a","B":"b"} == {"A":"a","B":"b"} true
17 == 17 true
"foo" == "bar" false
23 changes: 23 additions & 0 deletions doc/examples/operator__greater.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <json.hpp>

using namespace nlohmann;

int main()
{
// create several JSON values
json array_1 = {1, 2, 3};
json array_2 = {1, 2, 4};
json object_1 = {{"A", "a"}, {"B", "b"}};
json object_2 = {{"B", "b"}, {"A", "a"}};
json number_1 = 17;
json number_2 = 17.0000000000001L;
json string_1 = "foo";
json string_2 = "bar";

// output values and comparisons
std::cout << std::boolalpha;
std::cout << array_1 << " == " << array_2 << " " << (array_1 > array_2) << '\n';
std::cout << object_1 << " == " << object_2 << " " << (object_1 > object_2) << '\n';
std::cout << number_1 << " == " << number_2 << " " << (number_1 > number_2) << '\n';
std::cout << string_1 << " == " << string_2 << " " << (string_1 > string_2) << '\n';
}
1 change: 1 addition & 0 deletions doc/examples/operator__greater.link
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<a target="_blank" href="http://melpon.org/wandbox/permlink/TZmhplJw3tl08RFN"><b>online</b></a>
4 changes: 4 additions & 0 deletions doc/examples/operator__greater.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[1,2,3] == [1,2,4] false
{"A":"a","B":"b"} == {"A":"a","B":"b"} false
17 == 17.0000000000001 false
"foo" == "bar" true
23 changes: 23 additions & 0 deletions doc/examples/operator__greaterequal.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <json.hpp>

using namespace nlohmann;

int main()
{
// create several JSON values
json array_1 = {1, 2, 3};
json array_2 = {1, 2, 4};
json object_1 = {{"A", "a"}, {"B", "b"}};
json object_2 = {{"B", "b"}, {"A", "a"}};
json number_1 = 17;
json number_2 = 17.0000000000001L;
json string_1 = "foo";
json string_2 = "bar";

// output values and comparisons
std::cout << std::boolalpha;
std::cout << array_1 << " >= " << array_2 << " " << (array_1 >= array_2) << '\n';
std::cout << object_1 << " >= " << object_2 << " " << (object_1 >= object_2) << '\n';
std::cout << number_1 << " >= " << number_2 << " " << (number_1 >= number_2) << '\n';
std::cout << string_1 << " >= " << string_2 << " " << (string_1 >= string_2) << '\n';
}
1 change: 1 addition & 0 deletions doc/examples/operator__greaterequal.link
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<a target="_blank" href="http://melpon.org/wandbox/permlink/clvCFZxlFEerhtk8"><b>online</b></a>
4 changes: 4 additions & 0 deletions doc/examples/operator__greaterequal.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[1,2,3] >= [1,2,4] false
{"A":"a","B":"b"} >= {"A":"a","B":"b"} true
17 >= 17.0000000000001 false
"foo" >= "bar" true
23 changes: 23 additions & 0 deletions doc/examples/operator__less.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <json.hpp>

using namespace nlohmann;

int main()
{
// create several JSON values
json array_1 = {1, 2, 3};
json array_2 = {1, 2, 4};
json object_1 = {{"A", "a"}, {"B", "b"}};
json object_2 = {{"B", "b"}, {"A", "a"}};
json number_1 = 17;
json number_2 = 17.0000000000001L;
json string_1 = "foo";
json string_2 = "bar";

// output values and comparisons
std::cout << std::boolalpha;
std::cout << array_1 << " == " << array_2 << " " << (array_1 < array_2) << '\n';
std::cout << object_1 << " == " << object_2 << " " << (object_1 < object_2) << '\n';
std::cout << number_1 << " == " << number_2 << " " << (number_1 < number_2) << '\n';
std::cout << string_1 << " == " << string_2 << " " << (string_1 < string_2) << '\n';
}
1 change: 1 addition & 0 deletions doc/examples/operator__less.link
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<a target="_blank" href="http://melpon.org/wandbox/permlink/85XpxnwbJZR1PVtz"><b>online</b></a>
4 changes: 4 additions & 0 deletions doc/examples/operator__less.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[1,2,3] == [1,2,4] true
{"A":"a","B":"b"} == {"A":"a","B":"b"} false
17 == 17.0000000000001 true
"foo" == "bar" false
23 changes: 23 additions & 0 deletions doc/examples/operator__lessequal.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <json.hpp>

using namespace nlohmann;

int main()
{
// create several JSON values
json array_1 = {1, 2, 3};
json array_2 = {1, 2, 4};
json object_1 = {{"A", "a"}, {"B", "b"}};
json object_2 = {{"B", "b"}, {"A", "a"}};
json number_1 = 17;
json number_2 = 17.0000000000001L;
json string_1 = "foo";
json string_2 = "bar";

// output values and comparisons
std::cout << std::boolalpha;
std::cout << array_1 << " <= " << array_2 << " " << (array_1 <= array_2) << '\n';
std::cout << object_1 << " <= " << object_2 << " " << (object_1 <= object_2) << '\n';
std::cout << number_1 << " <= " << number_2 << " " << (number_1 <= number_2) << '\n';
std::cout << string_1 << " <= " << string_2 << " " << (string_1 <= string_2) << '\n';
}
1 change: 1 addition & 0 deletions doc/examples/operator__lessequal.link
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<a target="_blank" href="http://melpon.org/wandbox/permlink/JYP6JpBzl8Q9xQDZ"><b>online</b></a>
4 changes: 4 additions & 0 deletions doc/examples/operator__lessequal.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[1,2,3] <= [1,2,4] true
{"A":"a","B":"b"} <= {"A":"a","B":"b"} true
17 <= 17.0000000000001 true
"foo" <= "bar" false
23 changes: 23 additions & 0 deletions doc/examples/operator__notequal.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <json.hpp>

using namespace nlohmann;

int main()
{
// create several JSON values
json array_1 = {1, 2, 3};
json array_2 = {1, 2, 4};
json object_1 = {{"A", "a"}, {"B", "b"}};
json object_2 = {{"B", "b"}, {"A", "a"}};
json number_1 = 17;
json number_2 = 17.000000000000001L;
json string_1 = "foo";
json string_2 = "bar";

// output values and comparisons
std::cout << std::boolalpha;
std::cout << array_1 << " == " << array_2 << " " << (array_1 != array_2) << '\n';
std::cout << object_1 << " == " << object_2 << " " << (object_1 != object_2) << '\n';
std::cout << number_1 << " == " << number_2 << " " << (number_1 != number_2) << '\n';
std::cout << string_1 << " == " << string_2 << " " << (string_1 != string_2) << '\n';
}
1 change: 1 addition & 0 deletions doc/examples/operator__notequal.link
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<a target="_blank" href="http://melpon.org/wandbox/permlink/csiUCov9Mquff3ZZ"><b>online</b></a>
4 changes: 4 additions & 0 deletions doc/examples/operator__notequal.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[1,2,3] == [1,2,4] true
{"A":"a","B":"b"} == {"A":"a","B":"b"} false
17 == 17 false
"foo" == "bar" true
24 changes: 24 additions & 0 deletions doc/examples/push_back.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <json.hpp>

using namespace nlohmann;

int main()
{
// create JSON values
json array = {1, 2, 3, 4, 5};
json null;

// print values
std::cout << array << '\n';
std::cout << null << '\n';

// add values
array.push_back(6);
array += 7;
null += "first";
null += "second";

// print values
std::cout << array << '\n';
std::cout << null << '\n';
}
1 change: 1 addition & 0 deletions doc/examples/push_back.link
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<a target="_blank" href="http://melpon.org/wandbox/permlink/5ZglUDvkQ0VxYxQ4"><b>online</b></a>
4 changes: 4 additions & 0 deletions doc/examples/push_back.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[1,2,3,4,5]
null
[1,2,3,4,5,6,7]
["first","second"]
24 changes: 24 additions & 0 deletions doc/examples/push_back__object_t__value.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <json.hpp>

using namespace nlohmann;

int main()
{
// create JSON values
json object = {{"one", 1}, {"two", 2}};
json null;

// print values
std::cout << object << '\n';
std::cout << null << '\n';

// add values
object.push_back(json::object_t::value_type("three", 3));
object += json::object_t::value_type("four", 4);
null += json::object_t::value_type("A", "a");
null += json::object_t::value_type("B", "b");

// print values
std::cout << object << '\n';
std::cout << null << '\n';
}
1 change: 1 addition & 0 deletions doc/examples/push_back__object_t__value.link
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<a target="_blank" href="http://melpon.org/wandbox/permlink/xtErbxTG2iIC5wHh"><b>online</b></a>
4 changes: 4 additions & 0 deletions doc/examples/push_back__object_t__value.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{"one":1,"two":2}
null
{"four":4,"one":1,"three":3,"two":2}
{"A":"a","B":"b"}
19 changes: 19 additions & 0 deletions doc/examples/swap__object_t.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <json.hpp>

using namespace nlohmann;

int main()
{
// create a JSON value
json value = { {"translation", {{"one", "eins"}, {"two", "zwei"}}} };

// create an object_t
json::object_t object = {{"cow", "Kuh"}, {"dog", "Hund"}};

// swap the object stored in the JSON value
value["translation"].swap(object);

// output the values
std::cout << "value = " << value << '\n';
std::cout << "object = " << object << '\n';
}
1 change: 1 addition & 0 deletions doc/examples/swap__object_t.link
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<a target="_blank" href="http://melpon.org/wandbox/permlink/g5pkLUCrBVoNPRyE"><b>online</b></a>
2 changes: 2 additions & 0 deletions doc/examples/swap__object_t.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
value = {"translation":{"cow":"Kuh","dog":"Hund"}}
object = {"one":"eins","two":"zwei"}
19 changes: 19 additions & 0 deletions doc/examples/swap__string_t.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <json.hpp>

using namespace nlohmann;

int main()
{
// create a JSON value
json value = { "the good", "the bad", "the ugly" };

// create string_t
json::string_t string = "the fast";

// swap the object stored in the JSON value
value[1].swap(string);

// output the values
std::cout << "value = " << value << '\n';
std::cout << "string = " << string << '\n';
}
1 change: 1 addition & 0 deletions doc/examples/swap__string_t.link
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<a target="_blank" href="http://melpon.org/wandbox/permlink/UsEo3yK2GsjH8CyA"><b>online</b></a>
2 changes: 2 additions & 0 deletions doc/examples/swap__string_t.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
value = ["the good","the fast","the ugly"]
string = the bad
Loading

0 comments on commit c012b29

Please sign in to comment.