Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
internal::Stack< Allocator > Class Template Reference

A type-unsafe stack for storing different types of data. More...

#include <stack.h>

Public Member Functions

 Stack (Allocator *allocator, size_t stackCapacity)
 
 ~Stack ()
 
void Swap (Stack &rhs) RAPIDJSON_NOEXCEPT
 
void Clear ()
 
void ShrinkToFit ()
 
template<typename T >
RAPIDJSON_FORCEINLINE void Reserve (size_t count=1)
 
template<typename T >
RAPIDJSON_FORCEINLINE TPush (size_t count=1)
 
template<typename T >
RAPIDJSON_FORCEINLINE TPushUnsafe (size_t count=1)
 
template<typename T >
TPop (size_t count)
 
template<typename T >
TTop ()
 
template<typename T >
const TTop () const
 
template<typename T >
TEnd ()
 
template<typename T >
const TEnd () const
 
template<typename T >
TBottom ()
 
template<typename T >
const TBottom () const
 
bool HasAllocator () const
 
AllocatorGetAllocator ()
 
bool Empty () const
 
size_t GetSize () const
 
size_t GetCapacity () const
 

Detailed Description

template<typename Allocator>
class internal::Stack< Allocator >
Template Parameters
AllocatorAllocator for allocating stack memory.

Definition at line 37 of file stack.h.

Constructor & Destructor Documentation

◆ Stack()

template<typename Allocator >
internal::Stack< Allocator >::Stack ( Allocator * allocator,
size_t stackCapacity )
inline

Definition at line 41 of file stack.h.

41 : allocator_(allocator), ownAllocator_(0), stack_(0), stackTop_(0), stackEnd_(0), initialCapacity_(stackCapacity) {
42 }

◆ ~Stack()

template<typename Allocator >
internal::Stack< Allocator >::~Stack ( )
inline

Definition at line 62 of file stack.h.

62 {
63 Destroy();
64 }

Member Function Documentation

◆ Bottom() [1/2]

template<typename Allocator >
template<typename T >
T * internal::Stack< Allocator >::Bottom ( )
inline

Definition at line 163 of file stack.h.

163{ return reinterpret_cast<T*>(stack_); }
#define T(meth, val, expected)

◆ Bottom() [2/2]

template<typename Allocator >
template<typename T >
const T * internal::Stack< Allocator >::Bottom ( ) const
inline

Definition at line 166 of file stack.h.

166{ return reinterpret_cast<T*>(stack_); }

◆ Clear()

template<typename Allocator >
void internal::Stack< Allocator >::Clear ( )
inline

Definition at line 99 of file stack.h.

99{ stackTop_ = stack_; }
Here is the caller graph for this function:

◆ Empty()

template<typename Allocator >
bool internal::Stack< Allocator >::Empty ( ) const
inline

Definition at line 177 of file stack.h.

177{ return stackTop_ == stack_; }
Here is the caller graph for this function:

◆ End() [1/2]

template<typename Allocator >
template<typename T >
T * internal::Stack< Allocator >::End ( )
inline

Definition at line 157 of file stack.h.

157{ return reinterpret_cast<T*>(stackTop_); }

◆ End() [2/2]

template<typename Allocator >
template<typename T >
const T * internal::Stack< Allocator >::End ( ) const
inline

Definition at line 160 of file stack.h.

160{ return reinterpret_cast<T*>(stackTop_); }

◆ GetAllocator()

template<typename Allocator >
Allocator & internal::Stack< Allocator >::GetAllocator ( )
inline

Definition at line 172 of file stack.h.

172 {
173 RAPIDJSON_ASSERT(allocator_);
174 return *allocator_;
175 }
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition rapidjson.h:406
Here is the caller graph for this function:

◆ GetCapacity()

template<typename Allocator >
size_t internal::Stack< Allocator >::GetCapacity ( ) const
inline

Definition at line 179 of file stack.h.

179{ return static_cast<size_t>(stackEnd_ - stack_); }
Here is the caller graph for this function:

◆ GetSize()

template<typename Allocator >
size_t internal::Stack< Allocator >::GetSize ( ) const
inline

Definition at line 178 of file stack.h.

178{ return static_cast<size_t>(stackTop_ - stack_); }
Here is the caller graph for this function:

◆ HasAllocator()

template<typename Allocator >
bool internal::Stack< Allocator >::HasAllocator ( ) const
inline

Definition at line 168 of file stack.h.

168 {
169 return allocator_ != 0;
170 }
Here is the caller graph for this function:

◆ Pop()

template<typename Allocator >
template<typename T >
T * internal::Stack< Allocator >::Pop ( size_t count)
inline

Definition at line 138 of file stack.h.

138 {
139 RAPIDJSON_ASSERT(GetSize() >= count * sizeof(T));
140 stackTop_ -= count * sizeof(T);
141 return reinterpret_cast<T*>(stackTop_);
142 }
size_t GetSize() const
Definition stack.h:178
int * count
Here is the call graph for this function:

◆ Push()

template<typename Allocator >
template<typename T >
RAPIDJSON_FORCEINLINE T * internal::Stack< Allocator >::Push ( size_t count = 1)
inline

Definition at line 123 of file stack.h.

123 {
125 return PushUnsafe<T>(count);
126 }
RAPIDJSON_FORCEINLINE void Reserve(size_t count=1)
Definition stack.h:116
RAPIDJSON_FORCEINLINE T * PushUnsafe(size_t count=1)
Definition stack.h:129
Here is the call graph for this function:

◆ PushUnsafe()

template<typename Allocator >
template<typename T >
RAPIDJSON_FORCEINLINE T * internal::Stack< Allocator >::PushUnsafe ( size_t count = 1)
inline

Definition at line 129 of file stack.h.

129 {
130 RAPIDJSON_ASSERT(stackTop_);
131 RAPIDJSON_ASSERT(static_cast<std::ptrdiff_t>(sizeof(T) * count) <= (stackEnd_ - stackTop_));
132 T* ret = reinterpret_cast<T*>(stackTop_);
133 stackTop_ += sizeof(T) * count;
134 return ret;
135 }
CK_RV ret
Here is the caller graph for this function:

◆ Reserve()

template<typename Allocator >
template<typename T >
RAPIDJSON_FORCEINLINE void internal::Stack< Allocator >::Reserve ( size_t count = 1)
inline

Definition at line 116 of file stack.h.

116 {
117 // Expand the stack if needed
118 if (RAPIDJSON_UNLIKELY(static_cast<std::ptrdiff_t>(sizeof(T) * count) > (stackEnd_ - stackTop_)))
119 Expand<T>(count);
120 }
#define RAPIDJSON_UNLIKELY(x)
Compiler branching hint for expression with low probability to be true.
Definition rapidjson.h:476
Here is the caller graph for this function:

◆ ShrinkToFit()

template<typename Allocator >
void internal::Stack< Allocator >::ShrinkToFit ( )
inline

Definition at line 101 of file stack.h.

101 {
102 if (Empty()) {
103 // If the stack is empty, completely deallocate the memory.
104 Allocator::Free(stack_); // NOLINT (+clang-analyzer-unix.Malloc)
105 stack_ = 0;
106 stackTop_ = 0;
107 stackEnd_ = 0;
108 }
109 else
110 Resize(GetSize());
111 }
bool Empty() const
Definition stack.h:177
Here is the call graph for this function:

◆ Swap()

template<typename Allocator >
void internal::Stack< Allocator >::Swap ( Stack< Allocator > & rhs)
inline

Definition at line 90 of file stack.h.

90 {
91 internal::Swap(allocator_, rhs.allocator_);
92 internal::Swap(ownAllocator_, rhs.ownAllocator_);
93 internal::Swap(stack_, rhs.stack_);
94 internal::Swap(stackTop_, rhs.stackTop_);
95 internal::Swap(stackEnd_, rhs.stackEnd_);
96 internal::Swap(initialCapacity_, rhs.initialCapacity_);
97 }
void Swap(T &a, T &b) RAPIDJSON_NOEXCEPT
Custom swap() to avoid dependency on C++ <algorithm> header.
Definition swap.h:33
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Top() [1/2]

template<typename Allocator >
template<typename T >
T * internal::Stack< Allocator >::Top ( )
inline

Definition at line 145 of file stack.h.

145 {
146 RAPIDJSON_ASSERT(GetSize() >= sizeof(T));
147 return reinterpret_cast<T*>(stackTop_ - sizeof(T));
148 }
Here is the call graph for this function:

◆ Top() [2/2]

template<typename Allocator >
template<typename T >
const T * internal::Stack< Allocator >::Top ( ) const
inline

Definition at line 151 of file stack.h.

151 {
152 RAPIDJSON_ASSERT(GetSize() >= sizeof(T));
153 return reinterpret_cast<T*>(stackTop_ - sizeof(T));
154 }
Here is the call graph for this function:

The documentation for this class was generated from the following file: