Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
R
rapidjson
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
rapidjson
Commits
cd144c3c
Commit
cd144c3c
authored
Jun 28, 2014
by
Milo Yip
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added a simple example and a diagram showing the process.
parent
b2b12a63
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
138 additions
and
1 deletion
+138
-1
premake4.lua
build/premake4.lua
+5
-0
makefile
doc/diagram/makefile
+8
-0
simpledom.dot
doc/diagram/simpledom.dot
+55
-0
simpledom.png
doc/diagram/simpledom.png
+0
-0
simpledom.cpp
example/simpledom/simpledom.cpp
+28
-0
readme.md
readme.md
+42
-1
No files found.
build/premake4.lua
View file @
cd144c3c
...
...
@@ -176,3 +176,8 @@ solution "example"
kind
"ConsoleApp"
files
"../example/serialize/*"
setTargetObjDir
(
"../bin"
)
project
"simpledom"
kind
"ConsoleApp"
files
"../example/simpledom/*"
setTargetObjDir
(
"../bin"
)
doc/diagram/makefile
0 → 100644
View file @
cd144c3c
%.pdf
:
%.dot
dot
$<
-Tpdf
-o
$@
%.png
:
%.dot
dot
$<
-Tpng
-o
$@
DOTFILES
=
$
(
basename
$
(
wildcard
*
.dot
))
all
:
$(addsuffix .png
,
$(DOTFILES))
#
$(addsuffix .pdf
,
$(DOTFILES))
doc/diagram/simpledom.dot
0 → 100644
View file @
cd144c3c
digraph
{
compound
=
true
fontname
=
"Inconsolata, Consolas"
fontsize
=
10
margin
=
"0,0"
ranksep
=
0.2
penwidth
=
0.5
node
[
fontname
=
"Inconsolata, Consolas"
,
fontsize
=
10
,
penwidth
=
0.5
]
edge
[
fontname
=
"Inconsolata, Consolas"
,
fontsize
=
10
,
arrowhead
=
normal
]
{
node
[
shape
=
record
,
fontsize
=
"8"
,
margin
=
"0.04"
,
height
=
0.2
,
color
=
gray
]
srcjson
[
label
=
"\{|p|r|o|j|e|c|t|\"|:|\"|r|a|p|i|d|j|s|o|n|\"|,|\"|s|t|a|r|s|\"|:|1|0|\}"
]
dstjson
[
label
=
"\{|p|r|o|j|e|c|t|\"|:|\"|r|a|p|i|d|j|s|o|n|\"|,|\"|s|t|a|r|s|\"|:|1|1|\}"
]
}
{
node
[
shape
=
"box"
,
style
=
"filled"
,
fillcolor
=
"gray95"
]
Document2
[
label
=
"(Modified) Document"
]
Writer
}
subgraph
cluster1
{
margin
=
"10,10"
labeljust
=
"left"
label
=
"Document"
style
=
filled
fillcolor
=
gray95
node
[
shape
=
Mrecord
,
style
=
filled
,
colorscheme
=
spectral7
]
root
[
label
=
"{object|}"
,
fillcolor
=
3
]
{
project
[
label
=
"{string|\"project\"}"
,
fillcolor
=
5
]
rapidjson
[
label
=
"{string|\"rapidjson\"}"
,
fillcolor
=
5
]
stars
[
label
=
"{string|\"stars\"}"
,
fillcolor
=
5
]
ten
[
label
=
"{number|10}"
,
fillcolor
=
6
]
}
edge
[
arrowhead
=
vee
]
root
->
{
project
,
stars
}
edge
[
arrowhead
=
"none"
]
project
->
rapidjson
stars
->
ten
}
srcjson
->
root
[
label
=
" Parse()"
,
lhead
=
"cluster1"
]
ten
->
Document2
[
label
=
" Increase \"stars\""
,
ltail
=
"cluster1"
]
Document2
->
Writer
[
label
=
" Traverse DOM by Accept()"
]
Writer
->
dstjson
[
label
=
" Output to StringBuffer"
]
}
\ No newline at end of file
doc/diagram/simpledom.png
0 → 100644
View file @
cd144c3c
22.6 KB
example/simpledom/simpledom.cpp
0 → 100644
View file @
cd144c3c
// JSON simple example
// This example does not handle errors.
#include "rapidjson/document.h"
#include "rapidjson/writer.h"
#include "rapidjson/stringbuffer.h"
#include <iostream>
using
namespace
rapidjson
;
int
main
()
{
// 1. Parse a JSON string into DOM.
const
char
*
json
=
"{
\"
project
\"
:
\"
rapidjson
\"
,
\"
stars
\"
:10}"
;
Document
d
;
d
.
Parse
<
0
>
(
json
);
// 2. Modify it by DOM.
d
[
"stars"
].
SetInt
(
d
[
"stars"
].
GetInt
()
+
1
);
// 3. Stringify the DOM
StringBuffer
buffer
;
Writer
<
StringBuffer
>
writer
(
buffer
);
d
.
Accept
(
writer
);
// Output {"project":"rapidjson","stars":10}
std
::
cout
<<
buffer
.
GetString
()
<<
std
::
endl
;
return
0
;
}
readme.md
View file @
cd144c3c
...
...
@@ -41,9 +41,50 @@ Rapidjson is a header-only C++ library. Just copy the `rapidjson/include/rapidjs
To build the tests and examples:
1.
Obtain
[
premake4
]
(
http://industriousone.com/premake/download
)
.
1.
Obtain
[
premake4
](
http://industriousone.com/premake/download
)
.
2.
Copy premake4 executable to rapidjson/build (or system path)
3.
Run
`rapidjson/build/premake.bat`
on Windows,
`rapidjson/build/premake.sh`
on Linux or other platforms
4.
On Windows, build the solution at
`rapidjson/build/vs2008/`
or
`/vs2010/`
5.
On other platforms, run GNU make at
`rapidjson/build/gmake/`
(e.g.,
`make -f test.make config=release32`
,
`make -f example.make config=debug32`
)
6.
On success, the executable are generated at
`rapidjson/bin`
## Usage at a glance
This simple example parses a JSON string into a document (DOM), make a simple modification of the DOM, and finally stringify the DOM to a JSON string.
```
cpp
// example/simpledom/simpledom.cpp
#include "rapidjson/document.h"
#include "rapidjson/writer.h"
#include "rapidjson/stringbuffer.h"
#include <iostream>
using
namespace
rapidjson
;
int
main
()
{
// 1. Parse a JSON string into DOM.
const
char
*
json
=
"{
\"
project
\"
:
\"
rapidjson
\"
,
\"
stars
\"
:10}"
;
Document
d
;
d
.
Parse
<
0
>
(
json
);
// 2. Modify it by DOM.
d
[
"stars"
].
SetInt
(
d
[
"stars"
].
GetInt
()
+
1
);
// 3. Stringify the DOM
StringBuffer
buffer
;
Writer
<
StringBuffer
>
writer
(
buffer
);
d
.
Accept
(
writer
);
// Output {"project":"rapidjson","stars":10}
std
::
cout
<<
buffer
.
GetString
()
<<
std
::
endl
;
return
0
;
}
```
Note that this exmample did not handle potential errors.
The following diagram shows the process.
[
simpledom
](
doc/diagram/simpledom.png
)
More
[
examples
](
example/
)
are avaliable.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment