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

Provides: More...

#include <yarp/sig/Vector.h>

Public Types

using iterator = typename std::vector< T >::iterator
 
using const_iterator = typename std::vector< T >::const_iterator
 

Public Member Functions

 VectorOf ()=default
 
 VectorOf (size_t size)
 
 VectorOf (std::initializer_list< T > values)
 Initializer list constructor. More...
 
 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...
 
 VectorOf (VectorOf< T > &&other) noexcept
 Move constructor. More...
 
VectorOfoperator= (VectorOf< T > &&other) noexcept
 Move assignment operator. More...
 
size_t getElementSize () const override
 
int getBottleTag () const override
 
size_t getListSize () const override
 
const char * getMemoryBlock () const override
 
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...
 
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 reserve (size_t size)
 reserve, increase the capacity of the vector to a value that's greater or equal to size. More...
 
void push_back (const T &elem)
 Push a new element in the vector: size is changed. More...
 
void push_back (T &&elem)
 Move a new element in the vector: size is changed. More...
 
template<typename... _Args>
T & emplace_back (_Args &&... args)
 Construct a new element in the vector: size is changed. More...
 
void pop_back ()
 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...
 
size_t capacity () const
 capacity 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...
 
iterator begin () noexcept
 Returns an iterator to the beginning of the VectorOf. More...
 
iterator end () noexcept
 Returns an iterator to the end of the VectorOf. More...
 
const_iterator begin () const noexcept
 Returns a const iterator to the beginning of the VectorOf. More...
 
const_iterator end () const noexcept
 Returns a const iterator to the end of the VectorOf. More...
 
const_iterator cbegin () const noexcept
 Returns a const iterator to the beginning of the VectorOf. More...
 
const_iterator cend () const noexcept
 Returns a const iterator to the end of the VectorOf. More...
 
void clear ()
 
yarp::os::Type getType () const override
 

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

Member Typedef Documentation

◆ const_iterator

template<class T >
using yarp::sig::VectorOf< T >::const_iterator = typename std::vector<T>::const_iterator

Definition at line 128 of file Vector.h.

◆ iterator

template<class T >
using yarp::sig::VectorOf< T >::iterator = typename std::vector<T>::iterator

Definition at line 127 of file Vector.h.

Constructor & Destructor Documentation

◆ VectorOf() [1/7]

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

◆ VectorOf() [2/7]

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

Definition at line 132 of file Vector.h.

◆ VectorOf() [3/7]

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

Initializer list constructor.

Parameters
[in]values,listof values with which initialize the Vector.

Definition at line 139 of file Vector.h.

◆ VectorOf() [4/7]

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

◆ VectorOf() [5/7]

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

◆ VectorOf() [6/7]

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

Definition at line 162 of file Vector.h.

◆ VectorOf() [7/7]

template<class T >
yarp::sig::VectorOf< T >::VectorOf ( VectorOf< T > &&  other)
inlinenoexcept

Move constructor.

Parameters
otherthe VectorOf to be moved

Definition at line 181 of file Vector.h.

Member Function Documentation

◆ begin() [1/2]

template<class T >
const_iterator yarp::sig::VectorOf< T >::begin ( ) const
inlinenoexcept

Returns a const iterator to the beginning of the VectorOf.

Definition at line 497 of file Vector.h.

◆ begin() [2/2]

template<class T >
iterator yarp::sig::VectorOf< T >::begin ( )
inlinenoexcept

Returns an iterator to the beginning of the VectorOf.

Definition at line 483 of file Vector.h.

◆ capacity()

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

capacity

Returns
the number of elements that the container has currently allocated space for.

Definition at line 370 of file Vector.h.

◆ cbegin()

template<class T >
const_iterator yarp::sig::VectorOf< T >::cbegin ( ) const
inlinenoexcept

Returns a const iterator to the beginning of the VectorOf.

Definition at line 511 of file Vector.h.

◆ cend()

template<class T >
const_iterator yarp::sig::VectorOf< T >::cend ( ) const
inlinenoexcept

Returns a const iterator to the end of the VectorOf.

Definition at line 518 of file Vector.h.

◆ clear()

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

Definition at line 521 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 239 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 247 of file Vector.h.

◆ emplace_back()

template<class T >
template<typename... _Args>
T& yarp::sig::VectorOf< T >::emplace_back ( _Args &&...  args)
inline

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

Parameters
args,argumentsto be forwarded for constructing the new element.
Returns
the reference to the new element contructed.

Definition at line 302 of file Vector.h.

◆ end() [1/2]

template<class T >
const_iterator yarp::sig::VectorOf< T >::end ( ) const
inlinenoexcept

Returns a const iterator to the end of the VectorOf.

Definition at line 504 of file Vector.h.

◆ end() [2/2]

template<class T >
iterator yarp::sig::VectorOf< T >::end ( )
inlinenoexcept

Returns an iterator to the end of the VectorOf.

Definition at line 490 of file Vector.h.

◆ getBottleTag()

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

Definition at line 201 of file Vector.h.

◆ getElementSize()

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

Definition at line 197 of file Vector.h.

◆ getFirst() [1/2]

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

Definition at line 229 of file Vector.h.

◆ getFirst() [2/2]

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

Definition at line 222 of file Vector.h.

◆ getListSize()

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

Definition at line 205 of file Vector.h.

◆ getMemoryBlock() [1/2]

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

Definition at line 210 of file Vector.h.

◆ getMemoryBlock() [2/2]

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

Definition at line 215 of file Vector.h.

◆ getType()

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

Definition at line 525 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 363 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 340 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 350 of file Vector.h.

◆ operator=() [1/3]

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

Copy operator;.

Definition at line 168 of file Vector.h.

◆ operator=() [2/3]

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

◆ operator=() [3/3]

template<class T >
VectorOf& yarp::sig::VectorOf< T >::operator= ( VectorOf< T > &&  other)
inlinenoexcept

Move assignment operator.

Parameters
otherthe VectorOf to be moved
Returns
this object

Definition at line 190 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 475 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 320 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 330 of file Vector.h.

◆ pop_back()

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

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

Definition at line 310 of file Vector.h.

◆ push_back() [1/2]

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

◆ push_back() [2/2]

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

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

Parameters
elem,elementto be moved.

Definition at line 291 of file Vector.h.

◆ reserve()

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

reserve, increase the capacity of the vector to a value that's greater or equal to size.

If size is greater than the current capacity(), new storage is allocated, otherwise the method does nothing.

Parameters
size,newsize of the vector.

Definition at line 275 of file Vector.h.

◆ resize() [1/2]

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

Resize the vector.

Parameters
sthe new size

Definition at line 254 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 264 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 454 of file Vector.h.

◆ size()

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

Definition at line 355 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 433 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 391 of file Vector.h.

◆ zero()

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

Zero the elements of the vector.

Definition at line 377 of file Vector.h.


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