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

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

◆ iterator

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

Definition at line 124 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 129 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 136 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 144 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 153 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 469 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 455 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 338 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 483 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 490 of file Vector.h.

◆ clear()

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

Definition at line 493 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 207 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 215 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 270 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 476 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 462 of file Vector.h.

◆ getBottleTag()

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

Implements yarp::sig::VectorBase.

Definition at line 169 of file Vector.h.

◆ getElementSize()

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

Implements yarp::sig::VectorBase.

Definition at line 165 of file Vector.h.

◆ getFirst() [1/2]

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

Definition at line 197 of file Vector.h.

◆ getFirst() [2/2]

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

Definition at line 190 of file Vector.h.

◆ getListSize()

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

Implements yarp::sig::VectorBase.

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

◆ getMemoryBlock() [2/2]

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

Implements yarp::sig::VectorBase.

Definition at line 183 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 497 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 331 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 308 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 318 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 438 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 447 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 288 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 298 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 278 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 250 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 259 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 243 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 222 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 232 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 424 of file Vector.h.

◆ size()

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

Definition at line 323 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 402 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 359 of file Vector.h.

◆ zero()

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

Zero the elements of the vector.

Definition at line 345 of file Vector.h.


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