15 #ifndef CEREAL_RAPIDJSON_INTERNAL_STACK_H_
16 #define CEREAL_RAPIDJSON_INTERNAL_STACK_H_
18 #include "../allocators.h"
22 #if defined(__clang__)
23 CEREAL_RAPIDJSON_DIAG_PUSH
24 CEREAL_RAPIDJSON_DIAG_OFF(c++98-compat)
36 template <
typename Allocator>
44 #if CEREAL_RAPIDJSON_HAS_CXX11_RVALUE_REFS
54 rhs.ownAllocator_ = 0;
58 rhs.initialCapacity_ = 0;
66 #if CEREAL_RAPIDJSON_HAS_CXX11_RVALUE_REFS
80 rhs.ownAllocator_ = 0;
84 rhs.initialCapacity_ = 0;
116 CEREAL_RAPIDJSON_FORCEINLINE
void Reserve(
size_t count = 1) {
123 CEREAL_RAPIDJSON_FORCEINLINE T*
Push(
size_t count = 1) {
125 return PushUnsafe<T>(count);
129 CEREAL_RAPIDJSON_FORCEINLINE T*
PushUnsafe(
size_t count = 1) {
132 T* ret =
reinterpret_cast<T*
>(
stackTop_);
147 return reinterpret_cast<T*
>(
stackTop_ -
sizeof(T));
153 return reinterpret_cast<T*
>(
stackTop_ -
sizeof(T));
192 newCapacity += (newCapacity + 1) / 2;
194 size_t newSize =
GetSize() +
sizeof(T) * count;
195 if (newCapacity < newSize)
196 newCapacity = newSize;
228 #if defined(__clang__)
229 CEREAL_RAPIDJSON_DIAG_POP
#define CEREAL_RAPIDJSON_ASSERT(x)
Definition: json.hpp:50
A type-unsafe stack for storing different types of data.
Definition: stack.h:37
Allocator * allocator_
Definition: stack.h:217
void Clear()
Definition: stack.h:99
void Resize(size_t newCapacity)
Definition: stack.h:201
T * Bottom()
Definition: stack.h:163
size_t initialCapacity_
Definition: stack.h:222
bool Empty() const
Definition: stack.h:177
void ShrinkToFit()
Definition: stack.h:101
CEREAL_RAPIDJSON_FORCEINLINE void Reserve(size_t count=1)
Definition: stack.h:116
CEREAL_RAPIDJSON_FORCEINLINE T * PushUnsafe(size_t count=1)
Definition: stack.h:129
T * End()
Definition: stack.h:157
void Expand(size_t count)
Definition: stack.h:183
void Destroy()
Definition: stack.h:208
const T * End() const
Definition: stack.h:160
bool HasAllocator() const
Definition: stack.h:168
size_t GetCapacity() const
Definition: stack.h:179
Allocator * ownAllocator_
Definition: stack.h:218
T * Pop(size_t count)
Definition: stack.h:138
char * stackTop_
Definition: stack.h:220
Allocator & GetAllocator()
Definition: stack.h:172
T * Top()
Definition: stack.h:145
const T * Top() const
Definition: stack.h:151
size_t GetSize() const
Definition: stack.h:178
void Swap(Stack &rhs) CEREAL_RAPIDJSON_NOEXCEPT
Definition: stack.h:90
CEREAL_RAPIDJSON_FORCEINLINE T * Push(size_t count=1)
Definition: stack.h:123
Stack & operator=(const Stack &)
char * stack_
Definition: stack.h:219
Stack(Allocator *allocator, size_t stackCapacity)
Definition: stack.h:41
char * stackEnd_
Definition: stack.h:221
const T * Bottom() const
Definition: stack.h:166
~Stack()
Definition: stack.h:62
Concept for allocating, resizing and freeing memory block.
#define CEREAL_RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
Definition: rapidjson.h:121
#define CEREAL_RAPIDJSON_UNLIKELY(x)
Compiler branching hint for expression with low probability to be true.
Definition: rapidjson.h:476
#define CEREAL_RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
Definition: rapidjson.h:124
Definition: document.h:416
void Swap(T &a, T &b) CEREAL_RAPIDJSON_NOEXCEPT
Custom swap() to avoid dependency on C++ <algorithm> header.
Definition: swap.h:33
#define CEREAL_RAPIDJSON_DELETE(x)
! customization point for global delete
Definition: rapidjson.h:631
#define CEREAL_RAPIDJSON_NEW(TypeName)
! customization point for global new
Definition: rapidjson.h:627