Skip to content

Commit

Permalink
Fix issue nbsdx#4, add CMakeLists.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
abrock committed Mar 1, 2018
1 parent 8dd3e9b commit 45465a9
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 16 deletions.
17 changes: 17 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
cmake_minimum_required(VERSION 2.8)

project(SimpleJson)

add_library(SimpleJSON json.cpp)

foreach (example
array
init
iter
json
load
prim
)
add_executable(SimpleJson_${example}_example examples/${example}_example.cpp)
target_link_libraries(SimpleJson_${example}_example SimpleJSON)
endforeach()
2 changes: 1 addition & 1 deletion examples/array_example.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

#include "json.hpp"
#include "../json.hpp"
#include <iostream>

using json::JSON;
Expand Down
2 changes: 1 addition & 1 deletion examples/init_example.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

#include "json.hpp"
#include "../json.hpp"
#include <iostream>
#include <cstddef>

Expand Down
2 changes: 1 addition & 1 deletion examples/iter_example.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

#include "json.hpp"
#include "../json.hpp"
#include <iostream>

using json::JSON;
Expand Down
2 changes: 1 addition & 1 deletion examples/json_example.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

#include "json.hpp"
#include "../json.hpp"
#include <iostream>

using json::JSON;
Expand Down
2 changes: 1 addition & 1 deletion examples/load_example.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

#include "json.hpp"
#include "../json.hpp"
#include <iostream>

using namespace std;
Expand Down
2 changes: 1 addition & 1 deletion examples/prim_example.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

#include "json.hpp"
#include "../json.hpp"
#include <iostream>
#include <ios>

Expand Down
18 changes: 18 additions & 0 deletions json.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "json.hpp"

namespace json {
JSON JSON::Load( const string &str ) {
size_t offset = 0;
return std::move( parse_next( str, offset ) );
}

JSON Object() {
return std::move( JSON::Make( JSON::Class::Object ) );
}

std::ostream& operator<<( std::ostream &os, const JSON &json ) {
os << json.dump();
return os;
}

} // namespace json
19 changes: 9 additions & 10 deletions json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ class JSON
Class Type = Class::Null;
};

template<class T>
JSON Array() {
return std::move( JSON::Make( JSON::Class::Array ) );
}
Expand All @@ -429,14 +430,15 @@ JSON Array( T... args ) {
return std::move( arr );
}

JSON Object() {
return std::move( JSON::Make( JSON::Class::Object ) );
template <typename... T>
JSON Array() {
JSON arr = JSON::Make( JSON::Class::Array );
return std::move( arr );
}

std::ostream& operator<<( std::ostream &os, const JSON &json ) {
os << json.dump();
return os;
}
JSON Object();

std::ostream& operator<<( std::ostream &os, const JSON &json );

namespace {
JSON parse_next( const string &, size_t & );
Expand Down Expand Up @@ -641,9 +643,6 @@ namespace {
}
}

JSON JSON::Load( const string &str ) {
size_t offset = 0;
return std::move( parse_next( str, offset ) );
}


} // End Namespace json

0 comments on commit 45465a9

Please sign in to comment.