pinocchio  2.4.4
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
file-explorer.hpp
1 //
2 // Copyright (c) 2016 CNRS
3 //
4 
5 #ifndef __pinocchio_file_explorer_hpp__
6 #define __pinocchio_file_explorer_hpp__
7 
8 #include <string>
9 #include <iostream>
10 #include <vector>
11 
12 namespace pinocchio
13 {
14 
23  inline std::vector<std::string> extractPathFromEnvVar(const std::string & env_var_name, const std::string & delimiter = ":")
24  {
25  const char * env_var_value = std::getenv(env_var_name.c_str());
26  std::vector<std::string> env_var_paths;
27 
28  if (env_var_value != NULL)
29  {
30  std::string policyStr (env_var_value);
31  // Add a separator at the end so that last path is also retrieved
32  policyStr += std::string (":");
33  size_t lastOffset = 0;
34 
35  while(true)
36  {
37  size_t offset = policyStr.find_first_of(delimiter, lastOffset);
38  if (offset < policyStr.size())
39  env_var_paths.push_back(policyStr.substr(lastOffset, offset - lastOffset));
40  if (offset == std::string::npos)
41  break;
42  else
43  lastOffset = offset + 1; // add one to skip the delimiter
44  }
45  }
46 
47  return env_var_paths;
48  }
49 
50 
56  inline std::vector<std::string> rosPaths()
57  {
58  return extractPathFromEnvVar("ROS_PACKAGE_PATH");
59  }
60 
61 }
62 
63 #endif // __pinocchio_file_explorer_hpp__
std::vector< std::string > rosPaths()
Parse the environment variable ROS_PACKAGE_PATH and extract paths.
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.
Main pinocchio namespace.
Definition: treeview.dox:24