YARP
Yet Another Robot Platform
Name.cpp
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 #include <yarp/os/Name.h>
8 
9 using namespace yarp::os;
10 
11 Name::Name(const std::string& txt)
12 {
13  this->txt = txt;
14 }
15 
16 bool Name::isRooted() const
17 {
18  if (txt.length() >= 1) {
19  if (txt[0] == '/') {
20  return true;
21  }
22  }
23  return false;
24 }
25 
26 
28 {
29  size_t mid = txt.find(":/");
30  if (mid != std::string::npos && mid > 0) {
31  std::string first = txt.substr(0, mid);
32  std::string second = txt.substr(mid + 2);
33  if (first.length() >= 2) {
34  if (first[0] == '/') {
35  first = first.substr(1);
36  }
37  }
38  return Contact(second, first, "", -1);
39  }
40  return Contact(txt, "", "", -1);
41 }
42 
43 
44 std::string Name::getCarrierModifier(const char* mod, bool* hasModifier)
45 {
46  bool ok = false;
47  std::string work = txt;
48  size_t mid = work.find(":/");
49  if (mid != std::string::npos && mid > 0) {
50  work = work.substr(0, mid);
51  std::string target = std::string("+") + mod + ".";
52  size_t modLoc = work.find(target);
53  if (modLoc != std::string::npos) {
54  work = work.substr(modLoc + target.length(), work.length());
55  size_t endLoc = work.find('+');
56  if (endLoc != std::string::npos) {
57  work = work.substr(0, endLoc);
58  }
59  ok = true;
60  }
61  }
62  if (hasModifier != nullptr) {
63  *hasModifier = ok;
64  }
65  return ok ? work : "";
66 }
Represents how to reach a part of a YARP network.
Definition: Contact.h:36
Contact toAddress() const
Create an address from the name.
Definition: Name.cpp:27
Name(const std::string &txt)
Constructor.
Definition: Name.cpp:11
bool isRooted() const
Check if port name begins with "/".
Definition: Name.cpp:16
std::string getCarrierModifier(const char *mod, bool *hasModifier=nullptr)
Definition: Name.cpp:44
An interface to the operating system, including Port based communication.