Skip to content

Commit 45465a9

Browse files
committed
Fix issue nbsdx#4, add CMakeLists.txt
1 parent 8dd3e9b commit 45465a9

9 files changed

+50
-16
lines changed

CMakeLists.txt

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
cmake_minimum_required(VERSION 2.8)
2+
3+
project(SimpleJson)
4+
5+
add_library(SimpleJSON json.cpp)
6+
7+
foreach (example
8+
array
9+
init
10+
iter
11+
json
12+
load
13+
prim
14+
)
15+
add_executable(SimpleJson_${example}_example examples/${example}_example.cpp)
16+
target_link_libraries(SimpleJson_${example}_example SimpleJSON)
17+
endforeach()

examples/array_example.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#include "json.hpp"
2+
#include "../json.hpp"
33
#include <iostream>
44

55
using json::JSON;

examples/init_example.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#include "json.hpp"
2+
#include "../json.hpp"
33
#include <iostream>
44
#include <cstddef>
55

examples/iter_example.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#include "json.hpp"
2+
#include "../json.hpp"
33
#include <iostream>
44

55
using json::JSON;

examples/json_example.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#include "json.hpp"
2+
#include "../json.hpp"
33
#include <iostream>
44

55
using json::JSON;

examples/load_example.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#include "json.hpp"
2+
#include "../json.hpp"
33
#include <iostream>
44

55
using namespace std;

examples/prim_example.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
#include "json.hpp"
2+
#include "../json.hpp"
33
#include <iostream>
44
#include <ios>
55

json.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include "json.hpp"
2+
3+
namespace json {
4+
JSON JSON::Load( const string &str ) {
5+
size_t offset = 0;
6+
return std::move( parse_next( str, offset ) );
7+
}
8+
9+
JSON Object() {
10+
return std::move( JSON::Make( JSON::Class::Object ) );
11+
}
12+
13+
std::ostream& operator<<( std::ostream &os, const JSON &json ) {
14+
os << json.dump();
15+
return os;
16+
}
17+
18+
} // namespace json

json.hpp

+9-10
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ class JSON
418418
Class Type = Class::Null;
419419
};
420420

421+
template<class T>
421422
JSON Array() {
422423
return std::move( JSON::Make( JSON::Class::Array ) );
423424
}
@@ -429,14 +430,15 @@ JSON Array( T... args ) {
429430
return std::move( arr );
430431
}
431432

432-
JSON Object() {
433-
return std::move( JSON::Make( JSON::Class::Object ) );
433+
template <typename... T>
434+
JSON Array() {
435+
JSON arr = JSON::Make( JSON::Class::Array );
436+
return std::move( arr );
434437
}
435438

436-
std::ostream& operator<<( std::ostream &os, const JSON &json ) {
437-
os << json.dump();
438-
return os;
439-
}
439+
JSON Object();
440+
441+
std::ostream& operator<<( std::ostream &os, const JSON &json );
440442

441443
namespace {
442444
JSON parse_next( const string &, size_t & );
@@ -641,9 +643,6 @@ namespace {
641643
}
642644
}
643645

644-
JSON JSON::Load( const string &str ) {
645-
size_t offset = 0;
646-
return std::move( parse_next( str, offset ) );
647-
}
646+
648647

649648
} // End Namespace json

0 commit comments

Comments
 (0)