utils.hpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2015 - 2016 CNRS
3 //
4 
5 #ifndef __pinocchio_parsers_utils_hpp__
6 #define __pinocchio_parsers_utils_hpp__
7 
8 #include <iostream>
9 #include <limits>
10 #include <sstream>
11 // #include <stdexcept>
12 
13 #include <boost/filesystem/fstream.hpp>
14 #include <boost/foreach.hpp>
15 #include <boost/format.hpp>
16 
17 #include "pinocchio/utils/file-explorer.hpp"
18 #include <boost/filesystem.hpp>
19 
20 #include <exception>
21 
22 namespace pinocchio
23 {
28  UNKNOWN = 0,
30  };
31 
39  inline ModelFileExtensionType checkModelFileExtension(const std::string & filename)
40  {
41  const std::string extension = filename.substr(filename.find_last_of(".") + 1);
42 
43  if (extension == "urdf")
44  return URDF;
45 
46  return UNKNOWN;
47  }
48 
49 
50 
61  inline std::string retrieveResourcePath(const std::string & string,
62  const std::vector<std::string> & package_dirs)
63  {
64 
65  namespace bf = boost::filesystem;
66  std::string result_path;
67 
68  const std::string separator("://");
69  const std::size_t pos_separator = string.find(separator);
70 
71  if (pos_separator != std::string::npos)
72  {
73  std::string scheme = string.substr(0, pos_separator);
74  std::string path = string.substr(pos_separator+3, std::string::npos);
75 
76  if(scheme == "package")
77  {
78  // if exists p1/string, path = p1/string,
79  // else if exists p2/string, path = p2/string
80  // else return an empty string that may provoke an error in loadPolyhedronFromResource()
81 
82  // concatenate package_path with filename
83  for (std::size_t i = 0; i < package_dirs.size(); ++i)
84  {
85  if ( bf::exists( bf::path(package_dirs[i] + "/" + path)))
86  {
87  result_path = std::string( package_dirs[i] + "/" + path );
88  break;
89  }
90  }
91  }
92  else if (scheme == "file")
93  {
94  result_path = path;
95  }
96  else
97  {
98  const std::string exception_message ("Schemes of form" + scheme + "are not handled");
99  throw std::invalid_argument(exception_message);
100  }
101  }
102  else // return the entry string
103  {
104  result_path = string;
105  }
106 
107  return result_path;
108  }
109 
110 } // namespace pinocchio
111 
112 #endif // __pinocchio_parsers_utils_hpp__
ModelFileExtensionType
Supported model file extensions.
Definition: utils.hpp:27
ModelFileExtensionType checkModelFileExtension(const std::string &filename)
Extract the type of the given model file according to its extension.
Definition: utils.hpp:39
Main pinocchio namespace.
Definition: timings.cpp:30
std::string retrieveResourcePath(const std::string &string, const std::vector< std::string > &package_dirs)
Retrieve the path of the file whose path is given in an url-format. Currently convert from the follow...
Definition: utils.hpp:61


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