rapidjson::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 stack_capacity)
 
 ~Stack ()
 
void Clear ()
 
template<typename T >
T * Push (size_t count=1)
 
template<typename T >
T * Pop (size_t count)
 
template<typename T >
T * Top ()
 
template<typename T >
T * Bottom ()
 
AllocatorGetAllocator ()
 
size_t GetSize () const
 
size_t GetCapacity () const
 

Private Attributes

Allocatorallocator_
 
Allocatorown_allocator_
 
charstack_
 
charstack_top_
 
charstack_end_
 
size_t stack_capacity_
 

Detailed Description

template<typename Allocator>
class rapidjson::internal::Stack< Allocator >

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

Template Parameters
AllocatorAllocator for allocating stack memory.

Constructor & Destructor Documentation

◆ Stack()

template<typename Allocator >
rapidjson::internal::Stack< Allocator >::Stack ( Allocator allocator,
size_t  stack_capacity 
)
inline
41  : allocator_(allocator), own_allocator_(0), stack_(0), stack_top_(0), stack_end_(0), stack_capacity_(stack_capacity) {
43  if (!allocator_)
45  stack_top_ = stack_ = (char*)allocator_->Malloc(stack_capacity_);
47  }
Concept for allocating, resizing and freeing memory block.
char * stack_
Definition: stack.h:98
Allocator * own_allocator_
Definition: stack.h:97
size_t stack_capacity_
Definition: stack.h:101
char * stack_top_
Definition: stack.h:99
char * stack_end_
Definition: stack.h:100
Allocator * allocator_
Definition: stack.h:96
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:105

References rapidjson::internal::Stack< Allocator >::allocator_, rapidjson::internal::Stack< Allocator >::own_allocator_, RAPIDJSON_ASSERT, rapidjson::internal::Stack< Allocator >::stack_, rapidjson::internal::Stack< Allocator >::stack_capacity_, rapidjson::internal::Stack< Allocator >::stack_end_, and rapidjson::internal::Stack< Allocator >::stack_top_.

◆ ~Stack()

template<typename Allocator >
rapidjson::internal::Stack< Allocator >::~Stack ( )
inline
49  {
50  Allocator::Free(stack_);
51  delete own_allocator_; // Only delete if it is owned by the stack
52  }

References rapidjson::internal::Stack< Allocator >::own_allocator_, and rapidjson::internal::Stack< Allocator >::stack_.

Member Function Documentation

◆ Bottom()

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

◆ Clear()

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

◆ GetAllocator()

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

◆ GetCapacity()

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

◆ GetSize()

◆ Pop()

template<typename Allocator >
template<typename T >
T* rapidjson::internal::Stack< Allocator >::Pop ( size_t  count)
inline
76  {
77  RAPIDJSON_ASSERT(GetSize() >= count * sizeof(T));
78  stack_top_ -= count * sizeof(T);
79  return (T*)stack_top_;
80  }
size_t GetSize() const
Definition: stack.h:92

References rapidjson::internal::Stack< Allocator >::GetSize(), RAPIDJSON_ASSERT, and rapidjson::internal::Stack< Allocator >::stack_top_.

◆ Push()

template<typename Allocator >
template<typename T >
T* rapidjson::internal::Stack< Allocator >::Push ( size_t  count = 1)
inline
57  {
58  // Expand the stack if needed
59  if (stack_top_ + sizeof(T) * count >= stack_end_) {
60  size_t new_capacity = stack_capacity_ * 2;
61  size_t size = GetSize();
62  size_t new_size = GetSize() + sizeof(T) * count;
63  if (new_capacity < new_size)
64  new_capacity = new_size;
65  stack_ = (char*)allocator_->Realloc(stack_, stack_capacity_, new_capacity);
66  stack_capacity_ = new_capacity;
67  stack_top_ = stack_ + size;
69  }
70  T* ret = (T*)stack_top_;
71  stack_top_ += sizeof(T) * count;
72  return ret;
73  }

References rapidjson::internal::Stack< Allocator >::allocator_, rapidjson::internal::Stack< Allocator >::GetSize(), rapidjson::internal::Stack< Allocator >::stack_, rapidjson::internal::Stack< Allocator >::stack_capacity_, rapidjson::internal::Stack< Allocator >::stack_end_, and rapidjson::internal::Stack< Allocator >::stack_top_.

◆ Top()

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

Member Data Documentation

◆ allocator_

◆ own_allocator_

◆ stack_

◆ stack_capacity_

◆ stack_end_

◆ stack_top_


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