memorystream.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_MEMORYSTREAM_H_
16 #define RAPIDJSON_MEMORYSTREAM_H_
17 
18 #include "stream.h"
19 
20 #if __clang__
21 RAPIDJSON_DIAG_PUSH
22 RAPIDJSON_DIAG_OFF(unreachable - code)
23 RAPIDJSON_DIAG_OFF(missing - noreturn)
24 #endif
25 
27 
29 
43 {
44  typedef char Ch; // byte
45 
46  MemoryStream(const Ch* src, size_t size) : src_(src), begin_(src), end_(src + size), size_(size)
47  {
48  }
49 
50  Ch Peek() const
51  {
52  return RAPIDJSON_UNLIKELY(src_ == end_) ? '\0' : *src_;
53  }
54  Ch Take()
55  {
56  return RAPIDJSON_UNLIKELY(src_ == end_) ? '\0' : *src_++;
57  }
58  size_t Tell() const
59  {
60  return static_cast<size_t>(src_ - begin_);
61  }
62 
63  Ch* PutBegin()
64  {
65  RAPIDJSON_ASSERT(false);
66  return 0;
67  }
68  void Put(Ch)
69  {
70  RAPIDJSON_ASSERT(false);
71  }
72  void Flush()
73  {
74  RAPIDJSON_ASSERT(false);
75  }
76  size_t PutEnd(Ch*)
77  {
78  RAPIDJSON_ASSERT(false);
79  return 0;
80  }
81 
82  // For encoding detection only.
83  const Ch* Peek4() const
84  {
85  return Tell() + 4 <= size_ ? src_ : 0;
86  }
87 
88  const Ch* src_;
89  const Ch* begin_;
90  const Ch* end_;
91  size_t size_;
92 };
93 
95 
96 #if __clang__
97 RAPIDJSON_DIAG_POP
98 #endif
99 
100 #endif // RAPIDJSON_MEMORYBUFFER_H_
size_t PutEnd(Ch *)
Definition: memorystream.h:76
Represents an in-memory input byte stream.
Definition: memorystream.h:42
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:416
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
Definition: rapidjson.h:126
const Ch * end_
End of stream.
Definition: memorystream.h:90
void Put(Ch)
Definition: memorystream.h:68
MemoryStream(const Ch *src, size_t size)
Definition: memorystream.h:46
Ch * PutBegin()
Definition: memorystream.h:63
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
Definition: rapidjson.h:121
const Ch * src_
Current read position.
Definition: memorystream.h:88
const Ch * begin_
Original head of the string.
Definition: memorystream.h:89
const Ch * Peek4() const
Definition: memorystream.h:83
size_t size_
Size of the stream.
Definition: memorystream.h:91
Ch Peek() const
Definition: memorystream.h:50
size_t Tell() const
Definition: memorystream.h:58
#define RAPIDJSON_UNLIKELY(x)
Compiler branching hint for expression with low probability to be true.
Definition: rapidjson.h:495
void Flush()
Definition: memorystream.h:72


xbot_talker
Author(s): wangxiaoyun
autogenerated on Sat Oct 10 2020 03:27:53