|
||||
File indexing completed on 2025-01-18 10:10:03
0001 // Tencent is pleased to support the open source community by making RapidJSON available. 0002 // 0003 // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. 0004 // 0005 // Licensed under the MIT License (the "License"); you may not use this file except 0006 // in compliance with the License. You may obtain a copy of the License at 0007 // 0008 // http://opensource.org/licenses/MIT 0009 // 0010 // Unless required by applicable law or agreed to in writing, software distributed 0011 // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 0012 // CONDITIONS OF ANY KIND, either express or implied. See the License for the 0013 // specific language governing permissions and limitations under the License. 0014 0015 #ifndef RAPIDJSON_MEMORYSTREAM_H_ 0016 #define RAPIDJSON_MEMORYSTREAM_H_ 0017 0018 #include "stream.h" 0019 0020 #ifdef __clang__ 0021 RAPIDJSON_DIAG_PUSH 0022 RAPIDJSON_DIAG_OFF(unreachable-code) 0023 RAPIDJSON_DIAG_OFF(missing-noreturn) 0024 #endif 0025 0026 RAPIDJSON_NAMESPACE_BEGIN 0027 0028 //! Represents an in-memory input byte stream. 0029 /*! 0030 This class is mainly for being wrapped by EncodedInputStream or AutoUTFInputStream. 0031 0032 It is similar to FileReadBuffer but the source is an in-memory buffer instead of a file. 0033 0034 Differences between MemoryStream and StringStream: 0035 1. StringStream has encoding but MemoryStream is a byte stream. 0036 2. MemoryStream needs size of the source buffer and the buffer don't need to be null terminated. StringStream assume null-terminated string as source. 0037 3. MemoryStream supports Peek4() for encoding detection. StringStream is specified with an encoding so it should not have Peek4(). 0038 \note implements Stream concept 0039 */ 0040 struct MemoryStream { 0041 typedef char Ch; // byte 0042 0043 MemoryStream(const Ch *src, size_t size) : src_(src), begin_(src), end_(src + size), size_(size) {} 0044 0045 Ch Peek() const { return RAPIDJSON_UNLIKELY(src_ == end_) ? '\0' : *src_; } 0046 Ch Take() { return RAPIDJSON_UNLIKELY(src_ == end_) ? '\0' : *src_++; } 0047 size_t Tell() const { return static_cast<size_t>(src_ - begin_); } 0048 0049 Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 0050 void Put(Ch) { RAPIDJSON_ASSERT(false); } 0051 void Flush() { RAPIDJSON_ASSERT(false); } 0052 size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } 0053 0054 // For encoding detection only. 0055 const Ch* Peek4() const { 0056 return Tell() + 4 <= size_ ? src_ : 0; 0057 } 0058 0059 const Ch* src_; //!< Current read position. 0060 const Ch* begin_; //!< Original head of the string. 0061 const Ch* end_; //!< End of stream. 0062 size_t size_; //!< Size of the stream. 0063 }; 0064 0065 RAPIDJSON_NAMESPACE_END 0066 0067 #ifdef __clang__ 0068 RAPIDJSON_DIAG_POP 0069 #endif 0070 0071 #endif // RAPIDJSON_MEMORYBUFFER_H_
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |