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