|
| Array (Array const &)=default |
|
| Array (Array &&) noexcept=default |
|
Array & | operator= (Array const &)=default |
|
Array & | operator= (Array &&) noexcept=default |
|
| ~Array () noexcept=default |
|
| Array (T aDefaultValue=T(), int aSize=0, int aCapacity=1) |
|
bool | arrayEquals (const Array &aArray) const |
|
T & | operator[] (int aIndex) const |
| Get the array element at a specified index. 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) |
| deprecated (legacy): now has no effect More...
|
|
int | getCapacityIncrement () const |
| deprecated (legacy): has no effect 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 &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...
|
|
template<class T>
class OpenSim::Array< T >
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 (<).
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.
- Parameters
-
aIndex | Index of the desired array element. |
- Returns
- const reference to the array element.
- Exceptions
-
- See also
- operator[].
Get the array element at a specified index.
This overloaded operator can be used both to set and get element values:
Array<T> array(2);
T value = array[i];
array[i] = value;
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().
- Parameters
-
aIndex | Index of the desired element (0 <= aIndex < _size). |
- Returns
- Reference to the array element.
- See also
- get().
template<class T>
int OpenSim::Array< T >::searchBinary |
( |
const T & |
aValue, |
|
|
bool |
aFindFirst = false , |
|
|
int |
aLo = -1 , |
|
|
int |
aHi = -1 |
|
) |
| const |
|
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.
- Parameters
-
aValue | Value to which the array elements are compared. |
aFindFirst | DEPRECATED: this is now ALWAYS true - regardless of what you are calling it with. This makes the behavior predictable on all platforms. |
OLD BEHAVIOR: If true, find the first element that satisfies the search. OLD BEHAVIOR: 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. OLD BEHAVIOR: By default, this flag is false (now: it is always true)
- Parameters
-
aLo | Lowest array index to consider in the search. |
aHi | Highest array index to consider in the search. |
- Returns
- Index of the array element that has the largest value that is less than or equal to aValue. If an error is encountered (e.g., the array is empty), or if the array contains no element that is less than or equal to aValue, -1 is returned.
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.
- Parameters
-
aSize | Desired size of the array. The size must be greater than or equal to zero. |
Referenced by OpenSim::PropertyBoolArray::clearValues(), OpenSim::PropertyIntArray::clearValues(), OpenSim::PropertyStrArray::clearValues(), OpenSim::PropertyDblArray::clearValues(), OpenSim::Set< Force, ModelComponent >::getGroupNames(), OpenSim::Set< Force, ModelComponent >::getGroupNamesContaining(), OpenSim::Array< OpenSim::Object *>::insert(), OpenSim::PropertyDblVec_< 3 >::PropertyDblVec_(), OpenSim::Storage::purge(), and OpenSim::Array< OpenSim::Object *>::set().
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.
- Parameters
-
aIndex | Index of the desired array element. |
- Returns
- Writable reference to the array element.
- Exceptions
-
- See also
- operator[].