19 #ifndef RAPIDJSON_INTERNAL_STACK_H_ 20 #define RAPIDJSON_INTERNAL_STACK_H_ 23 #include "../allocators.h" 26 #if defined(__clang__) 28 RAPIDJSON_DIAG_OFF(c++ 98 - compat)
40 template <
typename Allocator>
45 Stack(Allocator *allocator,
size_t stackCapacity)
53 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS 62 rhs.ownAllocator_ = 0;
66 rhs.initialCapacity_ = 0;
72 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS 85 rhs.ownAllocator_ = 0;
89 rhs.initialCapacity_ = 0;
120 template <
typename T>
121 RAPIDJSON_FORCEINLINE
void Reserve(
size_t count = 1) {
128 template <
typename T>
129 RAPIDJSON_FORCEINLINE T *
Push(
size_t count = 1) {
131 return PushUnsafe<T>(count);
134 template <
typename T>
139 T *ret =
reinterpret_cast<T *
>(
stackTop_);
144 template <
typename T>
151 template <
typename T>
154 return reinterpret_cast<T *
>(
stackTop_ -
sizeof(T));
157 template <
typename T>
160 return reinterpret_cast<T *
>(
stackTop_ -
sizeof(T));
163 template <
typename T>
168 template <
typename T>
173 template <
typename T>
175 return reinterpret_cast<T *
>(
stack_);
178 template <
typename T>
180 return reinterpret_cast<T *
>(
stack_);
195 template <
typename T>
205 newCapacity += (newCapacity + 1) / 2;
207 size_t newSize =
GetSize() +
sizeof(T) * count;
208 if (newCapacity < newSize) newCapacity = newSize;
215 stack_ =
static_cast<char *
>(
241 #if defined(__clang__) 245 #endif // RAPIDJSON_STACK_H_
Allocator * ownAllocator_
#define RAPIDJSON_ASSERT(x)
Assertion.
RAPIDJSON_FORCEINLINE T * PushUnsafe(size_t count=1)
void Expand(size_t count)
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
void Resize(size_t newCapacity)
A type-unsafe stack for storing different types of data.
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
Stack & operator=(const Stack &)
RAPIDJSON_FORCEINLINE T * Push(size_t count=1)
#define RAPIDJSON_NEW(TypeName)
! customization point for global new
RAPIDJSON_FORCEINLINE void Reserve(size_t count=1)
void Swap(T &a, T &b) RAPIDJSON_NOEXCEPT
Custom swap() to avoid dependency on C++ <algorithm> header.
#define RAPIDJSON_DELETE(x)
! customization point for global delete
Allocator & GetAllocator()
bool HasAllocator() const
size_t GetCapacity() const
Stack(Allocator *allocator, size_t stackCapacity)
#define RAPIDJSON_UNLIKELY(x)
Compiler branching hint for expression with low probability to be true.
void Swap(Stack &rhs) RAPIDJSON_NOEXCEPT