Itasca C++ Interface
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
FArray< T, S > Class Template Reference

An array class that attempts to minimize unnecessary heap access. More...

#include <farray.h>

Public Types

using size_type = uint64
 Typedef to assist in STL compatibility.
 
using value_type = T
 Typedef to assist in STL compatibility.
 
using iterator = T *
 Typedef to assist in STL compatibility.
 
using const_iterator = const T *
 Typedef to assist in STL compatibility.
 

Public Member Functions

 FArray ()
 Default constructor - the array size is zero.
 
 FArray (size_type s, const T &t=T())
 
template<uint64 S2>
 FArray (const FArray< T, S2 > &f)
 Copy constructor, valid for FArrays of the same data type but different stack lengths.
 
 FArray (const FArray< T, S > &f)
 Specialized copy constructor, for the special case of when the stack lengths are the same.
 
 FArray (std::initializer_list< T > l)
 
 ~FArray ()
 Destructor.
 
const FArray< T, S > & operator= (const FArray< T, S > &f)
 
template<uint64 S2>
const FArray< T, S > & operator= (const FArray< T, S2 > &f)
 Assignment operator, valid for FArrays of the same data type but different stack lengths.
 
template<uint64 S2>
bool operator== (const FArray< T, S2 > &f) const
 
size_type size () const
 
size_type stackSize () const
 Returns the size of the array pre-allocated on the stack.
 
size_type allocated () const
 
bool empty () const
 
T * data ()
 
const T * data () const
 
T & front ()
 
const T & front () const
 
T & back ()
 
const T & back () const
 
size_type find (const T &t) const
 
size_type capacity () const
 
void push_back (const T &t)
 Adds a new element to the end of the array, increasing the array size by one.
 
T * emplace_back ()
 
T * emplace_n_back (uint64 n)
 
void pop_back ()
 Removes the last element in the array. The results are undefined if the array is of zero length.
 
void resize (size_type i, const T &t=T())
 
iterator insert (size_type i, const T &t)
 
void put (size_type i, const T &t)
 Adds a value to the array, first making certain it is big enough to hold it.
 
template<class C >
void append (const C &in)
 Appends the contents of one FArray onto another.
 
iterator insert (iterator it, const T &t)
 
bool remove (size_type i)
 
size_type removeAll (const T &t)
 
void clear ()
 
void reset ()
 
void reserve (size_type s)
 
void clip ()
 
iterator begin ()
 
const_iterator begin () const
 
const_iterator constBegin () const
 
iterator end ()
 
const_iterator end () const
 
const_iterator constEnd () const
 
T & at (size_type i)
 
const T & at (size_type i) const
 
T & operator[] (size_type i)
 
const T & operator[] (size_type i) const
 
value (int i, const T &t=T()) const
 
value (uint32 i, const T &t=T()) const
 
value (uint64 i, const T &t=T()) const
 

Detailed Description

template<typename T, uint64 S = 32>
class FArray< T, S >

An array class that attempts to minimize unnecessary heap access.

T is the data type.
S is the stack length.
This class attempts to provide a speed-optimized array for use in plot generation.
It does this in two ways.
First, it attempts to minimize heap churn by not deallocating memory.
Second, it has a second template argument that indicates how much memory to create ON THE STACK. Only if the array size needs to exceed S, does it actually use memory from the heap.

Member Function Documentation

◆ allocated()

template<typename T , uint64 S = 32>
size_type FArray< T, S >::allocated ( ) const
inline
Returns
the size allocated internally – this will be S (the stack length) unless the array has been made large enough to force heap access.

◆ at() [1/2]

template<typename T , uint64 S = 32>
T & FArray< T, S >::at ( size_type i)
inline
Returns
A reference to the element at the ith location in the array. Undefined if the array length is less than or equal to i. No bounds checking is performed, even in a debug compile.

◆ at() [2/2]

template<typename T , uint64 S = 32>
const T & FArray< T, S >::at ( size_type i) const
inline
Returns
A const reference to the element at the ith location in the array. Undefined if the array length is less than or equal to i. No bounds checking is performed, even in a debug compile.

◆ back() [1/2]

template<typename T , uint64 S = 32>
T & FArray< T, S >::back ( )
inline
Returns
a reference to the last element in the array. This is undefined if the array is of zero length.

◆ back() [2/2]

template<typename T , uint64 S = 32>
const T & FArray< T, S >::back ( ) const
inline
Returns
a const reference to the last element in the array. This is undefined if the array is of zero length.

◆ begin() [1/2]

template<typename T , uint64 S = 32>
iterator FArray< T, S >::begin ( )
inline
Returns
An iterator representing the first element in the array. Implemented as a pointer. STL compatible as a random-access iterator.

◆ begin() [2/2]

template<typename T , uint64 S = 32>
const_iterator FArray< T, S >::begin ( ) const
inline
Returns
An iterator representing the first element in the array. Implemented as a pointer. STL compatible as a random-access iterator.

◆ clip()

template<typename T , uint64 S = 32>
void FArray< T, S >::clip ( )
inline

Reduces the allocated length to the actual length of the array, or the stack length, whichever is greater. This and reset() are the only means of reducing the allocated length of an existing FArray.

◆ constBegin()

template<typename T , uint64 S = 32>
const_iterator FArray< T, S >::constBegin ( ) const
inline
Returns
An iterator representing the first element in the array. Implemented as a pointer. STL compatible as a random-access iterator.

◆ constEnd()

template<typename T , uint64 S = 32>
const_iterator FArray< T, S >::constEnd ( ) const
inline
Returns
An iterator representing one past the last element in the array. Implemented as a pointer. STL compatible as a random-access iterator.

◆ data() [1/2]

template<typename T , uint64 S = 32>
T * FArray< T, S >::data ( )
inline
Returns
a pointer to the beginning of the array data. An FARRAY guarantees that it's internal data is contiguous.

◆ data() [2/2]

template<typename T , uint64 S = 32>
const T * FArray< T, S >::data ( ) const
inline
Returns
a const pointer to the beginning of the array data. An FARRAY guarantees that it's internal data is contiguous.

◆ emplace_back()

template<typename T , uint64 S = 32>
T * FArray< T, S >::emplace_back ( )
inline

To avoid creating a temporary object, can call this to get memory location of new lcoation at end of stack and then use it to do an in-place new. new(fa.emplace_back()) Fred(arg1,arg2);

◆ empty()

template<typename T , uint64 S = 32>
bool FArray< T, S >::empty ( ) const
inline
Returns
true if the array is of zero length.

◆ end() [1/2]

template<typename T , uint64 S = 32>
iterator FArray< T, S >::end ( )
inline
Returns
An iterator representing one past the last element in the array. Implemented as a pointer. STL compatible as a random-access iterator.

◆ end() [2/2]

template<typename T , uint64 S = 32>
const_iterator FArray< T, S >::end ( ) const
inline
Returns
An iterator representing one past the last element in the array. Implemented as a pointer. STL compatible as a random-access iterator.

◆ front() [1/2]

template<typename T , uint64 S = 32>
T & FArray< T, S >::front ( )
inline
Returns
a reference to the first element in the array. This is undefined if the array is of zero length.

◆ front() [2/2]

template<typename T , uint64 S = 32>
const T & FArray< T, S >::front ( ) const
inline
Returns
a const reference to the first element in the array. This is undefined if the array is of zero length.

◆ operator[]() [1/2]

template<typename T , uint64 S = 32>
T & FArray< T, S >::operator[] ( size_type i)
inline
Returns
A reference to the element at the ith location in the array. Undefined if the array length is less than or equal to i. No bounds checking is performed, even in a debug compile.

◆ operator[]() [2/2]

template<typename T , uint64 S = 32>
const T & FArray< T, S >::operator[] ( size_type i) const
inline
Returns
A const reference to the element at the ith location in the array. Undefined if the array length is less than or equal to i. No bounds checking is performed, even in a debug compile.

◆ size()

template<typename T , uint64 S = 32>
size_type FArray< T, S >::size ( ) const
inline
Returns
the current size of the array - NOT the stack length OR the size allocated internally.

◆ value() [1/3]

template<typename T , uint64 S = 32>
T FArray< T, S >::value ( int i,
const T & t = T() ) const
inline
Returns
A copy of the value at the ith location in the array, or t if i is an invalid index. This version uses a signed integer type (32 bit) as an index.

◆ value() [2/3]

template<typename T , uint64 S = 32>
T FArray< T, S >::value ( uint32 i,
const T & t = T() ) const
inline
Returns
A copy of the value at the ith location in the array, or t if i is an invalid index. This version uses an unsigned 32 bit integer type as an index.

◆ value() [3/3]

template<typename T , uint64 S = 32>
T FArray< T, S >::value ( uint64 i,
const T & t = T() ) const
inline
Returns
A copy of the value at the ith location in the array, or t if i is an invalid index. This version uses an unsigned 64 bit integer type as an index.

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