YARP  2.3.70.1
Yet Another Robot Platform
yarp::sig::Vector Class Reference

A class for a Vector. More...

#include <yarp/sig/Vector.h>

+ Inheritance diagram for yarp::sig::Vector:

Public Member Functions

 Vector ()
 
 Vector (size_t s)
 
 Vector (size_t s, const double &def)
 Build a vector and initialize it with def. More...
 
 ~Vector ()
 
 Vector (size_t s, const double *p)
 Builds a vector and initialize it with values from 'p'. More...
 
 Vector (const Vector &r)
 Copy constructor. More...
 
const Vectoroperator= (const Vector &r)
 Copy operator;. More...
 
YARP_DEPRECATED void size (size_t s)
 Resize the vector, (warning: deprecated, use resize) here to maintain compatibility with the old Vector class. More...
 
void resize (size_t s)
 Resize the vector. More...
 
void resize (size_t size, const double &def)
 Resize the vector, if the vector is not empty preserve old content. More...
 
size_t size () const
 
size_t length () const
 Get the length of the vector. More...
 
void zero ()
 Zero the elements of the vector. More...
 
yarp::os::ConstString toString (int precision=-1, int width=-1) const
 Creates a string object containing a text representation of the object. More...
 
Vector subVector (unsigned int first, unsigned int last) const
 Creates and returns a new vector, being the portion of the original vector defined by the first and last indexes of the items to be included in the subvector. More...
 
bool setSubvector (int position, const Vector &v)
 Set a portion of this vector with the values of the specified vector. More...
 
const Vectoroperator= (double v)
 Set all elements of the vector to a scalar. More...
 
double * data ()
 Return a pointer to the first element of the vector. More...
 
const double * data () const
 Return a pointer to the first element of the vector, const version. More...
 
bool operator== (const yarp::sig::Vector &r) const
 True iff all elements of 'a' match all element of 'b'. More...
 
void push_back (const double &elem)
 Push a new element in the vector: size is changed. More...
 
void pop_back (void)
 Pop an element out of the vector: size is changed. More...
 
double & operator[] (size_t i)
 Single element access, no range check. More...
 
const double & operator[] (size_t i) const
 Single element access, no range check, const version. More...
 
double & operator() (size_t i)
 Single element access, no range check. More...
 
const double & operator() (size_t i) const
 Single element access, no range check, const version. More...
 
void clear ()
 Clears out the vector, it does not reallocate the buffer, but just sets the dynamic size to 0. More...
 
virtual bool read (yarp::os::ConnectionReader &connection) YARP_OVERRIDE
 Read this object from a network connection. More...
 
virtual bool write (yarp::os::ConnectionWriter &connection) YARP_OVERRIDE
 Write vector to a connection. More...
 
virtual yarp::os::Type getType () YARP_OVERRIDE
 
- Public Member Functions inherited from yarp::os::PortReader
virtual ~PortReader ()
 Destructor. More...
 
virtual Type getReadType ()
 
- Public Member Functions inherited from yarp::os::PortWriter
virtual ~PortWriter ()
 Destructor. More...
 
virtual void onCompletion ()
 This is called when the port has finished all writing operations. More...
 
virtual void onCommencement ()
 This is called when the port is about to begin writing operations. More...
 
virtual Type getWriteType ()
 

Private Attributes

VectorOf< double > storage
 

Additional Inherited Members

- Static Public Member Functions inherited from yarp::os::Portable
static bool copyPortable (PortWriter &writer, PortReader &reader)
 Copy one portable to another, via writing and reading. More...
 

Detailed Description

A class for a Vector.

A Vector can be sent/read to/from a port. Use the [] and () operator for single element access.

Examples:
os/portable_pair.cpp.

Definition at line 272 of file Vector.h.

Constructor & Destructor Documentation

◆ Vector() [1/5]

yarp::sig::Vector::Vector ( )
inline

Definition at line 277 of file Vector.h.

◆ Vector() [2/5]

yarp::sig::Vector::Vector ( size_t  s)
inlineexplicit

Definition at line 280 of file Vector.h.

◆ Vector() [3/5]

yarp::sig::Vector::Vector ( size_t  s,
const double &  def 
)
inlineexplicit

Build a vector and initialize it with def.

Parameters
sthe size
defa default value used to fill the vector

Definition at line 288 of file Vector.h.

◆ ~Vector()

yarp::sig::Vector::~Vector ( )
inline

Definition at line 293 of file Vector.h.

◆ Vector() [4/5]

Vector::Vector ( size_t  s,
const double *  p 
)

Builds a vector and initialize it with values from 'p'.

Copies memory.

Definition at line 148 of file Vector.cpp.

◆ Vector() [5/5]

yarp::sig::Vector::Vector ( const Vector r)
inline

Copy constructor.

Definition at line 305 of file Vector.h.

Member Function Documentation

◆ clear()

void yarp::sig::Vector::clear ( )
inline

Clears out the vector, it does not reallocate the buffer, but just sets the dynamic size to 0.

Definition at line 468 of file Vector.h.

◆ data() [1/2]

double* yarp::sig::Vector::data ( )
inline

Return a pointer to the first element of the vector.

Returns
a pointer to double (or NULL if the vector is of zero length)

Definition at line 400 of file Vector.h.

◆ data() [2/2]

const double* yarp::sig::Vector::data ( ) const
inline

Return a pointer to the first element of the vector, const version.

Returns
a (const) pointer to double (or NULL if the vector is of zero length)

Definition at line 408 of file Vector.h.

◆ getType()

virtual yarp::os::Type yarp::sig::Vector::getType ( )
inlinevirtual

Reimplemented from yarp::os::Portable.

Definition at line 484 of file Vector.h.

◆ length()

size_t yarp::sig::Vector::length ( ) const
inline

Get the length of the vector.

Returns
the length of the vector.

Definition at line 352 of file Vector.h.

◆ operator()() [1/2]

double& yarp::sig::Vector::operator() ( size_t  i)
inline

Single element access, no range check.

Parameters
ithe index of the element to access.
Returns
a reference to the requested element.

Definition at line 453 of file Vector.h.

◆ operator()() [2/2]

const double& yarp::sig::Vector::operator() ( size_t  i) const
inline

Single element access, no range check, const version.

Parameters
ithe index of the element to access.
Returns
a reference to the requested element.

Definition at line 461 of file Vector.h.

◆ operator=() [1/2]

const Vector & Vector::operator= ( const Vector r)

Copy operator;.

Definition at line 133 of file Vector.cpp.

◆ operator=() [2/2]

const Vector & Vector::operator= ( double  v)

Set all elements of the vector to a scalar.

Definition at line 160 of file Vector.cpp.

◆ operator==()

bool Vector::operator== ( const yarp::sig::Vector r) const

True iff all elements of 'a' match all element of 'b'.

Definition at line 170 of file Vector.cpp.

◆ operator[]() [1/2]

double& yarp::sig::Vector::operator[] ( size_t  i)
inline

Single element access, no range check.

Parameters
ithe index of the element to access.
Returns
a reference to the requested element.

Definition at line 437 of file Vector.h.

◆ operator[]() [2/2]

const double& yarp::sig::Vector::operator[] ( size_t  i) const
inline

Single element access, no range check, const version.

Parameters
ithe index of the element to access.
Returns
a reference to the requested element.

Definition at line 445 of file Vector.h.

◆ pop_back()

void yarp::sig::Vector::pop_back ( void  )
inline

Pop an element out of the vector: size is changed.

Definition at line 427 of file Vector.h.

◆ push_back()

void yarp::sig::Vector::push_back ( const double &  elem)
inline

Push a new element in the vector: size is changed.

Definition at line 419 of file Vector.h.

◆ read()

bool Vector::read ( yarp::os::ConnectionReader reader)
virtual

Read this object from a network connection.

Override this for your particular class.

Parameters
readeran interface to the network connection for reading
Returns
true iff the object is successfully read

Implements yarp::os::Portable.

Definition at line 189 of file Vector.cpp.

◆ resize() [1/2]

void yarp::sig::Vector::resize ( size_t  s)
inline

Resize the vector.

Parameters
sthe new size

Definition at line 330 of file Vector.h.

◆ resize() [2/2]

void yarp::sig::Vector::resize ( size_t  size,
const double &  def 
)
inline

Resize the vector, if the vector is not empty preserve old content.

Parameters
sizethe new size
defa default value used to fill the vector

Definition at line 340 of file Vector.h.

◆ setSubvector()

bool Vector::setSubvector ( int  position,
const Vector v 
)

Set a portion of this vector with the values of the specified vector.

If the specified vector v is to big the method does not resize the vector, but return false.

Parameters
positionindex of the first value to set
vvector containing the values to set
Returns
true if the operation succeeded, false otherwise

Definition at line 124 of file Vector.cpp.

◆ size() [1/2]

YARP_DEPRECATED void yarp::sig::Vector::size ( size_t  s)
inline

Resize the vector, (warning: deprecated, use resize) here to maintain compatibility with the old Vector class.

Parameters
sthe new size
Deprecated:
since YARP 2.3.65

Definition at line 320 of file Vector.h.

◆ size() [2/2]

size_t yarp::sig::Vector::size ( ) const
inline

Definition at line 345 of file Vector.h.

◆ subVector()

Vector Vector::subVector ( unsigned int  first,
unsigned int  last 
) const

Creates and returns a new vector, being the portion of the original vector defined by the first and last indexes of the items to be included in the subvector.

The indexes are checked: if wrong, a null vector is returned.

Definition at line 112 of file Vector.cpp.

◆ toString()

ConstString Vector::toString ( int  precision = -1,
int  width = -1 
) const

Creates a string object containing a text representation of the object.

Quick implementation, space for improvement.

Useful for printing. To get a nice format the optional parameters precision and width may be used (same meaning as in printf and cout).

Parameters
precisionthe number of digits to be printed after the decimal point.
widthminimum number of characters to be printed. If the value to be printed is shorter than this number, the result is padded with blank spaces. The value is never truncated. If width is specified the inter-value separator is a blank space, otherwise it is a tab. Warning: the string format might change in the future. This method is here to ease debugging.

Definition at line 90 of file Vector.cpp.

◆ write()

bool Vector::write ( yarp::os::ConnectionWriter connection)
virtual

Write vector to a connection.

return true iff a vector was written correctly

Implements yarp::os::Portable.

Definition at line 211 of file Vector.cpp.

◆ zero()

void Vector::zero ( )

Zero the elements of the vector.

Definition at line 155 of file Vector.cpp.

Member Data Documentation

◆ storage

VectorOf<double> yarp::sig::Vector::storage
private

Definition at line 274 of file Vector.h.


The documentation for this class was generated from the following files: