YARP
Yet Another Robot Platform
NameConfig.h
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 #ifndef YARP_OS_IMPL_NAMECONFIG_H
8 #define YARP_OS_IMPL_NAMECONFIG_H
9 
10 #include <yarp/os/Bottle.h>
11 #include <yarp/os/Contact.h>
12 
13 namespace yarp {
14 namespace os {
15 namespace impl {
16 
17 #define YARP_CONFIG_FILENAME "yarp.conf"
18 #define YARP_CONFIG_NAMESPACE_FILENAME "yarp_namespace.conf"
19 
25 {
26 public:
27  static std::string expandFilename(const char* fname);
28 
29  std::string getSafeString(const std::string& txt);
30 
31  std::string getConfigFileName(const char* stem = nullptr,
32  const char* ns = nullptr);
33 
34  std::string readConfig(const std::string& fileName);
35 
36  bool writeConfig(const std::string& fileName, const std::string& text);
37 
38  bool fromFile(const char* ns = nullptr);
39 
40  bool toFile(bool clean = false);
41 
42  void setAddress(const Contact& address);
43 
44  static std::string getHostName(bool prefer_loopback = false,
45  const std::string& seed = "");
46 
47  static std::string getIps();
48 
49  static yarp::os::Bottle getIpsAsBottle();
50 
51  static bool isLocalName(const std::string& name);
52 
53  Contact getAddress();
54 
55  std::string getMode()
56  {
57  return mode;
58  }
59 
60  void setMode(const std::string& mode)
61  {
62  this->mode = mode;
63  }
64 
65  std::string getNamespace(bool refresh = false);
66 
67  yarp::os::Bottle getNamespaces(bool refresh = false);
68 
69  void setNamespace(const std::string& ns);
70 
71 private:
72  Contact address;
73  YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::string) space;
74  yarp::os::Bottle spaces;
76 
77  bool fromString(const std::string& txt);
78 };
79 
80 } // namespace impl
81 } // namespace os
82 } // namespace yarp
83 
84 #endif // YARP_OS_IMPL_NAMECONFIG_H
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:74
Represents how to reach a part of a YARP network.
Definition: Contact.h:36
Small helper class to help deal with legacy YARP configuration files.
Definition: NameConfig.h:25
void setMode(const std::string &mode)
Definition: NameConfig.h:60
The main, catch-all namespace for YARP.
Definition: dirs.h:16
#define YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(x)
Suppress MSVC C4251 warning for the declaration.
Definition: system.h:336
#define YARP_os_impl_API
Definition: api.h:46