TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
rcIntArray Class Reference

A simple dynamic array of integers. More...

#include <RecastAlloc.h>

Public Member Functions

 rcIntArray ()
 Constructs an instance with an initial array size of zero. More...
 
 rcIntArray (int n)
 
 ~rcIntArray ()
 
void resize (int n)
 
void push (int item)
 
int pop ()
 
const int & operator[] (int i) const
 
int & operator[] (int i)
 
int size () const
 The current size of the integer array. More...
 

Private Member Functions

 rcIntArray (const rcIntArray &)
 
rcIntArrayoperator= (const rcIntArray &)
 

Private Attributes

int * m_data
 
int m_size
 
int m_cap
 

Detailed Description

A simple dynamic array of integers.

While it is possible to pre-allocate a specific array size during construction or by using the resize method, certain methods will automatically resize the array as needed.

Warning
The array memory is not initialized to zero when the size is manually set during construction or when using resize.

Constructor & Destructor Documentation

rcIntArray::rcIntArray ( const rcIntArray )
inlineprivate
rcIntArray::rcIntArray ( )
inline

Constructs an instance with an initial array size of zero.

70 : m_data(0), m_size(0), m_cap(0) {}
int m_size
Definition: RecastAlloc.h:64
int * m_data
Definition: RecastAlloc.h:63
int m_cap
Definition: RecastAlloc.h:64
rcIntArray::rcIntArray ( int  n)
inline

Constructs an instance initialized to the specified size.

Parameters
[in]nThe initial size of the integer array.
74 : m_data(0), m_size(0), m_cap(0) { resize(n); }
int m_size
Definition: RecastAlloc.h:64
int * m_data
Definition: RecastAlloc.h:63
int m_cap
Definition: RecastAlloc.h:64
void resize(int n)
Definition: RecastAlloc.cpp:75

+ Here is the call graph for this function:

rcIntArray::~rcIntArray ( )
inline
75 { rcFree(m_data); }
int * m_data
Definition: RecastAlloc.h:63
void rcFree(void *ptr)
Definition: RecastAlloc.cpp:55

+ Here is the call graph for this function:

Member Function Documentation

rcIntArray& rcIntArray::operator= ( const rcIntArray )
inlineprivate
const int& rcIntArray::operator[] ( int  i) const
inline

The value at the specified array index.

Warning
Does not provide overflow protection.
Parameters
[in]iThe index of the value.
92 { return m_data[i]; }
int * m_data
Definition: RecastAlloc.h:63
int& rcIntArray::operator[] ( int  i)
inline

The value at the specified array index.

Warning
Does not provide overflow protection.
Parameters
[in]iThe index of the value.
97 { return m_data[i]; }
int * m_data
Definition: RecastAlloc.h:63
int rcIntArray::pop ( )
inline

Returns the value at the end of the array and reduces the size by one.

Returns
The value at the end of the array.
87 { if (m_size > 0) m_size--; return m_data[m_size]; }
int m_size
Definition: RecastAlloc.h:64
int * m_data
Definition: RecastAlloc.h:63

+ Here is the caller graph for this function:

void rcIntArray::push ( int  item)
inline

Push the specified integer onto the end of the array and increases the size by one.

Parameters
[in]itemThe new value.
83 { resize(m_size+1); m_data[m_size-1] = item; }
int m_size
Definition: RecastAlloc.h:64
int * m_data
Definition: RecastAlloc.h:63
void resize(int n)
Definition: RecastAlloc.cpp:75

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void rcIntArray::resize ( int  n)

Specifies the new size of the integer array.

Parameters
[in]nThe new size of the integer array.

Using this method ensures the array is at least large enough to hold the specified number of elements. This can improve performance by avoiding auto-resizing during use.

76 {
77  if (n > m_cap)
78  {
79  if (!m_cap) m_cap = n;
80  while (m_cap < n) m_cap *= 2;
81  int* newData = (int*)rcAlloc(m_cap*sizeof(int), RC_ALLOC_TEMP);
82  if (m_size && newData) memcpy(newData, m_data, m_size*sizeof(int));
83  rcFree(m_data);
84  m_data = newData;
85  }
86  m_size = n;
87 }
int m_size
Definition: RecastAlloc.h:64
void rcFree(void *ptr)
Definition: RecastAlloc.cpp:55
int * m_data
Definition: RecastAlloc.h:63
int m_cap
Definition: RecastAlloc.h:64
void * rcAlloc(int size, rcAllocHint hint)
Definition: RecastAlloc.cpp:44
Memory used temporarily within a function.
Definition: RecastAlloc.h:27

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int rcIntArray::size ( ) const
inline

The current size of the integer array.

100 { return m_size; }
int m_size
Definition: RecastAlloc.h:64

+ Here is the caller graph for this function:

Member Data Documentation

int rcIntArray::m_cap
private
int* rcIntArray::m_data
private
int rcIntArray::m_size
private

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