GL Studio C++ Runtime API
DynamicArray< T, Obsolete > Class Template Reference

#include <dynamic_array.h>

Public Types

typedef T ElementType
 Typedef for the type of object contained in this array.
 

Public Member Functions

 DynamicArray (unsigned initialCapacity=0)
 
 DynamicArray (std::initializer_list< T > list)
 
 DynamicArray (const DynamicArray< T, true > &other)
 
 DynamicArray (const DynamicArray< T, false > &other)
 
DynamicArrayoperator= (const DynamicArray< T, true > &other)
 
DynamicArrayoperator= (const DynamicArray< T, false > &other)
 
 DynamicArray (DynamicArray< T, true > &&other)
 
 DynamicArray (DynamicArray< T, false > &&other)
 
DynamicArrayoperator= (DynamicArray< T, true > &&other)
 
DynamicArrayoperator= (DynamicArray< T, false > &&other)
 
 ~DynamicArray ()
 DynamicArray destructor. Clears the array but does not delete the objects being pointed to by the array.
 
unsigned Count () const
 
void Count (const unsigned newCount)
 
void Clear ()
 
unsigned Capacity () const
 
void Capacity (const unsigned newCapacity)
 
void StripCapacity ()
 
unsigned Insert (const T &object, unsigned loc)
 
unsigned PushBack (const T &object)
 
void PopBack ()
 Removes the last item in the array. If the array is empty, it has no effect.
 
T & Back ()
 
const T & Back () const
 
void PushFront (const T &object)
 
unsigned Insert (T &&object, unsigned loc)
 
unsigned PushBack (T &&object)
 
void PushFront (T &&object)
 
bool Erase (const T &object)
 
bool EraseAt (const unsigned index)
 
T & operator[] (const unsigned index)
 
const T & operator[] (const unsigned index) const
 
T * InternalArray ()
 
const T * InternalArray () const
 
bool IsEmpty () const
 
unsigned Size () const
 
void Size (unsigned newCapacity)
 
unsigned InsertObject (const T &object, unsigned loc)
 
unsigned InsertObject (const T &object)
 
unsigned InsertObjectAfter (const T &object, unsigned loc)
 
void PushObject (const T &object)
 
void InsertObject (T &&object, unsigned loc)
 
unsigned InsertObject (T &&object)
 
void InsertObjectAfter (T &&object, unsigned loc)
 
void PushObject (T &&object)
 
bool DeleteObject (const T &object)
 
bool DeleteObjectAtIndex (const unsigned index)
 
void EmptyList ()
 
void ClearList ()
 
int Position (const T &object) const
 

Detailed Description

template<class T, bool Obsolete = true>
class disti::DynamicArray< T, Obsolete >

A templated array of objects. The array dynamically resizes as needed.

Template Parameters
TThe type of the objects contained.
ObsoleteObsolete parameter retained for backwards compatibility. Please ignore.

Constructor & Destructor Documentation

◆ DynamicArray() [1/6]

DynamicArray ( unsigned  initialCapacity = 0)
inlineexplicit

DynamicArray constructor

Parameters
initialCapacityThe initial number of elements to be allocated for the array

◆ DynamicArray() [2/6]

DynamicArray ( std::initializer_list< T >  list)
inline

Construct from a list of items, e.g.:

const auto a = DynamicArray<int>{ 1, 2, 3, 4 };
Parameters
listThe list of items to construct from.

◆ DynamicArray() [3/6]

DynamicArray ( const DynamicArray< T, true > &  other)
inline

Initialize this array by deep-copying other

Parameters
otherThe array to copy from.

◆ DynamicArray() [4/6]

DynamicArray ( const DynamicArray< T, false > &  other)
inline

Initialize this array by deep-copying other

Parameters
otherThe array to copy from.

◆ DynamicArray() [5/6]

DynamicArray ( DynamicArray< T, true > &&  other)
inline

Construct this array by taking ownership of other's contents.

Parameters
otherThe array to move from.

◆ DynamicArray() [6/6]

DynamicArray ( DynamicArray< T, false > &&  other)
inline

Construct this array by taking ownership of other's contents.

Parameters
otherThe array to move from.

Member Function Documentation

◆ Back() [1/2]

T & Back ( )
inline
Returns
The last element in the array.
Exceptions
DistiExceptionif array is empty.

◆ Back() [2/2]

const T & Back ( ) const
inline
Returns
The last element in the array.
Exceptions
DistiExceptionif array is empty.

◆ Capacity() [1/2]

unsigned Capacity ( ) const
inline
Returns
The capacity of this dynamic array.
Note
Similar to std::vector::capacity()

◆ Capacity() [2/2]

void Capacity ( const unsigned  newCapacity)
inline

Reserves space for newCapacity elements in the array, reallocating as needed.

Parameters
newCapacityThe new number of elements reserved in the array.
Note
Similar to std::vector::reserve(), but does lower capacity when asked.

◆ Clear()

void Clear ( )
inline

Clears the list so Count() is zero, destroying all items. Does not strip capacity. Shorthand for Count( 0 ).

Note
Similar to std::vector::clear().
See also
StripCapacity()

◆ ClearList()

void ClearList ( )
inline

Clears the list so Count() is zero. Does not strip capacity. Shorthand for Count( 0 ).

Deprecated:
Renamed to Clear() for consistency.

◆ Count() [1/2]

unsigned Count ( ) const
inline

Returns the number of elements used of this dynamic array

Returns
The number of elements used of the array (number of elements)
Note
Similar to std::vector::size()

◆ Count() [2/2]

void Count ( const unsigned  newCount)
inline

Set the "Count" value for this array, destroying items or creating default-constructed items as needed.

Note
Similar to std::vector::resize()
Parameters
newCountThe new count to allocate.

◆ DeleteObject()

bool DeleteObject ( const T &  object)
inline

Removes the object, shrinking the array count. (Does not delete it, if pointer.)

Parameters
objectA pointer to the object to delete
Returns
true if object was found and deleted else false
Note
Similar to std::vector::erase()
Deprecated:
Renamed EraseAt() for clarity.

◆ DeleteObjectAtIndex()

bool DeleteObjectAtIndex ( const unsigned  index)
inline

Removes the object at the specified index. (Does not delete it, if pointer.)

Parameters
indexIndex of the object to delete
Returns
true if object was found and removed else false
Note
Similar to std::vector::erase()
Deprecated:
Renamed EraseAt() for clarity.

◆ EmptyList()

void EmptyList ( )
inline

Calls delete on each element and then clears the list.

Deprecated:
Use the non-member function DeleteEachAndClear( dynamicArray ) instead.

◆ Erase()

bool Erase ( const T &  object)
inline

Deletes the specified object from the list. Does not delete it, if a pointer.

Parameters
objectA pointer to the object to delete
Returns
true if object was found and deleted else false

◆ EraseAt()

bool EraseAt ( const unsigned  index)
inline

Removes the object at the specified index. (Does not delete it, if pointer.)

Parameters
indexIndex of the object to delete
Returns
true if object was found and deleted else false

◆ Insert() [1/2]

unsigned Insert ( const T &  object,
unsigned  loc 
)
inline

Attempts to insert the object into the list at the specified location. If the specified location is beyond the array bounds, the object is inserted at the next position in the array.

Parameters
objectThe object to insert
locThe index location to insert into
Returns
The actual location inserted, which may be different than loc if it exceeded the count but not the capacity.
Note
Similar to std::vector::insert( object, begin(*this) + loc );

◆ Insert() [2/2]

unsigned Insert ( T &&  object,
unsigned  loc 
)
inline

Attempts to insert the object into the list at the specified location. If the specified location is beyond the array bounds, the object is inserted at the next position in the array.

Parameters
objectThe object to insert
locThe index location to insert into
Returns
The actual location inserted, which may be different than loc if it exceeded the count but not the capacity.

◆ InsertObject() [1/4]

unsigned InsertObject ( const T &  object)
inline

Adds the specified object into the list, at the end of the list

Parameters
objectThe object to insert.
Returns
Where the object was inserted.
Note
similar to std::vector::push_back()
Deprecated:
Use PushBack( object ) instead.

◆ InsertObject() [2/4]

unsigned InsertObject ( const T &  object,
unsigned  loc 
)
inline

Attempts to insert the object into the list at the specified location. If the specified location is beyond the array bounds, the object is inserted at the next position in the array.

Parameters
objectThe object to insert
locThe index location to insert into
Returns
The actual location inserted, which may be different than loc if it exceeded the count but not the capacity.
Note
Similar to std::vector::insert()
Deprecated:
Use Insert( object, loc ) instead.

◆ InsertObject() [3/4]

unsigned InsertObject ( T &&  object)
inline

Adds the specified object into the list, at the end of the list

Parameters
objectThe object to insert.
Returns
Where the object was inserted.
Note
Similar to std::vector::push_back()
Deprecated:
Use PushBack( object ) instead.

◆ InsertObject() [4/4]

void InsertObject ( T &&  object,
unsigned  loc 
)
inline

Attempts to insert the object into the list at the specified location. If the specified location is beyond the array bounds, the object is inserted at the next position in the array.

Parameters
objectThe object to insert
locThe index location to insert into
Note
Similar to std::vector::insert()
Deprecated:
Use Insert( object, loc ) instead.

◆ InsertObjectAfter() [1/2]

unsigned InsertObjectAfter ( const T &  object,
unsigned  loc 
)
inline

Insert the object into the list at the specified location

Parameters
objectThe object to insert
locThe index location to insert into
Returns
The actual location inserted, which may be different than loc if it exceeded the count but not the capacity.
Note
similar to std::vector::insert()
Deprecated:
Use Insert( object, loc + 1 ) instead.

◆ InsertObjectAfter() [2/2]

void InsertObjectAfter ( T &&  object,
unsigned  loc 
)
inline

Insert the object into the list at the specified location

Parameters
objectThe object to insert
locThe index location to insert into
Note
Similar to std::vector::insert()
Deprecated:
Use Insert( object, loc + 1 ) instead.

◆ InternalArray() [1/2]

T * InternalArray ( )
inline
Returns
The internal array pointer.
Note
If you call any non-const methods on this object it may invalidate the pointer.

◆ InternalArray() [2/2]

const T * InternalArray ( ) const
inline
Returns
The internal array pointer.
Note
If you call any non-const methods on this object it may invalidate the pointer.

◆ IsEmpty()

bool IsEmpty ( ) const
inline
Returns
true if the list is empty

◆ operator=() [1/4]

DynamicArray & operator= ( const DynamicArray< T, false > &  other)
inline

Assign this array by deep-copying other

Parameters
otherThe array to copy from.
Returns
The resulting array (this).

◆ operator=() [2/4]

DynamicArray & operator= ( const DynamicArray< T, true > &  other)
inline

Assign this array by deep-copying other

Parameters
otherThe array to copy from.
Returns
The resulting array (this).

◆ operator=() [3/4]

DynamicArray & operator= ( DynamicArray< T, false > &&  other)
inline

Assign this array by clearing any current contents and then taking ownership of other's contents.

Parameters
otherThe array to move from.
Returns
The resulting array (this).

◆ operator=() [4/4]

DynamicArray & operator= ( DynamicArray< T, true > &&  other)
inline

Assign this array by clearing any current contents and then taking ownership of other's contents.

Parameters
otherThe array to move from.
Returns
The resulting array (this).

◆ operator[]() [1/2]

T & operator[] ( const unsigned  index)
inline

Overload of array operator to get element at desired index

Note
Resizes if index exceeds Capacity() or Count().
Parameters
indexThe index of the item to return.
Returns
The item found, which will be a new item if index is greater than the count.

◆ operator[]() [2/2]

const T & operator[] ( const unsigned  index) const
inline

Overload of array operator to get element at desired index

Note
Does not resize if index exceeds Capacity() or Count().
Parameters
indexThe index of the item to return.
Returns
The item found.

◆ Position()

int Position ( const T &  object) const
inline

Get the index position of the specified object in the list

Parameters
objectThe object whose index is to be found.
Returns
The index of the object in the list, -1 if it isn't in the list
Deprecated:
Use helper function FindIndexOf() instead, but note that it returns unsigned.

◆ PushBack() [1/2]

unsigned PushBack ( const T &  object)
inline

Adds the specified object into the list, at the end of the list

Parameters
objectA pointer to the object to add
Returns
Where the object was inserted
Note
Similar to std::vector::push_back()

◆ PushBack() [2/2]

unsigned PushBack ( T &&  object)
inline

Adds the specified object into the list, at the end of the list

Parameters
objectThe object to add.
Returns
Where the object was inserted

◆ PushFront() [1/2]

void PushFront ( const T &  object)
inline

Adds the specified object at the head of the list.

Note
Similar to std::vector::insert( object, begin(*this) );
Prefer PushBack() instead to avoid inefficiencies.
Parameters
objectThe object to add.

◆ PushFront() [2/2]

void PushFront ( T &&  object)
inline

Adds the specified object at the head of the list.

Note
Similar to std::vector::insert( object, begin(*this) );
Prefer PushBack() instead to avoid inefficiencies.
Parameters
objectThe object to add.

◆ PushObject() [1/2]

void PushObject ( const T &  object)
inline

Adds the specified object into the list, at the head of the list Treats the list like a stack, hence the name Push

Note
Similar to std::vector::insert( object, begin(*this) );
Parameters
objectThe object to add.
Deprecated:
Renamed to PushFront(), but prefer PushBack() instead to avoid inefficiencies.

◆ PushObject() [2/2]

void PushObject ( T &&  object)
inline

Adds the specified object at the head of the list.

Note
This must move or copy all existing items, so it may be expensive.
Similar to std::vector::insert( object, begin(*this) );
Parameters
objectThe object to add.
Deprecated:
Renamed to PushFront(), but prefer PushBack() instead to avoid inefficiencies.

◆ Size() [1/2]

unsigned Size ( ) const
inline
Returns
The capacity of this array.
Deprecated:
Renamed to Capacity() for clarity.
Note
similar to std::vector::capacity()

◆ Size() [2/2]

void Size ( unsigned  newCapacity)
inline

Reserves space for newCapacity elements in the array, reallocating as needed.

Parameters
newCapacityThe new number of elements reserved in the array
Note
similar to std::vector::reserve()
Deprecated:
Renamed to Capacity() for clarity.

◆ StripCapacity()

void StripCapacity ( )
inline

Remove all capacity, destroying any extant items (but deleting any pointees, if the item is a pointer; for that, see DeleteEachAndClear()).

See also
Clear(), DeleteEachAndClear()

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