YARP
Yet Another Robot Platform
PortablePair.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef YARP_OS_PORTABLEPAIR_H
8 #define YARP_OS_PORTABLEPAIR_H
9 
10 #include <yarp/os/Bottle.h>
11 #include <yarp/os/Portable.h>
12 
13 namespace yarp {
14 namespace os {
15 
17 {
18 public:
26  static bool readPair(ConnectionReader& connection,
27  Portable& head,
28  Portable& body);
29 
37  static bool writePair(ConnectionWriter& connection,
38  const Portable& head,
39  const Portable& body);
40 };
41 
46 template <class HEAD, class BODY>
48 {
49 public:
53  HEAD head;
54 
58  BODY body;
59 
65  bool read(ConnectionReader& connection) override
66  {
67  return readPair(connection, head, body);
68  }
69 
75  bool write(ConnectionWriter& connection) const override
76  {
77  return writePair(connection, head, body);
78  }
79 
84  void onCompletion() const override
85  {
86  head.onCompletion();
87  body.onCompletion();
88  }
89 };
90 
91 } // namespace os
92 } // namespace yarp
93 
94 #endif // YARP_OS_PORTABLEPAIR_H
An interface for reading from a network connection.
An interface for writing to a network connection.
static bool writePair(ConnectionWriter &connection, const Portable &head, const Portable &body)
Writes an object pair to a network connection.
static bool readPair(ConnectionReader &connection, Portable &head, Portable &body)
Reads an object pair from a network connection.
Group a pair of objects to be sent and received together.
Definition: PortablePair.h:48
BODY body
An object of the second type (BODY).
Definition: PortablePair.h:58
bool write(ConnectionWriter &connection) const override
Writes this object pair to a network connection.
Definition: PortablePair.h:75
HEAD head
An object of the first type (HEAD).
Definition: PortablePair.h:53
bool read(ConnectionReader &connection) override
Reads this object pair from a network connection.
Definition: PortablePair.h:65
void onCompletion() const override
This is called when the port has finished all writing operations.
Definition: PortablePair.h:84
This is a base class for objects that can be both read from and be written to the YARP network.
Definition: Portable.h:26
The main, catch-all namespace for YARP.
Definition: dirs.h:16
#define YARP_os_API
Definition: api.h:18