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