Simbody
Public Member Functions

SimTK::Vector_< ELT > Class Template Reference

This is the Vector class intended to appear in user code. More...

#include <BigMatrix.h>

Inheritance diagram for SimTK::Vector_< ELT >:

List of all members.

Public Member Functions

 Vector_ ()
 Vector_ (const Vector_ &src)
 Vector_ (const Base &src)
 Vector_ (const BaseNeg &src)
Vector_operator= (const Vector_ &src)
 Vector_ (int m)
 Vector_ (int m, const ELT *cppInitialValues)
 Vector_ (int m, const ELT &initialValue)
 Vector_ (int m, const S *cppData, bool)
 Construct a Vector which uses borrowed space with assumed element-to-element stride equal to the C++ element spacing.
 Vector_ (int m, S *cppData, bool)
 Vector_ (int m, int stride, const S *data, bool)
 Borrowed-space construction with explicit stride supplied as "number of scalars between elements".
 Vector_ (int m, int stride, S *data, bool)
template<int M>
 Vector_ (const Vec< M, ELT > &v)
 Convert a Vec to a Vector_.
Vector_operator= (const ELT &v)
 Fill current allocation with copies of element.
template<class EE >
Vector_operator= (const VectorBase< EE > &m)
template<class EE >
Vector_operator+= (const VectorBase< EE > &m)
template<class EE >
Vector_operator-= (const VectorBase< EE > &m)
Vector_operator*= (const StdNumber &t)
Vector_operator/= (const StdNumber &t)
Vector_operator+= (const ELT &b)
Vector_operator-= (const ELT &b)

Related Functions

(Note that these are not member functions.)
Matrix_<T> serialization and I/O

These methods are at namespace scope but are logically part of the Vector classes.

These deal with reading and writing Vectors 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 Vector as a whole.

template<class T >
std::ostream & operator<< (std::ostream &o, const VectorBase< T > &v)
 Output a human readable representation of a Vector to an std::ostream (like std::cout).
template<class T >
static std::istream & readVectorFromStream (std::istream &in, Vector_< T > &out)
 Read in a Vector_<T> from a stream, as a sequence of space-separated or comma-separated values optionally surrounded by parentheses (), or square brackets [], or the "transposed" ~() or ~[].
template<class T >
static std::istream & fillVectorFromStream (std::istream &in, Vector_< T > &out)
 Read in a fixed number of elements from a stream into a Vector.
template<class T >
std::istream & operator>> (std::istream &in, Vector_< T > &out)
 Read Vector_<T> from a stream as a sequence of space- or comma-separated values of type T, optionally delimited by parentheses, or brackets, and preceded by "~".

Detailed Description

template<class ELT>
class SimTK::Vector_< ELT >

This is the Vector class intended to appear in user code.

It can be a fixed-size view of someone else's data, or can be a resizable data owner itself, although of course it will always have just one column.


Constructor & Destructor Documentation

template<class ELT>
SimTK::Vector_< ELT >::Vector_ ( ) [inline]
template<class ELT>
SimTK::Vector_< ELT >::Vector_ ( const Vector_< ELT > &  src) [inline]
template<class ELT>
SimTK::Vector_< ELT >::Vector_ ( const Base src) [inline]
template<class ELT>
SimTK::Vector_< ELT >::Vector_ ( const BaseNeg src) [inline]
template<class ELT>
SimTK::Vector_< ELT >::Vector_ ( int  m) [inline, explicit]
template<class ELT>
SimTK::Vector_< ELT >::Vector_ ( int  m,
const ELT *  cppInitialValues 
) [inline]
template<class ELT>
SimTK::Vector_< ELT >::Vector_ ( int  m,
const ELT &  initialValue 
) [inline]
template<class ELT>
SimTK::Vector_< ELT >::Vector_ ( int  m,
const S *  cppData,
bool   
) [inline]

Construct a Vector which uses borrowed space with assumed element-to-element stride equal to the C++ element spacing.

Last parameter is a dummy to avoid overload conflicts when ELT=S; pass it as "true".

template<class ELT>
SimTK::Vector_< ELT >::Vector_ ( int  m,
S *  cppData,
bool   
) [inline]
template<class ELT>
SimTK::Vector_< ELT >::Vector_ ( int  m,
int  stride,
const S *  data,
bool   
) [inline]

Borrowed-space construction with explicit stride supplied as "number of scalars between elements".

Last parameter is a dummy to avoid overload conflicts; pass it as "true".

template<class ELT>
SimTK::Vector_< ELT >::Vector_ ( int  m,
int  stride,
S *  data,
bool   
) [inline]
template<class ELT>
template<int M>
SimTK::Vector_< ELT >::Vector_ ( const Vec< M, ELT > &  v) [inline, explicit]

Convert a Vec to a Vector_.


Member Function Documentation

template<class ELT>
Vector_& SimTK::Vector_< ELT >::operator= ( const Vector_< ELT > &  src) [inline]
template<class ELT>
Vector_& SimTK::Vector_< ELT >::operator= ( const ELT &  t) [inline]

Fill current allocation with copies of element.

Note that this is not the same behavior as assignment for Matrices, where only the diagonal is set (and everything else is set to zero.)

Reimplemented from SimTK::VectorBase< ELT >.

template<class ELT>
template<class EE >
Vector_& SimTK::Vector_< ELT >::operator= ( const VectorBase< EE > &  m) [inline]

Reimplemented from SimTK::VectorBase< ELT >.

template<class ELT>
template<class EE >
Vector_& SimTK::Vector_< ELT >::operator+= ( const VectorBase< EE > &  m) [inline]

Reimplemented from SimTK::VectorBase< ELT >.

template<class ELT>
template<class EE >
Vector_& SimTK::Vector_< ELT >::operator-= ( const VectorBase< EE > &  m) [inline]

Reimplemented from SimTK::VectorBase< ELT >.

template<class ELT>
Vector_& SimTK::Vector_< ELT >::operator*= ( const StdNumber t) [inline]

Reimplemented from SimTK::VectorBase< ELT >.

template<class ELT>
Vector_& SimTK::Vector_< ELT >::operator/= ( const StdNumber t) [inline]

Reimplemented from SimTK::VectorBase< ELT >.

template<class ELT>
Vector_& SimTK::Vector_< ELT >::operator+= ( const ELT &  b) [inline]
template<class ELT>
Vector_& SimTK::Vector_< ELT >::operator-= ( const ELT &  b) [inline]

Friends And Related Function Documentation

template<class T >
std::ostream & operator<< ( std::ostream &  o,
const VectorBase< T > &  v 
) [related]

Output a human readable representation of a Vector to an std::ostream (like std::cout).

The format is ~[ elements ] where elements is a space-separated list of the Vector's contents output by invoking the "<<" operator on the elements. This function will not compile if the element type does not support the "<<" operator. No newline is issued before or after the output.

template<class T >
static std::istream & readVectorFromStream ( std::istream &  in,
Vector_< T > &  out 
) [related]

Read in a Vector_<T> from a stream, as a sequence of space-separated or comma-separated values optionally surrounded by parentheses (), or square brackets [], or the "transposed" ~() or ~[].

In the case that the transpose operator is present, the parentheses or brackets are required, otherwise they are optional. We will continue to read elements of type T from the stream until we find a reason to stop, using type T's stream extraction operator>>() to read in each element and resizing the Vector as necessary. If the data is bracketed, we'll read until we hit the closing bracket. If it is not bracketed, we'll read until we hit eof() or get an error such as the element extractor setting the stream's fail bit due to bad formatting. On successful return, the stream will be positioned right after the final read-in element or terminating bracket, and the stream's status will be good() or eof(). We will not consume trailing whitespace after bracketed elements; that means the stream might actually be empty even if we don't return eof(). If you want to know whether there is anything else in the stream, follow this call with the STL whitespace skipper std::ws() like this:

    if (readVectorFromStream(in,vec) && !in.eof()) 
        std::ws(in); // might take us to eof
    if (in.fail()) {...} // probably a formatting error
    else {
        // Here if the stream is good() then there is more to read; if the
        // stream got used up the status is guaranteed to be eof().
    }

A compilation error will occur if you try to use this method on an Vector_<T> for a type T for which there is no stream extraction operator>>().

Note:
If you want to fill a resizeable Vector_<T> with a fixed amount of data from the stream, resize() the Vector to the appropriate length and then use fillVectorFromStream() instead.
See also:
fillVectorFromStream()
template<class T >
static std::istream & fillVectorFromStream ( std::istream &  in,
Vector_< T > &  out 
) [related]

Read in a fixed number of elements from a stream into a Vector.

We expect to read in exactly size() elements of type T, using type T's stream extraction operator>>(). This will stop reading when we've read size() elements, or set the fail bit in the stream if we run out of elements or if any element's extract operator sets the fail bit. On successful return, all size() elements will have been set, the stream will be positioned right after the final read-in element or terminating bracket, and the stream's status will be good() or eof(). We will not consume trailing whitespace after reading all the elements; that means the stream might actually be empty even if we don't return eof(). If you want to know whether there is anything else in the stream, follow this call with std::ws() like this:

    if (fillVectorFromStream(in,vec))
        if (!in.eof()) std::ws(in); // might take us to eof
    if (in.fail()) {...} // deal with I/O or formatting error
    // Here if the stream is good() then there is more to read; if the
    // stream got used up the status is guaranteed to be eof().

A compilation error will occur if you try to use this method on a Vector_<T> for a type T for which there is no stream extraction operator>>().

Note:
If you want to read in a variable number of elements and have the Vector_<T> resized as needed, use readVectorFromStream() instead.
See also:
readVectorFromStream()
template<class T >
std::istream & operator>> ( std::istream &  in,
Vector_< T > &  out 
) [related]

Read Vector_<T> from a stream as a sequence of space- or comma-separated values of type T, optionally delimited by parentheses, or brackets, and preceded by "~".

The Vector_<T> may be an owner (variable size) or a view (fixed size n). In the case of an owner, we'll read all the elements in brackets or until eof if there are no brackets. In the case of a view, there must be exactly n elements in brackets, or if there are no brackets we'll consume exactly n elements and then stop. Each element is read in with its own operator ">>" so this won't work if no such operator is defined for type T.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines