memorystream.h Source File

memorystream.h Source File#

Composable Kernel: memorystream.h Source File
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.
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#ifdef __clang__
21RAPIDJSON_DIAG_PUSH
22RAPIDJSON_DIAG_OFF(unreachable - code)
23RAPIDJSON_DIAG_OFF(missing - noreturn)
24#endif
25
27
29
42{
43 typedef char Ch; // byte
44
45 MemoryStream(const Ch* src, size_t size) : src_(src), begin_(src), end_(src + size), size_(size)
46 {
47 }
48
49 Ch Peek() const { return RAPIDJSON_UNLIKELY(src_ == end_) ? '\0' : *src_; }
50 Ch Take() { return RAPIDJSON_UNLIKELY(src_ == end_) ? '\0' : *src_++; }
51 size_t Tell() const { return static_cast<size_t>(src_ - begin_); }
52
54 {
55 RAPIDJSON_ASSERT(false);
56 return 0;
57 }
58 void Put(Ch) { RAPIDJSON_ASSERT(false); }
59 void Flush() { RAPIDJSON_ASSERT(false); }
60 size_t PutEnd(Ch*)
61 {
62 RAPIDJSON_ASSERT(false);
63 return 0;
64 }
65
66 // For encoding detection only.
67 const Ch* Peek4() const { return Tell() + 4 <= size_ ? src_ : 0; }
68
69 const Ch* src_;
70 const Ch* begin_;
71 const Ch* end_;
72 size_t size_;
73};
74
76
77#ifdef __clang__
78RAPIDJSON_DIAG_POP
79#endif
80
81#endif // RAPIDJSON_MEMORYBUFFER_H_
#define RAPIDJSON_UNLIKELY(x)
Compiler branching hint for expression with low probability to be true.
Definition rapidjson.h:531
#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
Ch Take()
Definition memorystream.h:50
MemoryStream(const Ch *src, size_t size)
Definition memorystream.h:45
size_t Tell() const
Definition memorystream.h:51
void Flush()
Definition memorystream.h:59
Ch * PutBegin()
Definition memorystream.h:53
const Ch * end_
End of stream.
Definition memorystream.h:71
const Ch * src_
Current read position.
Definition memorystream.h:69
char Ch
Definition memorystream.h:43
Ch Peek() const
Definition memorystream.h:49
size_t PutEnd(Ch *)
Definition memorystream.h:60
const Ch * Peek4() const
Definition memorystream.h:67
const Ch * begin_
Original head of the string.
Definition memorystream.h:70
size_t size_
Size of the stream.
Definition memorystream.h:72
void Put(Ch)
Definition memorystream.h:58