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

#include <dynamic_array.h>

Public Member Functions

 DynamicArray (unsigned initialCapacity=0)
 
 DynamicArray (std::initializer_list< T > list)
 
 DynamicArray (const DynamicArray< T, true > &other)
 Initialize this array by deep-copying other.
 
 DynamicArray (const DynamicArray< T, false > &other)
 Initialize this array by deep-copying other.
 
DynamicArrayoperator= (const DynamicArray< T, true > &other)
 Assign this array by deep-copying other.
 
DynamicArrayoperator= (const DynamicArray< T, false > &other)
 Assign this array by deep-copying other.
 
 DynamicArray (DynamicArray< T, true > &&other)
 Construct this array by taking ownership of other's contents.
 
 DynamicArray (DynamicArray< T, false > &&other)
 Construct this array by taking ownership of other's contents.
 
DynamicArrayoperator= (DynamicArray< T, true > &&other)
 Assign this array by clearing any current contents and then taking ownership of other's contents.
 
 ~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 ( unsigned  initialCapacity = 0)
inlineexplicit

DynamicArray constructor

Parameters
initialCapacityThe initial number of elements to be allocated for the array
DynamicArray ( std::initializer_list< T >  list)
inline

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

const auto a = DynamicArray<int>{ 1, 2, 3, 4 };

Member Function Documentation

T& Back ( )
inline

Returns the last element in the array.

Exceptions
DistiExceptionif array is empty.
const T& Back ( ) const
inline

Returns the last element in the array.

Exceptions
DistiExceptionif array is empty.
unsigned Capacity ( ) const
inline

Returns the capacity of this dynamic array

Note
Similar to std::vector::capacity()
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.
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()
void ClearList ( )
inline

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

Deprecated:
Renamed to Clear() for consistency.
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()
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()
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.
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.
void EmptyList ( )
inline

Calls delete on each element and then clears the list.

Deprecated:
Use the non-member function DeleteEachAndClear( dynamicArray ) instead.
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
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
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 );
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.
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.
unsigned InsertObject ( const T &  object)
inline

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

Returns
Where the object was inserted
Note
similar to std::vector::push_back()
Deprecated:
Use PushBack( object ) instead.
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
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.
unsigned InsertObject ( T &&  object)
inline

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

Returns
Where the object was inserted
Note
Similar to std::vector::push_back()
Deprecated:
Use PushBack( object ) instead.
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.
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
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.
T* InternalArray ( )
inline

Return the internal array pointer

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

Return the internal array pointer

Note
If you call any non-const methods on this object it may invalidate the pointer.
bool IsEmpty ( ) const
inline
Returns
true if the list is empty
T& operator[] ( const unsigned  index)
inline

Overload of array operator to get element at desired index

Note
Resizes if index exceeds Capacity() or Count().
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().
int Position ( const T &  object) const
inline

Get the index position of the specified object in the list

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.
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()
unsigned PushBack ( T &&  object)
inline

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

Returns
Where the object was inserted
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.
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.
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) );
Deprecated:
Renamed to PushFront(), but prefer PushBack() instead to avoid inefficiencies.
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) );
Deprecated:
Renamed to PushFront(), but prefer PushBack() instead to avoid inefficiencies.
unsigned Size ( ) const
inline

Returns the capacity of this array

Deprecated:
Renamed to Capacity() for clarity.
Note
similar to std::vector::capacity()
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
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::reserve()
Deprecated:
Renamed to Capacity() for clarity.
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: