Electroneum
Toggle main menu visibility
Loading...
Searching...
No Matches
stream.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
#include "
rapidjson.h
"
16
17
#ifndef RAPIDJSON_STREAM_H_
18
#define RAPIDJSON_STREAM_H_
19
20
#include "
encodings.h
"
21
22
RAPIDJSON_NAMESPACE_BEGIN
23
25
// Stream
26
39
Ch Peek() const;
40
42
Ch Take();
43
46
size_t Tell();
47
50
Ch* PutBegin();
51
53
void Put(Ch c);
54
56
void Flush();
57
61
size_t PutEnd(Ch* begin);
62
}
63
\endcode
64
*/
65
67
72
template
<
typename
Stream>
73
struct
StreamTraits
{
75
79
enum
{
copyOptimization
= 0 };
80
};
81
83
template
<
typename
Stream>
84
inline
void
PutReserve
(
Stream
& stream,
size_t
count) {
85
(void)stream;
86
(void)count;
87
}
88
90
template
<
typename
Stream>
91
inline
void
PutUnsafe
(
Stream
& stream,
typename
Stream::Ch c) {
92
stream.Put(c);
93
}
94
96
template
<
typename
Stream,
typename
Ch>
97
inline
void
PutN
(
Stream
& stream,
Ch
c,
size_t
n) {
98
PutReserve
(stream, n);
99
for
(
size_t
i = 0; i < n; i++)
100
PutUnsafe
(stream, c);
101
}
102
104
// GenericStreamWrapper
105
107
111
112
#if defined(_MSC_VER) && _MSC_VER <= 1800
113
RAPIDJSON_DIAG_PUSH
114
RAPIDJSON_DIAG_OFF(4702)
// unreachable code
115
RAPIDJSON_DIAG_OFF(4512)
// assignment operator could not be generated
116
#endif
117
118
template
<
typename
InputStream,
typename
Encoding = UTF8<> >
119
class
GenericStreamWrapper
{
120
public
:
121
typedef
typename
Encoding::Ch
Ch
;
122
GenericStreamWrapper
(InputStream& is):
is_
(is) {}
123
124
Ch
Peek
()
const
{
return
is_
.Peek(); }
125
Ch
Take
() {
return
is_
.Take(); }
126
size_t
Tell
() {
return
is_
.Tell(); }
127
Ch
*
PutBegin
() {
return
is_
.PutBegin(); }
128
void
Put
(
Ch
ch) {
is_
.Put(ch); }
129
void
Flush
() {
is_
.Flush(); }
130
size_t
PutEnd
(
Ch
* ch) {
return
is_
.PutEnd(ch); }
131
132
// wrapper for MemoryStream
133
const
Ch
*
Peek4
()
const
{
return
is_
.Peek4(); }
134
135
// wrapper for AutoUTFInputStream
136
UTFType
GetType
()
const
{
return
is_
.GetType(); }
137
bool
HasBOM
()
const
{
return
is_
.HasBOM(); }
138
139
protected
:
140
InputStream&
is_
;
141
};
142
143
#if defined(_MSC_VER) && _MSC_VER <= 1800
144
RAPIDJSON_DIAG_POP
145
#endif
146
148
// StringStream
149
151
153
template
<
typename
Encoding>
154
struct
GenericStringStream
{
155
typedef
typename
Encoding::Ch
Ch
;
156
157
GenericStringStream
(
const
Ch
*src) :
src_
(src),
head_
(src) {}
158
159
Ch
Peek
()
const
{
return
*
src_
; }
160
Ch
Take
() {
return
*
src_
++; }
161
size_t
Tell
()
const
{
return
static_cast<
size_t
>
(
src_
-
head_
); }
162
163
Ch
*
PutBegin
() {
RAPIDJSON_ASSERT
(
false
);
return
0; }
164
void
Put
(
Ch
) {
RAPIDJSON_ASSERT
(
false
); }
165
void
Flush
() {
RAPIDJSON_ASSERT
(
false
); }
166
size_t
PutEnd
(
Ch
*) {
RAPIDJSON_ASSERT
(
false
);
return
0; }
167
168
const
Ch
*
src_
;
169
const
Ch
*
head_
;
170
};
171
172
template
<
typename
Encoding>
173
struct
StreamTraits
<
GenericStringStream
<
Encoding
> > {
174
enum
{
copyOptimization
= 1 };
175
};
176
178
typedef
GenericStringStream<UTF8<>
>
StringStream
;
179
181
// InsituStringStream
182
184
187
template
<
typename
Encoding>
188
struct
GenericInsituStringStream
{
189
typedef
typename
Encoding::Ch
Ch
;
190
191
GenericInsituStringStream
(
Ch
*src) :
src_
(src),
dst_
(0),
head_
(src) {}
192
193
// Read
194
Ch
Peek
() {
return
*
src_
; }
195
Ch
Take
() {
return
*
src_
++; }
196
size_t
Tell
() {
return
static_cast<
size_t
>
(
src_
-
head_
); }
197
198
// Write
199
void
Put
(
Ch
c) {
RAPIDJSON_ASSERT
(
dst_
!= 0); *
dst_
++ = c; }
200
201
Ch
*
PutBegin
() {
return
dst_
=
src_
; }
202
size_t
PutEnd
(
Ch
* begin) {
return
static_cast<
size_t
>
(
dst_
- begin); }
203
void
Flush
() {}
204
205
Ch
*
Push
(
size_t
count) {
Ch
* begin =
dst_
;
dst_
+= count;
return
begin; }
206
void
Pop
(
size_t
count) {
dst_
-= count; }
207
208
Ch
*
src_
;
209
Ch
*
dst_
;
210
Ch
*
head_
;
211
};
212
213
template
<
typename
Encoding>
214
struct
StreamTraits
<
GenericInsituStringStream
<
Encoding
> > {
215
enum
{
copyOptimization
= 1 };
216
};
217
219
typedef
GenericInsituStringStream<UTF8<>
>
InsituStringStream
;
220
221
RAPIDJSON_NAMESPACE_END
222
223
#endif
// RAPIDJSON_STREAM_H_
GenericStreamWrapper::PutBegin
Ch * PutBegin()
Definition
stream.h:127
GenericStreamWrapper::Take
Ch Take()
Definition
stream.h:125
GenericStreamWrapper::Flush
void Flush()
Definition
stream.h:129
GenericStreamWrapper::is_
InputStream & is_
Definition
stream.h:140
GenericStreamWrapper::Put
void Put(Ch ch)
Definition
stream.h:128
GenericStreamWrapper::Tell
size_t Tell()
Definition
stream.h:126
GenericStreamWrapper::HasBOM
bool HasBOM() const
Definition
stream.h:137
GenericStreamWrapper::GetType
UTFType GetType() const
Definition
stream.h:136
GenericStreamWrapper::GenericStreamWrapper
GenericStreamWrapper(InputStream &is)
Definition
stream.h:122
GenericStreamWrapper::PutEnd
size_t PutEnd(Ch *ch)
Definition
stream.h:130
GenericStreamWrapper::Peek
Ch Peek() const
Definition
stream.h:124
GenericStreamWrapper::Ch
Encoding::Ch Ch
Definition
stream.h:121
GenericStreamWrapper::Peek4
const Ch * Peek4() const
Definition
stream.h:133
Encoding
Concept for encoding of Unicode characters.
Stream
Concept for reading and writing characters.
encodings.h
UTFType
UTFType
Runtime-specified UTF encoding type of a stream.
Definition
encodings.h:603
StringStream
GenericStringStream< UTF8< char > > StringStream
Definition
fwd.h:49
InsituStringStream
GenericInsituStringStream< UTF8< char > > InsituStringStream
Definition
fwd.h:54
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
Ch
#define Ch(x, y, z)
Definition
hash_impl.h:17
rapidjson.h
common definitions and configuration
PutReserve
void PutReserve(Stream &stream, size_t count)
Reserve n characters for writing to a stream.
Definition
stream.h:84
PutN
void PutN(Stream &stream, Ch c, size_t n)
Put N copies of a character to a stream.
Definition
stream.h:97
PutUnsafe
void PutUnsafe(Stream &stream, typename Stream::Ch c)
Write character to a stream, presuming buffer is reserved.
Definition
stream.h:91
GenericInsituStringStream
A read-write string stream.
Definition
stream.h:188
GenericInsituStringStream< UTF8< char > >::Ch
UTF8< char >::Ch Ch
Definition
stream.h:189
GenericInsituStringStream::Flush
void Flush()
Definition
stream.h:203
GenericInsituStringStream::Put
void Put(Ch c)
Definition
stream.h:199
GenericInsituStringStream::PutBegin
Ch * PutBegin()
Definition
stream.h:201
GenericInsituStringStream::PutEnd
size_t PutEnd(Ch *begin)
Definition
stream.h:202
GenericInsituStringStream::Tell
size_t Tell()
Definition
stream.h:196
GenericInsituStringStream< UTF8< char > >::dst_
Ch * dst_
Definition
stream.h:209
GenericInsituStringStream::Pop
void Pop(size_t count)
Definition
stream.h:206
GenericInsituStringStream::GenericInsituStringStream
GenericInsituStringStream(Ch *src)
Definition
stream.h:191
GenericInsituStringStream::Peek
Ch Peek()
Definition
stream.h:194
GenericInsituStringStream::Push
Ch * Push(size_t count)
Definition
stream.h:205
GenericInsituStringStream< UTF8< char > >::src_
Ch * src_
Definition
stream.h:208
GenericInsituStringStream< UTF8< char > >::head_
Ch * head_
Definition
stream.h:210
GenericInsituStringStream::Take
Ch Take()
Definition
stream.h:195
GenericStringStream
Read-only string stream.
Definition
stream.h:154
GenericStringStream::PutEnd
size_t PutEnd(Ch *)
Definition
stream.h:166
GenericStringStream::Peek
Ch Peek() const
Definition
stream.h:159
GenericStringStream::Take
Ch Take()
Definition
stream.h:160
GenericStringStream< UTF8< char > >::head_
const Ch * head_
Definition
stream.h:169
GenericStringStream< UTF8< char > >::Ch
UTF8< char >::Ch Ch
Definition
stream.h:155
GenericStringStream::PutBegin
Ch * PutBegin()
Definition
stream.h:163
GenericStringStream::Flush
void Flush()
Definition
stream.h:165
GenericStringStream::GenericStringStream
GenericStringStream(const Ch *src)
Definition
stream.h:157
GenericStringStream::Put
void Put(Ch)
Definition
stream.h:164
GenericStringStream::Tell
size_t Tell() const
Definition
stream.h:161
GenericStringStream< UTF8< char > >::src_
const Ch * src_
Definition
stream.h:168
StreamTraits< GenericInsituStringStream< Encoding > >::copyOptimization
@ copyOptimization
Definition
stream.h:215
StreamTraits< GenericStringStream< Encoding > >::copyOptimization
@ copyOptimization
Definition
stream.h:174
StreamTraits
Provides additional information for stream.
Definition
stream.h:73
StreamTraits::copyOptimization
@ copyOptimization
Definition
stream.h:79
external
rapidjson
include
rapidjson
stream.h
Generated on
for Electroneum by
1.17.0