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 "pinocchio/utils/file-explorer.hpp"
7 
8 namespace pinocchio
9 {
10 
11  void extractPathFromEnvVar(const std::string & env_var_name,
12  std::vector<std::string> & list_of_paths,
13  const std::string & delimiter)
14  {
15  const char * env_var_value = std::getenv(env_var_name.c_str());
16 
17  if(env_var_value != NULL)
18  {
19  std::string policyStr(env_var_value);
20  // Add a separator at the end so that last path is also retrieved
21  policyStr += std::string(":");
22  size_t lastOffset = 0;
23 
24  while(true)
25  {
26  size_t offset = policyStr.find_first_of(delimiter, lastOffset);
27  if (offset < policyStr.size())
28  list_of_paths.push_back(policyStr.substr(lastOffset, offset - lastOffset));
29  if (offset == std::string::npos)
30  break;
31  else
32  lastOffset = offset + 1; // add one to skip the delimiter
33  }
34  }
35  }
36 
37  std::vector<std::string> extractPathFromEnvVar(const std::string & env_var_name,
38  const std::string & delimiter)
39  {
40  std::vector<std::string> list_of_paths;
41  extractPathFromEnvVar(env_var_name,list_of_paths,delimiter);
42  return list_of_paths;
43  }
44 
45  std::vector<std::string> rosPaths()
46  {
47  std::vector<std::string> list_of_paths;
48  extractPathFromEnvVar("ROS_PACKAGE_PATH",list_of_paths);
49  extractPathFromEnvVar("AMENT_PREFIX_PATH",list_of_paths);
50 
51  return list_of_paths;
52  }
53 
54 }
void extractPathFromEnvVar(const std::string &env_var_name, std::vector< std::string > &list_of_paths, const std::string &delimiter)
Parse an environment variable if exists and extract paths according to the delimiter.
std::vector< std::string > rosPaths()
Parse the environment variable ROS_PACKAGE_PATH and extract paths.
Main pinocchio namespace.
Definition: timings.cpp:30


pinocchio
Author(s):
autogenerated on Tue Jun 1 2021 02:45:02