5 #ifndef __pinocchio_parsers_utils_hpp__
6 #define __pinocchio_parsers_utils_hpp__
13 #include <boost/filesystem/fstream.hpp>
14 #include <boost/foreach.hpp>
15 #include <boost/format.hpp>
17 #include "pinocchio/utils/file-explorer.hpp"
18 #include <boost/filesystem.hpp>
41 const std::string extension = filename.substr(filename.find_last_of(
".") + 1);
43 if (extension ==
"urdf")
62 const std::vector<std::string> & package_dirs)
65 namespace bf = boost::filesystem;
66 std::string result_path;
68 const std::string separator(
"://");
69 const std::size_t pos_separator =
string.find(separator);
70 bf::path string_path(
string);
72 if (pos_separator != std::string::npos)
74 std::string scheme =
string.substr(0, pos_separator);
75 std::string path =
string.substr(pos_separator+3, std::string::npos);
77 if(scheme ==
"package")
84 for (std::size_t i = 0; i < package_dirs.size(); ++i)
86 if ( bf::exists( bf::path(package_dirs[i] +
"/" + path)))
88 result_path = std::string( package_dirs[i] +
"/" + path );
93 else if (scheme ==
"file")
99 const std::string exception_message (
"Schemes of form" + scheme +
"are not handled");
100 throw std::invalid_argument(exception_message);
103 else if (string_path.is_relative())
106 for (std::size_t i = 0; i < package_dirs.size(); ++i)
108 if ( bf::exists( bf::path(package_dirs[i] +
"/" +
string)))
110 result_path = std::string( package_dirs[i] +
"/" +
string);
117 result_path = string;
125 #endif // __pinocchio_parsers_utils_hpp__