Simbody
3.5
|
This Array_ helper class is the base class for Array_, extending ArrayViewConst_ to add the ability to modify elements, but not the ability to change size or reallocate. More...
Public Types | |
Typedefs | |
Types required of STL containers, plus index_type which is an extension, and packed_size_type which is an implementation detail. | |
typedef T | value_type |
typedef X | index_type |
typedef T * | pointer |
typedef const T * | const_pointer |
typedef T & | reference |
typedef const T & | const_reference |
typedef T * | iterator |
typedef const T * | const_iterator |
typedef std::reverse_iterator< iterator > | reverse_iterator |
typedef std::reverse_iterator< const_iterator > | const_reverse_iterator |
typedef ArrayIndexTraits< X >::size_type | size_type |
typedef ArrayIndexTraits< X >::difference_type | difference_type |
typedef ArrayIndexPackType< size_type >::packed_size_type | packed_size_type |
Public Types inherited from SimTK::ArrayViewConst_< T, X > | |
typedef T | value_type |
The type of object stored in this container. More... | |
typedef X | index_type |
The index type (an extension). More... | |
typedef T * | pointer |
A writable pointer to a value_type. More... | |
typedef const T * | const_pointer |
A const pointer to a value_type. More... | |
typedef T & | reference |
A writable value_type reference. More... | |
typedef const T & | const_reference |
A const value_type reference. More... | |
typedef T * | iterator |
A writable iterator for this container (same as pointer here). More... | |
typedef const T * | const_iterator |
A const iterator for this container (same as const_pointer here). More... | |
typedef std::reverse_iterator< iterator > | reverse_iterator |
A writable reverse iterator for this container. More... | |
typedef std::reverse_iterator< const_iterator > | const_reverse_iterator |
A const reverse iterator for this container. More... | |
typedef ArrayIndexTraits< X >::size_type | size_type |
An integral type suitable for all indices and sizes for this array. More... | |
typedef ArrayIndexTraits< X >::difference_type | difference_type |
A signed integral type that can represent the difference between any two legitimate index values for this array. More... | |
typedef ArrayIndexPackType< size_type >::packed_size_type | packed_size_type |
The integral type we actually use internally to store size_type values. More... | |
Public Member Functions | |
Construction, conversion, and destruction | |
Constructors here are limited to those that don't allocate new data, however they can reference writable data. | |
ArrayView_ () | |
Default constructor allocates no heap space and is very fast. More... | |
ArrayView_ (const ArrayView_ &src) | |
Copy constructor is shallow. More... | |
ArrayView_ (T *first, const T *last1) | |
Construct from a range of writable memory. More... | |
template<class A > | |
ArrayView_ (std::vector< T, A > &v) | |
Construct to reference memory owned by a writable std::vector. More... | |
operator const Array_< T, X > & () const | |
Implicit conversion of const ArrayView_ to const Array_& (zero cost). More... | |
operator Array_< T, X > & () | |
Implicit conversion of non-const ArrayView_ to Array_& (zero cost). More... | |
void | disconnect () |
Forward to base class disconnect() method – clears the handle without doing anything to the data. More... | |
~ArrayView_ () | |
The destructor just disconnects the array view handle from its data; see ArrayViewConst_<T,X>::disconnect() for more information. More... | |
Assignment | |
Assignment is permitted only if the source and destination are the same size. The semantics here are different than for a resizeable Array_ object: here the meaning is elementwise assignment rather than destruction followed by copy construction. That is, if our elements are of type T, and the source elements are of type T2, we will use the operator of T that best matches the signature T::operator=(const T2&) to perform the assignments. When the source also has type T, this is just T's copy assignment operator. We never perform any element destruction or construction here. | |
ArrayView_ & | operator= (const ArrayView_ &src) |
Copy assignment; source must be the same size as this array. More... | |
template<class T2 , class X2 > | |
ArrayView_ & | operator= (const ArrayViewConst_< T2, X2 > &src) |
Assignment from any other array object is allowed as long as the number of elements matches and the types are assignment compatible. More... | |
template<class T2 , class X2 > | |
ArrayView_ & | operator= (const ArrayView_< T2, X2 > &src) |
Assignment from any other array object is allowed as long as the number of elements matches and the types are assignment compatible. More... | |
template<class T2 , class X2 > | |
ArrayView_ & | operator= (const Array_< T2, X2 > &src) |
Assignment from any other array object is allowed as long as the number of elements matches and the types are assignment compatible. More... | |
template<class T2 , class A2 > | |
ArrayView_ & | operator= (const std::vector< T2, A2 > &src) |
Assignment from any std::vector object is allowed as long as the number of elements matches and the types are assignment compatible. More... | |
ArrayView_ & | operator= (const T &fillValue) |
Fill assignment – all elements are set to fillValue. More... | |
ArrayView_ & | fill (const T &fillValue) |
Assign the supplied fill value to each element of this array, using T's copy assignment operator for each element. More... | |
void | assign (size_type n, const T &fillValue) |
This is the same as fill() but has the usual std::vector signature for compatibility; it will only work if the given number of elements is the same as this array's (fixed) size. More... | |
template<class T2 > | |
void | assign (const T2 *first, const T2 *last1) |
Assign to this array to make it a copy of the elements in range [first,last1) given by ordinary pointers, provided that the range is the same size as the array. More... | |
template<class Iter > | |
void | assign (const Iter &first, const Iter &last1) |
Assign to this array to make it a copy of the elements in range [first,last1) given by non-pointer iterators (the pointer case is handled with a specialized assign() variant). More... | |
Element access | |
These methods provide read and write access to individual elements that are currently present in the array; the ArrayViewConst_<T,X> base class provides the read-only (const) methods. | |
const T & | operator[] (index_type i) const |
Select an element by its index, returning a const reference. More... | |
T & | operator[] (index_type i) |
Select an element by its index, returning a writable (lvalue) reference. More... | |
const T & | at (index_type i) const |
Same as operator[] but always range-checked, even in a Release build. More... | |
T & | at (index_type i) |
Same as operator[] but always range-checked, even in a Release build. More... | |
const T & | getElt (index_type i) const |
Same as the const form of operator[]; exists to provide a non-operator method for element access in case that's needed. More... | |
T & | updElt (index_type i) |
Same as the non-const form of operator[]; exists to provide a non-operator method for element access in case that's needed. More... | |
const T & | front () const |
Return a const reference to the first element in this array, which must not be empty. More... | |
T & | front () |
Return a writable reference to the first element in this array, which must not be empty. More... | |
const T & | back () const |
Return a const reference to the last element in this array, which must not be empty. More... | |
T & | back () |
Return a writable reference to the last element in this array, which must not be empty. More... | |
ArrayView_ | operator() (index_type index, size_type length) |
Select a contiguous subarray of the elements of this array and create another ArrayView_ that refers only to those element (without copying). More... | |
ArrayView_ | updSubArray (index_type index, size_type length) |
Same as non-const operator()(index,length); exists to provide non-operator access to that functionality in case it is needed. More... | |
Iterators | |
These methods deal in iterators, which are STL generalized pointers. For this class, iterators are just ordinary pointers to T, and you may depend on that. By necessity, reverse iterators can't be just pointers; however, they contain an ordinary iterator (i.e. a pointer) that can be obtained by calling the reverse iterator's base() method. | |
const T * | cbegin () const |
Return a const pointer to the first element of this array if any, otherwise end(), which may be null (0) in that case but does not have to be. More... | |
const T * | begin () const |
The const version of begin() is the same as cbegin(). More... | |
T * | begin () |
Return a writable pointer to the first element of this array if any, otherwise end(). More... | |
const T * | cend () const |
Return a const pointer to what would be the element just after the last one in the array; this may be null (0) if there are no elements but doesn't have to be. More... | |
const T * | end () const |
The const version of end() is the same as cend(). More... | |
T * | end () |
Return a writable pointer to what would be the element just after the last one in this array. More... | |
const_reverse_iterator | crbegin () const |
Return a const reverse iterator pointing to the last element in the array or crend() if the array is empty. More... | |
const_reverse_iterator | rbegin () const |
The const version of rbegin() is the same as crbegin(). More... | |
reverse_iterator | rbegin () |
Return a writable reverse iterator pointing to the last element in the array or rend() if the array is empty. More... | |
const_reverse_iterator | crend () const |
Return the past-the-end reverse iterator that tests equal to a reverse iterator that has been incremented past the front of the array. More... | |
const_reverse_iterator | rend () const |
The const version of rend() is the same as crend(). More... | |
reverse_iterator | rend () |
Return a writable past-the-end reverse iterator that tests equal to a reverse iterator that has been incremented past the front of the array. More... | |
const T * | cdata () const |
Return a const pointer to the first element of the array, or possibly (but not necessarily) null (0) if the array is empty. More... | |
const T * | data () const |
The const version of the data() method is identical to cdata(). More... | |
T * | data () |
Return a writable pointer to the first allocated element of the array, or a null pointer if no space is associated with the array. More... | |
Public Member Functions inherited from SimTK::ArrayViewConst_< T, X > | |
ArrayViewConst_ () | |
Default constructor allocates no heap space and is very fast. More... | |
ArrayViewConst_ (const ArrayViewConst_ &src) | |
Copy constructor is shallow; the constructed const array object will be referencing the original source data. More... | |
ArrayViewConst_ (const T *first, const T *last1) | |
Construct an ArrayViewConst_<T> by referencing (sharing) a given range of const data [first,last1), without copying that data. More... | |
template<class A > | |
ArrayViewConst_ (const std::vector< T, A > &src) | |
Construct a ArrayViewConst_<T> by referencing (sharing) the data in a const std::vector<T>, without copying the data; this is also an implicit conversion. More... | |
operator const ArrayView_< T, X > & () const | |
This is an implicit conversion to const ArrayView_<T,X>&, which is harmless since the const result won't permit writing on the elements. More... | |
operator const Array_< T, X > & () const | |
This is an implicit conversion to const Array_<T,X>&, which is harmless since the const result can't be used to write on or resize the data. More... | |
void | disconnect () |
Disconnect this array handle from any data to which it refers, restoring it to the condition it would be in if it had just been default-constructed. More... | |
~ArrayViewConst_ () | |
The destructor just disconnects the array view handle from its data; see disconnect() for more information. More... | |
size_type | size () const |
Return the current number of elements stored in this array. More... | |
size_type | max_size () const |
Return the maximum allowable size for this array. More... | |
bool | empty () const |
Return true if there are no elements currently stored in this array. More... | |
size_type | capacity () const |
Return the number of elements this array can currently hold without requiring reallocation. More... | |
size_type | allocated () const |
Return the amount of heap space owned by this array; this is the same as capacity() for owner arrays but is zero for non-owners. More... | |
bool | isOwner () const |
Does this array own the data to which it refers? If not, it can't be resized, and the destructor will not free any heap space nor call any element destructors. More... | |
const T & | operator[] (index_type i) const |
Select an element by its index, returning a const reference. More... | |
const T & | at (index_type i) const |
Same as operator[] but always range-checked, even in a Release build. More... | |
const T & | getElt (index_type i) const |
Same as the const form of operator[]; exists to provide a non-operator method for element access in case that's needed. More... | |
const T & | front () const |
Return a const reference to the first element in this array, which must not be empty (we'll check in a Debug build but not Release). More... | |
const T & | back () const |
Return a const reference to the last element in this array, which must not be empty (we'll check in a Debug build but not Release). More... | |
ArrayViewConst_ | operator() (index_type index, size_type length) const |
Select a contiguous subarray of the elements of this array and create another ArrayViewConst_ that refers only to those element (without copying). More... | |
ArrayViewConst_ | getSubArray (index_type index, size_type length) const |
Same as const form of operator()(index,length); exists to provide non-operator access to that functionality in case it is needed. More... | |
const T * | cbegin () const |
Return a const pointer to the first element of this array if any, otherwise cend(), which may be null (0) in that case but does not have to be. More... | |
const T * | cend () const |
Return a const pointer to what would be the element just after the last one in the array; this may be null (0) if there are no elements but doesn't have to be. More... | |
const T * | begin () const |
The const version of begin() is the same as cbegin(). More... | |
const T * | end () const |
The const version of end() is the same as cend(). More... | |
const_reverse_iterator | crbegin () const |
Return a const reverse iterator pointing to the last element in the array or crend() if the array is empty. More... | |
const_reverse_iterator | crend () const |
Return the past-the-end reverse iterator that tests equal to a reverse iterator that has been incremented past the front of the array. More... | |
const_reverse_iterator | rbegin () const |
The const version of rbegin() is the same as crbegin(). More... | |
const_reverse_iterator | rend () const |
The const version of rend() is the same as crend(). More... | |
const T * | cdata () const |
Return a const pointer to the first element of the array, or possibly (but not necessarily) null (0) if the array is empty. More... | |
const T * | data () const |
The const version of the data() method is identical to cdata(). More... | |
Related Functions | |
(Note that these are not member functions.) | |
Array_<T> serialization and I/O | |
These methods are at namespace scope but are logically part of the Array classes. These deal with reading and writing Arrays from and to streams, which places an additional requirement on the element type T: the element must support the same operation you are trying to do on the Array as a whole. | |
template<class T , class X > | |
bool | readUnformatted (std::istream &in, ArrayView_< T, X > &v) |
Specialization of readUnformatted() for fixed-length ArrayView_<T,X>; reads whitespace-separated tokens until the expected number have been read. More... | |
template<class T , class X > | |
bool | readFormatted (std::istream &in, ArrayView_< T, X > &v) |
Specialization of readFormatted() for fixed-length ArrayView_<T,X>; uses fillArrayViewFromStream() to consume an appropriately-formatted fixed-size array. More... | |
template<class T , class X > | |
static std::istream & | fillArrayViewFromStream (std::istream &in, ArrayView_< T, X > &out) |
Read in a fixed number of elements from a stream into an ArrayView. More... | |
template<class T , class X > | |
std::istream & | operator>> (std::istream &in, ArrayView_< T, X > &out) |
Read a (fixed size n) ArrayView_<T> from a stream as a sequence of space- or comma-separated values of type T, optionally delimited by parentheses, square brackets, or curly braces. More... | |
Size and capacity | |
These methods report the number of elements (size) or the amount of allocated heap space (capacity) or both but cannot be used to change size. | |
size_type | size () const |
size_type | max_size () const |
bool | empty () const |
size_type | capacity () const |
size_type | allocated () const |
bool | isOwner () const |
This Array_ helper class is the base class for Array_, extending ArrayViewConst_ to add the ability to modify elements, but not the ability to change size or reallocate.
T | The type of object to be stored in this container. |
X | The type to be used for indexing this container, with default unsigned (not size_t). Any integral type may be used, as well as user types that satisfy the requirements discussed with class ArrayIndexTraits. |
typedef T SimTK::ArrayView_< T, X >::value_type |
typedef X SimTK::ArrayView_< T, X >::index_type |
typedef T* SimTK::ArrayView_< T, X >::pointer |
typedef const T* SimTK::ArrayView_< T, X >::const_pointer |
typedef T& SimTK::ArrayView_< T, X >::reference |
typedef const T& SimTK::ArrayView_< T, X >::const_reference |
typedef T* SimTK::ArrayView_< T, X >::iterator |
typedef const T* SimTK::ArrayView_< T, X >::const_iterator |
typedef std::reverse_iterator<iterator> SimTK::ArrayView_< T, X >::reverse_iterator |
typedef std::reverse_iterator<const_iterator> SimTK::ArrayView_< T, X >::const_reverse_iterator |
typedef ArrayIndexTraits<X>::size_type SimTK::ArrayView_< T, X >::size_type |
typedef ArrayIndexTraits<X>::difference_type SimTK::ArrayView_< T, X >::difference_type |
typedef ArrayIndexPackType<size_type>::packed_size_type SimTK::ArrayView_< T, X >::packed_size_type |
|
inline |
Default constructor allocates no heap space and is very fast.
|
inline |
Copy constructor is shallow.
|
inline |
Construct from a range of writable memory.
|
inline |
Construct to reference memory owned by a writable std::vector.
|
inline |
The destructor just disconnects the array view handle from its data; see ArrayViewConst_<T,X>::disconnect() for more information.
|
inline |
Implicit conversion of const ArrayView_ to const Array_& (zero cost).
|
inline |
Implicit conversion of non-const ArrayView_ to Array_& (zero cost).
|
inline |
Forward to base class disconnect() method – clears the handle without doing anything to the data.
|
inline |
Copy assignment; source must be the same size as this array.
|
inline |
Assignment from any other array object is allowed as long as the number of elements matches and the types are assignment compatible.
|
inline |
Assignment from any other array object is allowed as long as the number of elements matches and the types are assignment compatible.
|
inline |
Assignment from any other array object is allowed as long as the number of elements matches and the types are assignment compatible.
|
inline |
Assignment from any std::vector object is allowed as long as the number of elements matches and the types are assignment compatible.
|
inline |
Fill assignment – all elements are set to fillValue.
|
inline |
Assign the supplied fill value to each element of this array, using T's copy assignment operator for each element.
Note that this also serves to allow fill from an object whose type T2 is different from T, as long as there is a constructor T(T2) that works since that can be invoked (implicitly or explicitly) to convert the T2 object to type T prior to the call.
|
inline |
This is the same as fill() but has the usual std::vector signature for compatibility; it will only work if the given number of elements is the same as this array's (fixed) size.
|
inline |
Assign to this array to make it a copy of the elements in range [first,last1) given by ordinary pointers, provided that the range is the same size as the array.
It is not allowed for the source range to include any of the elements currently in the array. The source elements can be of a type T2 that may be the same or different than this array's element type T as long as there is a T=T2 assignment operator that works. Note that although the source arguments are pointers, those may be iterators for some container depending on implementation details of the container. Specifically, any ArrayViewConst_, ArrayView_, or Array_ iterator is an ordinary pointer.
[in] | first | A pointer to the first element to be copied. |
[in] | last1 | A pointer to the element one past the last element to be copied. |
|
inline |
Assign to this array to make it a copy of the elements in range [first,last1) given by non-pointer iterators (the pointer case is handled with a specialized assign() variant).
It is not allowed for this range to include any of the elements currently in the array. The source elements can be of a type T2 that may be the same or different than this array's element type T as long as there is a T=T2 operator that works.
The source must have the same number of elements as the current (fixed) size of this ArrayView. For input_iterators we'll be happy if we get enough elements and won't insist that the input stream is empty after that. For forward_ and bidirectional_iterators we'll copy the elements and complain at the end if there are too few or too many. For random_access_iterators we'll check in advance since we can do that fast.
[in] | first | An iterator pointing to the first element to be copied. |
[in] | last1 | An iterator pointing to the element one past the last element to be copied. |
|
inline |
Select an element by its index, returning a const reference.
Note that only a value of the array's templatized index type is allowed (default is unsigned). This will be range-checked in a Debug build but not in Release.
|
inline |
Select an element by its index, returning a writable (lvalue) reference.
Note that only a value of the Array's templatized index type is allowed (default is unsigned). This will be range-checked in a Debug build but not in Release.
|
inline |
Same as operator[] but always range-checked, even in a Release build.
|
inline |
Same as operator[] but always range-checked, even in a Release build.
|
inline |
Same as the const form of operator[]; exists to provide a non-operator method for element access in case that's needed.
|
inline |
Same as the non-const form of operator[]; exists to provide a non-operator method for element access in case that's needed.
|
inline |
Return a const reference to the first element in this array, which must not be empty.
|
inline |
Return a writable reference to the first element in this array, which must not be empty.
|
inline |
Return a const reference to the last element in this array, which must not be empty.
|
inline |
Return a writable reference to the last element in this array, which must not be empty.
|
inline |
Select a contiguous subarray of the elements of this array and create another ArrayView_ that refers only to those element (without copying).
[in] | index | The index of the first element to be included in the subarray; this can be one past the end of the array if length is zero. |
[in] | length | The length of the subarray to be produced. |
|
inline |
Same as non-const operator()(index,length); exists to provide non-operator access to that functionality in case it is needed.
|
inline |
|
inline |
|
inline |
|
inline |
Return a const pointer to what would be the element just after the last one in the array; this may be null (0) if there are no elements but doesn't have to be.
This method is from the proposed C++0x standard; there is also an overloaded end() from the original standard that returns a const pointer.
|
inline |
|
inline |
|
inline |
Return a const reverse iterator pointing to the last element in the array or crend() if the array is empty.
|
inline |
|
inline |
Return a writable reverse iterator pointing to the last element in the array or rend() if the array is empty.
|
inline |
Return the past-the-end reverse iterator that tests equal to a reverse iterator that has been incremented past the front of the array.
You cannot dereference this iterator.
|
inline |
|
inline |
Return a writable past-the-end reverse iterator that tests equal to a reverse iterator that has been incremented past the front of the array.
You cannot dereference this iterator.
|
inline |
Return a const pointer to the first element of the array, or possibly (but not necessarily) null (0) if the array is empty.
|
inline |
|
inline |
Return a writable pointer to the first allocated element of the array, or a null pointer if no space is associated with the array.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
related |
Specialization of readUnformatted() for fixed-length ArrayView_<T,X>; reads whitespace-separated tokens until the expected number have been read.
If fewer are available we fail.
|
related |
Specialization of readFormatted() for fixed-length ArrayView_<T,X>; uses fillArrayViewFromStream() to consume an appropriately-formatted fixed-size array.
|
related |
Read in a fixed number of elements from a stream into an ArrayView.
See fillArrayFromStream() for more information; this works the same way.
|
related |
Read a (fixed size n) ArrayView_<T> from a stream as a sequence of space- or comma-separated values of type T, optionally delimited by parentheses, square brackets, or curly braces.
If there are no delimiters then we will read size() values and then stop. Otherwise, there must be exactly size() values within the brackets. Each element is read in with its own operator ">>" so this won't work if no such operator is defined for type T.