Monero
Toggle main menu visibility
Loading...
Searching...
No Matches
external
rapidjson
include
rapidjson
istreamwrapper.h
Go to the documentation of this file.
1
// Tencent is pleased to support the open source community by making RapidJSON available.
2
//
3
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
4
//
5
// Licensed under the MIT License (the "License"); you may not use this file except
6
// in compliance with the License. You may obtain a copy of the License at
7
//
8
// http://opensource.org/licenses/MIT
9
//
10
// Unless required by applicable law or agreed to in writing, software distributed
11
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
13
// specific language governing permissions and limitations under the License.
14
15
#ifndef RAPIDJSON_ISTREAMWRAPPER_H_
16
#define RAPIDJSON_ISTREAMWRAPPER_H_
17
18
#include "
stream.h
"
19
#include <iosfwd>
20
21
#ifdef __clang__
22
RAPIDJSON_DIAG_PUSH
23
RAPIDJSON_DIAG_OFF(padded)
24
#elif defined(_MSC_VER)
25
RAPIDJSON_DIAG_PUSH
26
RAPIDJSON_DIAG_OFF(4351)
// new behavior: elements of array 'array' will be default initialized
27
#endif
28
29
RAPIDJSON_NAMESPACE_BEGIN
30
32
46
47
template
<
typename
StreamType>
48
class
BasicIStreamWrapper
{
49
public
:
50
typedef
typename
StreamType::char_type
Ch
;
51
BasicIStreamWrapper
(StreamType& stream) :
stream_
(stream),
count_
(),
peekBuffer_
() {}
52
53
Ch
Peek
()
const
{
54
typename
StreamType::int_type c =
stream_
.peek();
55
return
RAPIDJSON_LIKELY
(c != StreamType::traits_type::eof()) ?
static_cast<
Ch
>
(c) :
static_cast<
Ch
>
(
'\0'
);
56
}
57
58
Ch
Take
() {
59
typename
StreamType::int_type c =
stream_
.get();
60
if
(
RAPIDJSON_LIKELY
(c != StreamType::traits_type::eof())) {
61
count_
++;
62
return
static_cast<
Ch
>
(c);
63
}
64
else
65
return
'\0'
;
66
}
67
68
// tellg() may return -1 when failed. So we count by ourself.
69
size_t
Tell
()
const
{
return
count_
; }
70
71
Ch
*
PutBegin
() {
RAPIDJSON_ASSERT
(
false
);
return
0; }
72
void
Put
(
Ch
) {
RAPIDJSON_ASSERT
(
false
); }
73
void
Flush
() {
RAPIDJSON_ASSERT
(
false
); }
74
size_t
PutEnd
(
Ch
*) {
RAPIDJSON_ASSERT
(
false
);
return
0; }
75
76
// For encoding detection only.
77
const
Ch
*
Peek4
()
const
{
78
RAPIDJSON_ASSERT
(
sizeof
(
Ch
) == 1);
// Only usable for byte stream.
79
int
i;
80
bool
hasError =
false
;
81
for
(i = 0; i < 4; ++i) {
82
typename
StreamType::int_type c =
stream_
.get();
83
if
(c == StreamType::traits_type::eof()) {
84
hasError =
true
;
85
stream_
.clear();
86
break
;
87
}
88
peekBuffer_
[i] =
static_cast<
Ch
>
(c);
89
}
90
for
(--i; i >= 0; --i)
91
stream_
.putback(
peekBuffer_
[i]);
92
return
!hasError ?
peekBuffer_
: 0;
93
}
94
95
private
:
96
BasicIStreamWrapper
(
const
BasicIStreamWrapper
&);
97
BasicIStreamWrapper
&
operator=
(
const
BasicIStreamWrapper
&);
98
99
StreamType&
stream_
;
100
size_t
count_
;
101
mutable
Ch
peekBuffer_
[4];
102
};
103
104
typedef
BasicIStreamWrapper<std::istream>
IStreamWrapper
;
105
typedef
BasicIStreamWrapper<std::wistream>
WIStreamWrapper
;
106
107
#if defined(__clang__) || defined(_MSC_VER)
108
RAPIDJSON_DIAG_POP
109
#endif
110
111
RAPIDJSON_NAMESPACE_END
112
113
#endif
// RAPIDJSON_ISTREAMWRAPPER_H_
BasicIStreamWrapper
Wrapper of std::basic_istream into RapidJSON's Stream concept.
Definition
istreamwrapper.h:48
BasicIStreamWrapper< std::istream >::stream_
std::istream & stream_
Definition
istreamwrapper.h:99
BasicIStreamWrapper::Peek
Ch Peek() const
Definition
istreamwrapper.h:53
BasicIStreamWrapper::PutBegin
Ch * PutBegin()
Definition
istreamwrapper.h:71
BasicIStreamWrapper::BasicIStreamWrapper
BasicIStreamWrapper(const BasicIStreamWrapper &)
BasicIStreamWrapper::Flush
void Flush()
Definition
istreamwrapper.h:73
BasicIStreamWrapper::BasicIStreamWrapper
BasicIStreamWrapper(StreamType &stream)
Definition
istreamwrapper.h:51
BasicIStreamWrapper::Peek4
const Ch * Peek4() const
Definition
istreamwrapper.h:77
BasicIStreamWrapper::operator=
BasicIStreamWrapper & operator=(const BasicIStreamWrapper &)
BasicIStreamWrapper::Ch
StreamType::char_type Ch
Definition
istreamwrapper.h:50
BasicIStreamWrapper::PutEnd
size_t PutEnd(Ch *)
Definition
istreamwrapper.h:74
BasicIStreamWrapper< std::istream >::count_
size_t count_
Definition
istreamwrapper.h:100
BasicIStreamWrapper::Tell
size_t Tell() const
Definition
istreamwrapper.h:69
BasicIStreamWrapper< std::istream >::peekBuffer_
Ch peekBuffer_[4]
Definition
istreamwrapper.h:101
BasicIStreamWrapper::Put
void Put(Ch)
Definition
istreamwrapper.h:72
BasicIStreamWrapper::Take
Ch Take()
Definition
istreamwrapper.h:58
IStreamWrapper
Definition
readertest.cpp:1362
RAPIDJSON_LIKELY
#define RAPIDJSON_LIKELY(x)
Compiler branching hint for expression with high probability to be true.
Definition
rapidjson.h:468
RAPIDJSON_ASSERT
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition
rapidjson.h:411
RAPIDJSON_NAMESPACE_BEGIN
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
Definition
rapidjson.h:121
RAPIDJSON_NAMESPACE_END
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
Definition
rapidjson.h:124
WIStreamWrapper
BasicIStreamWrapper< std::wistream > WIStreamWrapper
Definition
istreamwrapper.h:105
stream.h
Generated on
for Monero by
1.17.0