YARP
Yet Another Robot Platform
port_power/TargetVer3.h

Part of a series of examples on the different ways of using ports. See Port power tutorial.

/*
* Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
* Copyright (C) 2006-2010 RobotCub Consortium
* All rights reserved.
*
* This software may be modified and distributed under the terms of the
* BSD-3-Clause license. See the accompanying LICENSE file for details.
*/
#ifndef TARGETVER3_INC
#define TARGETVER3_INC
class Target : public yarp::os::Portable {
public:
int x;
int y;
bool write(yarp::os::ConnectionWriter& connection) const override {
connection.appendInt32(2); // two elements
connection.appendInt32(x);
connection.appendInt32(y);
connection.convertTextMode(); // if connection is text-mode, convert!
return true;
}
bool read(yarp::os::ConnectionReader& connection) override {
connection.convertTextMode(); // if connection is text-mode, convert!
int tag = connection.expectInt32();
x = y = -1;
if (tag!=BOTTLE_TAG_LIST+BOTTLE_TAG_INT32) return false;
int ct = connection.expectInt32();
if (ct!=2) return false;
x = connection.expectInt32();
y = connection.expectInt32();
return true;
}
};
#endif
yarp::os::Portable
Definition: Portable.h:28
BOTTLE_TAG_LIST
#define BOTTLE_TAG_LIST
Definition: Bottle.h:30
Portable.h
yarp::os::Portable::write
bool write(ConnectionWriter &writer) const override=0
Write this object to a network connection.
BOTTLE_TAG_INT32
#define BOTTLE_TAG_INT32
Definition: Bottle.h:23
yarp::os::ConnectionReader::expectInt32
virtual std::int32_t expectInt32()=0
Read a 32-bit integer from the network connection.
yarp::os::ConnectionWriter
An interface for writing to a network connection.
Definition: ConnectionWriter.h:39
yarp::os::ConnectionReader::convertTextMode
virtual bool convertTextMode()=0
Reads in a standard description in text mode, and converts it to a standard description in binary.
yarp::os::ConnectionWriter::convertTextMode
virtual bool convertTextMode()=0
Converts a standard description in binary into a textual description, if the connection is in text-mo...
yarp::os::ConnectionWriter::appendInt32
virtual void appendInt32(std::int32_t data)=0
Send a representation of a 32-bit integer to the network connection.
yarp::os::ConnectionReader
An interface for reading from a network connection.
Definition: ConnectionReader.h:39
yarp::os::Portable::read
bool read(ConnectionReader &reader) override=0
Read this object from a network connection.