YARP
Yet Another Robot Platform
PortablePair.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 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
yarp::os::Portable
This is a base class for objects that can be both read from and be written to the YARP network.
Definition: Portable.h:29
yarp::os::PortablePair
Group a pair of objects to be sent and received together.
Definition: PortablePair.h:51
yarp::os::PortablePair::body
BODY body
An object of the second type (BODY).
Definition: PortablePair.h:61
yarp::os::PortablePairBase
Definition: PortablePair.h:20
Portable.h
yarp::os::PortablePair::read
bool read(ConnectionReader &connection) override
Reads this object pair from a network connection.
Definition: PortablePair.h:68
yarp::os::PortablePair::write
bool write(ConnectionWriter &connection) const override
Writes this object pair to a network connection.
Definition: PortablePair.h:78
yarp::os::PortablePairBase::readPair
static bool readPair(ConnectionReader &connection, Portable &head, Portable &body)
Reads an object pair from a network connection.
Definition: PortablePair.cpp:16
YARP_os_API
#define YARP_os_API
Definition: api.h:19
yarp::os::ConnectionWriter
An interface for writing to a network connection.
Definition: ConnectionWriter.h:40
yarp::os::PortablePair::onCompletion
void onCompletion() const override
This is called when the port has finished all writing operations.
Definition: PortablePair.h:87
yarp::os::ConnectionReader
An interface for reading from a network connection.
Definition: ConnectionReader.h:40
yarp::os::PortablePair::head
HEAD head
An object of the first type (HEAD).
Definition: PortablePair.h:56
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
yarp::os::PortablePairBase::writePair
static bool writePair(ConnectionWriter &connection, const Portable &head, const Portable &body)
Writes an object pair to a network connection.
Definition: PortablePair.cpp:40
Bottle.h