RetroArch
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 
23 
25 // Stream
26 
39 
42 
46 
50 
53 
56 
61 
66 
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) {
99  for (size_t i = 0; i < n; i++)
100  PutUnsafe(stream, c);
101 }
102 
104 // StringStream
105 
107 
109 template <typename Encoding>
110 struct GenericStringStream {
111  typedef typename Encoding::Ch Ch;
112 
114 
115  Ch Peek() const { return *src_; }
116  Ch Take() { return *src_++; }
117  size_t Tell() const { return static_cast<size_t>(src_ - head_); }
118 
119  Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; }
120  void Put(Ch) { RAPIDJSON_ASSERT(false); }
121  void Flush() { RAPIDJSON_ASSERT(false); }
122  size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; }
123 
124  const Ch* src_;
125  const Ch* head_;
126 };
127 
128 template <typename Encoding>
130  enum { copyOptimization = 1 };
131 };
132 
135 
137 // InsituStringStream
138 
140 
143 template <typename Encoding>
145  typedef typename Encoding::Ch Ch;
146 
148 
149  // Read
150  Ch Peek() { return *src_; }
151  Ch Take() { return *src_++; }
152  size_t Tell() { return static_cast<size_t>(src_ - head_); }
153 
154  // Write
155  void Put(Ch c) { RAPIDJSON_ASSERT(dst_ != 0); *dst_++ = c; }
156 
157  Ch* PutBegin() { return dst_ = src_; }
158  size_t PutEnd(Ch* begin) { return static_cast<size_t>(dst_ - begin); }
159  void Flush() {}
160 
161  Ch* Push(size_t count) { Ch* begin = dst_; dst_ += count; return begin; }
162  void Pop(size_t count) { dst_ -= count; }
163 
167 };
168 
169 template <typename Encoding>
171  enum { copyOptimization = 1 };
172 };
173 
176 
178 
179 #endif // RAPIDJSON_STREAM_H_
void Flush()
Definition: stream.h:159
Ch Peek()
Definition: stream.h:150
const Ch * head_
Original head of the string.
Definition: stream.h:125
GenericInsituStringStream(Ch *src)
Definition: stream.h:147
common definitions and configuration
Ch Peek() const
Definition: stream.h:115
void PutUnsafe(Stream &stream, typename Stream::Ch c)
Write character to a stream, presuming buffer is reserved.
Definition: stream.h:91
void Flush()
Definition: stream.h:121
A read-write string stream.
Definition: fwd.h:52
void PutN(Stream &stream, Ch c, size_t n)
Put N copies of a character to a stream.
Definition: stream.h:97
const Ch * src_
Current read position.
Definition: stream.h:124
typedef void(__stdcall *PFN_DESTRUCTION_CALLBACK)(void *pData)
void Pop(size_t count)
Definition: stream.h:162
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
Definition: rapidjson.h:119
Read-only string stream.
Definition: fwd.h:47
const GLubyte * c
Definition: glext.h:9812
GLuint GLuint GLsizei count
Definition: glext.h:6292
GenericInsituStringStream< UTF8<> > InsituStringStream
Insitu string stream with UTF8 encoding.
Definition: stream.h:175
size_t Tell() const
Definition: stream.h:117
GenericStringStream< UTF8<> > StringStream
String stream with UTF8 encoding.
Definition: stream.h:134
Ch * PutBegin()
Definition: stream.h:119
Ch Take()
Definition: stream.h:151
size_t PutEnd(Ch *)
Definition: stream.h:122
Ch * PutBegin()
Definition: stream.h:157
Definition: stream.h:79
GenericStringStream(const Ch *src)
Definition: stream.h:113
Ch * dst_
Definition: stream.h:165
Ch * Push(size_t count)
Definition: stream.h:161
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:402
GLenum src
Definition: glext.h:6980
size_t PutEnd(Ch *begin)
Definition: stream.h:158
void Put(Ch c)
Definition: stream.h:155
Ch Take()
Definition: stream.h:116
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
Definition: rapidjson.h:116
GLuint GLuint stream
Definition: glext.h:8189
Ch * src_
Definition: stream.h:164
void Put(Ch)
Definition: stream.h:120
void PutReserve(Stream &stream, size_t count)
Reserve n characters for writing to a stream.
Definition: stream.h:84
Ch * head_
Definition: stream.h:166
Encoding::Ch Ch
Definition: stream.h:111
byte Encoding
Definition: jsonsax_full.c:106
Provides additional information for stream.
Definition: stream.h:73
Encoding::Ch Ch
Definition: stream.h:145
GLdouble n
Definition: glext.h:8396
size_t Tell()
Definition: stream.h:152