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 >:

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)=default
 
VectorOf< T > & operator= (const VectorOf< T > &r)=default
 
 VectorOf (VectorOf< T > &&other) noexcept=default
 
VectorOfoperator= (VectorOf< T > &&other) noexcept=default
 
 ~VectorOf () override=default
 
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
 
- Public Member Functions inherited from yarp::sig::VectorBase
virtual size_t getElementSize () const =0
 
virtual int getBottleTag () const =0
 
virtual size_t getListSize () const =0
 
virtual const char * getMemoryBlock () const =0
 
virtual char * getMemoryBlock ()=0
 
virtual void resize (size_t size)=0
 
bool read (yarp::os::ConnectionReader &connection) override
 Read this object from a network connection. More...
 
bool write (yarp::os::ConnectionWriter &connection) const override
 Write vector to a connection. More...
 
bool read (ConnectionReader &reader) override=0
 Read this object from a network connection. More...
 
bool write (ConnectionWriter &writer) const override=0
 Write this object to a network connection. More...
 
virtual Type getType () const
 
- Public Member Functions inherited from yarp::os::PortReader
virtual ~PortReader ()
 Destructor. More...
 
virtual bool read (ConnectionReader &reader)=0
 Read this object from a network connection. More...
 
virtual Type getReadType () const
 
- Public Member Functions inherited from yarp::os::PortWriter
virtual ~PortWriter ()
 Destructor. More...
 
virtual bool write (ConnectionWriter &writer) const =0
 Write this object to a network connection. 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
 

Additional Inherited Members

- Static Public Member Functions inherited from yarp::os::Portable
static bool copyPortable (const 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
 

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.
Examples
dev/grabber_crop/grabber_crop.cpp.

Definition at line 116 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 123 of file Vector.h.

◆ iterator

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

Definition at line 122 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 127 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 134 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 142 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 151 of file Vector.h.

◆ VectorOf() [6/7]

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

◆ VectorOf() [7/7]

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

◆ ~VectorOf()

template<class T >
yarp::sig::VectorOf< T >::~VectorOf ( )
overridedefault

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 467 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 453 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 336 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 481 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 488 of file Vector.h.

◆ clear()

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

Definition at line 491 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 205 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 213 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 268 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 474 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 460 of file Vector.h.

◆ getBottleTag()

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

Implements yarp::sig::VectorBase.

Definition at line 167 of file Vector.h.

◆ getElementSize()

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

Implements yarp::sig::VectorBase.

Definition at line 163 of file Vector.h.

◆ getFirst() [1/2]

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

Definition at line 195 of file Vector.h.

◆ getFirst() [2/2]

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

Definition at line 188 of file Vector.h.

◆ getListSize()

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

Implements yarp::sig::VectorBase.

Definition at line 171 of file Vector.h.

◆ getMemoryBlock() [1/2]

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

Implements yarp::sig::VectorBase.

Definition at line 176 of file Vector.h.

◆ getMemoryBlock() [2/2]

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

Implements yarp::sig::VectorBase.

Definition at line 181 of file Vector.h.

◆ getType()

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

Reimplemented from yarp::os::Portable.

Definition at line 495 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 329 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 306 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 316 of file Vector.h.

◆ operator=() [1/3]

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

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

◆ operator=() [3/3]

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

◆ 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 445 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 286 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 296 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 276 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 248 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 257 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 241 of file Vector.h.

◆ resize() [1/2]

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

Resize the vector.

Parameters
sthe new size

Implements yarp::sig::VectorBase.

Definition at line 220 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 230 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 422 of file Vector.h.

◆ size()

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

Definition at line 321 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 400 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 357 of file Vector.h.

◆ zero()

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

Zero the elements of the vector.

Definition at line 343 of file Vector.h.


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