YARP
Yet Another Robot Platform
yarp::os::Bottle Class Reference

A simple collection of objects that can be described and transmitted in a portable way. More...

#include <yarp/os/Bottle.h>

+ Inheritance diagram for yarp::os::Bottle:

Public Types

using size_type = size_t
 

Public Member Functions

 Bottle ()
 Constructor. More...
 
 Bottle (const std::string &text)
 Creates a bottle from a string. More...
 
 Bottle (const Bottle &rhs)
 Copy constructor. More...
 
 Bottle (Bottle &&rhs) noexcept
 Move constructor. More...
 
 Bottle (std::initializer_list< yarp::os::Value > values)
 Initializer list constructor. More...
 
Bottleoperator= (const Bottle &rhs)
 Copy assignment operator. More...
 
Bottleoperator= (Bottle &&rhs) noexcept
 Move assignment operator. More...
 
 ~Bottle () override
 Destructor. More...
 
void clear ()
 Empties the bottle of any objects it contains. More...
 
void addInt (int x)
 Places an integer in the bottle, at the end of the list. More...
 
void addInt8 (std::int8_t x)
 Places a 8-bit integer in the bottle, at the end of the list. More...
 
void addInt16 (std::int16_t x)
 Places a 16-bit integer in the bottle, at the end of the list. More...
 
void addInt32 (std::int32_t x)
 Places a 32-bit integer in the bottle, at the end of the list. More...
 
void addInt64 (std::int64_t x)
 Places a 64-bit integer in the bottle, at the end of the list. More...
 
void addVocab (yarp::conf::vocab32_t x)
 Places a vocabulary item in the bottle, at the end of the list. More...
 
void addVocab32 (yarp::conf::vocab32_t x)
 Places a vocabulary item in the bottle, at the end of the list. More...
 
void addVocab32 (char a, char b=0, char c=0, char d=0)
 Places a vocabulary item in the bottle, at the end of the list. More...
 
void addVocab32 (const std::string &str)
 Places a vocabulary item in the bottle, at the end of the list. More...
 
void addDouble (double x)
 Places a floating point number in the bottle, at the end of the list. More...
 
void addFloat32 (yarp::conf::float32_t x)
 Places a 32-bit floating point number in the bottle, at the end of the list. More...
 
void addFloat64 (yarp::conf::float64_t x)
 Places a 64-bit floating point number in the bottle, at the end of the list. More...
 
void addString (const char *str)
 Places a string in the bottle, at the end of the list. More...
 
void addString (const std::string &str)
 Places a string in the bottle, at the end of the list. More...
 
void add (const Value &value)
 Add a Value to the bottle, at the end of the list. More...
 
void add (Value *value)
 Add a Value to the bottle, at the end of the list. More...
 
BottleaddList ()
 Places an empty nested list in the bottle, at the end of the list. More...
 
PropertyaddDict ()
 Places an empty key/value object in the bottle, at the end of the list. More...
 
Value pop ()
 Removes a Value v from the end of the list and returns this value. More...
 
Valueget (size_type index) const
 Reads a Value v from a certain part of the list. More...
 
size_type size () const
 Gets the number of elements in the bottle. More...
 
void fromString (const std::string &text)
 Initializes bottle from a string. More...
 
void fromBinary (const char *buf, size_t len)
 Initializes bottle from a binary representation. More...
 
const char * toBinary (size_t *size=nullptr)
 Returns binary representation of bottle. More...
 
std::string toString () const override
 Gives a human-readable textual representation of the bottle. More...
 
bool write (ConnectionWriter &writer) const override
 Output a representation of the bottle to a network connection. More...
 
bool read (ConnectionReader &reader) override
 Set the bottle's value based on input from a network connection. More...
 
bool write (PortReader &reader, bool textMode=false)
 Copy the bottle's value to a object that can read a serialization. More...
 
bool read (const PortWriter &writer, bool textMode=false)
 Set the bottle's value based on input from a serializable object. More...
 
void onCommencement () const override
 This is called when the port is about to begin writing operations. More...
 
bool check (const std::string &key) const override
 Check if there exists a property of the given name. More...
 
Valuefind (const std::string &key) const override
 Gets a value corresponding to a given keyword. More...
 
BottlefindGroup (const std::string &key) const override
 Gets a list corresponding to a given keyword. More...
 
bool isNull () const override
 Checks if the object is invalid. More...
 
void copy (const Bottle &alt, size_type first=0, size_type len=npos)
 Copy all or part of another Bottle. More...
 
bool operator== (const Bottle &alt) const
 Equality test. More...
 
bool operator!= (const Bottle &alt) const
 Inequality test. More...
 
void append (const Bottle &alt)
 Append the content of the given bottle to the current list. More...
 
Bottle tail () const
 Get all but the first element of a bottle. More...
 
void hasChanged ()
 Declare that the content of the Bottle has been changed. More...
 
int getSpecialization ()
 Get numeric bottle code for this bottle. More...
 
virtual bool check (const std::string &key) const=0
 Check if there exists a property of the given name. More...
 
virtual bool check (const std::string &key, const std::string &comment) const
 Check if there exists a property of the given name. More...
 
virtual bool check (const std::string &key, Value *&result, const std::string &comment="") const
 Gets a value corresponding to a given keyword. More...
 
virtual Value check (const std::string &key, const Value &fallback, const std::string &comment="") const
 Gets a value corresponding to a given keyword. More...
 
virtual BottlefindGroup (const std::string &key) const=0
 Gets a list corresponding to a given keyword. More...
 
BottlefindGroup (const std::string &key, const std::string &comment) const
 Gets a list corresponding to a given keyword. More...
 
- Public Member Functions inherited from yarp::os::Portable
virtual Type getType () const
 
- 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 yarp::os::Type getWriteType () const
 
- Public Member Functions inherited from yarp::os::Searchable
 Searchable ()
 Default constructor. More...
 
 Searchable (const Searchable &rhs)=default
 Copy constructor. More...
 
 Searchable (Searchable &&rhs) noexcept=default
 Move constructor. More...
 
virtual ~Searchable ()
 Destructor. More...
 
Searchableoperator= (const Searchable &rhs)=default
 Copy assignment operator. More...
 
Searchableoperator= (Searchable &&rhs) noexcept=default
 Move assignment operator. More...
 
virtual bool check (const std::string &key, const std::string &comment) const
 Check if there exists a property of the given name. More...
 
BottlefindGroup (const std::string &key, const std::string &comment) const
 Gets a list corresponding to a given keyword. More...
 
virtual bool check (const std::string &key, Value *&result, const std::string &comment="") const
 Gets a value corresponding to a given keyword. More...
 
virtual Value check (const std::string &key, const Value &fallback, const std::string &comment="") const
 Gets a value corresponding to a given keyword. More...
 

Static Public Member Functions

static BottlegetNullBottle ()
 A special Bottle with no content. More...
 
static std::string toString (int x)
 
static std::string describeBottleCode (int code)
 Convert a numeric bottle code to a string. More...
 
- 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...
 

Static Public Attributes

static const size_type npos = static_cast<Bottle::size_type>(-1)
 

Protected Member Functions

void setReadOnly (bool readOnly)
 

Friends

class yarp::os::NetworkBase
 

Detailed Description

A simple collection of objects that can be described and transmitted in a portable way.

Objects are stored in a list, which you can add to and access. It is handy to use until you feel the need to make your own more efficient formats for transmission.

Here's an example of using a Bottle:

/*
* SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
* SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <yarp/os/Bottle.h>
#include <cstdio>
int main(int argc, char* argv[])
{
YARP_UNUSED(argc);
YARP_UNUSED(argv);
// create a bottle representing the list (5,"plus",2,"is")
Bottle b("5 plus 2 is");
// add an integer that is the sum of element 0 and 2
b.addInt32(b.get(0).asInt32() + b.get(2).asInt32());
// print the result -- "result: 5 plus 2 is 7"
printf("result: %s\n", b.toString().c_str());
return 0;
}
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:74
Bottle()
Constructor.
Definition: Bottle.cpp:44
#define YARP_UNUSED(var)
Definition: api.h:162
int main(int argc, char *argv[])
Definition: yarpros.cpp:264

This class has a well-defined, documented representation in both binary and text form. The name of this class comes from the idea of throwing a "message in a bottle" into the network and hoping it will eventually wash ashore somewhere else. In the very early days of YARP, that is what communication felt like.

Examples
carrier/carrier_stub.cpp, os/bottle_add/bottle_add.cpp, os/browse_bottle/browse_bottle.cpp, os/buffered_port/buffered_port.cpp, os/database/database.cpp, os/make_count/make_count.cpp, os/portable_pair/portable_pair.cpp, os/simple_receiver/simple_receiver.cpp, os/simple_sender/simple_sender.cpp, os/summer/summer.cpp, and os/view_count/view_count.cpp.

Definition at line 73 of file Bottle.h.

Member Typedef Documentation

◆ size_type

Definition at line 79 of file Bottle.h.

Constructor & Destructor Documentation

◆ Bottle() [1/5]

Bottle::Bottle ( )

Constructor.

The bottle is initially empty.

Definition at line 44 of file Bottle.cpp.

◆ Bottle() [2/5]

Bottle::Bottle ( const std::string &  text)
explicit

Creates a bottle from a string.

The string which should contain a textual form of the bottle, e.g. text = "10 -5.3 1.0 \"hello there"" would give a bottle with 4 elements: an integer, two floating point numbers, and a string.

Parameters
textthe textual form of the bottle to be interpreted.

Definition at line 54 of file Bottle.cpp.

◆ Bottle() [3/5]

Bottle::Bottle ( const Bottle rhs)

Copy constructor.

Parameters
rhsThe object to copy.

Definition at line 65 of file Bottle.cpp.

◆ Bottle() [4/5]

Bottle::Bottle ( Bottle &&  rhs)
noexcept

Move constructor.

Parameters
rhsThe object to move.

Definition at line 76 of file Bottle.cpp.

◆ Bottle() [5/5]

yarp::os::Bottle::Bottle ( std::initializer_list< yarp::os::Value values)

Initializer list constructor.

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

◆ ~Bottle()

Bottle::~Bottle ( )
override

Destructor.

Definition at line 116 of file Bottle.cpp.

Member Function Documentation

◆ add() [1/2]

void Bottle::add ( const Value value)

Add a Value to the bottle, at the end of the list.

Parameters
valuethe Value to add.

Definition at line 336 of file Bottle.cpp.

◆ add() [2/2]

void Bottle::add ( Value value)

Add a Value to the bottle, at the end of the list.

The object passed will be placed directly into the list, without copying. The Bottle will be responsible for deallocating it when appropriate.

Parameters
valuethe Value to add.

Definition at line 330 of file Bottle.cpp.

◆ addDict()

Property & Bottle::addDict ( )

Places an empty key/value object in the bottle, at the end of the list.

Returns
a reference to the newly added property.

Definition at line 188 of file Bottle.cpp.

◆ addDouble()

void yarp::os::Bottle::addDouble ( double  x)
inline

Places a floating point number in the bottle, at the end of the list.

Parameters
xthe number to add.
Warning
Unsafe, sizeof(double) is platform dependent. Use addFloat64 instead.
Deprecated:
Since YARP 3.5.0. Use addFloat64 instead.

Definition at line 247 of file Bottle.h.

◆ addFloat32()

void Bottle::addFloat32 ( yarp::conf::float32_t  x)

Places a 32-bit floating point number in the bottle, at the end of the list.

Parameters
xthe number to add.

Definition at line 152 of file Bottle.cpp.

◆ addFloat64()

void Bottle::addFloat64 ( yarp::conf::float64_t  x)

Places a 64-bit floating point number in the bottle, at the end of the list.

Parameters
xthe number to add.

Definition at line 158 of file Bottle.cpp.

◆ addInt()

void yarp::os::Bottle::addInt ( int  x)
inline

Places an integer in the bottle, at the end of the list.

Parameters
xthe integer to add.
Warning
Unsafe, sizeof(int) is platform dependent. Use addInt32 instead.
Deprecated:
Since YARP 3.5.0. Use addInt32 instead.

Definition at line 159 of file Bottle.h.

◆ addInt16()

void Bottle::addInt16 ( std::int16_t  x)

Places a 16-bit integer in the bottle, at the end of the list.

Parameters
xthe 16-bit integer to add.

Definition at line 134 of file Bottle.cpp.

◆ addInt32()

void Bottle::addInt32 ( std::int32_t  x)

Places a 32-bit integer in the bottle, at the end of the list.

Parameters
xthe 32-bit integer to add.

Definition at line 140 of file Bottle.cpp.

◆ addInt64()

void Bottle::addInt64 ( std::int64_t  x)

Places a 64-bit integer in the bottle, at the end of the list.

Parameters
xthe 64-bit integer to add.

Definition at line 146 of file Bottle.cpp.

◆ addInt8()

void Bottle::addInt8 ( std::int8_t  x)

Places a 8-bit integer in the bottle, at the end of the list.

Parameters
xthe 8-bit integer to add.

Definition at line 128 of file Bottle.cpp.

◆ addList()

Bottle & Bottle::addList ( )

Places an empty nested list in the bottle, at the end of the list.

The list itself is represented as a bottle.

Returns
a reference to the newly added list.

Definition at line 182 of file Bottle.cpp.

◆ addString() [1/2]

void Bottle::addString ( const char *  str)

Places a string in the bottle, at the end of the list.

Parameters
strthe string to add.

Definition at line 170 of file Bottle.cpp.

◆ addString() [2/2]

void Bottle::addString ( const std::string &  str)

Places a string in the bottle, at the end of the list.

Parameters
strthe string to add.

Definition at line 176 of file Bottle.cpp.

◆ addVocab()

void yarp::os::Bottle::addVocab ( yarp::conf::vocab32_t  x)
inline

Places a vocabulary item in the bottle, at the end of the list.

Parameters
xthe item to add.
Deprecated:
Since YARP 3.5.0. Use addVocab32 instead.

Definition at line 201 of file Bottle.h.

◆ addVocab32() [1/3]

void yarp::os::Bottle::addVocab32 ( char  a,
char  b = 0,
char  c = 0,
char  d = 0 
)
inline

Places a vocabulary item in the bottle, at the end of the list.

Parameters
afirst character of the vocab
bsecond character of the vocab
cthird character of the vocab
dfourth character of the vocab

Definition at line 222 of file Bottle.h.

◆ addVocab32() [2/3]

void yarp::os::Bottle::addVocab32 ( const std::string &  str)
inline

Places a vocabulary item in the bottle, at the end of the list.

If the string is longer than 4 characters, only the first 4 are used.

Parameters
strThe string to encode and add.

Definition at line 232 of file Bottle.h.

◆ addVocab32() [3/3]

void Bottle::addVocab32 ( yarp::conf::vocab32_t  x)

Places a vocabulary item in the bottle, at the end of the list.

Parameters
xthe item to add.

Definition at line 164 of file Bottle.cpp.

◆ append()

void Bottle::append ( const Bottle alt)

Append the content of the given bottle to the current list.

Parameters
altthe content to add.

Definition at line 380 of file Bottle.cpp.

◆ check() [1/5]

bool Bottle::check ( const std::string &  key) const
overridevirtual

Check if there exists a property of the given name.

Parameters
keythe name to check for
Returns
true iff a property of the given name exists, even if it doesn't have a value associated with it

Implements yarp::os::Searchable.

Definition at line 277 of file Bottle.cpp.

◆ check() [2/5]

virtual bool yarp::os::Searchable::check

Check if there exists a property of the given name.

Parameters
keythe name to check for
Returns
true iff a property of the given name exists, even if it doesn't have a value associated with it

◆ check() [3/5]

bool yarp::os::Searchable::check

Check if there exists a property of the given name.

Parameters
keythe name to check for
commentHuman-readable explanation
Returns
true iff a property of the given name exists, even if it doesn't have a value associated with it

Definition at line 118 of file Searchable.cpp.

◆ check() [4/5]

yarp::os::Value yarp::os::Searchable::check

Gets a value corresponding to a given keyword.

Parameters
keyThe keyword to look for
fallbackA default value to return if nothing found
commentOptional human-readable explanation
Returns
A value corresponding to a given keyword, or the default if nothing is found. See the find() method for interpreting the value found.

Definition at line 195 of file Searchable.cpp.

◆ check() [5/5]

bool yarp::os::Searchable::check

Gets a value corresponding to a given keyword.

If a property does not exist, this returns false and does not modify the result pointer. If a property exists but does not have a value, this again returns false and does not modify the result pointer.

Property p;
p.fromString("(width 10) (height 15) (help)");
p.check("help") // this is true
p.check("width") // this is true
p.check("foo") // this is false
Value *v;
p.check("help", v) // this is false, there is no value associated
p.check("width", v) // this is true, and v->asInt32() is 10
Parameters
keyThe keyword to look for
resultA pointer to store the address of the result in
commentOptional human-readable explanation
Returns
True if there is a value corresponding to a given keyword, false otherwise. See the find() method for interpreting the value found.

Definition at line 181 of file Searchable.cpp.

◆ clear()

void Bottle::clear ( )

Empties the bottle of any objects it contains.

Definition at line 121 of file Bottle.cpp.

◆ copy()

void Bottle::copy ( const Bottle alt,
size_type  first = 0,
size_type  len = npos 
)

Copy all or part of another Bottle.

Parameters
altThe object to copy.
firstThe index of the first element to copy.
lenThe number of elements to copy (-1 for all).

Definition at line 266 of file Bottle.cpp.

◆ describeBottleCode()

std::string Bottle::describeBottleCode ( int  code)
static

Convert a numeric bottle code to a string.

Parameters
codethe code to convert
Returns
a string representation of the code's meaning

Definition at line 403 of file Bottle.cpp.

◆ find()

Value & Bottle::find ( const std::string &  key) const
overridevirtual

Gets a value corresponding to a given keyword.

Parameters
keyThe keyword to look for
Returns
A value corresponding to a given keyword. If there is no such value, then the isNull() method called on the result will be true. Otherwise, the value can be read by calling result.asInt32(), result.asString(), etc. as appropriate.

Implements yarp::os::Searchable.

Definition at line 287 of file Bottle.cpp.

◆ findGroup() [1/3]

Bottle & Bottle::findGroup ( const std::string &  key) const
overridevirtual

Gets a list corresponding to a given keyword.

Parameters
keyThe keyword to look for
Returns
A list corresponding to a given keyword. If there is no such list, then the isNull() method called on the result will be true. Otherwise, the elements of the list can be read through result.get(index) where result.get(0) is the keyword, and result.get(i) for i>=1 are the "real" elements of the list.

Implements yarp::os::Searchable.

Definition at line 302 of file Bottle.cpp.

◆ findGroup() [2/3]

virtual Bottle& yarp::os::Searchable::findGroup

Gets a list corresponding to a given keyword.

Parameters
keyThe keyword to look for
Returns
A list corresponding to a given keyword. If there is no such list, then the isNull() method called on the result will be true. Otherwise, the elements of the list can be read through result.get(index) where result.get(0) is the keyword, and result.get(i) for i>=1 are the "real" elements of the list.

◆ findGroup() [3/3]

yarp::os::Bottle & yarp::os::Searchable::findGroup

Gets a list corresponding to a given keyword.

Parameters
keyThe keyword to look for
commentHuman-readable explanation
Returns
A list corresponding to a given keyword. If there is no such list, then the isNull() method called on the result will be true. Otherwise, the elements of the list can be read through result.get(index) where result.get(0) is the keyword, and result.get(i) for i>=1 are the "real" elements of the list.

Definition at line 154 of file Searchable.cpp.

◆ fromBinary()

void Bottle::fromBinary ( const char *  buf,
size_t  len 
)

Initializes bottle from a binary representation.

Parameters
bufthe binary form of the bottle to be interpreted.
lenthe length of the binary form.

Definition at line 216 of file Bottle.cpp.

◆ fromString()

void Bottle::fromString ( const std::string &  text)

Initializes bottle from a string.

The string should contain a textual form of the bottle, e.g. text = "10 -5.3 1.0 \"hello there"" would give a bottle with 4 elements: an integer, two floating point numbers, and a string.

Parameters
textthe textual form of the bottle to be interpreted.
Examples
carrier/carrier_stub.cpp.

Definition at line 204 of file Bottle.cpp.

◆ get()

Value & Bottle::get ( size_type  index) const

Reads a Value v from a certain part of the list.

Methods like v.isInt32() or v.isString() can be used to check the type of the result. Methods like v.asInt32() or v.asString() can be used to access the result as a particular type.

Parameters
indexthe part of the list to read from.
Returns
the Value v; if the index lies outside the range of elements present, then v.isNull() will be true.

Definition at line 246 of file Bottle.cpp.

◆ getNullBottle()

Bottle & Bottle::getNullBottle ( )
static

A special Bottle with no content.

Returns
the special invalid "null" Bottle.

Definition at line 342 of file Bottle.cpp.

◆ getSpecialization()

int Bottle::getSpecialization ( )

Get numeric bottle code for this bottle.

Returns
the numeric code

Definition at line 261 of file Bottle.cpp.

◆ hasChanged()

void Bottle::hasChanged ( )

Declare that the content of the Bottle has been changed.

It is important to call this if you modify an individual element of the Bottle through assignment, so that serialization happens correctly.

Definition at line 256 of file Bottle.cpp.

◆ isNull()

bool Bottle::isNull ( ) const
overridevirtual

Checks if the object is invalid.

Returns
True if the object is invalid or "null".

Reimplemented from yarp::os::Searchable.

Definition at line 370 of file Bottle.cpp.

◆ onCommencement()

void Bottle::onCommencement ( ) const
overridevirtual

This is called when the port is about to begin writing operations.

After this point, the write method may be called zero, once, or many times by YARP depending on the mix of formats and protocols in use.

Reimplemented from yarp::os::PortWriter.

Definition at line 235 of file Bottle.cpp.

◆ operator!=()

bool Bottle::operator!= ( const Bottle alt) const

Inequality test.

Parameters
altthe value to compare against.
Returns
true iff the values are not equal.

Definition at line 375 of file Bottle.cpp.

◆ operator=() [1/2]

Bottle & Bottle::operator= ( Bottle &&  rhs)
noexcept

Move assignment operator.

Parameters
rhsThe object to move.
Returns
the Bottle itself.

Definition at line 108 of file Bottle.cpp.

◆ operator=() [2/2]

Bottle & Bottle::operator= ( const Bottle rhs)

Copy assignment operator.

Parameters
rhsThe object to copy.
Returns
the Bottle itself.

Definition at line 99 of file Bottle.cpp.

◆ operator==()

bool Bottle::operator== ( const Bottle alt) const

Equality test.

Parameters
altthe value to compare against.
Returns
true iff the values are equal.

Definition at line 348 of file Bottle.cpp.

◆ pop()

Value Bottle::pop ( )

Removes a Value v from the end of the list and returns this value.

Returns
the value popped from the end of the bottle.

Definition at line 194 of file Bottle.cpp.

◆ read() [1/2]

bool Bottle::read ( ConnectionReader reader)
overridevirtual

Set the bottle's value based on input from a network connection.

Parameters
readerthe interface to the network connection for reading
Returns
true iff the bottle was read successfully.

Implements yarp::os::Portable.

Definition at line 240 of file Bottle.cpp.

◆ read() [2/2]

bool Bottle::read ( const PortWriter writer,
bool  textMode = false 
)

Set the bottle's value based on input from a serializable object.

Must be serialized in standard Bottle-compatible format.

Parameters
writerthe serializable object.
textModetrue if text serialization should be used.
Returns
true iff the bottle was read successfully.

Definition at line 361 of file Bottle.cpp.

◆ setReadOnly()

void Bottle::setReadOnly ( bool  readOnly)
protected

Definition at line 439 of file Bottle.cpp.

◆ size()

size_t Bottle::size ( ) const

Gets the number of elements in the bottle.

Returns
number of elements in the bottle.

Definition at line 251 of file Bottle.cpp.

◆ tail()

Bottle Bottle::tail ( ) const

Get all but the first element of a bottle.

Returns
a bottle containing all but the first element of the current bottle.

Definition at line 388 of file Bottle.cpp.

◆ toBinary()

const char * Bottle::toBinary ( size_t *  size = nullptr)

Returns binary representation of bottle.

Lifetime is until next modification of bottle.

Parameters
sizeif non-null, the referenced variable is set to the buffer size.
Returns
pointer to a buffer holding the binary representation of the bottle.

Definition at line 222 of file Bottle.cpp.

◆ toString() [1/2]

std::string Bottle::toString ( ) const
overridevirtual

Gives a human-readable textual representation of the bottle.

This representation is suitable for passing to Bottle::fromString (see that method for examples).

Returns
a textual representation of the bottle.

Implements yarp::os::Searchable.

Examples
carrier/carrier_stub.cpp.

Definition at line 211 of file Bottle.cpp.

◆ toString() [2/2]

std::string Bottle::toString ( int  x)
static

Definition at line 398 of file Bottle.cpp.

◆ write() [1/2]

bool Bottle::write ( ConnectionWriter writer) const
overridevirtual

Output a representation of the bottle to a network connection.

Parameters
writerthe interface to the network connection for writing
Returns
true iff the representation was written successfully.

Implements yarp::os::Portable.

Definition at line 230 of file Bottle.cpp.

◆ write() [2/2]

bool Bottle::write ( PortReader reader,
bool  textMode = false 
)

Copy the bottle's value to a object that can read a serialization.

Must be serialized in standard Bottle-compatible format.

Parameters
readerthe serializable object.
textModetrue if text serialization should be used.
Returns
true iff the bottle was written successfully.

Definition at line 353 of file Bottle.cpp.

Friends And Related Function Documentation

◆ yarp::os::NetworkBase

friend class yarp::os::NetworkBase
friend

Definition at line 520 of file Bottle.h.

Member Data Documentation

◆ npos

const Bottle::size_type Bottle::npos = static_cast<Bottle::size_type>(-1)
static

Definition at line 82 of file Bottle.h.


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