YARP
Yet Another Robot Platform
ResourceFinder.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/ResourceFinder.h>
11 
12 #include <yarp/conf/environment.h>
13 #include <yarp/conf/filesystem.h>
14 
15 #include <yarp/os/Bottle.h>
16 #include <yarp/os/Network.h>
17 #include <yarp/os/Os.h>
18 #include <yarp/os/Property.h>
19 #include <yarp/os/SystemClock.h>
20 #include <yarp/os/Time.h>
24 
25 #include <cerrno>
26 #include <cstdio>
27 #include <cstdlib>
28 #include <string>
29 
30 using namespace yarp::os;
31 using namespace yarp::os::impl;
32 namespace fs = yarp::conf::filesystem;
33 
34 #define RTARGET stderr
35 #define RESOURCE_FINDER_CACHE_TIME 10
36 
37 namespace {
38 #ifndef YARP_NO_DEPRECATED // since YARP 3.4
39 // The log component cannot be const because we still support setVerbose and
40 // setQuiet
41 YARP_OS_NON_CONST_LOG_COMPONENT(RESOURCEFINDER, "yarp.os.ResourceFinder")
42 #else
43 YARP_OS_LOG_COMPONENT(RESOURCEFINDER, "yarp.os.ResourceFinder")
44 #endif
45 }
46 
47 static std::string getPwd()
48 {
49  std::string result;
50  int len = 5;
51  char* buf = nullptr;
52  while (true) {
53  delete[] buf;
54  buf = new char[len];
55  if (buf == nullptr) {
56  break;
57  }
58  char* dir = yarp::os::getcwd(buf, len);
59  if (dir != nullptr) {
60  result = dir;
61  break;
62  }
63  if (errno != ERANGE) {
64  break;
65  }
66  len *= 2;
67  }
68  delete[] buf;
69  buf = nullptr;
70  return result;
71 }
72 
73 
74 static Bottle parsePaths(const std::string& txt)
75 {
76  if (txt.empty()) {
77  return Bottle();
78  }
81  Bottle result;
82  const char* at = txt.c_str();
83  int slash_tweak = 0;
84  int len = 0;
85  for (char ch : txt) {
86  if (ch == sep) {
87  result.addString(std::string(at, len - slash_tweak));
88  at += len + 1;
89  len = 0;
90  slash_tweak = 0;
91  continue;
92  }
93  slash_tweak = (ch == slash && len > 0) ? 1 : 0;
94  len++;
95  }
96  if (len > 0) {
97  result.addString(std::string(at, len - slash_tweak));
98  }
99  return result;
100 }
101 
102 
103 static void appendResourceType(std::string& path,
104  const std::string& resourceType)
105 {
106  if (resourceType.empty()) {
107  return;
108  }
109  std::string slash{fs::preferred_separator};
110  if (path.length() > 0) {
111  if (path[path.length() - 1] != slash[0]) {
112  path +=slash;
113  }
114  }
115  path += resourceType;
116 }
117 
118 static void prependResourceType(std::string& path,
119  const std::string& resourceType)
120 {
121  if (resourceType.empty()) {
122  return;
123  }
124  std::string slash{fs::preferred_separator};
125  path = resourceType + slash + path;
126 }
127 
128 static void appendResourceType(Bottle& paths,
129  const std::string& resourceType)
130 {
131  if (resourceType.empty()) {
132  return;
133  }
134  for (size_t i = 0; i < paths.size(); i++) {
135  std::string txt = paths.get(i).asString();
136  appendResourceType(txt, resourceType);
137  paths.get(i) = Value(txt);
138  }
139 }
140 
141 
143 {
144 private:
145  yarp::os::Bottle apps;
146  std::string configFilePath;
147  yarp::os::Property cache;
148  bool mainActive{false};
149  bool useNearMain{false};
150 
151 public:
152  bool addAppName(const std::string& appName)
153  {
154  apps.addString(appName);
155  return true;
156  }
157 
159  {
160  apps.clear();
161  return true;
162  }
163 
164  static std::string extractPath(const std::string& fname)
165  {
166  std::string s{fname};
167  auto n = s.rfind('/');
168 #if defined(_WIN32)
169  if (n == std::string::npos) {
170  n = s.rfind('\\');
171  }
172 #endif
173  if (n != std::string::npos) {
174  return s.substr(0, n);
175  }
176  return {};
177  }
178 
179  bool configure(Property& config, int argc, char* argv[], bool skip)
180  {
181  Property p;
182  p.fromCommand(argc, argv, skip);
183 
184  bool user_specified_from = p.check("from");
185 
186  if (p.check("verbose")) {
187  yCWarning(RESOURCEFINDER, "The 'verbose' option is deprecated.");
188  }
189 
190  yCDebug(RESOURCEFINDER, "configuring");
191 
192  bool configured_normally = true;
193 
194  if (p.check("context")) {
195  clearAppNames();
196  std::string c = p.check("context", Value("default")).asString();
197  addAppName(c.c_str());
198  yCDebug(RESOURCEFINDER, "added context %s", c.c_str());
199  }
200 
201  config.fromCommand(argc, argv, skip, false);
202  if (config.check("from")) {
203  std::string from = config.check("from",
204  Value("config.ini"))
205  .toString();
206  yCDebug(RESOURCEFINDER, "default config file specified as %s", from.c_str());
207  mainActive = true;
208  std::string corrected = findFile(config, from, nullptr);
209  mainActive = false;
210  if (!corrected.empty()) {
211  from = corrected;
212  }
213  std::string fromPath = extractPath(from.c_str());
214  configFilePath = fromPath;
215  if (!config.fromConfigFile(from, false) && user_specified_from) {
216  configured_normally = false;
217  }
218  config.fromCommand(argc, argv, skip, false);
219  }
220  return configured_normally;
221  }
222 
223  bool setDefault(Property& config, const std::string& key, const yarp::os::Value& val)
224  {
225  if (!config.check(key)) {
226  config.put(key, val);
227  }
228  return true;
229  }
230 
231  bool isAbsolute(const std::string& str)
232  {
233  if (str.length() > 0 && (str[0] == '/' || str[0] == '\\')) {
234  return true;
235  }
236  if (str.length() > 1) {
237  if (str[1] == ':') {
238  return true;
239  }
240  }
241  return false;
242  }
243 
244  bool isRooted(const std::string& str)
245  {
246  if (isAbsolute(str)) {
247  return true;
248  }
249  if (str.length() >= 2) {
250  if (str[0] == '.' && (str[1] == '/' || str[1] == '\\')) {
251  return true;
252  }
253  } else if (str == ".") {
254  return true;
255  }
256  return false;
257  }
258 
259  std::string getPath(const std::string& base1,
260  const std::string& base2,
261  const std::string& base3,
262  const std::string& name)
263  {
264  if (isAbsolute(name)) {
265  return name;
266  }
267 
268  std::string s;
269  std::string slash{fs::preferred_separator};
270 
271  if (!base1.empty()) {
272  s = base1;
273  s = s + slash;
274  }
275 
276  if (isRooted(base2)) {
277  s = base2;
278  } else {
279  s = s + base2;
280  }
281  if (!base2.empty()) {
282  s = s + slash;
283  }
284 
285  if (isRooted(base3)) {
286  s = base3;
287  } else {
288  s = s + base3;
289  }
290  if (!base3.empty()) {
291  s = s + slash;
292  }
293 
294  s = s + name;
295 
296  return s;
297  }
298 
299  std::string check(const std::string& base1,
300  const std::string& base2,
301  const std::string& base3,
302  const std::string& name,
303  bool isDir,
304  const Bottle& doc,
305  const std::string& doc2)
306  {
307  std::string s = getPath(base1, base2, base3, name);
308 
309  // check cache first
310  Bottle* prev = cache.find(s).asList();
311  if (prev != nullptr) {
312  double t = prev->get(0).asFloat64();
313  int flag = prev->get(1).asInt32();
315  if (flag != 0) {
316  return s;
317  }
318  return {};
319  }
320  }
321 
322  std::string base = doc.toString();
323  yCDebug(RESOURCEFINDER, "checking [%s] (%s%s%s)", s.c_str(), base.c_str(), (base.length() == 0) ? "" : " ", doc2.c_str());
324 
325  bool ok = exists(s.c_str(), isDir);
326  Value status;
327  yCAssert(RESOURCEFINDER, status.asList());
329  status.asList()->addInt32(ok ? 1 : 0);
330  cache.put(s, status);
331  if (ok) {
332  yCDebug(RESOURCEFINDER, "found %s", s.c_str());
333  return s;
334  }
335  return {};
336  }
337 
338  std::string findPath(Property& config, const std::string& name, const ResourceFinderOptions* externalOptions)
339  {
340  std::string fname = config.check(name, Value(name)).asString();
341  std::string result = findFileBase(config, fname, true, externalOptions);
342  return result;
343  }
344 
345  yarp::os::Bottle findPaths(Property& config, const std::string& name, const ResourceFinderOptions* externalOptions, bool enforcePlural = true)
346  {
347  std::string fname = config.check(name, Value(name)).asString();
348  Bottle paths;
349  if (externalOptions != nullptr) {
350  if (externalOptions->duplicateFilesPolicy == ResourceFinderOptions::All) {
351  findFileBase(config, fname, true, paths, *externalOptions);
352  return paths;
353  }
354  }
356  if (externalOptions != nullptr) {
357  opts = *externalOptions;
358  }
359  if (enforcePlural) {
361  }
362  findFileBase(config, fname, true, paths, opts);
363  return paths;
364  }
365 
366  std::string findPath(Property& config)
367  {
368  std::string result = findFileBase(config, "", true, nullptr);
369  if (result.empty()) {
370  result = getPwd();
371  }
372  return result;
373  }
374 
375  std::string findFile(Property& config, const std::string& name, const ResourceFinderOptions* externalOptions)
376  {
377  std::string fname = config.check(name, Value(name)).asString();
378  std::string result = findFileBase(config, fname, false, externalOptions);
379  return result;
380  }
381 
382  std::string findFileByName(Property& config, const std::string& fname, const ResourceFinderOptions* externalOptions)
383  {
384  std::string result = findFileBase(config, fname, false, externalOptions);
385  return result;
386  }
387 
388  std::string findFileBase(Property& config, const std::string& name, bool isDir, const ResourceFinderOptions* externalOptions)
389  {
390  Bottle output;
392  if (externalOptions == nullptr) {
393  externalOptions = &opts;
394  }
395  findFileBase(config, name, isDir, output, *externalOptions);
396  return output.get(0).asString();
397  }
398 
399  bool canShowErrors(const ResourceFinderOptions& opts) const
400  {
402  return false;
403  }
404  return true;
405  }
406 
407  void findFileBase(Property& config, const std::string& name, bool isDir, Bottle& output, const ResourceFinderOptions& opts)
408  {
409  Bottle doc;
410  size_t prelen = output.size();
411  findFileBaseInner(config, name, isDir, true, output, opts, doc, {});
412  if (output.size() != prelen) {
413  return;
414  }
415  bool justTop = (opts.duplicateFilesPolicy == ResourceFinderOptions::First);
416  if (justTop) {
417  if (canShowErrors(opts)) {
418  yCDebug(RESOURCEFINDER, "did not find %s", name.c_str());
419  }
420  }
421  }
422 
423  void addString(Bottle& output, const std::string& txt)
424  {
425  for (size_t i = 0; i < output.size(); i++) {
426  if (txt == output.get(i).asString()) {
427  return;
428  }
429  }
430  output.addString(txt);
431  }
432 
433  void findFileBaseInner(Property& config, const std::string& name, bool isDir, bool allowPathd, Bottle& output, const ResourceFinderOptions& opts, const Bottle& predoc, const std::string& reason)
434  {
435  Bottle doc;
436  doc = predoc;
437  if (!reason.empty()) {
438  doc.addString(reason);
439  }
442  std::string resourceType = opts.resourceType;
443 
444  bool justTop = (opts.duplicateFilesPolicy == ResourceFinderOptions::First);
445 
446  // check current directory
447  if ((locs & ResourceFinderOptions::Directory) != 0) {
448  if (name.empty() && isDir) {
449  addString(output, getPwd());
450  if (justTop) {
451  return;
452  }
453  }
454  std::string str = check(getPwd(), resourceType, "", name, isDir, doc, "pwd");
455  if (!str.empty()) {
456  if (mainActive) {
457  useNearMain = true;
458  }
459  addString(output, str);
460  if (justTop) {
461  return;
462  }
463  }
464  }
465 
466  if (((locs & ResourceFinderOptions::NearMainConfig) != 0) && useNearMain) {
467  if (!configFilePath.empty()) {
468  std::string str = check(configFilePath, resourceType, "", name, isDir, doc, "defaultConfigFile path");
469  if (!str.empty()) {
470  addString(output, str);
471  if (justTop) {
472  return;
473  }
474  }
475  }
476  }
477 
478  if ((locs & ResourceFinderOptions::Robot) != 0) {
479  std::string slash{fs::preferred_separator};
480  bool found = false;
481  std::string robot = yarp::conf::environment::getEnvironment("YARP_ROBOT_NAME", &found);
482  if (!found) {
483  robot = "default";
484  }
485 
486  // Nested search to locate robot directory
487  Bottle paths;
488  ResourceFinderOptions opts2;
490  opts2.resourceType = "robots";
492  findFileBaseInner(config, robot, true, allowPathd, paths, opts2, doc, "robot");
493  appendResourceType(paths, resourceType);
494  for (size_t j = 0; j < paths.size(); j++) {
495  std::string str = check(paths.get(j).asString(),
496  "",
497  "",
498  name,
499  isDir,
500  doc,
501  "robot");
502  if (!str.empty()) {
503  addString(output, str);
504  if (justTop) {
505  return;
506  }
507  }
508  }
509  }
510 
511  if (((locs & ResourceFinderOptions::Context) != 0) && !useNearMain) {
512  for (size_t i = 0; i < apps.size(); i++) {
513  std::string app = apps.get(i).asString();
514 
515  // New context still apparently applies only to "applications"
516  // which means we need to restrict our attention to "app"
517  // directories.
518 
519  // Nested search to locate context directory
520  Bottle paths;
521  ResourceFinderOptions opts2;
522  prependResourceType(app, "contexts");
525  findFileBaseInner(config, app, true, allowPathd, paths, opts2, doc, "context");
526  appendResourceType(paths, resourceType);
527  for (size_t j = 0; j < paths.size(); j++) {
528  std::string str = check(paths.get(j).asString(), "", "", name, isDir, doc, "context");
529  if (!str.empty()) {
530  addString(output, str);
531  if (justTop) {
532  return;
533  }
534  }
535  }
536  }
537  }
538 
539  // check YARP_CONFIG_HOME
540  if (((locs & ResourceFinderOptions::User) != 0) && ((flavor & ResourceFinderOptions::ConfigLike) != 0)) {
541  std::string home = ResourceFinder::getConfigHomeNoCreate();
542  if (!home.empty()) {
543  appendResourceType(home, resourceType);
544  std::string str = check(home, "", "", name, isDir, doc, "YARP_CONFIG_HOME");
545  if (!str.empty()) {
546  addString(output, str);
547  if (justTop) {
548  return;
549  }
550  }
551  }
552  }
553 
554  // check YARP_DATA_HOME
555  if (((locs & ResourceFinderOptions::User) != 0) && ((flavor & ResourceFinderOptions::DataLike) != 0)) {
556  std::string home = ResourceFinder::getDataHomeNoCreate();
557  if (!home.empty()) {
558  appendResourceType(home, resourceType);
559  std::string str = check(home, "", "", name, isDir, doc, "YARP_DATA_HOME");
560  if (!str.empty()) {
561  addString(output, str);
562  if (justTop) {
563  return;
564  }
565  }
566  }
567  }
568 
569  // check YARP_CONFIG_DIRS
570  if ((locs & ResourceFinderOptions::Sysadmin) != 0) {
572  appendResourceType(dirs, resourceType);
573  for (size_t i = 0; i < dirs.size(); i++) {
574  std::string str = check(dirs.get(i).asString(),
575  "",
576  "",
577  name,
578  isDir,
579  doc,
580  "YARP_CONFIG_DIRS");
581  if (!str.empty()) {
582  addString(output, str);
583  if (justTop) {
584  return;
585  }
586  }
587  }
588  }
589 
590  // check YARP_DATA_DIRS
591  if ((locs & ResourceFinderOptions::Installed) != 0) {
593  appendResourceType(dirs, resourceType);
594  for (size_t i = 0; i < dirs.size(); i++) {
595  std::string str = check(dirs.get(i).asString(),
596  "",
597  "",
598  name,
599  isDir,
600  doc,
601  "YARP_DATA_DIRS");
602  if (!str.empty()) {
603  addString(output, str);
604  if (justTop) {
605  return;
606  }
607  }
608  }
609  }
610 
611  if (allowPathd && ((locs & ResourceFinderOptions::Installed) != 0)) {
612  // Nested search to locate path.d directories
613  Bottle pathds;
614  ResourceFinderOptions opts2;
616  opts2.resourceType = "config";
617  findFileBaseInner(config, "path.d", true, false, pathds, opts2, doc, "path.d");
618 
619  for (size_t i = 0; i < pathds.size(); i++) {
620  // check /.../path.d/*
621  // this directory is expected to contain *.ini files like this:
622  // [search BUNDLE_NAME]
623  // path /PATH1 /PATH2
624  // for example:
625  // [search icub]
626  // path /usr/share/iCub
627  Property pathd;
628  pathd.fromConfigFile(pathds.get(i).asString());
629  Bottle sections = pathd.findGroup("search").tail();
630  for (size_t i = 0; i < sections.size(); i++) {
631  std::string search_name = sections.get(i).asString();
632  Bottle group = pathd.findGroup(search_name);
633  Bottle paths = group.findGroup("path").tail();
634  appendResourceType(paths, resourceType);
635  for (size_t j = 0; j < paths.size(); j++) {
636  std::string str = check(paths.get(j).asString(), "", "", name, isDir, doc, "yarp.d");
637  if (!str.empty()) {
638  addString(output, str);
639  if (justTop) {
640  return;
641  }
642  }
643  }
644  }
645  }
646  }
647  }
648 
649  bool exists(const std::string& fname, bool isDir)
650  {
651  int result = yarp::os::stat(fname.c_str());
652  if (result != 0) {
653  return false;
654  }
655  if (!isDir) {
656  // if not required to be a directory, pass anything.
657  return true;
658  }
659 
660  // ACE doesn't seem to help us interpret the results of stat
661  // in a portable fashion.
662 
663  // ACE on Ubuntu 9.10 has issues.
664  // Suppressing check for file here since it isn't really needed
665  // and causes a lot of problems.
666  /*
667  YARP_DIR *dir = ACE_OS::opendir(fname);
668  if (dir!=nullptr) {
669  ACE_OS::closedir(dir);
670  dir = nullptr;
671  return true;
672  }
673  return false;
674  */
675  return true;
676  }
677 
678 
679  std::string getContext()
680  {
681  return apps.get(0).asString();
682  }
683 
685  {
686  return apps;
687  }
688 
689  std::string getHomeContextPath(Property& config, const std::string& context)
690  {
691  YARP_UNUSED(config);
692  if (useNearMain) {
693  return configFilePath;
694  }
695  std::string path = getPath(ResourceFinder::getDataHome(), "contexts", context, "");
696 
697  std::string slash{fs::preferred_separator};
698  if (path.length() > 1) {
699  if (path[path.length() - 1] == slash[0]) {
700  path = path.substr(0, path.length() - slash.size());
701  }
702  }
703 
704  std::string parentPath = getPath(ResourceFinder::getDataHome(), "contexts", "", "");
705  if (yarp::os::stat(parentPath.c_str()) != 0) {
706  yarp::os::mkdir(parentPath.c_str());
707  }
708 
709  if (yarp::os::mkdir(path.c_str()) < 0 && errno != EEXIST) {
710  yCWarning(RESOURCEFINDER, "Could not create %s directory", path.c_str());
711  }
712  return path;
713  }
714 
715  std::string getHomeRobotPath()
716  {
717  if (useNearMain) {
718  return configFilePath;
719  }
720  bool found = false;
721  std::string robot = yarp::conf::environment::getEnvironment("YARP_ROBOT_NAME", &found);
722  if (!found) {
723  robot = "default";
724  }
725  std::string path = getPath(ResourceFinder::getDataHome(), "robots", robot, "");
726 
727  std::string slash{fs::preferred_separator};
728  if (path.length() > 1) {
729  if (path[path.length() - 1] == slash[0]) {
730  path = path.substr(0, path.length() - slash.size());
731  }
732  }
733 
734  std::string parentPath = getPath(ResourceFinder::getDataHome(), "robots", "", "");
735  if (yarp::os::stat(parentPath.c_str()) != 0) {
736  yarp::os::mkdir(parentPath.c_str());
737  }
738 
739  if (yarp::os::mkdir(path.c_str()) < 0 && errno != EEXIST) {
740  yCWarning(RESOURCEFINDER, "Could not create %s directory", path.c_str());
741  }
742  return path;
743  }
744 };
745 
746 
748  Searchable(),
749  owned(true),
750  nullConfig(false),
751  isConfiguredFlag(false),
752  mPriv(nullptr)
753 {
755  mPriv = new Private();
756 }
757 
759  Searchable(alt),
760  owned(true),
761  nullConfig(false),
762  isConfiguredFlag(false),
763  mPriv(nullptr)
764 {
766  mPriv = new Private();
767  *this = alt;
768 }
769 
770 ResourceFinder::ResourceFinder(Searchable& data, Private* altPriv) :
771  Searchable(),
772  owned(false),
773  nullConfig(data.isNull()),
774  isConfiguredFlag(true),
775  mPriv(nullptr)
776 {
778  this->mPriv = altPriv;
779  if (!data.isNull()) {
780  config.fromString(data.toString());
781  }
782 }
783 
785 {
786  if (owned) {
787  delete mPriv;
788  }
789 }
790 
792 {
793  if (&alt != this) {
794  *(mPriv) = *(alt.mPriv);
795  owned = true;
796  nullConfig = alt.nullConfig;
797  isConfiguredFlag = alt.isConfiguredFlag;
798  config = alt.config;
799  }
800  return *this;
801 }
802 
803 bool ResourceFinder::configure(int argc, char* argv[], bool skipFirstArgument)
804 {
805  isConfiguredFlag = true;
806  return mPriv->configure(config, argc, argv, skipFirstArgument);
807 }
808 
809 
810 bool ResourceFinder::addContext(const std::string& appName)
811 {
812  if (appName[0] == '\0') {
813  return true;
814  }
815  yCDebug(RESOURCEFINDER, "adding context [%s]", appName.c_str());
816  return mPriv->addAppName(appName);
817 }
818 
819 bool ResourceFinder::clearContext()
820 {
821  yCDebug(RESOURCEFINDER, "clearing context");
822  return mPriv->clearAppNames();
823 }
824 
825 bool ResourceFinder::setDefault(const std::string& key, const std::string& val)
826 {
827  Value val2;
828  val2.fromString(val.c_str());
829  return mPriv->setDefault(config, key, val2);
830 }
831 
832 bool ResourceFinder::setDefault(const std::string& key, std::int32_t val)
833 {
834  return mPriv->setDefault(config, key, Value(val));
835 }
836 
837 bool ResourceFinder::setDefault(const std::string& key, yarp::conf::float64_t val)
838 {
839  return mPriv->setDefault(config, key, Value(val));
840 }
841 
842 bool ResourceFinder::setDefault(const std::string& key, const yarp::os::Value& val)
843 {
844  return mPriv->setDefault(config, key, val);
845 }
846 
847 std::string ResourceFinder::findFile(const std::string& name)
848 {
849  yCDebug(RESOURCEFINDER, "finding file [%s]", name.c_str());
850  return mPriv->findFile(config, name, nullptr);
851 }
852 
853 std::string ResourceFinder::findFile(const std::string& name,
854  const ResourceFinderOptions& options)
855 {
856  yCDebug(RESOURCEFINDER, "finding file [%s]", name.c_str());
857  return mPriv->findFile(config, name, &options);
858 }
859 
860 std::string ResourceFinder::findFileByName(const std::string& name)
861 {
862  yCDebug(RESOURCEFINDER, "finding file %s", name.c_str());
863  return mPriv->findFileByName(config, name, nullptr);
864 }
865 
866 std::string ResourceFinder::findFileByName(const std::string& name,
867  const ResourceFinderOptions& options)
868 {
869  yCDebug(RESOURCEFINDER, "finding file %s", name.c_str());
870  return mPriv->findFileByName(config, name, &options);
871 }
872 
873 
874 std::string ResourceFinder::findPath(const std::string& name)
875 {
876  yCDebug(RESOURCEFINDER, "finding path [%s]", name.c_str());
877  return mPriv->findPath(config, name, nullptr);
878 }
879 
880 std::string ResourceFinder::findPath(const std::string& name,
881  const ResourceFinderOptions& options)
882 {
883  yCDebug(RESOURCEFINDER, "finding path [%s]", name.c_str());
884  return mPriv->findPath(config, name, &options);
885 }
886 
888 {
889  yCDebug(RESOURCEFINDER, "finding paths [%s]", name.c_str());
890  return mPriv->findPaths(config, name, nullptr);
891 }
892 
894  const ResourceFinderOptions& options)
895 {
896  yCDebug(RESOURCEFINDER, "finding paths [%s]", name.c_str());
897  return mPriv->findPaths(config, name, &options);
898 }
899 
901 {
902  yCDebug(RESOURCEFINDER, "finding path");
903  return mPriv->findPath(config);
904 }
905 
906 #ifndef YARP_NO_DEPRECATED // Since YARP 3.4
907 bool ResourceFinder::setVerbose(bool verbose)
908 {
909  RESOURCEFINDER().setMinimumPrintLevel(verbose ? yarp::os::Log::DebugType : yarp::os::Log::InfoType);
910  return true;
911 }
912 
913 bool ResourceFinder::setQuiet(bool quiet)
914 {
915  RESOURCEFINDER().setMinimumPrintLevel(quiet ? yarp::os::Log::WarningType : yarp::os::Log::InfoType);
916  return true;
917 }
918 #endif
919 
920 bool ResourceFinder::check(const std::string& key) const
921 {
922  return config.check(key);
923 }
924 
925 
926 Value& ResourceFinder::find(const std::string& key) const
927 {
928  return config.find(key);
929 }
930 
931 
932 Bottle& ResourceFinder::findGroup(const std::string& key) const
933 {
934  return config.findGroup(key);
935 }
936 
937 
939 {
940  return nullConfig || config.isNull();
941 }
942 
943 
944 std::string ResourceFinder::toString() const
945 {
946  return config.toString();
947 }
948 
950 {
951  return mPriv->getContext();
952 }
953 
955 {
956  return mPriv->getHomeContextPath(config, mPriv->getContext());
957 }
958 
960 {
961  return mPriv->getHomeRobotPath();
962 }
963 
965 {
966  return mPriv->getContexts();
967 }
968 
969 
971 {
972  return ResourceFinder(findGroup(key), mPriv);
973 }
974 
975 
977 {
978  static ResourceFinder instance;
979  return instance;
980 }
981 
982 std::string ResourceFinder::getDataHomeWithPossibleCreation(bool mayCreate)
983 {
984  std::string slash{fs::preferred_separator};
985  bool found = false;
986  std::string yarp_version = yarp::conf::environment::getEnvironment("YARP_DATA_HOME",
987  &found);
988  if (!yarp_version.empty()) {
989  return yarp_version;
990  }
991  std::string xdg_version = yarp::conf::environment::getEnvironment("XDG_DATA_HOME",
992  &found);
993  if (found) {
994  return createIfAbsent(mayCreate, xdg_version + slash + "yarp");
995  }
996 #if defined(_WIN32)
997  std::string app_version = yarp::conf::environment::getEnvironment("APPDATA");
998  if (app_version != "") {
999  return createIfAbsent(mayCreate, app_version + slash + "yarp");
1000  }
1001 #endif
1002  std::string home_version = yarp::conf::environment::getEnvironment("HOME");
1003 #if defined(__APPLE__)
1004  if (home_version != "") {
1005  return createIfAbsent(mayCreate,
1006  home_version
1007  + slash + "Library"
1008  + slash + "Application Support"
1009  + slash + "yarp");
1010  }
1011 #endif
1012  if (!home_version.empty()) {
1013  return createIfAbsent(mayCreate,
1014  home_version
1015  + slash + ".local"
1016  + slash + "share"
1017  + slash + "yarp");
1018  }
1019  return {};
1020 }
1021 
1022 
1023 std::string ResourceFinder::getConfigHomeWithPossibleCreation(bool mayCreate)
1024 {
1025  std::string slash{fs::preferred_separator};
1026  bool found = false;
1027  std::string yarp_version = yarp::conf::environment::getEnvironment("YARP_CONFIG_HOME",
1028  &found);
1029  if (found) {
1030  return yarp_version;
1031  }
1032  std::string xdg_version = yarp::conf::environment::getEnvironment("XDG_CONFIG_HOME",
1033  &found);
1034  if (found) {
1035  return createIfAbsent(mayCreate, xdg_version + slash + "yarp");
1036  }
1037 #if defined(_WIN32)
1038  std::string app_version = yarp::conf::environment::getEnvironment("APPDATA");
1039  if (app_version != "") {
1040  return createIfAbsent(mayCreate,
1041  app_version + slash + "yarp" + slash + "config");
1042  }
1043 #endif
1044 
1045 #if defined(__APPLE__)
1046  std::string home_mac_version = getDataHomeNoCreate();
1047  if (home_mac_version != "") {
1048  return createIfAbsent(mayCreate,
1049  home_mac_version
1050  + slash + "config");
1051  }
1052 #endif
1053  std::string home_version = yarp::conf::environment::getEnvironment("HOME");
1054  if (!home_version.empty()) {
1055  return createIfAbsent(mayCreate,
1056  home_version
1057  + slash + ".config"
1058  + slash + "yarp");
1059  }
1060  return {};
1061 }
1062 
1063 std::string ResourceFinder::createIfAbsent(bool mayCreate,
1064  const std::string& path)
1065 {
1066  if (!mayCreate) {
1067  return path;
1068  }
1069  yarp::os::mkdir_p(path.c_str(), 0);
1070  return path;
1071 }
1072 
1074 {
1075  std::string slash{fs::preferred_separator};
1076  bool found = false;
1077  Bottle yarp_version = parsePaths(yarp::conf::environment::getEnvironment("YARP_DATA_DIRS",
1078  &found));
1079  if (found) {
1080  return yarp_version;
1081  }
1082  Bottle xdg_version = parsePaths(yarp::conf::environment::getEnvironment("XDG_DATA_DIRS",
1083  &found));
1084  if (found) {
1085  appendResourceType(xdg_version, "yarp");
1086  return xdg_version;
1087  }
1088 #if defined(_WIN32)
1089  std::string app_version = yarp::conf::environment::getEnvironment("YARP_DIR");
1090  if (app_version != "") {
1091  appendResourceType(app_version, "share");
1092  appendResourceType(app_version, "yarp");
1093  Bottle result;
1094  result.addString(app_version);
1095  return result;
1096  }
1097 #endif
1098  Bottle result;
1099  result.addString("/usr/local/share/yarp");
1100  result.addString("/usr/share/yarp");
1101  return result;
1102 }
1103 
1104 
1106 {
1107  bool found = false;
1108  Bottle yarp_version = parsePaths(yarp::conf::environment::getEnvironment("YARP_CONFIG_DIRS",
1109  &found));
1110  if (found) {
1111  return yarp_version;
1112  }
1113  Bottle xdg_version = parsePaths(yarp::conf::environment::getEnvironment("XDG_CONFIG_DIRS",
1114  &found));
1115  if (found) {
1116  appendResourceType(xdg_version, "yarp");
1117  return xdg_version;
1118  }
1119 #if defined(_WIN32)
1120  std::string app_version = yarp::conf::environment::getEnvironment("ALLUSERSPROFILE");
1121  if (app_version != "") {
1122  appendResourceType(app_version, "yarp");
1123  Bottle result;
1124  result.addString(app_version);
1125  return result;
1126  }
1127 #endif
1128 
1129  Bottle result;
1130 #if defined(__APPLE__)
1131  result.addString("/Library/Preferences/yarp");
1132 #endif
1133  result.addString("/etc/yarp");
1134  return result;
1135 }
1136 
1137 
1139  const std::string& key,
1140  const ResourceFinderOptions& options)
1141 {
1142  Bottle bot = mPriv->findPaths(config, key, &options, false);
1143 
1144  for (int i = bot.size() - 1; i >= 0; i--) {
1145  std::string fname = bot.get(i).asString();
1146  config.fromConfigFile(fname, false);
1147  }
1148 
1149  return bot.size() >= 1;
1150 }
RESOURCE_FINDER_CACHE_TIME
#define RESOURCE_FINDER_CACHE_TIME
Definition: ResourceFinder.cpp:35
filesystem.h
yarp::os::ResourceFinderOptions::Sysadmin
@ Sysadmin
Definition: ResourceFinderOptions.h:37
yarp::os::Bottle
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:73
yarp::os::ResourceFinderOptions::searchFlavor
SearchFlavor searchFlavor
Definition: ResourceFinderOptions.h:70
yarp::os::ResourceFinderOptions::Robot
@ Robot
Definition: ResourceFinderOptions.h:35
yarp::os::ResourceFinder::readConfig
bool readConfig(Property &config, const std::string &key, const ResourceFinderOptions &options)
Definition: ResourceFinder.cpp:1138
yarp::os::Bottle::toString
std::string toString() const override
Gives a human-readable textual representation of the bottle.
Definition: Bottle.cpp:214
yarp::os::Property::put
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
Definition: Property.cpp:998
SystemClock.h
yarp::conf::filesystem
Definition: filesystem.h:15
yarp::os::Log::InfoType
@ InfoType
Definition: Log.h:79
yarp::os::Bottle::clear
void clear()
Empties the bottle of any objects it contains.
Definition: Bottle.cpp:124
yarp::os::ResourceFinder::Private::findFileBase
std::string findFileBase(Property &config, const std::string &name, bool isDir, const ResourceFinderOptions *externalOptions)
Definition: ResourceFinder.cpp:388
Network.h
yarp::os::ResourceFinder::Private::configure
bool configure(Property &config, int argc, char *argv[], bool skip)
Definition: ResourceFinder.cpp:179
yarp::os::Searchable
A base class for nested structures that can be searched.
Definition: Searchable.h:69
yarp::os::ResourceFinder::getContexts
yarp::os::Bottle getContexts()
Return the full stack of contexts used in searching for configuration files.
Definition: ResourceFinder.cpp:964
yarp::os::ResourceFinderOptions::NearMainConfig
@ NearMainConfig
Definition: ResourceFinderOptions.h:39
yarp::os::Bottle::size
size_type size() const
Gets the number of elements in the bottle.
Definition: Bottle.cpp:254
yarp::conf::filesystem::value_type
char value_type
Definition: filesystem.h:27
t
float t
Definition: FfmpegWriter.cpp:74
yarp::os::ResourceFinder::getHomeRobotPath
std::string getHomeRobotPath()
Return the path to the "user" robot directory.
Definition: ResourceFinder.cpp:959
yarp::os::ResourceFinderOptions::Installed
@ Installed
Definition: ResourceFinderOptions.h:38
yCWarning
#define yCWarning(component,...)
Definition: LogComponent.h:146
yarp::os::ResourceFinder::ResourceFinder
ResourceFinder()
Definition: ResourceFinder.cpp:747
yarp::os::ResourceFinderOptions::ShowNone
@ ShowNone
Definition: ResourceFinderOptions.h:61
yarp::os::ResourceFinder::~ResourceFinder
virtual ~ResourceFinder()
Definition: ResourceFinder.cpp:784
yarp::os::ResourceFinder::Private::findFileBaseInner
void findFileBaseInner(Property &config, const std::string &name, bool isDir, bool allowPathd, Bottle &output, const ResourceFinderOptions &opts, const Bottle &predoc, const std::string &reason)
Definition: ResourceFinder.cpp:433
yarp::conf::environment::getEnvironment
std::string getEnvironment(const char *key, bool *found=nullptr)
Read a variable from the environment.
Definition: environment.h:31
yarp::os::Searchable::toString
virtual std::string toString() const =0
Return a standard text representation of the content of the object.
yarp::os::Property::fromString
void fromString(const std::string &txt, bool wipe=true)
Interprets a string as a list of properties.
Definition: Property.cpp:1046
yarp::os::ResourceFinderOptions
These options are loosely based on http://wiki.icub.org/wiki/YARP_ResourceFinder.
Definition: ResourceFinderOptions.h:28
yarp::os::Log::WarningType
@ WarningType
Definition: Log.h:80
yarp::os::ResourceFinderOptions::Context
@ Context
Definition: ResourceFinderOptions.h:34
yarp::conf::filesystem::path_separator
static constexpr value_type path_separator
Definition: filesystem.h:29
yarp::os::ResourceFinderOptions::duplicateFilesPolicy
DuplicateFilesPolicy duplicateFilesPolicy
Definition: ResourceFinderOptions.h:69
YARP_UNUSED
#define YARP_UNUSED(var)
Definition: api.h:159
yarp::os::ResourceFinder::Private::findFile
std::string findFile(Property &config, const std::string &name, const ResourceFinderOptions *externalOptions)
Definition: ResourceFinder.cpp:375
yarp::os::Property::find
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
Definition: Property.cpp:1034
yarp::os::ResourceFinder::findPaths
yarp::os::Bottle findPaths(const std::string &name)
Expand a partial path to a list of paths.
Definition: ResourceFinder.cpp:887
yarp::os::ResourceFinder::Private::isAbsolute
bool isAbsolute(const std::string &str)
Definition: ResourceFinder.cpp:231
LogComponent.h
yarp::os::Bottle::addFloat64
void addFloat64(yarp::conf::float64_t x)
Places a 64-bit floating point number in the bottle, at the end of the list.
Definition: Bottle.cpp:161
yarp::os::ResourceFinder::Private::findPaths
yarp::os::Bottle findPaths(Property &config, const std::string &name, const ResourceFinderOptions *externalOptions, bool enforcePlural=true)
Definition: ResourceFinder.cpp:345
yarp::os::ResourceFinderOptions::All
@ All
Definition: ResourceFinderOptions.h:49
yarp::os::ResourceFinderOptions::SearchLocations
SearchLocations
Definition: ResourceFinderOptions.h:31
yarp::os::SystemClock::nowSystem
static double nowSystem()
Definition: SystemClock.cpp:37
sep
constexpr fs::value_type sep
Definition: Run.cpp:101
yarp::os::ResourceFinder::findGroup
virtual Bottle & findGroup(const std::string &key) const=0
Gets a list corresponding to a given keyword.
yarp::os::ResourceFinder::Private::clearAppNames
bool clearAppNames()
Definition: ResourceFinder.cpp:158
yarp::os::Bottle::findGroup
Bottle & findGroup(const std::string &key) const override
Gets a list corresponding to a given keyword.
Definition: Bottle.cpp:305
yarp::os::ResourceFinderOptions::First
@ First
Definition: ResourceFinderOptions.h:48
yarp::os::ResourceFinder::getContext
std::string getContext()
Return the default "context" or "application name" used in searching for configuration files.
Definition: ResourceFinder.cpp:949
prependResourceType
static void prependResourceType(std::string &path, const std::string &resourceType)
Definition: ResourceFinder.cpp:118
yarp::os::ResourceFinderOptions::resourceType
std::string resourceType
Definition: ResourceFinderOptions.h:71
yarp::os::ResourceFinder::findFile
std::string findFile(const std::string &name)
Find the full path to a file.
Definition: ResourceFinder.cpp:847
yarp::os::ResourceFinder::operator=
const ResourceFinder & operator=(const ResourceFinder &alt)
Definition: ResourceFinder.cpp:791
yarp::os::ResourceFinder::findPath
std::string findPath()
Find the first existing directory in the search path.
Definition: ResourceFinder.cpp:900
yarp::os::YARP_CLOCK_SYSTEM
@ YARP_CLOCK_SYSTEM
Definition: Time.h:32
yarp::os::ResourceFinder::getConfigDirs
static Bottle getConfigDirs()
Locations where system administrator data and config files are stored.
Definition: ResourceFinder.cpp:1105
yarp::os::Property::fromCommand
void fromCommand(int argc, char *argv[], bool skipFirst=true, bool wipe=true)
Interprets a list of command arguments as a list of properties.
Definition: Property.cpp:1057
yarp::os::ResourceFinder::setDefault
bool setDefault(const std::string &key, const std::string &val)
Provide a default value for a given key.
Definition: ResourceFinder.cpp:825
yarp::os::ResourceFinder::configure
bool configure(int argc, char *argv[], bool skipFirstArgument=true)
Sets up the ResourceFinder.
Definition: ResourceFinder.cpp:803
yarp::os::Bottle::get
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
Definition: Bottle.cpp:249
parsePaths
static Bottle parsePaths(const std::string &txt)
Definition: ResourceFinder.cpp:74
yarp::os::ResourceFinder::Private::findPath
std::string findPath(Property &config)
Definition: ResourceFinder.cpp:366
yarp::os::Property::toString
std::string toString() const override
Return a standard text representation of the content of the object.
Definition: Property.cpp:1052
Property.h
yarp::os::ResourceFinderOptions::User
@ User
Definition: ResourceFinderOptions.h:36
yarp::os::ResourceFinderOptions::searchLocations
SearchLocations searchLocations
Definition: ResourceFinderOptions.h:68
yarp::os::ResourceFinder::Private::getHomeRobotPath
std::string getHomeRobotPath()
Definition: ResourceFinder.cpp:715
getPwd
static std::string getPwd()
Definition: ResourceFinder.cpp:47
yarp::os::ResourceFinder::Private::isRooted
bool isRooted(const std::string &str)
Definition: ResourceFinder.cpp:244
yarp::os::ResourceFinder::check
virtual bool check(const std::string &key) const=0
Check if there exists a property of the given name.
yarp::os::Value::asString
virtual std::string asString() const
Get string value.
Definition: Value.cpp:237
Os.h
yarp::os::ResourceFinder::find
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
Definition: ResourceFinder.cpp:926
yarp::os::ResourceFinder::Private
Definition: ResourceFinder.cpp:143
yarp::os::ResourceFinder::getHomeContextPath
std::string getHomeContextPath()
Return the path to the "user" context directory for the current context.
Definition: ResourceFinder.cpp:954
yarp::os::ResourceFinder::Private::findFileBase
void findFileBase(Property &config, const std::string &name, bool isDir, Bottle &output, const ResourceFinderOptions &opts)
Definition: ResourceFinder.cpp:407
yarp::os::Bottle::addInt32
void addInt32(std::int32_t x)
Places a 32-bit integer in the bottle, at the end of the list.
Definition: Bottle.cpp:143
yarp::os::ResourceFinder::Private::getContext
std::string getContext()
Definition: ResourceFinder.cpp:679
yarp::os::ResourceFinderOptions::messageFilter
MessageFilter messageFilter
Definition: ResourceFinderOptions.h:72
NameConfig.h
yarp::os::ResourceFinderOptions::SearchFlavor
SearchFlavor
Definition: ResourceFinderOptions.h:53
yarp::os::Property::check
bool check(const std::string &key) const override
Check if there exists a property of the given name.
Definition: Property.cpp:1024
yarp::os::ResourceFinderOptions::DataLike
@ DataLike
Definition: ResourceFinderOptions.h:55
yarp::os::ResourceFinder::Private::canShowErrors
bool canShowErrors(const ResourceFinderOptions &opts) const
Definition: ResourceFinder.cpp:399
yarp::os::getcwd
char * getcwd(char *buf, size_t size)
Portable wrapper for the getcwd() function.
Definition: Os.cpp:115
yarp::os::stat
int stat(const char *path)
Portable wrapper for the stat() function.
Definition: Os.cpp:88
yarp::os::NetworkBase::autoInitMinimum
static void autoInitMinimum()
Basic system initialization, not including plugins.
Definition: Network.cpp:860
yarp::os::Bottle::addString
void addString(const char *str)
Places a string in the bottle, at the end of the list.
Definition: Bottle.cpp:173
yarp::os::ResourceFinder::Private::addAppName
bool addAppName(const std::string &appName)
Definition: ResourceFinder.cpp:152
yarp::os::mkdir_p
int mkdir_p(const char *p, int ignoreLevels=0)
Create a directory and all parent directories needed.
Definition: Os.cpp:45
yCAssert
#define yCAssert(component, x)
Definition: LogComponent.h:172
yarp::os::ResourceFinder::getDataDirs
static Bottle getDataDirs()
Locations where packaged data and config files are stored.
Definition: ResourceFinder.cpp:1073
yarp::os::ResourceFinder::Private::getPath
std::string getPath(const std::string &base1, const std::string &base2, const std::string &base3, const std::string &name)
Definition: ResourceFinder.cpp:259
yarp::os::ResourceFinder::Private::getHomeContextPath
std::string getHomeContextPath(Property &config, const std::string &context)
Definition: ResourceFinder.cpp:689
yarp::os::mkdir
int mkdir(const char *p)
Portable wrapper for the mkdir() function.
Definition: Os.cpp:40
yarp::os::Bottle::tail
Bottle tail() const
Get all but the first element of a bottle.
Definition: Bottle.cpp:391
yarp::os::ResourceFinder::getResourceFinderSingleton
static ResourceFinder & getResourceFinderSingleton()
Access a ResourceFinder singleton whose lifetime will match that of the YARP library.
Definition: ResourceFinder.cpp:976
yarp::os::ResourceFinder::Private::addString
void addString(Bottle &output, const std::string &txt)
Definition: ResourceFinder.cpp:423
yarp::os::ResourceFinder::setVerbose
bool setVerbose(bool verbose=true)
Request that information be printed to the console on how resources are being found.
Definition: ResourceFinder.cpp:907
yarp::os::ResourceFinderOptions::Default
@ Default
Definition: ResourceFinderOptions.h:42
yarp::os::Value::asInt32
virtual std::int32_t asInt32() const
Get 32-bit integer value.
Definition: Value.cpp:207
yarp::os::Property::fromConfigFile
bool fromConfigFile(const std::string &fname, bool wipe=true)
Interprets a file as a list of properties.
Definition: Property.cpp:1081
yarp::os::ResourceFinder::findNestedResourceFinder
virtual ResourceFinder findNestedResourceFinder(const std::string &key)
Gets a section as a ResourceFinder object, retaining the context and configuration of the current Res...
Definition: ResourceFinder.cpp:970
yarp::os::ResourceFinderOptions::Directory
@ Directory
Definition: ResourceFinderOptions.h:33
yarp::os
An interface to the operating system, including Port based communication.
Definition: AbstractCarrier.h:17
yCDebug
#define yCDebug(component,...)
Definition: LogComponent.h:112
yarp::os::ResourceFinder::isNull
bool isNull() const override
Checks if the object is invalid.
Definition: ResourceFinder.cpp:938
yarp::os::ResourceFinder::Private::setDefault
bool setDefault(Property &config, const std::string &key, const yarp::os::Value &val)
Definition: ResourceFinder.cpp:223
yarp::os::ResourceFinder::getDataHomeNoCreate
static std::string getDataHomeNoCreate()
Variant of getDataHome that will never create the directory returned.
Definition: ResourceFinder.h:294
YARP_OS_NON_CONST_LOG_COMPONENT
#define YARP_OS_NON_CONST_LOG_COMPONENT(name, name_string)
Definition: LogComponent.h:48
yarp::os::ResourceFinder::setQuiet
bool setQuiet(bool quiet=true)
Request that information be suppressed from the console.
Definition: ResourceFinder.cpp:913
PlatformSysStat.h
yarp::os::ResourceFinder::Private::findPath
std::string findPath(Property &config, const std::string &name, const ResourceFinderOptions *externalOptions)
Definition: ResourceFinder.cpp:338
yarp::os::Value::fromString
void fromString(const char *str)
Set value to correspond to a textual representation.
Definition: Value.cpp:354
environment.h
yarp::os::Searchable::isNull
virtual bool isNull() const
Checks if the object is invalid.
Definition: Searchable.cpp:110
yarp::conf::filesystem::preferred_separator
static constexpr value_type preferred_separator
Definition: filesystem.h:28
yarp::os::ResourceFinder::getConfigHomeNoCreate
static std::string getConfigHomeNoCreate()
Variant of getConfigHome that will never create the directory returned.
Definition: ResourceFinder.h:325
yarp::os::Value::asList
virtual Bottle * asList() const
Get list value.
Definition: Value.cpp:243
yarp::os::ResourceFinder::Private::exists
bool exists(const std::string &fname, bool isDir)
Definition: ResourceFinder.cpp:649
yarp::conf::float64_t
double float64_t
Definition: numeric.h:51
yarp::os::Property::findGroup
Bottle & findGroup(const std::string &key) const override
Gets a list corresponding to a given keyword.
Definition: Property.cpp:1125
Time.h
yarp::os::ResourceFinder::findFileByName
std::string findFileByName(const std::string &name)
Find the full path to a file.
Definition: ResourceFinder.cpp:860
yarp::os::Value
A single value (typically within a Bottle).
Definition: Value.h:47
appendResourceType
static void appendResourceType(std::string &path, const std::string &resourceType)
Definition: ResourceFinder.cpp:103
yarp::os::ResourceFinder::Private::findFileByName
std::string findFileByName(Property &config, const std::string &fname, const ResourceFinderOptions *externalOptions)
Definition: ResourceFinder.cpp:382
yarp::os::ResourceFinder::Private::getContexts
Bottle getContexts()
Definition: ResourceFinder.cpp:684
yarp::os::ResourceFinder::getDataHome
static std::string getDataHome()
Location where user data files are stored.
Definition: ResourceFinder.h:282
yarp::os::ResourceFinderOptions::ConfigLike
@ ConfigLike
Definition: ResourceFinderOptions.h:54
YARP_OS_LOG_COMPONENT
#define YARP_OS_LOG_COMPONENT(name, name_string)
Definition: LogComponent.h:37
yarp::os::impl
The components from which ports and connections are built.
yarp::os::Value::asFloat64
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
Definition: Value.cpp:225
yarp::os::Log::DebugType
@ DebugType
Definition: Log.h:78
yarp::os::ResourceFinder::Private::check
std::string check(const std::string &base1, const std::string &base2, const std::string &base3, const std::string &name, bool isDir, const Bottle &doc, const std::string &doc2)
Definition: ResourceFinder.cpp:299
Bottle.h
slash
constexpr fs::value_type slash
Definition: Run.cpp:100
ResourceFinder.h
yarp::os::Property
A class for storing options and configuration information.
Definition: Property.h:37
yarp::os::ResourceFinder::Private::extractPath
static std::string extractPath(const std::string &fname)
Definition: ResourceFinder.cpp:164
yarp::os::ResourceFinder::toString
std::string toString() const override
Return a standard text representation of the content of the object.
Definition: ResourceFinder.cpp:944
yarp::os::ResourceFinder
Helper class for finding config files and other external resources.
Definition: ResourceFinder.h:33