YARP
Yet Another Robot Platform
yarp::sig::VectorOf< T > Class Template Reference

Provides: More...

#include <yarp/sig/Vector.h>

+ Inheritance diagram for yarp::sig::VectorOf< T >:

Detailed Description

template<class T>
class yarp::sig::VectorOf< T >

Provides:

  • push_back(), pop_back() to add/remove an element at the end of the vector
  • resize(), to create an array of elements
  • clear(), to clean the array (remove all elements)
  • use [] to access single elements without range checking
  • use size() to get the current size of the Vector
  • use operator= to copy Vectors
  • read/write network methods Warning: the class is designed to work with simple types (i.e. types that do not allocate internal memory). Template instantiation needs to be checked to avoid unresolved externals. Network communication assumes same data representation (endianness) between machines.

Definition at line 29 of file Vector.h.

Public Member Functions

 VectorOf ()
 
 VectorOf (size_t size)
 
 VectorOf (size_t s, const T &def)
 Build a vector and initialize it with def. More...
 
 VectorOf (size_t s, const T *p)
 Builds a vector and initialize it with values from 'p'. More...
 
 VectorOf (const VectorOf &r)
 
const VectorOf< T > & operator= (const VectorOf< T > &r)
 Copy operator;. More...
 
virtual size_t getElementSize () const override
 
virtual int getBottleTag () const override
 
virtual size_t getListSize () const override
 
virtual const char * getMemoryBlock () const override
 
virtual char * getMemoryBlock () override
 
const T * getFirst () const
 
T * getFirst ()
 
T * data ()
 Return a pointer to the first element of the vector. More...
 
const T * data () const
 Return a pointer to the first element of the vector, const version. More...
 
virtual void resize (size_t size) override
 Resize the vector. More...
 
void resize (size_t size, const T &def)
 Resize the vector and initilize the element to a default value. More...
 
void push_back (const T &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...
 
T & operator[] (size_t i)
 Single element access, no range check. More...
 
const T & operator[] (size_t i) const
 Single element access, no range check, const version. More...
 
T & operator() (size_t i)
 Single element access, no range check. More...
 
const T & operator() (size_t i) const
 Single element access, no range check, const version. 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...
 
std::string toString (int precision=-1, int width=-1) const
 Creates a string object containing a text representation of the object. More...
 
VectorOf< T > 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 VectorOf< T > &v)
 Set a portion of this vector with the values of the specified vector. More...
 
const VectorOf< T > & operator= (T v)
 Set all elements of the vector to a scalar. More...
 
bool operator== (const VectorOf< T > &r) const
 True iff all elements of 'a' match all element of 'b'. More...
 
void clear ()
 
virtual yarp::os::Type getType () const override
 
- Public Member Functions inherited from yarp::sig::VectorBase
virtual bool read (yarp::os::ConnectionReader &connection) override
 Read this object from a network connection. More...
 
virtual bool write (yarp::os::ConnectionWriter &connection) const override
 Write vector to a connection. More...
 
- Public Member Functions inherited from yarp::os::PortReader
virtual ~PortReader ()
 Destructor. More...
 
virtual Type getReadType () const
 
- Public Member Functions inherited from yarp::os::PortWriter
virtual ~PortWriter ()
 Destructor. More...
 
virtual void onCompletion () const
 This is called when the port has finished all writing operations. More...
 
virtual void onCommencement () const
 This is called when the port is about to begin writing operations. More...
 
virtual yarp::os::Type getWriteType () const
 

Private Member Functions

void _updatePointers ()
 

Private Attributes

yarp::os::ManagedBytes bytes
 
T * first
 
size_t len
 

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...
 
- Protected Member Functions inherited from yarp::sig::VectorBase
virtual std::string getFormatStr (int tag) const
 

Constructor & Destructor Documentation

◆ VectorOf() [1/5]

template<class T>
yarp::sig::VectorOf< T >::VectorOf ( )
inline

Definition at line 133 of file Vector.h.

◆ VectorOf() [2/5]

template<class T>
yarp::sig::VectorOf< T >::VectorOf ( size_t  size)
inline

Definition at line 140 of file Vector.h.

◆ VectorOf() [3/5]

template<class T>
yarp::sig::VectorOf< T >::VectorOf ( size_t  s,
const T &  def 
)
inline

Build a vector and initialize it with def.

Parameters
sthe size
defa default value used to fill the vector

Definition at line 150 of file Vector.h.

◆ VectorOf() [4/5]

template<class T>
yarp::sig::VectorOf< T >::VectorOf ( size_t  s,
const T *  p 
)
inline

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

Copies memory.

Parameters
sthe size of the data to be copied
T*the pointer to the data

Definition at line 161 of file Vector.h.

◆ VectorOf() [5/5]

template<class T>
yarp::sig::VectorOf< T >::VectorOf ( const VectorOf< T > &  r)
inline

Definition at line 169 of file Vector.h.

Member Function Documentation

◆ _updatePointers()

template<class T>
void yarp::sig::VectorOf< T >::_updatePointers ( )
inlineprivate

Definition at line 123 of file Vector.h.

◆ clear()

template<class T>
void yarp::sig::VectorOf< T >::clear ( )
inline

Definition at line 470 of file Vector.h.

◆ data() [1/2]

template<class T>
T* yarp::sig::VectorOf< T >::data ( )
inline

Return a pointer to the first element of the vector.

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

Definition at line 230 of file Vector.h.

◆ data() [2/2]

template<class T>
const T* yarp::sig::VectorOf< T >::data ( ) const
inline

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

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

Definition at line 238 of file Vector.h.

◆ getBottleTag()

template<class T>
virtual int yarp::sig::VectorOf< T >::getBottleTag ( ) const
inlineoverridevirtual

Implements yarp::sig::VectorBase.

Definition at line 197 of file Vector.h.

◆ getElementSize()

template<class T>
virtual size_t yarp::sig::VectorOf< T >::getElementSize ( ) const
inlineoverridevirtual

Implements yarp::sig::VectorBase.

Definition at line 193 of file Vector.h.

◆ getFirst() [1/2]

template<class T>
const T* yarp::sig::VectorOf< T >::getFirst ( ) const
inline

Definition at line 216 of file Vector.h.

◆ getFirst() [2/2]

template<class T>
T* yarp::sig::VectorOf< T >::getFirst ( )
inline

Definition at line 221 of file Vector.h.

◆ getListSize()

template<class T>
virtual size_t yarp::sig::VectorOf< T >::getListSize ( ) const
inlineoverridevirtual

Implements yarp::sig::VectorBase.

Definition at line 201 of file Vector.h.

◆ getMemoryBlock() [1/2]

template<class T>
virtual const char* yarp::sig::VectorOf< T >::getMemoryBlock ( ) const
inlineoverridevirtual

Implements yarp::sig::VectorBase.

Definition at line 206 of file Vector.h.

◆ getMemoryBlock() [2/2]

template<class T>
virtual char* yarp::sig::VectorOf< T >::getMemoryBlock ( )
inlineoverridevirtual

Implements yarp::sig::VectorBase.

Definition at line 211 of file Vector.h.

◆ getType()

template<class T>
virtual yarp::os::Type yarp::sig::VectorOf< T >::getType ( ) const
inlineoverridevirtual

Reimplemented from yarp::os::Portable.

Definition at line 477 of file Vector.h.

◆ length()

template<class T>
size_t yarp::sig::VectorOf< T >::length ( ) const
inline

Get the length of the vector.

Returns
the length of the vector.

Definition at line 342 of file Vector.h.

◆ operator()() [1/2]

template<class T>
T& yarp::sig::VectorOf< T >::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 319 of file Vector.h.

◆ operator()() [2/2]

template<class T>
const T& yarp::sig::VectorOf< T >::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 329 of file Vector.h.

◆ operator=() [1/2]

template<class T>
const VectorOf<T>& yarp::sig::VectorOf< T >::operator= ( const VectorOf< T > &  r)
inline

Copy operator;.

Definition at line 177 of file Vector.h.

◆ operator=() [2/2]

template<class T>
const VectorOf<T>& yarp::sig::VectorOf< T >::operator= ( v)
inline

Set all elements of the vector to a scalar.

Definition at line 437 of file Vector.h.

◆ operator==()

template<class T>
bool yarp::sig::VectorOf< T >::operator== ( const VectorOf< T > &  r) const
inline

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

Definition at line 450 of file Vector.h.

◆ operator[]() [1/2]

template<class T>
T& yarp::sig::VectorOf< T >::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 299 of file Vector.h.

◆ operator[]() [2/2]

template<class T>
const T& yarp::sig::VectorOf< T >::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 309 of file Vector.h.

◆ pop_back()

template<class T>
void yarp::sig::VectorOf< T >::pop_back ( void  )
inline

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

Definition at line 285 of file Vector.h.

◆ push_back()

template<class T>
void yarp::sig::VectorOf< T >::push_back ( const T &  elem)
inline

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

Definition at line 274 of file Vector.h.

◆ resize() [1/2]

template<class T>
virtual void yarp::sig::VectorOf< T >::resize ( size_t  size)
inlineoverridevirtual

Resize the vector.

Parameters
sthe new size

Implements yarp::sig::VectorBase.

Definition at line 245 of file Vector.h.

◆ resize() [2/2]

template<class T>
void yarp::sig::VectorOf< T >::resize ( size_t  size,
const T &  def 
)
inline

Resize the vector and initilize the element to a default value.

Parameters
sthe new size
defthe default value

Definition at line 261 of file Vector.h.

◆ setSubvector()

template<class T>
bool yarp::sig::VectorOf< T >::setSubvector ( int  position,
const VectorOf< T > &  v 
)
inline

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 425 of file Vector.h.

◆ size()

template<class T>
size_t yarp::sig::VectorOf< T >::size ( ) const
inline

Definition at line 334 of file Vector.h.

◆ subVector()

template<class T>
VectorOf<T> yarp::sig::VectorOf< T >::subVector ( unsigned int  first,
unsigned int  last 
) const
inline

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 404 of file Vector.h.

◆ toString()

template<class T>
std::string yarp::sig::VectorOf< T >::toString ( int  precision = -1,
int  width = -1 
) const
inline

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

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 362 of file Vector.h.

◆ zero()

template<class T>
void yarp::sig::VectorOf< T >::zero ( )
inline

Zero the elements of the vector.

Definition at line 348 of file Vector.h.

Member Data Documentation

◆ bytes

template<class T>
yarp::os::ManagedBytes yarp::sig::VectorOf< T >::bytes
private

Definition at line 119 of file Vector.h.

◆ first

template<class T>
T* yarp::sig::VectorOf< T >::first
private

Definition at line 120 of file Vector.h.

◆ len

template<class T>
size_t yarp::sig::VectorOf< T >::len
private

Definition at line 121 of file Vector.h.


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