Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
畅游知识海洋
json
提交
4dbb433a
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(gitcode.net)2024年7月9日维护升级公告
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
4dbb433a
编写于
8月 14, 2017
作者:
T
Théo DELRIEU
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add detail/parsing/output_adapters.hpp
上级
ae6f6604
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
117 addition
and
102 deletion
+117
-102
Makefile
Makefile
+2
-1
src/detail/parsing/output_adapters.hpp
src/detail/parsing/output_adapters.hpp
+114
-0
src/json.hpp
src/json.hpp
+1
-101
未找到文件。
Makefile
浏览文件 @
4dbb433a
...
...
@@ -17,7 +17,8 @@ SRCS = ${SRCDIR}/json.hpp \
${SRCDIR}
/detail/iterators/internal_iterator.hpp
\
${SRCDIR}
/detail/iterators/iter_impl.hpp
\
${SRCDIR}
/detail/iterators/iteration_proxy.hpp
\
${SRCDIR}
/detail/iterators/json_reverse_iterator.hpp
${SRCDIR}
/detail/iterators/json_reverse_iterator.hpp
\
${SRCDIR}
/detail/parsing/output_adapters.hpp
...
...
src/detail/parsing/output_adapters.hpp
0 → 100644
浏览文件 @
4dbb433a
#ifndef NLOHMANN_JSON_DETAIL_PARSING_OUTPUT_ADAPTERS_HPP
#define NLOHMANN_JSON_DETAIL_PARSING_OUTPUT_ADAPTERS_HPP
#include <algorithm>
#include <cstddef>
#include <iosfwd>
#include <iterator>
#include <memory>
#include <vector>
namespace
nlohmann
{
namespace
detail
{
/// abstract output adapter interface
template
<
typename
CharType
>
struct
output_adapter_protocol
{
virtual
void
write_character
(
CharType
c
)
=
0
;
virtual
void
write_characters
(
const
CharType
*
s
,
std
::
size_t
length
)
=
0
;
virtual
~
output_adapter_protocol
()
=
default
;
};
/// a type to simplify interfaces
template
<
typename
CharType
>
using
output_adapter_t
=
std
::
shared_ptr
<
output_adapter_protocol
<
CharType
>>
;
/// output adapter for byte vectors
template
<
typename
CharType
>
class
output_vector_adapter
:
public
output_adapter_protocol
<
CharType
>
{
public:
explicit
output_vector_adapter
(
std
::
vector
<
CharType
>&
vec
)
:
v
(
vec
)
{}
void
write_character
(
CharType
c
)
override
{
v
.
push_back
(
c
);
}
void
write_characters
(
const
CharType
*
s
,
std
::
size_t
length
)
override
{
std
::
copy
(
s
,
s
+
length
,
std
::
back_inserter
(
v
));
}
private:
std
::
vector
<
CharType
>&
v
;
};
/// output adapter for output streams
template
<
typename
CharType
>
class
output_stream_adapter
:
public
output_adapter_protocol
<
CharType
>
{
public:
explicit
output_stream_adapter
(
std
::
basic_ostream
<
CharType
>&
s
)
:
stream
(
s
)
{}
void
write_character
(
CharType
c
)
override
{
stream
.
put
(
c
);
}
void
write_characters
(
const
CharType
*
s
,
std
::
size_t
length
)
override
{
stream
.
write
(
s
,
static_cast
<
std
::
streamsize
>
(
length
));
}
private:
std
::
basic_ostream
<
CharType
>&
stream
;
};
/// output adapter for basic_string
template
<
typename
CharType
>
class
output_string_adapter
:
public
output_adapter_protocol
<
CharType
>
{
public:
explicit
output_string_adapter
(
std
::
basic_string
<
CharType
>&
s
)
:
str
(
s
)
{}
void
write_character
(
CharType
c
)
override
{
str
.
push_back
(
c
);
}
void
write_characters
(
const
CharType
*
s
,
std
::
size_t
length
)
override
{
str
.
append
(
s
,
length
);
}
private:
std
::
basic_string
<
CharType
>&
str
;
};
template
<
typename
CharType
>
class
output_adapter
{
public:
output_adapter
(
std
::
vector
<
CharType
>&
vec
)
:
oa
(
std
::
make_shared
<
output_vector_adapter
<
CharType
>>
(
vec
))
{}
output_adapter
(
std
::
basic_ostream
<
CharType
>&
s
)
:
oa
(
std
::
make_shared
<
output_stream_adapter
<
CharType
>>
(
s
))
{}
output_adapter
(
std
::
basic_string
<
CharType
>&
s
)
:
oa
(
std
::
make_shared
<
output_string_adapter
<
CharType
>>
(
s
))
{}
operator
output_adapter_t
<
CharType
>
()
{
return
oa
;
}
private:
output_adapter_t
<
CharType
>
oa
=
nullptr
;
};
}
}
#endif
src/json.hpp
浏览文件 @
4dbb433a
...
...
@@ -65,6 +65,7 @@ SOFTWARE.
#include "detail/iterators/iter_impl.hpp"
#include "detail/iterators/iteration_proxy.hpp"
#include "detail/iterators/json_reverse_iterator.hpp"
#include "detail/parsing/output_adapters.hpp"
/*!
@brief namespace for Niels Lohmann
...
...
@@ -75,107 +76,6 @@ namespace nlohmann
{
namespace
detail
{
/////////////////////
// output adapters //
/////////////////////
/// abstract output adapter interface
template
<
typename
CharType
>
struct
output_adapter_protocol
{
virtual
void
write_character
(
CharType
c
)
=
0
;
virtual
void
write_characters
(
const
CharType
*
s
,
std
::
size_t
length
)
=
0
;
virtual
~
output_adapter_protocol
()
=
default
;
};
/// a type to simplify interfaces
template
<
typename
CharType
>
using
output_adapter_t
=
std
::
shared_ptr
<
output_adapter_protocol
<
CharType
>>
;
/// output adapter for byte vectors
template
<
typename
CharType
>
class
output_vector_adapter
:
public
output_adapter_protocol
<
CharType
>
{
public:
explicit
output_vector_adapter
(
std
::
vector
<
CharType
>&
vec
)
:
v
(
vec
)
{}
void
write_character
(
CharType
c
)
override
{
v
.
push_back
(
c
);
}
void
write_characters
(
const
CharType
*
s
,
std
::
size_t
length
)
override
{
std
::
copy
(
s
,
s
+
length
,
std
::
back_inserter
(
v
));
}
private:
std
::
vector
<
CharType
>&
v
;
};
/// output adapter for output streams
template
<
typename
CharType
>
class
output_stream_adapter
:
public
output_adapter_protocol
<
CharType
>
{
public:
explicit
output_stream_adapter
(
std
::
basic_ostream
<
CharType
>&
s
)
:
stream
(
s
)
{}
void
write_character
(
CharType
c
)
override
{
stream
.
put
(
c
);
}
void
write_characters
(
const
CharType
*
s
,
std
::
size_t
length
)
override
{
stream
.
write
(
s
,
static_cast
<
std
::
streamsize
>
(
length
));
}
private:
std
::
basic_ostream
<
CharType
>&
stream
;
};
/// output adapter for basic_string
template
<
typename
CharType
>
class
output_string_adapter
:
public
output_adapter_protocol
<
CharType
>
{
public:
explicit
output_string_adapter
(
std
::
basic_string
<
CharType
>&
s
)
:
str
(
s
)
{}
void
write_character
(
CharType
c
)
override
{
str
.
push_back
(
c
);
}
void
write_characters
(
const
CharType
*
s
,
std
::
size_t
length
)
override
{
str
.
append
(
s
,
length
);
}
private:
std
::
basic_string
<
CharType
>&
str
;
};
template
<
typename
CharType
>
class
output_adapter
{
public:
output_adapter
(
std
::
vector
<
CharType
>&
vec
)
:
oa
(
std
::
make_shared
<
output_vector_adapter
<
CharType
>>
(
vec
))
{}
output_adapter
(
std
::
basic_ostream
<
CharType
>&
s
)
:
oa
(
std
::
make_shared
<
output_stream_adapter
<
CharType
>>
(
s
))
{}
output_adapter
(
std
::
basic_string
<
CharType
>&
s
)
:
oa
(
std
::
make_shared
<
output_string_adapter
<
CharType
>>
(
s
))
{}
operator
output_adapter_t
<
CharType
>
()
{
return
oa
;
}
private:
output_adapter_t
<
CharType
>
oa
=
nullptr
;
};
//////////////////////////////
// binary reader and writer //
//////////////////////////////
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录