34 #include <boost/algorithm/string/split.hpp> 35 #include <boost/algorithm/string/join.hpp> 36 #include <boost/algorithm/string/classification.hpp> 37 #include <boost/thread/mutex.hpp> 47 std::string
command(
const std::string& _cmd)
49 boost::mutex::scoped_lock lock(librospack_mutex);
60 std::cerr <<
"ROSPack::run returned non-zero." << std::endl;
63 catch(std::runtime_error &e)
66 std::cerr <<
"[rospack] " << e.what() << std::endl;
68 return std::string(
"");
73 std::string out_string =
command(cmd);
75 boost::split(full_list, out_string, boost::is_any_of(
"\r\n"));
78 V_string::iterator it = full_list.begin();
79 V_string::iterator end = full_list.end();
80 for (; it != end; ++it)
84 output.push_back(*it);
89 std::string
getPath(
const std::string& package_name)
91 std::string path =
command(
"find " + package_name);
94 for (
size_t newline = path.find(
'\n'); newline != std::string::npos;
95 newline = path.find(
'\n'))
97 path.erase(newline, 1);
105 command(
"list-names", packages);
118 command(
"plugins --attrib=" + attribute +
" " + package, lines);
120 V_string::iterator it = lines.begin();
121 V_string::iterator end = lines.end();
122 for (; it != end; ++it)
125 boost::split(tokens, *it, boost::is_any_of(
" "));
127 if (tokens.size() >= 2)
129 std::string
package = tokens[0];
130 std::string rest = boost::join(
V_string(tokens.begin() + 1, tokens.end()),
" ");
131 packages.push_back(package);
132 plugins.push_back(rest);
138 const std::string& name,
139 const std::string& attribute,
140 std::vector<std::pair<std::string, std::string> >& exports,
145 getPlugins(name, attribute, packages, plugins, force_recrawl);
147 for (std::size_t i = 0; i < packages.size(); ++i ) {
148 exports.push_back(std::pair<std::string, std::string>(packages[i], plugins[i]));
152 void getPlugins(
const std::string& package,
const std::string& attribute,
V_string& plugins,
bool force_recrawl)
155 getPlugins(package, attribute, packages, plugins, force_recrawl);
158 void getPlugins(
const std::string& package,
const std::string& attribute,
M_string& plugins,
bool force_recrawl)
161 getPlugins(package, attribute, packages, plugins_v, force_recrawl);
162 for (std::size_t i = 0 ; i < packages.size() ; ++i)
163 plugins[packages[i]] = plugins_v[i];
std::map< std::string, std::string > M_string
ROSLIB_DECL bool getAll(V_string &packages)
Gets a list of all packages. Returns false if it could not run the command.
std::vector< std::string > V_string
static boost::mutex librospack_mutex
ROSLIB_DECL std::string command(const std::string &cmd)
Runs a rospack command of the form 'rospack <cmd>', returning the output as a single string...
ROSLIB_DECL std::string getPath(const std::string &package_name)
Returns the fully-qualified path to a package, or an empty string if the package is not found...
ROSLIB_DECL void getPlugins(const std::string &package, const std::string &attribute, V_string &plugins, bool force_recrawl=false)
Call the "rospack plugins" command, eg. "rospack plugins --attrib=<attribute> <package>". Returns a vector of strings which are export values.
int run(int argc, char **argv)