summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/stack.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/stack.h')
-rw-r--r--src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/stack.h49
1 files changed, 42 insertions, 7 deletions
diff --git a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/stack.h b/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/stack.h
index 344785dcd..5c5398c35 100644
--- a/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/stack.h
+++ b/src/3rdparty/assimp/contrib/rapidjson/include/rapidjson/internal/stack.h
@@ -15,9 +15,14 @@
#ifndef RAPIDJSON_INTERNAL_STACK_H_
#define RAPIDJSON_INTERNAL_STACK_H_
-#include "../rapidjson.h"
+#include "../allocators.h"
#include "swap.h"
+#if defined(__clang__)
+RAPIDJSON_DIAG_PUSH
+RAPIDJSON_DIAG_OFF(c++98-compat)
+#endif
+
RAPIDJSON_NAMESPACE_BEGIN
namespace internal {
@@ -33,7 +38,6 @@ public:
// Optimization note: Do not allocate memory for stack_ in constructor.
// Do it lazily when first Push() -> Expand() -> Resize().
Stack(Allocator* allocator, size_t stackCapacity) : allocator_(allocator), ownAllocator_(0), stack_(0), stackTop_(0), stackEnd_(0), initialCapacity_(stackCapacity) {
- RAPIDJSON_ASSERT(stackCapacity > 0);
}
#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
@@ -108,11 +112,22 @@ public:
// Optimization note: try to minimize the size of this function for force inline.
// Expansion is run very infrequently, so it is moved to another (probably non-inline) function.
template<typename T>
- RAPIDJSON_FORCEINLINE T* Push(size_t count = 1) {
+ RAPIDJSON_FORCEINLINE void Reserve(size_t count = 1) {
// Expand the stack if needed
- if (stackTop_ + sizeof(T) * count >= stackEnd_)
+ if (RAPIDJSON_UNLIKELY(stackTop_ + sizeof(T) * count > stackEnd_))
Expand<T>(count);
+ }
+
+ template<typename T>
+ RAPIDJSON_FORCEINLINE T* Push(size_t count = 1) {
+ Reserve<T>(count);
+ return PushUnsafe<T>(count);
+ }
+ template<typename T>
+ RAPIDJSON_FORCEINLINE T* PushUnsafe(size_t count = 1) {
+ RAPIDJSON_ASSERT(stackTop_);
+ RAPIDJSON_ASSERT(stackTop_ + sizeof(T) * count <= stackEnd_);
T* ret = reinterpret_cast<T*>(stackTop_);
stackTop_ += sizeof(T) * count;
return ret;
@@ -132,7 +147,22 @@ public:
}
template<typename T>
- T* Bottom() { return (T*)stack_; }
+ const T* Top() const {
+ RAPIDJSON_ASSERT(GetSize() >= sizeof(T));
+ return reinterpret_cast<T*>(stackTop_ - sizeof(T));
+ }
+
+ template<typename T>
+ T* End() { return reinterpret_cast<T*>(stackTop_); }
+
+ template<typename T>
+ const T* End() const { return reinterpret_cast<T*>(stackTop_); }
+
+ template<typename T>
+ T* Bottom() { return reinterpret_cast<T*>(stack_); }
+
+ template<typename T>
+ const T* Bottom() const { return reinterpret_cast<T*>(stack_); }
bool HasAllocator() const {
return allocator_ != 0;
@@ -142,6 +172,7 @@ public:
RAPIDJSON_ASSERT(allocator_);
return *allocator_;
}
+
bool Empty() const { return stackTop_ == stack_; }
size_t GetSize() const { return static_cast<size_t>(stackTop_ - stack_); }
size_t GetCapacity() const { return static_cast<size_t>(stackEnd_ - stack_); }
@@ -153,7 +184,7 @@ private:
size_t newCapacity;
if (stack_ == 0) {
if (!allocator_)
- ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator());
+ ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)();
newCapacity = initialCapacity_;
} else {
newCapacity = GetCapacity();
@@ -168,7 +199,7 @@ private:
void Resize(size_t newCapacity) {
const size_t size = GetSize(); // Backup the current size
- stack_ = (char*)allocator_->Realloc(stack_, GetCapacity(), newCapacity);
+ stack_ = static_cast<char*>(allocator_->Realloc(stack_, GetCapacity(), newCapacity));
stackTop_ = stack_ + size;
stackEnd_ = stack_ + newCapacity;
}
@@ -193,4 +224,8 @@ private:
} // namespace internal
RAPIDJSON_NAMESPACE_END
+#if defined(__clang__)
+RAPIDJSON_DIAG_POP
+#endif
+
#endif // RAPIDJSON_STACK_H_