iCub-main
Loading...
Searching...
No Matches
VectorPair.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2026 Istituto Italiano di Tecnologia (IIT)
3 * CopyPolicy: Released under the terms of the GNU GPL v2.0.
4 */
5
6#ifndef LM_VECTORPAIR_H
7#define LM_VECTORPAIR_H
8
9#include <cstdint>
10
11#include <yarp/os/Bottle.h>
12#include <yarp/os/ConnectionReader.h>
13#include <yarp/os/ConnectionWriter.h>
14#include <yarp/os/Portable.h>
15#include <yarp/sig/Vector.h>
16
17namespace iCub {
18namespace learningmachine {
19
27class VectorPair : public yarp::os::Portable
28{
29public:
30 yarp::sig::Vector head;
31 yarp::sig::Vector body;
32
33 bool read(yarp::os::ConnectionReader& connection) override
34 {
35 connection.convertTextMode();
36
37 const std::int32_t header = connection.expectInt32();
38 if (header != BOTTLE_TAG_LIST) {
39 return false;
40 }
41
42 const std::int32_t length = connection.expectInt32();
43 if (length != 2) {
44 return false;
45 }
46
47 return head.read(connection) && body.read(connection);
48 }
49
50 bool write(yarp::os::ConnectionWriter& connection) const override
51 {
52 connection.appendInt32(BOTTLE_TAG_LIST);
53 connection.appendInt32(2);
54
55 const bool ok = head.write(connection) && body.write(connection);
56 if (ok) {
57 connection.convertTextMode();
58 }
59 return ok;
60 }
61
62 void onCompletion() const override
63 {
64 head.onCompletion();
65 body.onCompletion();
66 }
67};
68
69} // namespace learningmachine
70} // namespace iCub
71
72#endif // LM_VECTORPAIR_H
A pair of vectors using the wire format formerly provided by yarp::os::PortablePair<yarp::sig::Vector...
Definition VectorPair.h:28
void onCompletion() const override
Definition VectorPair.h:62
bool read(yarp::os::ConnectionReader &connection) override
Definition VectorPair.h:33
bool write(yarp::os::ConnectionWriter &connection) const override
Definition VectorPair.h:50
This file contains the definition of unique IDs for the body parts and the skin parts of the robot.