 |
YARP
Yet Another Robot Platform
|
|
Go to the documentation of this file.
10 #ifndef YARP_SIG_VECTOR_H
11 #define YARP_SIG_VECTOR_H
33 template<
class T>
class VectorOf;
63 virtual void resize(
size_t size) = 0;
124 std::vector<T> bytes;
127 using iterator =
typename std::vector<T>::iterator;
139 VectorOf(std::initializer_list<T> values) : bytes(values) {
159 memcpy(this->
data(), p,
sizeof(T)*s);
171 if (
this == &r)
return *
this;
192 bytes = std::move(other.bytes);
202 return BottleTagMap <T>();
212 return reinterpret_cast<const char*
>(this->
data());
217 return reinterpret_cast<char*
>(this->
data());
219 #ifndef YARP_NO_DEPRECATED // since YARP 3.2.0
221 " or cbegin() if you need the iterator")
228 " or begin() if you need the iterator")
233 #endif // YARP_NO_DEPRECATED
240 {
return bytes.empty() ? nullptr : &(bytes.at(0)); }
248 {
return bytes.empty() ? nullptr : &(bytes.at(0)); }
267 std::fill(bytes.begin(), bytes.end(), def);
284 bytes.push_back(elem);
293 bytes.push_back(std::move(elem));
301 template<
typename... _Args>
304 bytes.emplace_back(std::forward<_Args>(args)...);
342 return this->
data()[i];
352 return this->
data()[i];
364 {
return this->
size();}
371 return bytes.capacity();
379 std::fill(bytes.begin(), bytes.end(), 0);
391 std::string
toString(
int precision=-1,
int width=-1)
const
393 std::string
ret =
"";
395 const size_t buffSize = 256;
397 std::string formatStr;
400 formatStr =
"% .*lf\t";
401 for (c=0;c<
length();c++) {
402 snprintf(tmp, buffSize, formatStr.c_str(), precision, (*
this)[c]);
407 formatStr =
"% *.*lf ";
409 snprintf(tmp, buffSize, formatStr.c_str(), width, precision, (*
this)[c]);
416 for (c=0;c<
length();c++) {
417 snprintf(tmp, buffSize, formatStr.c_str(), (*
this)[c]);
423 return ret.substr(0,
ret.length()-1);
436 if ((first<=last)&&((
int)last<(
int)this->
size()))
439 for (
unsigned int k=first; k<=last; k++)
440 ret[k-first]=(*
this)[k];
456 if (position+v.
size() > this->size())
458 for (
size_t i=0;i<v.
size();i++)
459 (*
this)[position+i] = v(i);
468 std::fill(bytes.begin(), bytes.end(), v);
477 return bytes == r.bytes;
484 return bytes.begin();
498 return bytes.begin();
512 return bytes.cbegin();
535 #endif // YARP_SIG_VECTOR_H
virtual char * getMemoryBlock()=0
This is a base class for objects that can be both read from and be written to the YARP network.
void resize(size_t size) override
Resize the vector.
char * getMemoryBlock() override
const char * getMemoryBlock() const override
const VectorOf< T > & operator=(T v)
Set all elements of the vector to a scalar.
const_iterator cbegin() const noexcept
Returns a const iterator to the beginning of the VectorOf.
void resize(size_t size, const T &def)
Resize the vector and initilize the element to a default value.
int getBottleTag() const override
VectorOf(size_t s, const T *p)
Builds a vector and initialize it with values from 'p'.
virtual std::string getFormatStr(int tag) const
VectorOf & operator=(VectorOf< T > &&other) noexcept
Move assignment operator.
const_iterator end() const noexcept
Returns a const iterator to the end of the VectorOf.
T & operator()(size_t i)
Single element access, no range check.
const_iterator begin() const noexcept
Returns a const iterator to the beginning of the VectorOf.
const T & operator()(size_t i) const
Single element access, no range check, const version.
typename std::vector< unsigned char >::iterator iterator
virtual size_t getListSize() const =0
static Type byName(const char *name)
const_iterator cend() const noexcept
Returns a const iterator to the end of the VectorOf.
An interface for writing to a network connection.
size_t getListSize() const override
size_t capacity() const
capacity
void pop_back()
Pop an element out of the vector: size is changed.
T & emplace_back(_Args &&... args)
Construct a new element in the vector: size is changed.
void zero()
Zero the elements of the vector.
typename std::vector< unsigned char >::const_iterator const_iterator
size_t length() const
Get the length of the vector.
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
int BottleTagMap< double >()
iterator end() noexcept
Returns an iterator to the end of the VectorOf.
A Base class for a VectorOf<T>, provide default implementation for read/write methods.
VectorOf(const VectorOf &r)
An interface for reading from a network connection.
T * data()
Return a pointer to the first element of the vector.
#define BOTTLE_TAG_FLOAT64
std::string toString(int precision=-1, int width=-1) const
Creates a string object containing a text representation of the object.
bool operator==(const VectorOf< T > &r) const
True iff all elements of 'a' match all element of 'b'.
VectorOf< double > Vector
const T * data() const
Return a pointer to the first element of the vector, const version.
#define YARP_DEPRECATED_MSG(MSG)
Expands to either the standard [[deprecated]] attribute or a compiler-specific decorator such as __at...
The main, catch-all namespace for YARP.
virtual size_t getElementSize() const =0
void reserve(size_t size)
reserve, increase the capacity of the vector to a value that's greater or equal to size.
VectorOf(VectorOf< T > &&other) noexcept
Move constructor.
const T & operator[](size_t i) const
Single element access, no range check, const version.
VectorOf(size_t s, const T &def)
Build a vector and initialize it with def.
T & operator[](size_t i)
Single element access, no range check.
int BottleTagMap< int >()
void push_back(T &&elem)
Move a new element in the vector: size is changed.
virtual int getBottleTag() const =0
iterator begin() noexcept
Returns an iterator to the beginning of the VectorOf.
const T * getFirst() const
VectorOf(std::initializer_list< T > values)
Initializer list constructor.
size_t getElementSize() const override
void push_back(const T &elem)
Push a new element in the vector: size is changed.
yarp::os::Type getType() const override
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 l...
virtual const char * getMemoryBlock() const =0
const VectorOf< T > & operator=(const VectorOf< T > &r)
Copy operator;.
bool write(yarp::os::ConnectionWriter &connection) const override
Write vector to a connection.
virtual void resize(size_t size)=0
bool setSubvector(int position, const VectorOf< T > &v)
Set a portion of this vector with the values of the specified vector.