/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-composable-kernel/checkouts/develop/include/rapidjson/stream.h Source File

/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-composable-kernel/checkouts/develop/include/rapidjson/stream.h Source File#

Composable Kernel: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-composable-kernel/checkouts/develop/include/rapidjson/stream.h Source File
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.
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 
23 
25 // Stream
26 
39 
42 
46 
50 
53 
56 
61 
67 
72 template <typename Stream>
74 {
76 
80  enum
81  {
83  };
84 };
85 
87 template <typename Stream>
88 inline void PutReserve(Stream& stream, size_t count)
89 {
90  (void)stream;
91  (void)count;
92 }
93 
95 template <typename Stream>
96 inline void PutUnsafe(Stream& stream, typename Stream::Ch c)
97 {
98  stream.Put(c);
99 }
100 
102 template <typename Stream, typename Ch>
103 inline void PutN(Stream& stream, Ch c, size_t n)
104 {
105  PutReserve(stream, n);
106  for(size_t i = 0; i < n; i++)
107  PutUnsafe(stream, c);
108 }
109 
111 // GenericStreamWrapper
112 
114 
119 #if defined(_MSC_VER) && _MSC_VER <= 1800
120 RAPIDJSON_DIAG_PUSH
121 RAPIDJSON_DIAG_OFF(4702) // unreachable code
122 RAPIDJSON_DIAG_OFF(4512) // assignment operator could not be generated
123 #endif
124 
125 template <typename InputStream, typename Encoding = UTF8<>>
127 {
128  public:
129  typedef typename Encoding::Ch Ch;
130  GenericStreamWrapper(InputStream& is) : is_(is) {}
131 
132  Ch Peek() const { return is_.Peek(); }
133  Ch Take() { return is_.Take(); }
134  size_t Tell() { return is_.Tell(); }
135  Ch* PutBegin() { return is_.PutBegin(); }
136  void Put(Ch ch) { is_.Put(ch); }
137  void Flush() { is_.Flush(); }
138  size_t PutEnd(Ch* ch) { return is_.PutEnd(ch); }
139 
140  // wrapper for MemoryStream
141  const Ch* Peek4() const { return is_.Peek4(); }
142 
143  // wrapper for AutoUTFInputStream
144  UTFType GetType() const { return is_.GetType(); }
145  bool HasBOM() const { return is_.HasBOM(); }
146 
147  protected:
148  InputStream& is_;
149 };
150 
151 #if defined(_MSC_VER) && _MSC_VER <= 1800
152 RAPIDJSON_DIAG_POP
153 #endif
154 
156 // StringStream
157 
159 
161 template <typename Encoding>
163 {
164  typedef typename Encoding::Ch Ch;
165 
166  GenericStringStream(const Ch* src) : src_(src), head_(src) {}
167 
168  Ch Peek() const { return *src_; }
169  Ch Take() { return *src_++; }
170  size_t Tell() const { return static_cast<size_t>(src_ - head_); }
171 
173  {
174  RAPIDJSON_ASSERT(false);
175  return 0;
176  }
177  void Put(Ch) { RAPIDJSON_ASSERT(false); }
178  void Flush() { RAPIDJSON_ASSERT(false); }
179  size_t PutEnd(Ch*)
180  {
181  RAPIDJSON_ASSERT(false);
182  return 0;
183  }
184 
185  const Ch* src_;
186  const Ch* head_;
187 };
188 
189 template <typename Encoding>
191 {
192  enum
193  {
194  copyOptimization = 1
195  };
196 };
197 
200 
202 // InsituStringStream
203 
205 
208 template <typename Encoding>
210 {
211  typedef typename Encoding::Ch Ch;
212 
213  GenericInsituStringStream(Ch* src) : src_(src), dst_(0), head_(src) {}
214 
215  // Read
216  Ch Peek() { return *src_; }
217  Ch Take() { return *src_++; }
218  size_t Tell() { return static_cast<size_t>(src_ - head_); }
219 
220  // Write
221  void Put(Ch c)
222  {
223  RAPIDJSON_ASSERT(dst_ != 0);
224  *dst_++ = c;
225  }
226 
227  Ch* PutBegin() { return dst_ = src_; }
228  size_t PutEnd(Ch* begin) { return static_cast<size_t>(dst_ - begin); }
229  void Flush() {}
230 
231  Ch* Push(size_t count)
232  {
233  Ch* begin = dst_;
234  dst_ += count;
235  return begin;
236  }
237  void Pop(size_t count) { dst_ -= count; }
238 
242 };
243 
244 template <typename Encoding>
246 {
247  enum
248  {
249  copyOptimization = 1
250  };
251 };
252 
255 
257 
258 #endif // RAPIDJSON_STREAM_H_
A Stream Wrapper.
Definition: stream.h:127
Ch Take()
Definition: stream.h:133
void Flush()
Definition: stream.h:137
InputStream & is_
Definition: stream.h:148
void Put(Ch ch)
Definition: stream.h:136
Ch * PutBegin()
Definition: stream.h:135
size_t Tell()
Definition: stream.h:134
bool HasBOM() const
Definition: stream.h:145
UTFType GetType() const
Definition: stream.h:144
GenericStreamWrapper(InputStream &is)
Definition: stream.h:130
size_t PutEnd(Ch *ch)
Definition: stream.h:138
Ch Peek() const
Definition: stream.h:132
Encoding::Ch Ch
Definition: stream.h:129
const Ch * Peek4() const
Definition: stream.h:141
Concept for encoding of Unicode characters.
Concept for reading and writing characters.
UTFType
Runtime-specified UTF encoding type of a stream.
Definition: encodings.h:757
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:451
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
Definition: rapidjson.h:121
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
Definition: rapidjson.h:124
common definitions and configuration
GenericStringStream< UTF8<> > StringStream
String stream with UTF8 encoding.
Definition: stream.h:199
GenericInsituStringStream< UTF8<> > InsituStringStream
Insitu string stream with UTF8 encoding.
Definition: stream.h:254
void PutReserve(Stream &stream, size_t count)
Reserve n characters for writing to a stream.
Definition: stream.h:88
void PutN(Stream &stream, Ch c, size_t n)
Put N copies of a character to a stream.
Definition: stream.h:103
void PutUnsafe(Stream &stream, typename Stream::Ch c)
Write character to a stream, presuming buffer is reserved.
Definition: stream.h:96
A read-write string stream.
Definition: stream.h:210
Encoding::Ch Ch
Definition: stream.h:211
void Flush()
Definition: stream.h:229
void Put(Ch c)
Definition: stream.h:221
size_t PutEnd(Ch *begin)
Definition: stream.h:228
size_t Tell()
Definition: stream.h:218
Ch * dst_
Definition: stream.h:240
void Pop(size_t count)
Definition: stream.h:237
GenericInsituStringStream(Ch *src)
Definition: stream.h:213
Ch Peek()
Definition: stream.h:216
Ch * src_
Definition: stream.h:239
Ch * head_
Definition: stream.h:241
Ch * Push(size_t count)
Definition: stream.h:231
Ch * PutBegin()
Definition: stream.h:227
Ch Take()
Definition: stream.h:217
Read-only string stream.
Definition: stream.h:163
size_t PutEnd(Ch *)
Definition: stream.h:179
Ch Peek() const
Definition: stream.h:168
Ch Take()
Definition: stream.h:169
const Ch * head_
Original head of the string.
Definition: stream.h:186
Encoding::Ch Ch
Definition: stream.h:164
void Flush()
Definition: stream.h:178
GenericStringStream(const Ch *src)
Definition: stream.h:166
Ch * PutBegin()
Definition: stream.h:172
void Put(Ch)
Definition: stream.h:177
size_t Tell() const
Definition: stream.h:170
const Ch * src_
Current read position.
Definition: stream.h:185
Provides additional information for stream.
Definition: stream.h:74
@ copyOptimization
Definition: stream.h:82