API
4.2
For MATLAB, Python, Java, and C++ users
|
A class for storing an array of values of type T. More...
Public Member Functions | |
virtual | ~Array () |
Destructor. More... | |
Array (const T &aDefaultValue=T(), int aSize=0, int aCapacity=Array_CAPMIN) | |
Default constructor. More... | |
Array (const Array< T > &aArray) | |
Copy constructor. More... | |
bool | arrayEquals (const Array< T > &aArray) const |
T & | operator[] (int aIndex) const |
Get the array element at a specified index. More... | |
Array< T > & | operator= (const Array< T > &aArray) |
Assign this array to a specified array. More... | |
bool | operator== (const Array< T > &aArray) const |
Determine if two arrays are equal. More... | |
bool | computeNewCapacity (int aMinCapacity, int &rNewCapacity) |
Compute a new capacity that is at least as large as a specified minimum capacity; this method does not change the capacity, it simply computes a new recommended capacity. More... | |
bool | ensureCapacity (int aCapacity) |
Ensure that the capacity of this array is at least the specified amount. More... | |
void | trim () |
Trim the capacity of this array so that it is one larger than the size of this array. More... | |
int | getCapacity () const |
Get the capacity of this storage instance. More... | |
void | setCapacityIncrement (int aIncrement) |
Set the amount by which the capacity is increased when the capacity of of the array in exceeded. More... | |
int | getCapacityIncrement () const |
Get the amount by which the capacity is increased. More... | |
bool | setSize (int aSize) |
Set the size of the array. More... | |
int | getSize () const |
Get the size of the array. More... | |
int | size () const |
Alternate name for getSize(). More... | |
int | append (const T &aValue) |
Append a value onto the array. More... | |
int | append (const Array< T > &aArray) |
Append an array of values. More... | |
int | append (int aSize, const T *aArray) |
Append an array of values. More... | |
int | insert (int aIndex, const T &aValue) |
Insert a value into the array at a specified index. More... | |
int | remove (int aIndex) |
Remove a value from the array at a specified index. More... | |
void | set (int aIndex, const T &aValue) |
Set the value at a specified index. More... | |
T * | get () |
Get a pointer to the low-level array. More... | |
const T * | get () const |
Get a pointer to the low-level array. More... | |
const T & | get (int aIndex) const |
Get a const reference to the value at a specified array index. More... | |
T & | updElt (int aIndex) const |
Get a writable reference to value at a specified array index. More... | |
const T & | getLast () const |
Get the last value in the array. More... | |
T & | updLast () const |
Get writable reference to last value in the array. More... | |
int | findIndex (const T &aValue) const |
Linear search for an element matching a given value. More... | |
int | rfindIndex (const T &aValue) const |
Linear search in reverse for an element matching a given value. More... | |
int | searchBinary (const T &aValue, bool aFindFirst=false, int aLo=-1, int aHi=-1) const |
Search for the largest value in the array that is less than or equal to a specified value. More... | |
A class for storing an array of values of type T.
The capacity of the class grows as needed. To use this template for a class of type T, class T should implement the following methods: default constructor, copy constructor, assignment operator (=), equality operator (==), and less than operator (<).
|
inlinevirtual |
Destructor.
When the array is deleted, references to elements of this array become invalid.
References OpenSim::Array< T >::_array.
|
inlineexplicit |
Default constructor.
aDefaultValue | Default value of an array element. This value is used to initialize array elements as the size of the array is changed. |
aSize | Initial size of the array. The array elements are initialized to aDefaultValue. |
aCapacity | Initial capacity of the array. The initial capacity is guaranteed to be at least as large as aSize + 1. |
References OpenSim::Array< T >::_defaultValue, OpenSim::Array< T >::_size, OpenSim::Array< T >::computeNewCapacity(), and OpenSim::Array< T >::ensureCapacity().
|
inline |
Copy constructor.
aArray | Array to be copied. |
|
inline |
Append an array of values.
aArray | Array of values to append. |
References OpenSim::Array< T >::_size, OpenSim::Array< T >::append(), and OpenSim::Array< T >::getSize().
|
inline |
Append a value onto the array.
aValue | Value to be appended. |
References OpenSim::Array< T >::_array, OpenSim::Array< T >::_capacity, OpenSim::Array< T >::_size, OpenSim::Array< T >::computeNewCapacity(), and OpenSim::Array< T >::ensureCapacity().
Referenced by OpenSim::Array< T >::append(), OpenSim::MocoBounds::getAsArray(), OpenSim::Set< T, C >::getGroupNames(), OpenSim::Set< T, C >::getGroupNamesContaining(), and OpenSim::Set< T, C >::getNames().
|
inline |
Append an array of values.
aSize | Size of the array to append. |
aArray | Array of values to append. |
References OpenSim::Array< T >::_size, and OpenSim::Array< T >::append().
|
inline |
|
inline |
Compute a new capacity that is at least as large as a specified minimum capacity; this method does not change the capacity, it simply computes a new recommended capacity.
If the capacity increment is negative, the current capacity is doubled until the computed capacity is greater than or equal to the specified minimum capacity. If the capacity increment is positive, the current capacity increment by this amount until the computed capacity is greater than or equal to the specified minimum capacity. If the capacity increment is zero, the computed capacity is set to the current capacity and false is returned.
rNewCapacity | New computed capacity. |
aMinCapacity | Minimum new computed capacity. The computed capacity is incremented until it is at least as large as aMinCapacity, assuming the capacity increment is not zero. |
References OpenSim::Array< T >::_capacity, and OpenSim::Array< T >::_capacityIncrement.
Referenced by OpenSim::Array< T >::append(), OpenSim::Array< T >::Array(), OpenSim::Array< T >::insert(), OpenSim::Array< T >::set(), and OpenSim::Array< T >::setSize().
|
inline |
Ensure that the capacity of this array is at least the specified amount.
Note that the newly allocated array elements are not initialized.
aCapacity | Desired capacity. |
References OpenSim::Array< T >::_array, OpenSim::Array< T >::_capacity, OpenSim::Array< T >::_defaultValue, and OpenSim::Array< T >::_size.
Referenced by OpenSim::Array< T >::append(), OpenSim::Array< T >::Array(), OpenSim::Array< T >::insert(), OpenSim::Array< T >::set(), and OpenSim::Array< T >::setSize().
|
inline |
Linear search for an element matching a given value.
aValue | Value to which the array elements are compared. |
References OpenSim::Array< T >::_array, and OpenSim::Array< T >::_size.
|
inline |
Get a pointer to the low-level array.
References OpenSim::Array< T >::_array.
Referenced by OpenSim::MarkerPair::getMarkerName().
|
inline |
Get a pointer to the low-level array.
References OpenSim::Array< T >::_array.
|
inline |
Get a const reference to the value at a specified array index.
If the index is negative or passed the end of the array, an exception is thrown.
For faster execution, the array elements can be accessed through the overloaded operator[], which does no bounds checking.
aIndex | Index of the desired array element. |
Exception | if (aIndex<0)||(aIndex>=_size). |
References OpenSim::Array< T >::_array, and OpenSim::Array< T >::_size.
|
inline |
Get the capacity of this storage instance.
References OpenSim::Array< T >::_capacity.
|
inline |
Get the amount by which the capacity is increased.
References OpenSim::Array< T >::_capacityIncrement.
|
inline |
Get the last value in the array.
Exception | if the array is empty. |
References OpenSim::Array< T >::_array, and OpenSim::Array< T >::_size.
|
inline |
Get the size of the array.
References OpenSim::Array< T >::_size.
Referenced by OpenSim::Array< T >::append(), OpenSim::PropertyBoolArray::getArraySize(), OpenSim::PropertyDblArray::getArraySize(), OpenSim::PropertyIntArray::getArraySize(), OpenSim::PropertyStrArray::getArraySize(), OpenSim::MarkerPair::getMarkerName(), OpenSim::GCVSpline::getNumberOfPoints(), OpenSim::PiecewiseConstantFunction::getNumberOfPoints(), OpenSim::PiecewiseLinearFunction::getNumberOfPoints(), OpenSim::SimmSpline::getNumberOfPoints(), OpenSim::Storage::getSize(), OpenSim::XMLDocument::hasDefaultObjects(), OpenSim::PropertyDblVec_< M >::setValue(), and OpenSim::Array< T >::size().
|
inline |
Insert a value into the array at a specified index.
This method is relatively computationally costly since many of the array elements may need to be shifted.
aValue | Value to be inserted. |
aIndex | Index at which to insert the new value. All current elements from aIndex to the end of the array are shifted one place in the direction of the end of the array. If the specified index is greater than the current size of the array, the size of the array is increased to aIndex+1 and the intervening new elements are initialized to the default value that was specified at the time of construction. |
References OpenSim::Array< T >::_array, OpenSim::Array< T >::_capacity, OpenSim::Array< T >::_size, OpenSim::Array< T >::computeNewCapacity(), OpenSim::Array< T >::ensureCapacity(), and OpenSim::Array< T >::setSize().
|
inline |
Assign this array to a specified array.
This operator makes a complete copy of the specified array; all member variables are copied. So, the result is two identical, independent arrays.
aArray | Array to be copied. |
References OpenSim::Array< T >::_array, OpenSim::Array< T >::_capacity, OpenSim::Array< T >::_capacityIncrement, OpenSim::Array< T >::_defaultValue, and OpenSim::Array< T >::_size.
|
inline |
Determine if two arrays are equal.
Two arrays are equal if their contents are equal. That is, each array must be the same length and their corresponding array elements must be equal.
aArray | Array to be tested as equal. |
References OpenSim::Array< T >::_array, and OpenSim::Array< T >::_size.
|
inline |
Get the array element at a specified index.
This overloaded operator can be used both to set and get element values:
This operator is intended for accessing array elements with as little overhead as possible, so no error checking is performed. The caller must make sure the specified index is within the bounds of the array. If error checking is desired, use Array::get().
aIndex | Index of the desired element (0 <= aIndex < _size). |
References OpenSim::Array< T >::_array.
|
inline |
Remove a value from the array at a specified index.
This method is relatively computationally costly since many of the array elements may need to be shifted.
aIndex | Index of the value to remove. All elements from aIndex to the end of the array are shifted one place toward the beginning of the array. If aIndex is less than 0 or greater than or equal to the current size of the array, no element is removed. |
References OpenSim::Array< T >::_array, OpenSim::Array< T >::_defaultValue, and OpenSim::Array< T >::_size.
|
inline |
Linear search in reverse for an element matching a given value.
aValue | Value to which the array elements are compared. |
References OpenSim::Array< T >::_array, and OpenSim::Array< T >::_size.
|
inline |
Search for the largest value in the array that is less than or equal to a specified value.
If there is more than one element with this largest value, the index of the first of these elements can optionally be found, but this can be up to twice as costly.
This method assumes that the array element values monotonically increase as the array index increases. Note that monotonically increase means never decrease, so it is permissible for elements to
A binary search is performed (i.e., the array is repeatedly subdivided into two bins one of which must contain the specified until the appropriate element is identified), so the performance of this method is approximately ln(n), where n is the size of the array.
aValue | Value to which the array elements are compared. |
aFindFirst | If true, find the first element that satisfies the search. If false, the index of any element that satisfies the search can be returned- which index will be returned depends on the length of the array and is therefore somewhat arbitrary. By default, this flag is false. |
aLo | Lowest array index to consider in the search. |
aHi | Highest array index to consider in the search. |
References OpenSim::Array< T >::_array, and OpenSim::Array< T >::_size.
|
inline |
Set the value at a specified index.
aIndex | Index of the array element to be set. It is permissible for aIndex to be past the current end of the array- the capacity will be increased if necessary. Values between the current end of the array and aIndex are not initialized. |
aValue | Value. |
References OpenSim::Array< T >::_array, OpenSim::Array< T >::_capacity, OpenSim::Array< T >::_size, OpenSim::Array< T >::computeNewCapacity(), and OpenSim::Array< T >::ensureCapacity().
Referenced by OpenSim::MarkerPair::setMarkerName().
|
inline |
Set the amount by which the capacity is increased when the capacity of of the array in exceeded.
If the specified increment is negative, the capacity is set to double whenever the capacity is exceeded.
aIncrement | Desired capacity increment. |
References OpenSim::Array< T >::_capacityIncrement.
|
inline |
Set the size of the array.
This method can be used to either increase or decrease the size of the array. If this size of the array is increased, the new elements are initialized to the default value that was specified at the time of construction.
Note that the size of an array is different than its capacity. The size indicates how many valid elements are stored in an array. The capacity indicates how much the size of the array can be increased without allocated more memory. At all times size <= capacity.
aSize | Desired size of the array. The size must be greater than or equal to zero. |
References OpenSim::Array< T >::_array, OpenSim::Array< T >::_capacity, OpenSim::Array< T >::_defaultValue, OpenSim::Array< T >::_size, OpenSim::Array< T >::computeNewCapacity(), and OpenSim::Array< T >::ensureCapacity().
Referenced by OpenSim::PropertyBoolArray::clearValues(), OpenSim::PropertyDblArray::clearValues(), OpenSim::PropertyIntArray::clearValues(), OpenSim::PropertyStrArray::clearValues(), OpenSim::Set< T, C >::getGroupNames(), OpenSim::Set< T, C >::getGroupNamesContaining(), OpenSim::Array< T >::insert(), OpenSim::PropertyDblVec_< M >::PropertyDblVec_(), and OpenSim::Storage::purge().
|
inline |
Alternate name for getSize().
References OpenSim::Array< T >::getSize().
|
inline |
Trim the capacity of this array so that it is one larger than the size of this array.
This is useful for reducing the amount of memory used by this array. This capacity is kept at one larger than the size so that, for example, an array of characters can be treated as a NULL terminated string.
References OpenSim::Array< T >::_array, OpenSim::Array< T >::_capacity, and OpenSim::Array< T >::_size.
|
inline |
Get a writable reference to value at a specified array index.
If the index is negative or passed the end of the array, an exception is thrown.
For faster execution, the array elements can be accessed through the overloaded operator[], which does no bounds checking.
aIndex | Index of the desired array element. |
Exception | if (aIndex<0)||(aIndex>=_size). |
References OpenSim::Array< T >::_array, and OpenSim::Array< T >::_size.
|
inline |
Get writable reference to last value in the array.
Exception | if the array is empty. |
References OpenSim::Array< T >::_array, and OpenSim::Array< T >::_size.