file-explorer.cpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2016-2021 CNRS INRIA
3 //
4 
5 #include <cstdlib>
6 #include <boost/filesystem.hpp>
8 
9 namespace fs = boost::filesystem;
10 namespace pinocchio
11 {
12 
14  const std::string & env_var_name,
15  std::vector<std::string> & list_of_paths,
16  const std::string & delimiter)
17  {
18  const char * env_var_value = std::getenv(env_var_name.c_str());
19 
20  if (env_var_value != NULL)
21  {
22  std::string policyStr(env_var_value);
23  // Add a separator at the end so that last path is also retrieved
24  policyStr += delimiter;
25  size_t lastOffset = 0;
26  while (true)
27  {
28  size_t offset = policyStr.find_first_of(delimiter, lastOffset);
29  if (offset < policyStr.size())
30  {
31  list_of_paths.push_back(policyStr.substr(lastOffset, offset - lastOffset));
32  // Support for devel spaces: We also need to look one package above:
33  // Work-around for https://github.com/stack-of-tasks/pinocchio/issues/1463
34  list_of_paths.push_back(policyStr.substr(lastOffset, offset - lastOffset) + "/..");
35  }
36  if (offset == std::string::npos)
37  break;
38  else
39  lastOffset = offset + 1; // add one to skip the delimiter
40  }
41  }
42  }
43 
44  std::vector<std::string>
45  extractPathFromEnvVar(const std::string & env_var_name, const std::string & delimiter)
46  {
47  std::vector<std::string> list_of_paths;
48  extractPathFromEnvVar(env_var_name, list_of_paths, delimiter);
49  return list_of_paths;
50  }
51 
52  void appendSuffixToPaths(std::vector<std::string> & list_of_paths, const std::string & suffix)
53  {
54  for (size_t i = 0; i < list_of_paths.size(); ++i)
55  {
56  list_of_paths[i] += suffix;
57  }
58  }
59 
60  std::vector<std::string> rosPaths()
61  {
62  std::vector<std::string> raw_list_of_paths;
63  std::vector<std::string> raw_list_of_prefixes;
64  extractPathFromEnvVar("ROS_PACKAGE_PATH", raw_list_of_paths);
65  extractPathFromEnvVar("AMENT_PREFIX_PATH", raw_list_of_prefixes);
66 
67  appendSuffixToPaths(raw_list_of_prefixes, "/share");
68  raw_list_of_paths.insert(
69  raw_list_of_paths.end(), raw_list_of_prefixes.begin(), raw_list_of_prefixes.end());
70 
71  // Work-around for https://github.com/stack-of-tasks/pinocchio/issues/1463
72  // To support ROS devel/isolated spaces, we also need to look one package above the package.xml:
73  fs::path path;
74  std::vector<std::string> list_of_paths;
75  for (std::vector<std::string>::iterator it = raw_list_of_paths.begin();
76  it != raw_list_of_paths.end(); ++it)
77  {
78  list_of_paths.push_back(*it);
79  path = fs::path(*it);
80  if (fs::exists(path / "package.xml"))
81  {
82  list_of_paths.push_back(fs::path(path / "..").string());
83  }
84  }
85  return list_of_paths;
86  }
87 
88 } // namespace pinocchio
quadrotor-ocp.path
string path
Definition: quadrotor-ocp.py:11
pinocchio::appendSuffixToPaths
PINOCCHIO_PARSERS_DLLAPI void appendSuffixToPaths(std::vector< std::string > &list_of_paths, const std::string &suffix)
For a given vector of paths, add a suffix inplace to each path and return the vector inplace.
Definition: file-explorer.cpp:52
pinocchio::rosPaths
PINOCCHIO_PARSERS_DLLAPI std::vector< std::string > rosPaths()
Parse the environment variables ROS_PACKAGE_PATH / AMENT_PREFIX_PATH and extract paths.
Definition: file-explorer.cpp:60
inverse-kinematics.i
int i
Definition: inverse-kinematics.py:17
inverse-kinematics-3d.it
int it
Definition: inverse-kinematics-3d.py:17
file-explorer.hpp
pinocchio::extractPathFromEnvVar
PINOCCHIO_PARSERS_DLLAPI std::vector< std::string > extractPathFromEnvVar(const std::string &env_var_name, const std::string &delimiter=":")
Parse an environment variable if exists and extract paths according to the delimiter.
Definition: file-explorer.cpp:45
pinocchio
Main pinocchio namespace.
Definition: timings.cpp:27


pinocchio
Author(s):
autogenerated on Mon Dec 16 2024 03:41:01