NXWidgets: TNxArray< T > Class Template Reference

NXWidgets 1.19

Public Member Functions | Private Member Functions | Private Attributes | List of all members
TNxArray< T > Class Template Reference

`#include <tnxarray.hxx>`

## Public Member Functions
| TNxArray ()
| TNxArray (int initialSize)
| ~TNxArray ()
void | preallocate (void)
const int | size (void) const
void | push_back (const T &value)
void | insert (const int index, const T &value)
void | pop_back (void)
void | erase (const int index)
T & | at (const int index) const
bool | empty (void) const
void | clear ()
T & | operator[] (const int index) const

## Private Member Functions
void | reallocate (const int newSize)
void | resize (void)

## Private Attributes
T * | m_data
int | m_size
int | m_reservedSize

## Detailed Description

### template<class T>
class TNxArray< T >

Class providing a dynamic array; that is, an array that will automatically grow to accommodate new data. It provides a fast way to randomly access a list of data. Essentially, it provides the most important functionality of the STL vector class without any of the overhead of including an STL class.

If the data to be stored will store a lot of data that will predominantly be read sequentially, consider using the LinkedList class instead. Resizing the list is an expensive operation that will occur frequently when filling the array with large amounts of data. Adding new data to the linked list is very inexpensive.

Definition at line 109 of file tnxarray.hxx.

## Constructor & Destructor Documentation

## ◆ TNxArray() [1/2]

template<class T >

TNxArray< T >::TNxArray | ( |  | ) |
| inline

Constructor. Creates an un-allocated array. The array will be allocated when items are added to it or when preallocate() is called.

Definition at line 232 of file tnxarray.hxx.

## ◆ TNxArray() [2/2]

template<class T >

TNxArray< T >::TNxArray | ( | int | initialSize | ) |
| inline

Constructor. Creates an allocated array.

Parameters

  initialSize | The initial size of the array.

Definition at line 243 of file tnxarray.hxx.

## ◆ ~TNxArray()

template<class T >

TNxArray< T >::~TNxArray | ( |  | ) |
| inline

Destructor.

Definition at line 252 of file tnxarray.hxx.

## Member Function Documentation

## ◆ at()

template<class T >

T & TNxArray< T >::at | ( | const int | index | ) | const
| inline

Get a value at the specified location. Does not perform bounds checking.

Parameters

  index | The index of the desired value.

Returns
  The value at the specified index.

Definition at line 404 of file tnxarray.hxx.

## ◆ clear()

template<class T >

void TNxArray< T >::clear | ( |  | ) |

Remove all data.

Definition at line 428 of file tnxarray.hxx.

## ◆ empty()

template<class T >

bool TNxArray< T >::empty | ( | void |  | ) | const
| inline

Check if the array has any data.

Returns
  True if the array is empty.

Definition at line 413 of file tnxarray.hxx.

## ◆ erase()

template<class T >

void TNxArray< T >::erase | ( | const int | index | ) |

Erase a single value at the specified index

Definition at line 326 of file tnxarray.hxx.

## ◆ insert()

template<class T>

void TNxArray< T >::insert | ( | const int | index,
|  | const T & | value
| ) |  |

Insert a value into the array.

Parameters

  index | The index to insert into.
  value | The value to insert.

Definition at line 295 of file tnxarray.hxx.

## ◆ operator[]()

template<class T >

T & TNxArray< T >::operator[] | ( | const int | index | ) | const

Overload the [] operator to allow array-style access.

Parameters

  index | The index to retrieve.

Returns
  The value at the specified index.

Definition at line 419 of file tnxarray.hxx.

## ◆ pop_back()

template<class T >

void TNxArray< T >::pop_back | ( | void |  | ) |

Remove the last element from the array.

Definition at line 283 of file tnxarray.hxx.

## ◆ preallocate()

template<class T>

void TNxArray< T >::preallocate | ( | void |  | ) |

Set the initial size of the array. Normally, the array is unallocated until the first data is pushed into the array. That works great for stacks and lists. But if you want a array of unitialized elements, then this method will preallocate the array for you.

Returns
  The size of the array.

## ◆ push_back()

template<class T>

void TNxArray< T >::push_back | ( | const T & | value | ) |

Add a value to the end of the array.

Parameters

  value | The value to add to the array.

Definition at line 267 of file tnxarray.hxx.

## ◆ reallocate()

template<class T >

void TNxArray< T >::reallocate | ( | const int | newSize | ) |
| private

Re-allocate the array to this size;

Definition at line 348 of file tnxarray.hxx.

## ◆ resize()

template<class T >

void TNxArray< T >::resize | ( | void |  | ) |
| private

Resize the array if it is full.

Definition at line 380 of file tnxarray.hxx.

## ◆ size()

template<class T >

const int TNxArray< T >::size | ( | void |  | ) | const
| inline

Get the size of the array.

Returns
  The size of the array.

Definition at line 261 of file tnxarray.hxx.

## Member Data Documentation

## ◆ m_data

template<class T>

T* TNxArray< T >::m_data
| private

Internal array of data items

Definition at line 112 of file tnxarray.hxx.

## ◆ m_reservedSize

template<class T>

int TNxArray< T >::m_reservedSize
| private

Total size of the array including unpopulated slots

Definition at line 114 of file tnxarray.hxx.

## ◆ m_size

template<class T>

int TNxArray< T >::m_size
| private

Number of items in the array

Definition at line 113 of file tnxarray.hxx.

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

- tnxarray.hxx