Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
畅游知识海洋
json
提交
4bb51265
J
json
项目概览
畅游知识海洋
/
json
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
json
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4bb51265
编写于
6月 21, 2015
作者:
N
Niels
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more documentation
上级
d972483b
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
186 addition
and
32 deletion
+186
-32
Makefile
Makefile
+1
-0
docs/examples/basic_json__copyassignment.cpp
docs/examples/basic_json__copyassignment.cpp
+17
-0
docs/examples/basic_json__copyassignment.output
docs/examples/basic_json__copyassignment.output
+2
-0
docs/examples/basic_json__moveconstructor.cpp
docs/examples/basic_json__moveconstructor.cpp
+16
-0
docs/examples/basic_json__moveconstructor.output
docs/examples/basic_json__moveconstructor.output
+2
-0
docs/examples/dump.cpp
docs/examples/dump.cpp
+20
-0
docs/examples/dump.output
docs/examples/dump.output
+34
-0
src/json.hpp
src/json.hpp
+47
-16
src/json.hpp.re2c
src/json.hpp.re2c
+47
-16
未找到文件。
Makefile
浏览文件 @
4bb51265
...
...
@@ -50,6 +50,7 @@ update_doxygen_online:
rm
-fr
html
mv
/tmp/github-html html
-
cd
html
;
git
rm
$(
shell
git ls-files
--deleted
)
git add html
git commit
-m
"Doxygen update"
git checkout master
...
...
docs/examples/basic_json__copyassignment.cpp
0 → 100644
浏览文件 @
4bb51265
#include <json.hpp>
using
namespace
nlohmann
;
int
main
()
{
// create JSON values
json
a
=
23
;
json
b
=
42
;
// copy-assign a to b
b
=
a
;
// serialize the JSON arrays
std
::
cout
<<
a
<<
'\n'
;
std
::
cout
<<
b
<<
'\n'
;
}
docs/examples/basic_json__copyassignment.output
0 → 100644
浏览文件 @
4bb51265
23
23
docs/examples/basic_json__moveconstructor.cpp
0 → 100644
浏览文件 @
4bb51265
#include <json.hpp>
using
namespace
nlohmann
;
int
main
()
{
// create a JSON value
json
a
=
23
;
// move contents of a to b
json
b
(
std
::
move
(
a
));
// serialize the JSON arrays
std
::
cout
<<
a
<<
'\n'
;
std
::
cout
<<
b
<<
'\n'
;
}
docs/examples/basic_json__moveconstructor.output
0 → 100644
浏览文件 @
4bb51265
null
23
docs/examples/dump.cpp
0 → 100644
浏览文件 @
4bb51265
#include <json.hpp>
using
namespace
nlohmann
;
int
main
()
{
// create JSON values
json
j_object
=
{{
"one"
,
1
},
{
"two"
,
2
}};
json
j_array
=
{
1
,
2
,
4
,
8
,
16
};
// call dump()
std
::
cout
<<
j_object
.
dump
()
<<
"
\n\n
"
;
std
::
cout
<<
j_object
.
dump
(
-
1
)
<<
"
\n\n
"
;
std
::
cout
<<
j_object
.
dump
(
0
)
<<
"
\n\n
"
;
std
::
cout
<<
j_object
.
dump
(
4
)
<<
"
\n\n
"
;
std
::
cout
<<
j_array
.
dump
()
<<
"
\n\n
"
;
std
::
cout
<<
j_array
.
dump
(
-
1
)
<<
"
\n\n
"
;
std
::
cout
<<
j_array
.
dump
(
0
)
<<
"
\n\n
"
;
std
::
cout
<<
j_array
.
dump
(
4
)
<<
"
\n\n
"
;
}
docs/examples/dump.output
0 → 100644
浏览文件 @
4bb51265
{"one":1,"two":2}
{"one":1,"two":2}
{
"one": 1,
"two": 2
}
{
"one": 1,
"two": 2
}
[1,2,4,8,16]
[1,2,4,8,16]
[
1,
2,
4,
8,
16
]
[
1,
2,
4,
8,
16
]
src/json.hpp
浏览文件 @
4bb51265
...
...
@@ -85,16 +85,16 @@ struct has_mapped_type
(@c std::allocator by default)
@requirement This class satisfies the Container requirements (see http://en.cppreference.com/w/cpp/concept/Container):
-
@ref
basic_json()
-
@ref
basic_json(const basic_json&)
-
@ref
reference& operator=(basic_json)
-
@ref
~basic_json()
-
@ref iterator begin(), @ref const_iterator begin(), @ref
const_iterator cbegin()
-
@ref iterator end(), @ref const_iterator end(), @ref
const_iterator cend()
-
@ref bool operator==(const_reference, const_reference), @ref
bool operator!=(const_reference, const_reference)
-
@ref
void swap(reference other)
-
@ref size_type size(), @ref
size_type max_size()
-
@ref
bool empty()
- basic_json()
- basic_json(const basic_json&)
- reference& operator=(basic_json)
- ~basic_json()
-
iterator begin(), const_iterator begin(),
const_iterator cbegin()
-
iterator end(), const_iterator end(),
const_iterator cend()
-
bool operator==(const_reference, const_reference),
bool operator!=(const_reference, const_reference)
- void swap(reference other)
-
size_type size(),
size_type max_size()
- bool empty()
@note ObjectType trick from http://stackoverflow.com/a/9860911
...
...
@@ -686,7 +686,8 @@ class basic_json
3. In all other cases, the initializer list could not be interpreted as
JSON object type, so interpreting it as JSON array type is safe.
With the rules described above, the following JSON values cannot be expressed by an initializer list:
With the rules described above, the following JSON values cannot be
expressed by an initializer list:
- the empty array (`[]`): use @ref array(list_init_t) with an empty
initializer list in this case
...
...
@@ -1037,7 +1038,22 @@ class basic_json
}
}
/// move constructor
/*!
@brief move constructor
Move constructor. Constructs a JSON value with the contents of the given
value @a other using move semantics. It "steals" the resources from @a
other and leaves it as JSON null value.
@param other value to move to this object
@post @a other is a JSON null value
@complexity Constant.
@liveexample{The code below shows the move constructor explicitly called
via std::move.,basic_json__moveconstructor}
*/
basic_json
(
basic_json
&&
other
)
noexcept
:
m_type
(
std
::
move
(
other
.
m_type
)),
m_value
(
std
::
move
(
other
.
m_value
))
...
...
@@ -1050,14 +1066,22 @@ class basic_json
/*!
@brief copy assignment
The copy assignment operator is expressed in terms of the copy constructor,
destructor, and the swap() member function.
Copy assignment operator. Copies a JSON value via the "copy and swap"
strategy: It is expressed in terms of the copy constructor, destructor, and
the swap() member function.
@param other value to copy from
@complexity Linear.
@requirement This function satisfies the Container requirements:
- The complexity is linear.
@liveexample{The code below shows and example for the copy assignment. It
creates a copy of value `a` which is then swapped with `b`. Finally\, the
copy of `a` (which is the null value after the swap) is
destroyed.,basic_json__copyassignment}
@ingroup container
*/
reference
&
operator
=
(
basic_json
other
)
noexcept
(
...
...
@@ -1076,7 +1100,7 @@ class basic_json
/*!
@brief destructor
Destroys the JSON value and frees all memory.
Destroys the JSON value and frees all
allocated
memory.
@complexity Linear.
...
...
@@ -1137,7 +1161,7 @@ class basic_json
/*!
@brief serialization
Serialization function for JSON
object
s. The function tries to mimick
Serialization function for JSON
value
s. The function tries to mimick
Python's @p json.dumps() function, and currently supports its @p indent
parameter.
...
...
@@ -1146,6 +1170,13 @@ class basic_json
will only insert newlines. -1 (the default) selects the most compact
representation
@return string containing the serialization of the JSON value
@complexity Linear.
@liveexample{The following example shows the effect of different @a indent
parameters to the result of the serializaion.,dump}
@see https://docs.python.org/2/library/json.html#json.dump
*/
string_t
dump
(
const
int
indent
=
-
1
)
const
noexcept
...
...
src/json.hpp.re2c
浏览文件 @
4bb51265
...
...
@@ -85,16 +85,16 @@ struct has_mapped_type
(@c std::allocator by default)
@requirement This class satisfies the Container requirements (see http://en.cppreference.com/w/cpp/concept/Container):
-
@ref
basic_json()
-
@ref
basic_json(const basic_json&)
-
@ref
reference& operator=(basic_json)
-
@ref
~basic_json()
-
@ref iterator begin(), @ref const_iterator begin(), @ref
const_iterator cbegin()
-
@ref iterator end(), @ref const_iterator end(), @ref
const_iterator cend()
-
@ref bool operator==(const_reference, const_reference), @ref
bool operator!=(const_reference, const_reference)
-
@ref
void swap(reference other)
-
@ref size_type size(), @ref
size_type max_size()
-
@ref
bool empty()
- basic_json()
- basic_json(const basic_json&)
- reference& operator=(basic_json)
- ~basic_json()
-
iterator begin(), const_iterator begin(),
const_iterator cbegin()
-
iterator end(), const_iterator end(),
const_iterator cend()
-
bool operator==(const_reference, const_reference),
bool operator!=(const_reference, const_reference)
- void swap(reference other)
-
size_type size(),
size_type max_size()
- bool empty()
@note ObjectType trick from http://stackoverflow.com/a/9860911
...
...
@@ -686,7 +686,8 @@ class basic_json
3. In all other cases, the initializer list could not be interpreted as
JSON object type, so interpreting it as JSON array type is safe.
With the rules described above, the following JSON values cannot be expressed by an initializer list:
With the rules described above, the following JSON values cannot be
expressed by an initializer list:
- the empty array (`[]`): use @ref array(list_init_t) with an empty
initializer list in this case
...
...
@@ -1037,7 +1038,22 @@ class basic_json
}
}
/// move constructor
/*!
@brief move constructor
Move constructor. Constructs a JSON value with the contents of the given
value @a other using move semantics. It "steals" the resources from @a
other and leaves it as JSON null value.
@param other value to move to this object
@post @a other is a JSON null value
@complexity Constant.
@liveexample{The code below shows the move constructor explicitly called
via std::move.,basic_json__moveconstructor}
*/
basic_json(basic_json&& other) noexcept
: m_type(std::move(other.m_type)),
m_value(std::move(other.m_value))
...
...
@@ -1050,14 +1066,22 @@ class basic_json
/*!
@brief copy assignment
The copy assignment operator is expressed in terms of the copy constructor,
destructor, and the swap() member function.
Copy assignment operator. Copies a JSON value via the "copy and swap"
strategy: It is expressed in terms of the copy constructor, destructor, and
the swap() member function.
@param other value to copy from
@complexity Linear.
@requirement This function satisfies the Container requirements:
- The complexity is linear.
@liveexample{The code below shows and example for the copy assignment. It
creates a copy of value `a` which is then swapped with `b`. Finally\, the
copy of `a` (which is the null value after the swap) is
destroyed.,basic_json__copyassignment}
@ingroup container
*/
reference& operator=(basic_json other) noexcept (
...
...
@@ -1076,7 +1100,7 @@ class basic_json
/*!
@brief destructor
Destroys the JSON value and frees all memory.
Destroys the JSON value and frees all
allocated
memory.
@complexity Linear.
...
...
@@ -1137,7 +1161,7 @@ class basic_json
/*!
@brief serialization
Serialization function for JSON
object
s. The function tries to mimick
Serialization function for JSON
value
s. The function tries to mimick
Python's @p json.dumps() function, and currently supports its @p indent
parameter.
...
...
@@ -1146,6 +1170,13 @@ class basic_json
will only insert newlines. -1 (the default) selects the most compact
representation
@return string containing the serialization of the JSON value
@complexity Linear.
@liveexample{The following example shows the effect of different @a indent
parameters to the result of the serializaion.,dump}
@see https://docs.python.org/2/library/json.html#json.dump
*/
string_t dump(const int indent = -1) const noexcept
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录