Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
畅游知识海洋
json
提交
330ffd95
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,发现更多精彩内容 >>
提交
330ffd95
编写于
2月 08, 2015
作者:
N
Niels
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
removed reverse_iterators and fixed some bugs
上级
4c59ccd1
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
471 addition
and
102 deletion
+471
-102
src/json.hpp
src/json.hpp
+1
-51
src/json.hpp.re2c
src/json.hpp.re2c
+1
-51
test/unit.cpp
test/unit.cpp
+469
-0
未找到文件。
src/json.hpp
浏览文件 @
330ffd95
...
...
@@ -84,10 +84,6 @@ class basic_json
using
iterator
=
basic_json
::
iterator
;
/// a const iterator for a basic_json container
using
const_iterator
=
basic_json
::
const_iterator
;
// a reverse iterator for a basic_json container
using
reverse_iterator
=
std
::
reverse_iterator
<
iterator
>
;
/// a const reverse iterator for a basic_json container
using
const_reverse_iterator
=
std
::
reverse_iterator
<
const_iterator
>
;
///////////////////////////
...
...
@@ -259,8 +255,6 @@ class basic_json
std
::
enable_if
<
not
std
::
is_same
<
V
,
basic_json
::
iterator
>
::
value
and
not
std
::
is_same
<
V
,
basic_json
::
const_iterator
>::
value
and
not
std
::
is_same
<
V
,
basic_json
::
reverse_iterator
>::
value
and
not
std
::
is_same
<
V
,
basic_json
::
const_reverse_iterator
>::
value
and
std
::
is_constructible
<
basic_json
,
typename
V
::
value_type
>::
value
,
int
>::
type
=
0
>
inline
basic_json
(
const
V
&
value
)
...
...
@@ -732,18 +726,6 @@ class basic_json
return
m_value
.
object
->
operator
[](
key
);
}
/// access specified element
inline
reference
operator
[](
typename
object_t
::
key_type
&&
key
)
{
// at only works for objects
if
(
m_type
!=
value_t
::
object
)
{
throw
std
::
runtime_error
(
"cannot use [] with "
+
type_name
());
}
return
m_value
.
object
->
operator
[](
std
::
move
(
key
));
}
/// find an element in an object
inline
iterator
find
(
typename
object_t
::
key_type
key
)
...
...
@@ -824,38 +806,6 @@ class basic_json
return
result
;
}
/// returns a reverse iterator to the end of the container
inline
reverse_iterator
rbegin
()
const
noexcept
{
reverse_iterator
result
(
this
);
result
.
set_end
();
return
result
;
}
/// returns a reverse iterator to the beginning of the container
inline
reverse_iterator
rend
()
const
noexcept
{
reverse_iterator
result
(
this
);
result
.
set_begin
();
return
result
;
}
/// returns a const reverse iterator to the end of the container
inline
const_reverse_iterator
crbegin
()
const
noexcept
{
const_reverse_iterator
result
(
this
);
result
.
set_end
();
return
result
;
}
/// returns a const reverse iterator to the beginning of the container
inline
const_reverse_iterator
crend
()
const
noexcept
{
const_reverse_iterator
result
(
this
);
result
.
set_begin
();
return
result
;
}
//////////////
// capacity //
...
...
@@ -2326,7 +2276,7 @@ class basic_json
/// post-decrement (it--)
inline
const_iterator
operator
--
(
int
)
{
iterator
result
=
*
this
;
const_
iterator
result
=
*
this
;
switch
(
m_object
->
m_type
)
{
...
...
src/json.hpp.re2c
浏览文件 @
330ffd95
...
...
@@ -84,10 +84,6 @@ class basic_json
using iterator = basic_json::iterator;
/// a const iterator for a basic_json container
using const_iterator = basic_json::const_iterator;
// a reverse iterator for a basic_json container
using reverse_iterator = std::reverse_iterator<iterator>;
/// a const reverse iterator for a basic_json container
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
///////////////////////////
...
...
@@ -259,8 +255,6 @@ class basic_json
std::enable_if<
not std::is_same<V, basic_json::iterator>::value and
not std::is_same<V, basic_json::const_iterator>::value and
not std::is_same<V, basic_json::reverse_iterator>::value and
not std::is_same<V, basic_json::const_reverse_iterator>::value and
std::is_constructible<basic_json, typename V::value_type>::value, int>::type
= 0>
inline basic_json(const V& value)
...
...
@@ -732,18 +726,6 @@ class basic_json
return m_value.object->operator[](key);
}
/// access specified element
inline reference operator[](typename object_t::key_type&& key)
{
// at only works for objects
if (m_type != value_t::object)
{
throw std::runtime_error("cannot use [] with " + type_name());
}
return m_value.object->operator[](std::move(key));
}
/// find an element in an object
inline iterator find(typename object_t::key_type key)
...
...
@@ -824,38 +806,6 @@ class basic_json
return result;
}
/// returns a reverse iterator to the end of the container
inline reverse_iterator rbegin() const noexcept
{
reverse_iterator result(this);
result.set_end();
return result;
}
/// returns a reverse iterator to the beginning of the container
inline reverse_iterator rend() const noexcept
{
reverse_iterator result(this);
result.set_begin();
return result;
}
/// returns a const reverse iterator to the end of the container
inline const_reverse_iterator crbegin() const noexcept
{
const_reverse_iterator result(this);
result.set_end();
return result;
}
/// returns a const reverse iterator to the beginning of the container
inline const_reverse_iterator crend() const noexcept
{
const_reverse_iterator result(this);
result.set_begin();
return result;
}
//////////////
// capacity //
...
...
@@ -2326,7 +2276,7 @@ class basic_json
/// post-decrement (it--)
inline const_iterator operator--(int)
{
iterator result = *this;
const_
iterator result = *this;
switch (m_object->m_type)
{
...
...
test/unit.cpp
浏览文件 @
330ffd95
...
...
@@ -2275,3 +2275,472 @@ TEST_CASE("element access")
}
}
}
TEST_CASE
(
"iterators"
)
{
SECTION
(
"boolean"
)
{
json
j
=
true
;
json
j_const
(
j
);
SECTION
(
"json + begin/end"
)
{
auto
it
=
j
.
begin
();
CHECK
(
it
!=
j
.
end
());
CHECK
(
*
it
==
j
);
it
++
;
CHECK
(
it
!=
j
.
begin
());
CHECK
(
it
==
j
.
end
());
it
--
;
CHECK
(
it
==
j
.
begin
());
CHECK
(
it
!=
j
.
end
());
CHECK
(
*
it
==
j
);
++
it
;
CHECK
(
it
!=
j
.
begin
());
CHECK
(
it
==
j
.
end
());
--
it
;
CHECK
(
it
==
j
.
begin
());
CHECK
(
it
!=
j
.
end
());
CHECK
(
*
it
==
j
);
}
SECTION
(
"const json + begin/end"
)
{
auto
it
=
j_const
.
begin
();
CHECK
(
it
!=
j_const
.
end
());
CHECK
(
*
it
==
j_const
);
it
++
;
CHECK
(
it
!=
j_const
.
begin
());
CHECK
(
it
==
j_const
.
end
());
it
--
;
CHECK
(
it
==
j_const
.
begin
());
CHECK
(
it
!=
j_const
.
end
());
CHECK
(
*
it
==
j_const
);
++
it
;
CHECK
(
it
!=
j_const
.
begin
());
CHECK
(
it
==
j_const
.
end
());
--
it
;
CHECK
(
it
==
j_const
.
begin
());
CHECK
(
it
!=
j_const
.
end
());
CHECK
(
*
it
==
j_const
);
}
SECTION
(
"json + cbegin/cend"
)
{
auto
it
=
j
.
cbegin
();
CHECK
(
it
!=
j
.
cend
());
CHECK
(
*
it
==
j
);
it
++
;
CHECK
(
it
!=
j
.
cbegin
());
CHECK
(
it
==
j
.
cend
());
it
--
;
CHECK
(
it
==
j
.
cbegin
());
CHECK
(
it
!=
j
.
cend
());
CHECK
(
*
it
==
j
);
++
it
;
CHECK
(
it
!=
j
.
cbegin
());
CHECK
(
it
==
j
.
cend
());
--
it
;
CHECK
(
it
==
j
.
cbegin
());
CHECK
(
it
!=
j
.
cend
());
CHECK
(
*
it
==
j
);
}
SECTION
(
"const json + cbegin/cend"
)
{
auto
it
=
j_const
.
cbegin
();
CHECK
(
it
!=
j_const
.
cend
());
CHECK
(
*
it
==
j_const
);
it
++
;
CHECK
(
it
!=
j_const
.
cbegin
());
CHECK
(
it
==
j_const
.
cend
());
it
--
;
CHECK
(
it
==
j_const
.
cbegin
());
CHECK
(
it
!=
j_const
.
cend
());
CHECK
(
*
it
==
j_const
);
++
it
;
CHECK
(
it
!=
j_const
.
cbegin
());
CHECK
(
it
==
j_const
.
cend
());
--
it
;
CHECK
(
it
==
j_const
.
cbegin
());
CHECK
(
it
!=
j_const
.
cend
());
CHECK
(
*
it
==
j_const
);
}
}
SECTION
(
"string"
)
{
json
j
=
"hello world"
;
json
j_const
(
j
);
SECTION
(
"json + begin/end"
)
{
auto
it
=
j
.
begin
();
CHECK
(
it
!=
j
.
end
());
CHECK
(
*
it
==
j
);
it
++
;
CHECK
(
it
!=
j
.
begin
());
CHECK
(
it
==
j
.
end
());
it
--
;
CHECK
(
it
==
j
.
begin
());
CHECK
(
it
!=
j
.
end
());
CHECK
(
*
it
==
j
);
++
it
;
CHECK
(
it
!=
j
.
begin
());
CHECK
(
it
==
j
.
end
());
--
it
;
CHECK
(
it
==
j
.
begin
());
CHECK
(
it
!=
j
.
end
());
CHECK
(
*
it
==
j
);
}
SECTION
(
"const json + begin/end"
)
{
auto
it
=
j_const
.
begin
();
CHECK
(
it
!=
j_const
.
end
());
CHECK
(
*
it
==
j_const
);
it
++
;
CHECK
(
it
!=
j_const
.
begin
());
CHECK
(
it
==
j_const
.
end
());
it
--
;
CHECK
(
it
==
j_const
.
begin
());
CHECK
(
it
!=
j_const
.
end
());
CHECK
(
*
it
==
j_const
);
++
it
;
CHECK
(
it
!=
j_const
.
begin
());
CHECK
(
it
==
j_const
.
end
());
--
it
;
CHECK
(
it
==
j_const
.
begin
());
CHECK
(
it
!=
j_const
.
end
());
CHECK
(
*
it
==
j_const
);
}
SECTION
(
"json + cbegin/cend"
)
{
auto
it
=
j
.
cbegin
();
CHECK
(
it
!=
j
.
cend
());
CHECK
(
*
it
==
j
);
it
++
;
CHECK
(
it
!=
j
.
cbegin
());
CHECK
(
it
==
j
.
cend
());
it
--
;
CHECK
(
it
==
j
.
cbegin
());
CHECK
(
it
!=
j
.
cend
());
CHECK
(
*
it
==
j
);
++
it
;
CHECK
(
it
!=
j
.
cbegin
());
CHECK
(
it
==
j
.
cend
());
--
it
;
CHECK
(
it
==
j
.
cbegin
());
CHECK
(
it
!=
j
.
cend
());
CHECK
(
*
it
==
j
);
}
SECTION
(
"const json + cbegin/cend"
)
{
auto
it
=
j_const
.
cbegin
();
CHECK
(
it
!=
j_const
.
cend
());
CHECK
(
*
it
==
j_const
);
it
++
;
CHECK
(
it
!=
j_const
.
cbegin
());
CHECK
(
it
==
j_const
.
cend
());
it
--
;
CHECK
(
it
==
j_const
.
cbegin
());
CHECK
(
it
!=
j_const
.
cend
());
CHECK
(
*
it
==
j_const
);
++
it
;
CHECK
(
it
!=
j_const
.
cbegin
());
CHECK
(
it
==
j_const
.
cend
());
--
it
;
CHECK
(
it
==
j_const
.
cbegin
());
CHECK
(
it
!=
j_const
.
cend
());
CHECK
(
*
it
==
j_const
);
}
}
SECTION
(
"array"
)
{
json
j
=
{
1
,
2
,
3
,
4
};
json
j_const
(
j
);
}
SECTION
(
"object"
)
{
json
j
=
{{
"one"
,
1
},
{
"two"
,
2
},
{
"three"
,
3
}};
json
j_const
(
j
);
}
SECTION
(
"number (integer)"
)
{
json
j
=
23
;
json
j_const
(
j
);
SECTION
(
"json + begin/end"
)
{
auto
it
=
j
.
begin
();
CHECK
(
it
!=
j
.
end
());
CHECK
(
*
it
==
j
);
it
++
;
CHECK
(
it
!=
j
.
begin
());
CHECK
(
it
==
j
.
end
());
it
--
;
CHECK
(
it
==
j
.
begin
());
CHECK
(
it
!=
j
.
end
());
CHECK
(
*
it
==
j
);
++
it
;
CHECK
(
it
!=
j
.
begin
());
CHECK
(
it
==
j
.
end
());
--
it
;
CHECK
(
it
==
j
.
begin
());
CHECK
(
it
!=
j
.
end
());
CHECK
(
*
it
==
j
);
}
SECTION
(
"const json + begin/end"
)
{
auto
it
=
j_const
.
begin
();
CHECK
(
it
!=
j_const
.
end
());
CHECK
(
*
it
==
j_const
);
it
++
;
CHECK
(
it
!=
j_const
.
begin
());
CHECK
(
it
==
j_const
.
end
());
it
--
;
CHECK
(
it
==
j_const
.
begin
());
CHECK
(
it
!=
j_const
.
end
());
CHECK
(
*
it
==
j_const
);
++
it
;
CHECK
(
it
!=
j_const
.
begin
());
CHECK
(
it
==
j_const
.
end
());
--
it
;
CHECK
(
it
==
j_const
.
begin
());
CHECK
(
it
!=
j_const
.
end
());
CHECK
(
*
it
==
j_const
);
}
SECTION
(
"json + cbegin/cend"
)
{
auto
it
=
j
.
cbegin
();
CHECK
(
it
!=
j
.
cend
());
CHECK
(
*
it
==
j
);
it
++
;
CHECK
(
it
!=
j
.
cbegin
());
CHECK
(
it
==
j
.
cend
());
it
--
;
CHECK
(
it
==
j
.
cbegin
());
CHECK
(
it
!=
j
.
cend
());
CHECK
(
*
it
==
j
);
++
it
;
CHECK
(
it
!=
j
.
cbegin
());
CHECK
(
it
==
j
.
cend
());
--
it
;
CHECK
(
it
==
j
.
cbegin
());
CHECK
(
it
!=
j
.
cend
());
CHECK
(
*
it
==
j
);
}
SECTION
(
"const json + cbegin/cend"
)
{
auto
it
=
j_const
.
cbegin
();
CHECK
(
it
!=
j_const
.
cend
());
CHECK
(
*
it
==
j_const
);
it
++
;
CHECK
(
it
!=
j_const
.
cbegin
());
CHECK
(
it
==
j_const
.
cend
());
it
--
;
CHECK
(
it
==
j_const
.
cbegin
());
CHECK
(
it
!=
j_const
.
cend
());
CHECK
(
*
it
==
j_const
);
++
it
;
CHECK
(
it
!=
j_const
.
cbegin
());
CHECK
(
it
==
j_const
.
cend
());
--
it
;
CHECK
(
it
==
j_const
.
cbegin
());
CHECK
(
it
!=
j_const
.
cend
());
CHECK
(
*
it
==
j_const
);
}
}
SECTION
(
"number (float)"
)
{
json
j
=
23.42
;
json
j_const
(
j
);
SECTION
(
"json + begin/end"
)
{
auto
it
=
j
.
begin
();
CHECK
(
it
!=
j
.
end
());
CHECK
(
*
it
==
j
);
it
++
;
CHECK
(
it
!=
j
.
begin
());
CHECK
(
it
==
j
.
end
());
it
--
;
CHECK
(
it
==
j
.
begin
());
CHECK
(
it
!=
j
.
end
());
CHECK
(
*
it
==
j
);
++
it
;
CHECK
(
it
!=
j
.
begin
());
CHECK
(
it
==
j
.
end
());
--
it
;
CHECK
(
it
==
j
.
begin
());
CHECK
(
it
!=
j
.
end
());
CHECK
(
*
it
==
j
);
}
SECTION
(
"const json + begin/end"
)
{
auto
it
=
j_const
.
begin
();
CHECK
(
it
!=
j_const
.
end
());
CHECK
(
*
it
==
j_const
);
it
++
;
CHECK
(
it
!=
j_const
.
begin
());
CHECK
(
it
==
j_const
.
end
());
it
--
;
CHECK
(
it
==
j_const
.
begin
());
CHECK
(
it
!=
j_const
.
end
());
CHECK
(
*
it
==
j_const
);
++
it
;
CHECK
(
it
!=
j_const
.
begin
());
CHECK
(
it
==
j_const
.
end
());
--
it
;
CHECK
(
it
==
j_const
.
begin
());
CHECK
(
it
!=
j_const
.
end
());
CHECK
(
*
it
==
j_const
);
}
SECTION
(
"json + cbegin/cend"
)
{
auto
it
=
j
.
cbegin
();
CHECK
(
it
!=
j
.
cend
());
CHECK
(
*
it
==
j
);
it
++
;
CHECK
(
it
!=
j
.
cbegin
());
CHECK
(
it
==
j
.
cend
());
it
--
;
CHECK
(
it
==
j
.
cbegin
());
CHECK
(
it
!=
j
.
cend
());
CHECK
(
*
it
==
j
);
++
it
;
CHECK
(
it
!=
j
.
cbegin
());
CHECK
(
it
==
j
.
cend
());
--
it
;
CHECK
(
it
==
j
.
cbegin
());
CHECK
(
it
!=
j
.
cend
());
CHECK
(
*
it
==
j
);
}
SECTION
(
"const json + cbegin/cend"
)
{
auto
it
=
j_const
.
cbegin
();
CHECK
(
it
!=
j_const
.
cend
());
CHECK
(
*
it
==
j_const
);
it
++
;
CHECK
(
it
!=
j_const
.
cbegin
());
CHECK
(
it
==
j_const
.
cend
());
it
--
;
CHECK
(
it
==
j_const
.
cbegin
());
CHECK
(
it
!=
j_const
.
cend
());
CHECK
(
*
it
==
j_const
);
++
it
;
CHECK
(
it
!=
j_const
.
cbegin
());
CHECK
(
it
==
j_const
.
cend
());
--
it
;
CHECK
(
it
==
j_const
.
cbegin
());
CHECK
(
it
!=
j_const
.
cend
());
CHECK
(
*
it
==
j_const
);
}
}
SECTION
(
"null"
)
{
json
j
=
nullptr
;
json
j_const
(
j
);
SECTION
(
"json + begin/end"
)
{
auto
it
=
j
.
begin
();
CHECK
(
it
==
j
.
end
());
}
SECTION
(
"const json + begin/end"
)
{
auto
it
=
j_const
.
begin
();
CHECK
(
it
==
j_const
.
end
());
}
SECTION
(
"json + cbegin/cend"
)
{
auto
it
=
j
.
cbegin
();
CHECK
(
it
==
j
.
cend
());
}
SECTION
(
"const json + cbegin/cend"
)
{
auto
it
=
j_const
.
cbegin
();
CHECK
(
it
==
j_const
.
cend
());
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录