Skip to content

Commit 1362162

Browse files
committed
Add JSON Spirit (required boost)
1 parent 5dbf5a9 commit 1362162

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+6935
-1
lines changed

src/config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// Define this if installed boost
44
#ifndef HAS_BOOST
5-
#define HAS_BOOST 0
5+
#define HAS_BOOST 1
66
#endif
77

88
// Define this to profile memory usage in tests

src/tests/jsonspirittest.cpp

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#include "../test.h"
2+
3+
#if HAS_BOOST
4+
5+
#include "json_spirit/json_spirit/json_spirit_reader_template.h"
6+
#include "json_spirit/json_spirit/json_spirit_writer_template.h"
7+
8+
using namespace json_spirit;
9+
10+
static void GenStat(Stat& stat, const Value& v) {
11+
switch (v.type()) {
12+
case obj_type:
13+
{
14+
const Object& o = v.get_obj();
15+
for (Object::const_iterator itr = o.begin(); itr != o.end(); ++itr) {
16+
stat.stringLength += itr->name_.size();
17+
GenStat(stat, itr->value_);
18+
}
19+
stat.objectCount++;
20+
stat.memberCount += o.size();
21+
stat.stringCount += o.size();
22+
}
23+
break;
24+
25+
case array_type:
26+
{
27+
const Array& a = v.get_array();
28+
29+
for (Array::const_iterator i = a.begin(); i != a.end(); ++i)
30+
GenStat(stat, *i);
31+
stat.arrayCount++;
32+
stat.elementCount += a.size();
33+
}
34+
break;
35+
36+
case str_type:
37+
stat.stringCount++;
38+
stat.stringLength += v.get_str().size();
39+
break;
40+
41+
case int_type:
42+
case real_type:
43+
stat.numberCount++;
44+
break;
45+
46+
case bool_type:
47+
if (v.get_bool())
48+
stat.trueCount++;
49+
else
50+
stat.falseCount++; break;
51+
break;
52+
53+
case null_type:
54+
stat.nullCount++; break;
55+
}
56+
}
57+
58+
class JsonspiritParseResult : public ParseResultBase {
59+
public:
60+
Value root;
61+
};
62+
63+
class JsonspiritStringResult : public StringResultBase {
64+
public:
65+
virtual const char* c_str() const { return s.c_str(); }
66+
67+
std::string s;
68+
};
69+
70+
class JsonspiritTest : public TestBase {
71+
public:
72+
#if TEST_INFO
73+
virtual const char* GetName() const { return "JSON Spirit (C++)"; }
74+
virtual const char* GetFilename() const { return __FILE__; }
75+
#endif
76+
77+
#if TEST_PARSE
78+
virtual ParseResultBase* Parse(const char* json, size_t length) const {
79+
JsonspiritParseResult* pr = new JsonspiritParseResult;
80+
if (!read_string(std::string(json, length), pr->root))
81+
{
82+
delete pr;
83+
return 0;
84+
}
85+
return pr;
86+
}
87+
#endif
88+
89+
#if TEST_STRINGIFY
90+
virtual StringResultBase* Stringify(const ParseResultBase* parseResult) const {
91+
const JsonspiritParseResult* pr = static_cast<const JsonspiritParseResult*>(parseResult);
92+
JsonspiritStringResult* sr = new JsonspiritStringResult;
93+
sr->s = write_string(pr->root);
94+
return sr;
95+
}
96+
#endif
97+
98+
#if TEST_PRETTIFY
99+
virtual StringResultBase* Prettify(const ParseResultBase* parseResult) const {
100+
const JsonspiritParseResult* pr = static_cast<const JsonspiritParseResult*>(parseResult);
101+
JsonspiritStringResult* sr = new JsonspiritStringResult;
102+
sr->s = write_string(pr->root, pretty_print);
103+
return sr;
104+
}
105+
#endif
106+
107+
#if TEST_STATISTICS
108+
virtual bool Statistics(const ParseResultBase* parseResult, Stat* stat) const {
109+
const JsonspiritParseResult* pr = static_cast<const JsonspiritParseResult*>(parseResult);
110+
memset(stat, 0, sizeof(Stat));
111+
GenStat(*stat, pr->root);
112+
return true;
113+
}
114+
#endif
115+
};
116+
117+
REGISTER_TEST(JsonspiritTest);
118+
119+
#endif

thirdparty/json_spirit/CMakeLists.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
2+
3+
PROJECT(json_spirit)
4+
SUBDIRS(json_spirit json_demo json_headers_only_demo json_map_demo json_test)
5+
INCLUDE_DIRECTORIES(json_spirit)
6+
7+
INSTALL(
8+
FILES
9+
${CMAKE_SOURCE_DIR}/json_spirit/json_spirit.h
10+
${CMAKE_SOURCE_DIR}/json_spirit/json_spirit_error_position.h
11+
${CMAKE_SOURCE_DIR}/json_spirit/json_spirit_reader.h
12+
${CMAKE_SOURCE_DIR}/json_spirit/json_spirit_reader_template.h
13+
${CMAKE_SOURCE_DIR}/json_spirit/json_spirit_stream_reader.h
14+
${CMAKE_SOURCE_DIR}/json_spirit/json_spirit_utils.h
15+
${CMAKE_SOURCE_DIR}/json_spirit/json_spirit_value.h
16+
${CMAKE_SOURCE_DIR}/json_spirit/json_spirit_writer.h
17+
${CMAKE_SOURCE_DIR}/json_spirit/json_spirit_writer_template.h
18+
${CMAKE_SOURCE_DIR}/json_spirit/json_spirit_writer_options.h
19+
DESTINATION include)
20+
21+
INSTALL(
22+
FILES
23+
${CMAKE_BINARY_DIR}/json_spirit/libjson_spirit.a
24+
DESTINATION lib)
25+
26+
INCLUDE(CPack)

thirdparty/json_spirit/LICENSE.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
The MIT License
2+
3+
Copyright (c) 2007 - 2010 John W. Wilkinson
4+
5+
Permission is hereby granted, free of charge, to any person
6+
obtaining a copy of this software and associated documentation
7+
files (the "Software"), to deal in the Software without
8+
restriction, including without limitation the rights to use,
9+
copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the
11+
Software is furnished to do so, subject to the following
12+
conditions:
13+
14+
The above copyright notice and this permission notice shall be
15+
included in all copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24+
OTHER DEALINGS IN THE SOFTWARE.

thirdparty/json_spirit/README.cmake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
For using the cmake build system do the following steps:
2+
3+
1. Install cmake (under Ubuntu with "sudo apt-get install cmake", on Mac OS X with "sudo port install cmake")
4+
2. Create an build dir (for example json_spirit_v3.00/build) an switch to this new directory.
5+
3. Create files for your build system
6+
"cmake .." generates makefiles for GNU automake
7+
"cmake -G Xcode" generates an Xcode project
8+
4. Start the build
9+
10+
BOOST_ROOT Please set BOOST_ROOT to the root
11+
directory containing Boost or BOOST_INCLUDEDIR to the directory containing
12+
Boost's headers.

thirdparty/json_spirit/VERSION.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
V4.08

thirdparty/json_spirit/json.sln

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 9.00
3+
# Visual C++ Express 2005
4+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "json_test", "json_test\json_test.vcproj", "{2DA49050-32A7-49D4-AF55-9BEE2BDDF889}"
5+
ProjectSection(ProjectDependencies) = postProject
6+
{BE262A86-CC26-4B25-A877-883ED2688CEC} = {BE262A86-CC26-4B25-A877-883ED2688CEC}
7+
EndProjectSection
8+
EndProject
9+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "json_map_demo", "json_map_demo\json_map_demo.vcproj", "{07D8AA9F-D637-45A2-B06C-FF741462EAE8}"
10+
ProjectSection(ProjectDependencies) = postProject
11+
{BE262A86-CC26-4B25-A877-883ED2688CEC} = {BE262A86-CC26-4B25-A877-883ED2688CEC}
12+
EndProjectSection
13+
EndProject
14+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "json_spirit_lib", "json_spirit\json_spirit.vcproj", "{BE262A86-CC26-4B25-A877-883ED2688CEC}"
15+
EndProject
16+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "json_demo", "json_demo\json_demo.vcproj", "{EFA1226E-A818-481B-A094-93A22D68130C}"
17+
ProjectSection(ProjectDependencies) = postProject
18+
{BE262A86-CC26-4B25-A877-883ED2688CEC} = {BE262A86-CC26-4B25-A877-883ED2688CEC}
19+
EndProjectSection
20+
EndProject
21+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "json_headers_only_demo", "json_headers_only_demo\json_headers_only_demo.vcproj", "{4F019AE5-7DB7-460D-A64A-BBC8E7CF3AA3}"
22+
EndProject
23+
Global
24+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
25+
Debug|Win32 = Debug|Win32
26+
Release|Win32 = Release|Win32
27+
EndGlobalSection
28+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
29+
{2DA49050-32A7-49D4-AF55-9BEE2BDDF889}.Debug|Win32.ActiveCfg = Debug|Win32
30+
{2DA49050-32A7-49D4-AF55-9BEE2BDDF889}.Debug|Win32.Build.0 = Debug|Win32
31+
{2DA49050-32A7-49D4-AF55-9BEE2BDDF889}.Release|Win32.ActiveCfg = Release|Win32
32+
{2DA49050-32A7-49D4-AF55-9BEE2BDDF889}.Release|Win32.Build.0 = Release|Win32
33+
{07D8AA9F-D637-45A2-B06C-FF741462EAE8}.Debug|Win32.ActiveCfg = Debug|Win32
34+
{07D8AA9F-D637-45A2-B06C-FF741462EAE8}.Debug|Win32.Build.0 = Debug|Win32
35+
{07D8AA9F-D637-45A2-B06C-FF741462EAE8}.Release|Win32.ActiveCfg = Release|Win32
36+
{07D8AA9F-D637-45A2-B06C-FF741462EAE8}.Release|Win32.Build.0 = Release|Win32
37+
{BE262A86-CC26-4B25-A877-883ED2688CEC}.Debug|Win32.ActiveCfg = Debug|Win32
38+
{BE262A86-CC26-4B25-A877-883ED2688CEC}.Debug|Win32.Build.0 = Debug|Win32
39+
{BE262A86-CC26-4B25-A877-883ED2688CEC}.Release|Win32.ActiveCfg = Release|Win32
40+
{BE262A86-CC26-4B25-A877-883ED2688CEC}.Release|Win32.Build.0 = Release|Win32
41+
{EFA1226E-A818-481B-A094-93A22D68130C}.Debug|Win32.ActiveCfg = Debug|Win32
42+
{EFA1226E-A818-481B-A094-93A22D68130C}.Debug|Win32.Build.0 = Debug|Win32
43+
{EFA1226E-A818-481B-A094-93A22D68130C}.Release|Win32.ActiveCfg = Release|Win32
44+
{EFA1226E-A818-481B-A094-93A22D68130C}.Release|Win32.Build.0 = Release|Win32
45+
{4F019AE5-7DB7-460D-A64A-BBC8E7CF3AA3}.Debug|Win32.ActiveCfg = Debug|Win32
46+
{4F019AE5-7DB7-460D-A64A-BBC8E7CF3AA3}.Debug|Win32.Build.0 = Debug|Win32
47+
{4F019AE5-7DB7-460D-A64A-BBC8E7CF3AA3}.Release|Win32.ActiveCfg = Release|Win32
48+
{4F019AE5-7DB7-460D-A64A-BBC8E7CF3AA3}.Release|Win32.Build.0 = Release|Win32
49+
EndGlobalSection
50+
GlobalSection(SolutionProperties) = preSolution
51+
HideSolutionNode = FALSE
52+
EndGlobalSection
53+
EndGlobal

0 commit comments

Comments
 (0)