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 >
TPush (size_t count=1)
 
template<typename T >
TPop (size_t count)
 
template<typename T >
TTop ()
 
template<typename T >
TBottom ()
 
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
16  : allocator_(allocator), own_allocator_(0), stack_(0), stack_top_(0), stack_end_(0), stack_capacity_(stack_capacity) {
18  if (!allocator_)
20  stack_top_ = stack_ = (char*)allocator_->Malloc(stack_capacity_);
22  }
Concept for allocating, resizing and freeing memory block.
char * stack_
Definition: stack.h:73
Allocator * own_allocator_
Definition: stack.h:72
size_t stack_capacity_
Definition: stack.h:76
char * stack_top_
Definition: stack.h:74
char * stack_end_
Definition: stack.h:75
Allocator * allocator_
Definition: stack.h:71
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:80

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
24  {
25  Allocator::Free(stack_);
26  delete own_allocator_; // Only delete if it is owned by the stack
27  }

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
51  {
52  RAPIDJSON_ASSERT(GetSize() >= count * sizeof(T));
53  stack_top_ -= count * sizeof(T);
54  return (T*)stack_top_;
55  }
Eigen::Triplet< double > T
Definition: EigenUnitTest.cpp:11
size_t GetSize() const
Definition: stack.h:67

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
32  {
33  // Expand the stack if needed
34  if (stack_top_ + sizeof(T) * count >= stack_end_) {
35  size_t new_capacity = stack_capacity_ * 2;
36  size_t size = GetSize();
37  size_t new_size = GetSize() + sizeof(T) * count;
38  if (new_capacity < new_size)
39  new_capacity = new_size;
40  stack_ = (char*)allocator_->Realloc(stack_, stack_capacity_, new_capacity);
41  stack_capacity_ = new_capacity;
44  }
45  T* ret = (T*)stack_top_;
46  stack_top_ += sizeof(T) * count;
47  return ret;
48  }
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
Eigen::DenseIndex ret
Definition: level1_cplx_impl.h:43

References rapidjson::internal::Stack< Allocator >::allocator_, rapidjson::internal::Stack< Allocator >::GetSize(), ret, size, 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: