YARP
Yet Another Robot Platform
Route.cpp
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 #include <yarp/os/Route.h>
11 
12 #include <yarp/os/Contact.h>
13 
14 #include <string>
15 #include <utility>
16 
17 
18 using yarp::os::Contact;
19 using yarp::os::Route;
20 
21 #ifndef DOXYGEN_SHOULD_SKIP_THIS
22 
23 class Route::Private
24 {
25 public:
26  Private(std::string fromName,
27  std::string toName,
28  Contact toContact,
29  std::string carrierName) :
30  fromName(std::move(fromName)),
31  toName(std::move(toName)),
32  toContact(std::move(toContact)),
33  carrierName(std::move(carrierName))
34  {
35  }
36 
37  std::string fromName;
38  std::string toName;
39  Contact toContact;
40  std::string carrierName;
41 };
42 
43 #endif // DOXYGEN_SHOULD_SKIP_THIS
44 
45 
46 Route::Route() :
47  mPriv(new Private(std::string(),
48  std::string(),
49  Contact(),
50  std::string()))
51 {
52 }
53 
54 Route::Route(const std::string& fromName,
55  const std::string& toName,
56  const std::string& carrierName) :
57  mPriv(new Private(fromName,
58  toName,
59  Contact(),
60  carrierName))
61 {
62 }
63 
64 Route::Route(const Route& rhs) :
65  mPriv(new Private(*(rhs.mPriv)))
66 {
67 }
68 
69 Route::Route(Route&& rhs) noexcept :
70  mPriv(rhs.mPriv)
71 {
72  rhs.mPriv = nullptr;
73 }
74 
76 {
77  delete mPriv;
78 }
79 
81 {
82  if (&rhs != this) {
83  *mPriv = *(rhs.mPriv);
84  }
85  return *this;
86 }
87 
88 Route& Route::operator=(Route&& rhs) noexcept
89 {
90  if (&rhs != this) {
91  std::swap(mPriv, rhs.mPriv);
92  }
93  return *this;
94 }
95 
96 const std::string& Route::getFromName() const
97 {
98  return mPriv->fromName;
99 }
100 
101 void Route::setFromName(const std::string& fromName)
102 {
103  mPriv->fromName = fromName;
104 }
105 
106 const std::string& Route::getToName() const
107 {
108  return mPriv->toName;
109 }
110 
111 void Route::setToName(const std::string& toName)
112 {
113  mPriv->toName = toName;
114 }
115 
117 {
118  return mPriv->toContact;
119 }
120 
121 void Route::setToContact(const Contact& toContact)
122 {
123  mPriv->toContact = toContact;
124 }
125 
126 const std::string& Route::getCarrierName() const
127 {
128  return mPriv->carrierName;
129 }
130 
131 void Route::setCarrierName(const std::string& carrierName)
132 {
133  mPriv->carrierName = carrierName;
134 }
135 
137 {
138  mPriv->fromName.swap(mPriv->toName);
139 }
140 
141 std::string Route::toString() const
142 {
143  return getFromName() + "->" + getCarrierName() + "->" + getToName();
144 }
yarp::os::Route::toString
std::string toString() const
Render a text form of the route, "source->carrier->dest".
Definition: Route.cpp:141
yarp::os::Route::swapNames
void swapNames()
Swap from and to names.
Definition: Route.cpp:136
yarp::os::Route::operator=
Route & operator=(const Route &rhs)
Copy assignment operator.
Definition: Route.cpp:80
yarp::os::Route::getCarrierName
const std::string & getCarrierName() const
Get the carrier type of the route.
Definition: Route.cpp:126
yarp::os::Route
Information about a connection between two ports.
Definition: Route.h:32
Route.h
yarp::os::Route::setCarrierName
void setCarrierName(const std::string &carrierName)
Set the carrier type of the route.
Definition: Route.cpp:131
yarp::os::Route::~Route
virtual ~Route()
Destructor.
Definition: Route.cpp:75
yarp::os::Route::setFromName
void setFromName(const std::string &fromName)
Set the source of the route.
Definition: Route.cpp:101
yarp::os::Route::getToContact
const Contact & getToContact() const
Get the destination contact of the route, if available.
Definition: Route.cpp:116
yarp::os::Route::setToName
void setToName(const std::string &toName)
Set the destination of the route.
Definition: Route.cpp:111
yarp::os::Contact
Represents how to reach a part of a YARP network.
Definition: Contact.h:39
yarp::os::Route::getToName
const std::string & getToName() const
Get the destination of the route.
Definition: Route.cpp:106
yarp::os::Route::setToContact
void setToContact(const Contact &toContact)
Set the destination contact of the route.
Definition: Route.cpp:121
yarp::os::Route::Route
Route()
Default constructor.
Definition: Route.cpp:46
Contact.h
yarp::os::Route::getFromName
const std::string & getFromName() const
Get the source of the route.
Definition: Route.cpp:96