YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
yarp::sig::VectorOf< T > Class Template Reference

Provides: More...

#include <yarp/sig/Vector.h>

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

Public Types

using value_type = T
 
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.
 
 VectorOf (size_t s, const T &def)
 Build a vector and initialize it with def.
 
 VectorOf (size_t s, const T *p)
 Builds a vector and initialize it with values from 'p'.
 
 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.
 
const T * data () const
 Return a pointer to the first element of the vector, const version.
 
void resize (size_t size) override
 Resize the vector.
 
void resize (size_t size, const T &def)
 Resize the vector and initilize the element to a default value.
 
void reserve (size_t size)
 reserve, increase the capacity of the vector to a value that's greater or equal to size.
 
void push_back (const T &elem)
 Push a new element in the vector: size is changed.
 
void push_back (T &&elem)
 Move a new element in the vector: size is changed.
 
template<typename... _Args>
T & emplace_back (_Args &&... args)
 Construct a new element in the vector: size is changed.
 
void pop_back ()
 Pop an element out of the vector: size is changed.
 
T & operator[] (size_t i)
 Single element access, no range check.
 
const T & operator[] (size_t i) const
 Single element access, no range check, const version.
 
T & operator() (size_t i)
 Single element access, no range check.
 
const T & operator() (size_t i) const
 Single element access, no range check, const version.
 
size_t size () const
 
size_t length () const
 Get the length of the vector.
 
size_t capacity () const
 capacity
 
void zero ()
 Zero the elements of the vector.
 
std::string toString (int precision=-1, int width=-1) const
 Creates a string object containing a text representation of the object.
 
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.
 
bool setSubvector (int position, const VectorOf< T > &v)
 Set a portion of this vector with the values of the specified vector.
 
const VectorOf< T > & operator= (T v)
 Set all elements of the vector to a scalar.
 
bool operator== (const VectorOf< T > &r) const
 True iff all elements of 'a' match all element of 'b'.
 
iterator begin () noexcept
 Returns an iterator to the beginning of the VectorOf.
 
iterator end () noexcept
 Returns an iterator to the end of the VectorOf.
 
const_iterator begin () const noexcept
 Returns a const iterator to the beginning of the VectorOf.
 
const_iterator end () const noexcept
 Returns a const iterator to the end of the VectorOf.
 
const_iterator cbegin () const noexcept
 Returns a const iterator to the beginning of the VectorOf.
 
const_iterator cend () const noexcept
 Returns a const iterator to the end of the VectorOf.
 
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.
 
bool write (yarp::os::ConnectionWriter &connection) const override
 Write vector to a connection.
 
- Public Member Functions inherited from yarp::os::PortReader
virtual ~PortReader ()
 Destructor.
 
virtual Type getReadType () const
 
- Public Member Functions inherited from yarp::os::PortWriter
virtual ~PortWriter ()
 Destructor.
 
virtual void onCompletion () const
 This is called when the port has finished all writing operations.
 
virtual void onCommencement () const
 This is called when the port is about to begin writing operations.
 
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.
 
- 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 124 of file Vector.h.

◆ iterator

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

Definition at line 123 of file Vector.h.

◆ value_type

template<class T >
using yarp::sig::VectorOf< T >::value_type = T

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 128 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 135 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 143 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 152 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 468 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 454 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 337 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 482 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 489 of file Vector.h.

◆ clear()

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

Definition at line 492 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 206 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 214 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 269 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 475 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 461 of file Vector.h.

◆ getBottleTag()

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

Implements yarp::sig::VectorBase.

Definition at line 168 of file Vector.h.

◆ getElementSize()

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

Implements yarp::sig::VectorBase.

Definition at line 164 of file Vector.h.

◆ getFirst() [1/2]

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

Definition at line 196 of file Vector.h.

◆ getFirst() [2/2]

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

Definition at line 189 of file Vector.h.

◆ getListSize()

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

Implements yarp::sig::VectorBase.

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

◆ getMemoryBlock() [2/2]

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

Implements yarp::sig::VectorBase.

Definition at line 182 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 496 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 330 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 307 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 317 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 437 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 446 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 287 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 297 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 277 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 249 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 258 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 242 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 221 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 231 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 423 of file Vector.h.

◆ size()

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

Definition at line 322 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 401 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 358 of file Vector.h.

◆ zero()

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

Zero the elements of the vector.

Definition at line 344 of file Vector.h.


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