Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
memorybuffer.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_MEMORYBUFFER_H_
17#define RAPIDJSON_MEMORYBUFFER_H_
18
19#include "stream.h"
20#include "internal/stack.h"
21
23
25
37template <typename Allocator = CrtAllocator>
39 typedef char Ch; // byte
40
41 GenericMemoryBuffer(Allocator* allocator = 0, size_t capacity = kDefaultCapacity) : stack_(allocator, capacity) {}
42
43 void Put(Ch c) { *stack_.template Push<Ch>() = c; }
44 void Flush() {}
45
46 void Clear() { stack_.Clear(); }
47 void ShrinkToFit() { stack_.ShrinkToFit(); }
48 Ch* Push(size_t count) { return stack_.template Push<Ch>(count); }
49 void Pop(size_t count) { stack_.template Pop<Ch>(count); }
50
51 const Ch* GetBuffer() const {
52 return stack_.template Bottom<Ch>();
53 }
54
55 size_t GetSize() const { return stack_.GetSize(); }
56
57 static const size_t kDefaultCapacity = 256;
58 mutable internal::Stack<Allocator> stack_;
59};
60
62
64template<>
65inline void PutN(MemoryBuffer& memoryBuffer, char c, size_t n) {
66 std::memset(memoryBuffer.stack_.Push<char>(n), c, n * sizeof(c));
67}
68
70
71#endif // RAPIDJSON_MEMORYBUFFER_H_
A type-unsafe stack for storing different types of data.
Definition stack.h:38
Concept for allocating, resizing and freeing memory block.
#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 output byte stream.