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