YARP
Yet Another Robot Platform
ResourceFinder.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_RESOURCEFINDER_H
8#define YARP_OS_RESOURCEFINDER_H
9
10#include <yarp/os/Bottle.h>
11#include <yarp/os/Property.h>
13#include <yarp/os/Searchable.h>
14#include <yarp/os/Value.h>
15
16#include <string>
17
18namespace yarp::os {
19
29{
30public:
32
34
35 virtual ~ResourceFinder();
36
37 const ResourceFinder& operator=(const ResourceFinder& alt);
38
50 bool configure(int argc, char* argv[], bool skipFirstArgument = true);
51
60 bool setDefaultContext(const std::string& contextName)
61 {
62 clearContext();
63 return addContext(contextName);
64 }
65
72 bool setDefault(const std::string& key, const std::string& val);
73
80 bool setDefault(const std::string& key, std::int32_t val);
81
88 bool setDefault(const std::string& key, yarp::conf::float64_t val);
89
95 bool setDefault(const std::string& key, const yarp::os::Value& val);
96
103 bool setDefaultConfigFile(const std::string& fname)
104 {
105 return setDefault("from", fname);
106 }
107
124 std::string findFile(const std::string& name);
125
133 std::string findFileByName(const std::string& name);
134
150 std::string findPath(const std::string& name);
151
166 yarp::os::Bottle findPaths(const std::string& name);
167
173 std::string findPath();
174
175
183 std::string getContext();
184
191 yarp::os::Bottle getContexts();
192
193 // Searchable interface
194 bool check(const std::string& key) const override;
195 Value& find(const std::string& key) const override;
196 Bottle& findGroup(const std::string& key) const override;
197 bool isNull() const override;
198 std::string toString() const override;
199
200
209 virtual ResourceFinder findNestedResourceFinder(const std::string& key);
210
211
212 bool isConfigured() const
213 {
214 return m_isConfiguredFlag;
215 }
216
225 static ResourceFinder& getResourceFinderSingleton();
226
227 using Searchable::check;
229
233 std::string getHomeContextPath();
234
238 std::string getHomeRobotPath();
239
240 yarp::os::Bottle findPaths(const std::string& name,
241 const ResourceFinderOptions& options);
242
243 std::string findPath(const std::string& name,
244 const ResourceFinderOptions& options);
245
246 std::string findFile(const std::string& name,
247 const ResourceFinderOptions& options);
248
249 std::string findFileByName(const std::string& name,
250 const ResourceFinderOptions& options);
251
252 bool readConfig(Property& config,
253 const std::string& key,
254 const ResourceFinderOptions& options);
255
256#ifndef YARP_NO_DEPRECATED // Since YARP 3.4
268 bool setVerbose(bool verbose = true);
269
280 bool setQuiet(bool quiet = true);
281#endif // YARP_NO_DEPRECATED
282
283#ifndef YARP_NO_DEPRECATED // SINCE YARP 3.5
302 YARP_DEPRECATED_MSG("Use yarp::conf::dirs::data_home() + yarp::os::mkdir_p() instead")
303 static std::string getDataHome()
304 {
305 return getDataHomeWithPossibleCreation(true);
306 }
307
308
315 YARP_DEPRECATED_MSG("Use yarp::conf::dirs::data_home() instead")
316 static std::string getDataHomeNoCreate()
317 {
318 return getDataHomeWithPossibleCreation(false);
319 }
320
336 YARP_DEPRECATED_MSG("Use yarp::conf::dirs::config_home() + yarp::os::mkdir_p() instead")
337 static std::string getConfigHome()
338 {
339 return getConfigHomeWithPossibleCreation(true);
340 }
341
348 YARP_DEPRECATED_MSG("Use yarp::conf::dirs::config_home() instead")
349 static std::string getConfigHomeNoCreate()
350 {
351 return getConfigHomeWithPossibleCreation(false);
352 }
353
369 YARP_DEPRECATED_MSG("Use yarp::conf::dirs::yarpdatadirs() instead")
370 static Bottle getDataDirs();
371
387 YARP_DEPRECATED_MSG("Use yarp::conf::dirs::config_dirs() instead")
388 static Bottle getConfigDirs();
389#endif // YARP_NO_DEPRECATED
390
391
392private:
393 // this might be useful, but is not in spec
394 bool addContext(const std::string& appName);
395
396 // this might be useful, but is not in spec
397 bool clearContext();
398
399 bool m_owned;
400 bool m_nullConfig;
401 bool m_isConfiguredFlag;
402 yarp::os::Property m_configprop;
403
404 static std::string createIfAbsent(bool mayCreate, const std::string& path);
405
406#ifndef YARP_NO_DEPRECATED // SINCE YARP 3.5
407 static std::string getDataHomeWithPossibleCreation(bool mayCreate);
408 static std::string getConfigHomeWithPossibleCreation(bool mayCreate);
409#endif
410
411#ifndef DOXYGEN_SHOULD_SKIP_THIS
412private:
413 class Private;
414 Private* mPriv;
415 ResourceFinder(Searchable& data, Private* altPriv);
416#endif // DOXYGEN_SHOULD_SKIP_THIS
417};
418
419} // namespace yarp::os
420
421#endif // YARP_OS_RESOURCEFINDER_H
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:64
A class for storing options and configuration information.
Definition: Property.h:33
These options are loosely based on http://wiki.icub.org/wiki/YARP_ResourceFinder.
Helper class for finding config files and other external resources.
bool setDefaultContext(const std::string &contextName)
Sets the context for the current ResourceFinder object.
static std::string getDataHome()
Location where user data files are stored.
bool setDefaultConfigFile(const std::string &fname)
Provide a default value for the configuration file (can be overridden from command line with the –fro...
A base class for nested structures that can be searched.
Definition: Searchable.h:56
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual Bottle & findGroup(const std::string &key) const =0
Gets a list corresponding to a given keyword.
A single value (typically within a Bottle).
Definition: Value.h:43
#define YARP_DEPRECATED_MSG(MSG)
Expands to either the standard [[deprecated]] attribute or a compiler-specific decorator such as __at...
Definition: compiler.h:2885
std::string toString(const T &value)
convert an arbitrary type to string.
STL namespace.
double float64_t
Definition: numeric.h:77
An interface to the operating system, including Port based communication.
std::string findGroup(const robotinterface::ParamList &list, const std::string &name)
Definition: Types.cpp:47
The main, catch-all namespace for YARP.
Definition: dirs.h:16
#define YARP_os_API
Definition: api.h:18