/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-composable-kernel/checkouts/develop/include/rapidjson/memorybuffer.h Source File

/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-composable-kernel/checkouts/develop/include/rapidjson/memorybuffer.h Source File#

Composable Kernel: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-composable-kernel/checkouts/develop/include/rapidjson/memorybuffer.h Source File
memorybuffer.h
Go to the documentation of this file.
1 // Tencent is pleased to support the open source community by making RapidJSON available.
2 //
3 // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
4 //
5 // Licensed under the MIT License (the "License"); you may not use this file except
6 // in compliance with the License. You may obtain a copy of the License at
7 //
8 // http://opensource.org/licenses/MIT
9 //
10 // Unless required by applicable law or agreed to in writing, software distributed
11 // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 // specific language governing permissions and limitations under the License.
14 
15 #ifndef RAPIDJSON_MEMORYBUFFER_H_
16 #define RAPIDJSON_MEMORYBUFFER_H_
17 
18 #include "stream.h"
19 #include "internal/stack.h"
20 
22 
24 
37 template <typename Allocator = CrtAllocator>
39 {
40  typedef char Ch; // byte
41 
42  GenericMemoryBuffer(Allocator* allocator = 0, size_t capacity = kDefaultCapacity)
43  : stack_(allocator, capacity)
44  {
45  }
46 
47  void Put(Ch c) { *stack_.template Push<Ch>() = c; }
48  void Flush() {}
49 
50  void Clear() { stack_.Clear(); }
51  void ShrinkToFit() { stack_.ShrinkToFit(); }
52  Ch* Push(size_t count) { return stack_.template Push<Ch>(count); }
53  void Pop(size_t count) { stack_.template Pop<Ch>(count); }
54 
55  const Ch* GetBuffer() const { return stack_.template Bottom<Ch>(); }
56 
57  size_t GetSize() const { return stack_.GetSize(); }
58 
59  static const size_t kDefaultCapacity = 256;
61 };
62 
64 
66 template <>
67 inline void PutN(MemoryBuffer& memoryBuffer, char c, size_t n)
68 {
69  std::memset(memoryBuffer.stack_.Push<char>(n), c, n * sizeof(c));
70 }
71 
73 
74 #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:121
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
Definition: rapidjson.h:124
void PutN(MemoryBuffer &memoryBuffer, char c, size_t n)
Implement specialized version of PutN() with memset() for better performance.
Definition: memorybuffer.h:67
GenericMemoryBuffer MemoryBuffer
Definition: memorybuffer.h:63
Represents an in-memory output byte stream.
Definition: memorybuffer.h:39
void Clear()
Definition: memorybuffer.h:50
char Ch
Definition: memorybuffer.h:40
void ShrinkToFit()
Definition: memorybuffer.h:51
Ch * Push(size_t count)
Definition: memorybuffer.h:52
void Pop(size_t count)
Definition: memorybuffer.h:53
const Ch * GetBuffer() const
Definition: memorybuffer.h:55
internal::Stack< Allocator > stack_
Definition: memorybuffer.h:60
void Flush()
Definition: memorybuffer.h:48
void Put(Ch c)
Definition: memorybuffer.h:47
size_t GetSize() const
Definition: memorybuffer.h:57
GenericMemoryBuffer(Allocator *allocator=0, size_t capacity=kDefaultCapacity)
Definition: memorybuffer.h:42
static const size_t kDefaultCapacity
Definition: memorybuffer.h:59