YARP
Yet Another Robot Platform
PortablePair.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2019 Istituto Italiano di Tecnologia (IIT)
3  * Copyright (C) 2006-2010 RobotCub Consortium
4  * All rights reserved.
5  *
6  * This software may be modified and distributed under the terms of the
7  * BSD-3-Clause license. See the accompanying LICENSE file for details.
8  */
9 
10 #ifndef YARP_OS_PORTABLEPAIR_H
11 #define YARP_OS_PORTABLEPAIR_H
12 
13 #include <yarp/os/Bottle.h>
14 #include <yarp/os/Portable.h>
15 
16 namespace yarp {
17 namespace os {
18 
20 {
21 public:
29  static bool readPair(ConnectionReader& connection,
30  Portable& head,
31  Portable& body);
32 
40  static bool writePair(ConnectionWriter& connection,
41  const Portable& head,
42  const Portable& body);
43 };
44 
49 template <class HEAD, class BODY>
51 {
52 public:
56  HEAD head;
57 
61  BODY body;
62 
68  bool read(ConnectionReader& connection) override
69  {
70  return readPair(connection, head, body);
71  }
72 
78  bool write(ConnectionWriter& connection) const override
79  {
80  return writePair(connection, head, body);
81  }
82 
87  void onCompletion() const override
88  {
89  head.onCompletion();
90  body.onCompletion();
91  }
92 };
93 
94 } // namespace os
95 } // namespace yarp
96 
97 #endif // YARP_OS_PORTABLEPAIR_H
void onCompletion() const override
This is called when the port has finished all writing operations.
Definition: PortablePair.h:87
This is a base class for objects that can be both read from and be written to the YARP network...
Definition: Portable.h:28
#define YARP_OS_API
Definition: api.h:19
HEAD head
An object of the first type (HEAD).
Definition: PortablePair.h:56
The main, catch-all namespace for YARP.
Definition: numeric.h:47
bool read(ConnectionReader &connection) override
Reads this object pair from a network connection.
Definition: PortablePair.h:68
bool write(ConnectionWriter &connection) const override
Writes this object pair to a network connection.
Definition: PortablePair.h:78
BODY body
An object of the second type (BODY).
Definition: PortablePair.h:61
An interface for writing to a network connection.
Group a pair of objects to be sent and received together.
Definition: PortablePair.h:50
An interface for reading from a network connection.