memorybuffer.h
Go to the documentation of this file.
1 // Tencent is pleased to support the open source community by making RapidJSON
2 // available.
3 //
4 // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All
5 // rights reserved.
6 //
7 // Licensed under the MIT License (the "License"); you may not use this file
8 // except in compliance with the License. You may obtain a copy of the License
9 // at
10 //
11 // http://opensource.org/licenses/MIT
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16 // License for the specific language governing permissions and limitations under
17 // the License.
18 
19 #ifndef RAPIDJSON_MEMORYBUFFER_H_
20 #define RAPIDJSON_MEMORYBUFFER_H_
21 
22 #include "internal/stack.h"
23 #include "stream.h"
24 
26 
28 
43 template <typename Allocator = CrtAllocator>
44 struct GenericMemoryBuffer {
45  typedef char Ch; // byte
46 
47  GenericMemoryBuffer(Allocator *allocator = 0,
48  size_t capacity = kDefaultCapacity)
49  : stack_(allocator, capacity) {}
50 
51  void Put(Ch c) { *stack_.template Push<Ch>() = c; }
52  void Flush() {}
53 
54  void Clear() { stack_.Clear(); }
55  void ShrinkToFit() { stack_.ShrinkToFit(); }
56  Ch *Push(size_t count) { return stack_.template Push<Ch>(count); }
57  void Pop(size_t count) { stack_.template Pop<Ch>(count); }
58 
59  const Ch *GetBuffer() const { return stack_.template Bottom<Ch>(); }
60 
61  size_t GetSize() const { return stack_.GetSize(); }
62 
63  static const size_t kDefaultCapacity = 256;
65 };
66 
68 
71 template <>
72 inline void PutN(MemoryBuffer &memoryBuffer, char c, size_t n) {
73  std::memset(memoryBuffer.stack_.Push<char>(n), c, n * sizeof(c));
74 }
75 
77 
78 #endif // RAPIDJSON_MEMORYBUFFER_H_
static const size_t kDefaultCapacity
Definition: memorybuffer.h:63
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
Definition: rapidjson.h:131
Represents an in-memory output byte stream.
Definition: fwd.h:87
A type-unsafe stack for storing different types of data.
Definition: stack.h:41
size_t GetSize() const
Definition: memorybuffer.h:61
GenericMemoryBuffer(Allocator *allocator=0, size_t capacity=kDefaultCapacity)
Definition: memorybuffer.h:47
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
Definition: rapidjson.h:128
void Pop(size_t count)
Definition: memorybuffer.h:57
Ch * Push(size_t count)
Definition: memorybuffer.h:56
const Ch * GetBuffer() const
Definition: memorybuffer.h:59
internal::Stack< Allocator > stack_
Definition: memorybuffer.h:64
void PutN(MemoryBuffer &memoryBuffer, char c, size_t n)
Definition: memorybuffer.h:72
GenericMemoryBuffer MemoryBuffer
Definition: memorybuffer.h:67


livox_ros_driver
Author(s): Livox Dev Team
autogenerated on Mon Mar 15 2021 02:40:46