Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
stream.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2// Tencent is pleased to support the open source community by making RapidJSON available.
3//
4// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
5//
6// Licensed under the MIT License (the "License"); you may not use this file except
7// in compliance with the License. You may obtain a copy of the License at
8//
9// http://opensource.org/licenses/MIT
10//
11// Unless required by applicable law or agreed to in writing, software distributed
12// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
13// CONDITIONS OF ANY KIND, either express or implied. See the License for the
14// specific language governing permissions and limitations under the License.
15
16#include "rapidjson.h"
17
18#ifndef RAPIDJSON_STREAM_H_
19#define RAPIDJSON_STREAM_H_
20
21#include "encodings.h"
22
24
26// Stream
27
40
43
47
51
54
57
62
68
73template<typename Stream>
76
80 enum { copyOptimization = 0 };
81};
82
84template<typename Stream>
85inline void PutReserve(Stream& stream, size_t count) {
86 (void)stream;
87 (void)count;
88}
89
91template<typename Stream>
92inline void PutUnsafe(Stream& stream, typename Stream::Ch c) {
93 stream.Put(c);
94}
95
97template<typename Stream, typename Ch>
98inline void PutN(Stream& stream, Ch c, size_t n) {
99 PutReserve(stream, n);
100 for (size_t i = 0; i < n; i++)
101 PutUnsafe(stream, c);
102}
103
105// GenericStreamWrapper
106
108
113#if defined(_MSC_VER) && _MSC_VER <= 1800
114RAPIDJSON_DIAG_PUSH
115RAPIDJSON_DIAG_OFF(4702) // unreachable code
116RAPIDJSON_DIAG_OFF(4512) // assignment operator could not be generated
117#endif
118
119template <typename InputStream, typename Encoding = UTF8<> >
121public:
122 typedef typename Encoding::Ch Ch;
123 GenericStreamWrapper(InputStream& is): is_(is) {}
124
125 Ch Peek() const { return is_.Peek(); }
126 Ch Take() { return is_.Take(); }
127 size_t Tell() { return is_.Tell(); }
128 Ch* PutBegin() { return is_.PutBegin(); }
129 void Put(Ch ch) { is_.Put(ch); }
130 void Flush() { is_.Flush(); }
131 size_t PutEnd(Ch* ch) { return is_.PutEnd(ch); }
132
133 // wrapper for MemoryStream
134 const Ch* Peek4() const { return is_.Peek4(); }
135
136 // wrapper for AutoUTFInputStream
137 UTFType GetType() const { return is_.GetType(); }
138 bool HasBOM() const { return is_.HasBOM(); }
139
140protected:
141 InputStream& is_;
142};
143
144#if defined(_MSC_VER) && _MSC_VER <= 1800
145RAPIDJSON_DIAG_POP
146#endif
147
149// StringStream
150
152
154template <typename Encoding>
156 typedef typename Encoding::Ch Ch;
157
158 GenericStringStream(const Ch *src) : src_(src), head_(src) {}
159
160 Ch Peek() const { return *src_; }
161 Ch Take() { return *src_++; }
162 size_t Tell() const { return static_cast<size_t>(src_ - head_); }
163
164 Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; }
165 void Put(Ch) { RAPIDJSON_ASSERT(false); }
166 void Flush() { RAPIDJSON_ASSERT(false); }
167 size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; }
168
169 const Ch* src_;
170 const Ch* head_;
171};
172
173template <typename Encoding>
175 enum { copyOptimization = 1 };
176};
177
180
182// InsituStringStream
183
185
188template <typename Encoding>
190 typedef typename Encoding::Ch Ch;
191
192 GenericInsituStringStream(Ch *src) : src_(src), dst_(0), head_(src) {}
193
194 // Read
195 Ch Peek() { return *src_; }
196 Ch Take() { return *src_++; }
197 size_t Tell() { return static_cast<size_t>(src_ - head_); }
198
199 // Write
200 void Put(Ch c) { RAPIDJSON_ASSERT(dst_ != 0); *dst_++ = c; }
201
202 Ch* PutBegin() { return dst_ = src_; }
203 size_t PutEnd(Ch* begin) { return static_cast<size_t>(dst_ - begin); }
204 void Flush() {}
205
206 Ch* Push(size_t count) { Ch* begin = dst_; dst_ += count; return begin; }
207 void Pop(size_t count) { dst_ -= count; }
208
209 Ch* src_;
210 Ch* dst_;
211 Ch* head_;
212};
213
214template <typename Encoding>
216 enum { copyOptimization = 1 };
217};
218
221
223
224#endif // RAPIDJSON_STREAM_H_
A Stream Wrapper.
Definition stream.h:120
Concept for encoding of Unicode characters.
Concept for reading and writing characters.
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition rapidjson.h:407
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
Definition rapidjson.h:122
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
Definition rapidjson.h:125
common definitions and configuration
A read-write string stream.
Definition stream.h:189
Read-only string stream.
Definition stream.h:155
const Ch * head_
Original head of the string.
Definition stream.h:170
const Ch * src_
Current read position.
Definition stream.h:169
Provides additional information for stream.
Definition stream.h:74