Workspace 6.21.5
Classes | Public Member Functions | Static Public Attributes | List of all members
VariableLengthArray< T, StackPrealloc > Class Template Reference

An array class similar to std::vector or QVector. More...

#include <Workspace/Application/LanguageUtils/variablelengtharray.h>

Inheritance diagram for VariableLengthArray< T, StackPrealloc >:
[legend]

Classes

class  const_iterator
 
class  iterator
 

Public Member Functions

 VariableLengthArray ()=default
 
 VariableLengthArray (const VariableLengthArray< T, StackPrealloc > &other)
 
 VariableLengthArray (int size)
 
void append (const T &item)
 
void append (const T *buf, int size)
 
void append (const VariableLengthArray< T, StackPrealloc > &other)
 
T & back ()
 
const T & back () const
 
iterator begin ()
 
const_iterator begin () const
 
int capacity () const
 
void clear ()
 
const T * constData () const
 
bool contains (const T &element) const
 
int count () const
 
T * data ()
 
const T * data () const
 
bool empty () const
 
iterator end ()
 
const_iterator end () const
 
T & first ()
 
const T & first () const
 
T & front ()
 
const T & front () const
 
bool isEmpty () const
 
T & last ()
 
const T & last () const
 
VariableLengthArrayoperator= (const VariableLengthArray< T, StackPrealloc > &other)
 
bool operator== (const VariableLengthArray< T, StackPrealloc > &other) const
 
T & operator[] (int idx)
 
const T & operator[] (int idx) const
 
void pop_back ()
 
void push_back (const T &item)
 
void reserve (int size)
 
void resize (int size)
 
int size () const
 

Static Public Attributes

static const int STACK_PREALLOC = StackPrealloc
 

Detailed Description

template<typename T, int StackPrealloc>
class CSIRO::Application::VariableLengthArray< T, StackPrealloc >

The reasons for this are:

-STL containers (vector, list etc) cannot be safely exported from modules - issues will arise if the clients STL library is not exactly the same. Under Windows it is possible but will give compiler warnings (http://support.microsoft.com/kb/168958). The general consensus is that this should be avoided.

-QVector and QList are terrible in terms of re-allocations under situations when you want to empty the list and reuse it. Unlike std::vector these Qt classes deallocate memory when cleared. This class is based on QVarLengthArray which also has the advantage of using stack memory (rather than heap memory) as long as the size stays smaller than the provided template parameter.

-QVarLengthArray is missing a number of features so this class is a simple wrapper around it that add a few helpful methods.

Do not use Qt foreach() with this class as it does not use implicit sharing and foreach()

Constructor & Destructor Documentation

◆ VariableLengthArray() [1/3]

VariableLengthArray ( )
default

◆ VariableLengthArray() [2/3]

VariableLengthArray ( const VariableLengthArray< T, StackPrealloc > &  other)
inline

◆ VariableLengthArray() [3/3]

VariableLengthArray ( int  size)
inlineexplicit

Member Function Documentation

◆ append() [1/3]

void append ( const T &  item)
inline

◆ append() [2/3]

void append ( const T *  buf,
int  size 
)
inline

◆ append() [3/3]

void append ( const VariableLengthArray< T, StackPrealloc > &  other)
inline

◆ back() [1/2]

T & back ( )
inline

◆ back() [2/2]

const T & back ( ) const
inline

◆ begin() [1/2]

iterator begin ( )
inline

◆ begin() [2/2]

const_iterator begin ( ) const
inline

◆ capacity()

int capacity ( ) const
inline

◆ clear()

void clear ( )
inline

◆ constData()

const T * constData ( ) const
inline

◆ contains()

bool contains ( const T &  element) const
inline

◆ count()

int count ( ) const
inline

◆ data() [1/2]

T * data ( )
inline

◆ data() [2/2]

const T * data ( ) const
inline

◆ empty()

bool empty ( ) const
inline

◆ end() [1/2]

iterator end ( )
inline

◆ end() [2/2]

const_iterator end ( ) const
inline

◆ first() [1/2]

T & first ( )
inline

◆ first() [2/2]

const T & first ( ) const
inline

◆ front() [1/2]

T & front ( )
inline

◆ front() [2/2]

const T & front ( ) const
inline

◆ isEmpty()

bool isEmpty ( ) const
inline

◆ last() [1/2]

T & last ( )
inline

◆ last() [2/2]

const T & last ( ) const
inline

◆ operator=()

VariableLengthArray & operator= ( const VariableLengthArray< T, StackPrealloc > &  other)
inline

◆ operator==()

bool operator== ( const VariableLengthArray< T, StackPrealloc > &  other) const
inline

◆ operator[]() [1/2]

T & operator[] ( int  idx)
inline

◆ operator[]() [2/2]

const T & operator[] ( int  idx) const
inline

◆ pop_back()

void pop_back ( )
inline

◆ push_back()

void push_back ( const T &  item)
inline

◆ reserve()

void reserve ( int  size)
inline

◆ resize()

void resize ( int  size)
inline

◆ size()

int size ( ) const
inline

Member Data Documentation

◆ STACK_PREALLOC

const int STACK_PREALLOC = StackPrealloc
static