git repos / blockattack-game

blame: source/code/Libs/include/cereal/external/rapidjson/memorystream.h

normal view · raw

6c5f2c01 sago007 2017-03-15 17:56 1
// Tencent is pleased to support the open source community by making RapidJSON available.
6c5f2c01 sago007 2017-03-15 17:56 2
//
6c5f2c01 sago007 2017-03-15 17:56 3
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
6c5f2c01 sago007 2017-03-15 17:56 4
//
6c5f2c01 sago007 2017-03-15 17:56 5
// Licensed under the MIT License (the "License"); you may not use this file except
6c5f2c01 sago007 2017-03-15 17:56 6
// in compliance with the License. You may obtain a copy of the License at
6c5f2c01 sago007 2017-03-15 17:56 7
//
6c5f2c01 sago007 2017-03-15 17:56 8
// http://opensource.org/licenses/MIT
6c5f2c01 sago007 2017-03-15 17:56 9
//
6c5f2c01 sago007 2017-03-15 17:56 10
// Unless required by applicable law or agreed to in writing, software distributed
6c5f2c01 sago007 2017-03-15 17:56 11
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
6c5f2c01 sago007 2017-03-15 17:56 12
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
6c5f2c01 sago007 2017-03-15 17:56 13
// specific language governing permissions and limitations under the License.
6c5f2c01 sago007 2017-03-15 17:56 14
6c5f2c01 sago007 2017-03-15 17:56 15
#ifndef CEREAL_RAPIDJSON_MEMORYSTREAM_H_
6c5f2c01 sago007 2017-03-15 17:56 16
#define CEREAL_RAPIDJSON_MEMORYSTREAM_H_
6c5f2c01 sago007 2017-03-15 17:56 17
6c5f2c01 sago007 2017-03-15 17:56 18
#include "stream.h"
6c5f2c01 sago007 2017-03-15 17:56 19
6c5f2c01 sago007 2017-03-15 17:56 20
#ifdef __clang__
6c5f2c01 sago007 2017-03-15 17:56 21
CEREAL_RAPIDJSON_DIAG_PUSH
6c5f2c01 sago007 2017-03-15 17:56 22
CEREAL_RAPIDJSON_DIAG_OFF(unreachable-code)
6c5f2c01 sago007 2017-03-15 17:56 23
CEREAL_RAPIDJSON_DIAG_OFF(missing-noreturn)
6c5f2c01 sago007 2017-03-15 17:56 24
#endif
6c5f2c01 sago007 2017-03-15 17:56 25
6c5f2c01 sago007 2017-03-15 17:56 26
#ifdef _MSC_VER
6c5f2c01 sago007 2017-03-15 17:56 27
CEREAL_RAPIDJSON_DIAG_PUSH
6c5f2c01 sago007 2017-03-15 17:56 28
CEREAL_RAPIDJSON_DIAG_OFF( 4127 ) // ignore assert(false) for triggering exception
6c5f2c01 sago007 2017-03-15 17:56 29
#endif
6c5f2c01 sago007 2017-03-15 17:56 30
6c5f2c01 sago007 2017-03-15 17:56 31
CEREAL_RAPIDJSON_NAMESPACE_BEGIN
6c5f2c01 sago007 2017-03-15 17:56 32
6c5f2c01 sago007 2017-03-15 17:56 33
//! Represents an in-memory input byte stream.
6c5f2c01 sago007 2017-03-15 17:56 34
/*!
6c5f2c01 sago007 2017-03-15 17:56 35
    This class is mainly for being wrapped by EncodedInputStream or AutoUTFInputStream.
6c5f2c01 sago007 2017-03-15 17:56 36
6c5f2c01 sago007 2017-03-15 17:56 37
    It is similar to FileReadBuffer but the source is an in-memory buffer instead of a file.
6c5f2c01 sago007 2017-03-15 17:56 38
6c5f2c01 sago007 2017-03-15 17:56 39
    Differences between MemoryStream and StringStream:
6c5f2c01 sago007 2017-03-15 17:56 40
    1. StringStream has encoding but MemoryStream is a byte stream.
6c5f2c01 sago007 2017-03-15 17:56 41
    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.
6c5f2c01 sago007 2017-03-15 17:56 42
    3. MemoryStream supports Peek4() for encoding detection. StringStream is specified with an encoding so it should not have Peek4().
6c5f2c01 sago007 2017-03-15 17:56 43
    \note implements Stream concept
6c5f2c01 sago007 2017-03-15 17:56 44
*/
6c5f2c01 sago007 2017-03-15 17:56 45
struct MemoryStream {
6c5f2c01 sago007 2017-03-15 17:56 46
    typedef char Ch; // byte
6c5f2c01 sago007 2017-03-15 17:56 47
6c5f2c01 sago007 2017-03-15 17:56 48
    MemoryStream(const Ch *src, size_t size) : src_(src), begin_(src), end_(src + size), size_(size) {}
6c5f2c01 sago007 2017-03-15 17:56 49
6c5f2c01 sago007 2017-03-15 17:56 50
    Ch Peek() const { return CEREAL_RAPIDJSON_UNLIKELY(src_ == end_) ? '\0' : *src_; }
6c5f2c01 sago007 2017-03-15 17:56 51
    Ch Take() { return CEREAL_RAPIDJSON_UNLIKELY(src_ == end_) ? '\0' : *src_++; }
6c5f2c01 sago007 2017-03-15 17:56 52
    size_t Tell() const { return static_cast<size_t>(src_ - begin_); }
6c5f2c01 sago007 2017-03-15 17:56 53
6c5f2c01 sago007 2017-03-15 17:56 54
    Ch* PutBegin() { CEREAL_RAPIDJSON_ASSERT(false); return 0; }
6c5f2c01 sago007 2017-03-15 17:56 55
    void Put(Ch) { CEREAL_RAPIDJSON_ASSERT(false); }
6c5f2c01 sago007 2017-03-15 17:56 56
    void Flush() { CEREAL_RAPIDJSON_ASSERT(false); }
6c5f2c01 sago007 2017-03-15 17:56 57
    size_t PutEnd(Ch*) { CEREAL_RAPIDJSON_ASSERT(false); return 0; }
6c5f2c01 sago007 2017-03-15 17:56 58
6c5f2c01 sago007 2017-03-15 17:56 59
    // For encoding detection only.
6c5f2c01 sago007 2017-03-15 17:56 60
    const Ch* Peek4() const {
6c5f2c01 sago007 2017-03-15 17:56 61
        return Tell() + 4 <= size_ ? src_ : 0;
6c5f2c01 sago007 2017-03-15 17:56 62
    }
6c5f2c01 sago007 2017-03-15 17:56 63
6c5f2c01 sago007 2017-03-15 17:56 64
    const Ch* src_;     //!< Current read position.
6c5f2c01 sago007 2017-03-15 17:56 65
    const Ch* begin_;   //!< Original head of the string.
6c5f2c01 sago007 2017-03-15 17:56 66
    const Ch* end_;     //!< End of stream.
6c5f2c01 sago007 2017-03-15 17:56 67
    size_t size_;       //!< Size of the stream.
6c5f2c01 sago007 2017-03-15 17:56 68
};
6c5f2c01 sago007 2017-03-15 17:56 69
6c5f2c01 sago007 2017-03-15 17:56 70
CEREAL_RAPIDJSON_NAMESPACE_END
6c5f2c01 sago007 2017-03-15 17:56 71
6c5f2c01 sago007 2017-03-15 17:56 72
#if defined(__clang__) || defined(_MSC_VER)
6c5f2c01 sago007 2017-03-15 17:56 73
CEREAL_RAPIDJSON_DIAG_POP
6c5f2c01 sago007 2017-03-15 17:56 74
#endif
6c5f2c01 sago007 2017-03-15 17:56 75
6c5f2c01 sago007 2017-03-15 17:56 76
#endif // CEREAL_RAPIDJSON_MEMORYBUFFER_H_
1970-01-01 00:00 77