memorystream.h
Go to the documentation of this file.
1 // Tencent is pleased to support the open source community by making RapidJSON
2 // available.
3 //
4 // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All
5 // rights reserved.
6 //
7 // Licensed under the MIT License (the "License"); you may not use this file
8 // except in compliance with the License. You may obtain a copy of the License
9 // at
10 //
11 // http://opensource.org/licenses/MIT
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16 // License for the specific language governing permissions and limitations under
17 // the License.
18 
19 #ifndef RAPIDJSON_MEMORYSTREAM_H_
20 #define RAPIDJSON_MEMORYSTREAM_H_
21 
22 #include "stream.h"
23 
24 #ifdef __clang__
25 RAPIDJSON_DIAG_PUSH
26 RAPIDJSON_DIAG_OFF(unreachable - code)
27 RAPIDJSON_DIAG_OFF(missing - noreturn)
28 #endif
29 
31 
33 
48 struct MemoryStream {
49  typedef char Ch; // byte
50 
51  MemoryStream(const Ch *src, size_t size)
52  : src_(src), begin_(src), end_(src + size), size_(size) {}
53 
54  Ch Peek() const { return RAPIDJSON_UNLIKELY(src_ == end_) ? '\0' : *src_; }
55  Ch Take() { return RAPIDJSON_UNLIKELY(src_ == end_) ? '\0' : *src_++; }
56  size_t Tell() const { return static_cast<size_t>(src_ - begin_); }
57 
58  Ch *PutBegin() {
59  RAPIDJSON_ASSERT(false);
60  return 0;
61  }
62  void Put(Ch) { RAPIDJSON_ASSERT(false); }
63  void Flush() { RAPIDJSON_ASSERT(false); }
64  size_t PutEnd(Ch *) {
65  RAPIDJSON_ASSERT(false);
66  return 0;
67  }
68 
69  // For encoding detection only.
70  const Ch *Peek4() const { return Tell() + 4 <= size_ ? src_ : 0; }
71 
72  const Ch *src_;
73  const Ch *begin_;
74  const Ch *end_;
75  size_t size_;
76 };
77 
79 
80 #ifdef __clang__
81 RAPIDJSON_DIAG_POP
82 #endif
83 
84 #endif // RAPIDJSON_MEMORYBUFFER_H_
size_t PutEnd(Ch *)
Definition: memorystream.h:64
Represents an in-memory input byte stream.
Definition: memorystream.h:48
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:433
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
Definition: rapidjson.h:131
const Ch * end_
End of stream.
Definition: memorystream.h:74
void Put(Ch)
Definition: memorystream.h:62
MemoryStream(const Ch *src, size_t size)
Definition: memorystream.h:51
Ch * PutBegin()
Definition: memorystream.h:58
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
Definition: rapidjson.h:128
const Ch * src_
Current read position.
Definition: memorystream.h:72
const Ch * begin_
Original head of the string.
Definition: memorystream.h:73
const Ch * Peek4() const
Definition: memorystream.h:70
size_t size_
Size of the stream.
Definition: memorystream.h:75
Ch Peek() const
Definition: memorystream.h:54
size_t Tell() const
Definition: memorystream.h:56
#define RAPIDJSON_UNLIKELY(x)
Compiler branching hint for expression with low probability to be true.
Definition: rapidjson.h:508
void Flush()
Definition: memorystream.h:63


livox_ros_driver
Author(s): Livox Dev Team
autogenerated on Mon Mar 15 2021 02:40:46