00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef PLUGINLIB_BOOST_FS_WRAPPER_H
00030 #define PLUGINLIB_BOOST_FS_WRAPPER_H
00031
00032
00033 #include "pluginlib/boost_fs_wrapper.h"
00034 #include "boost/filesystem.hpp"
00035 #include "ros/package.h"
00036
00037 namespace pluginlib
00038 {
00039
00040 std::string joinPaths(const std::string& path1, const std::string& path2)
00041 {
00042 boost::filesystem::path p1(path1);
00043 return (p1 / path2).string();
00044 }
00045
00046 std::string getPackageFromLibraryPath(const std::string & path)
00047 {
00048
00049 std::string package_name;
00050
00051 boost::filesystem::path p(path);
00052 boost::filesystem::path parent = p.parent_path();
00053
00054 while (true)
00055 {
00056 if (boost::filesystem::exists(parent / "manifest.xml"))
00057 {
00058 #if BOOST_FILESYSTEM_VERSION && BOOST_FILESYSTEM_VERSION == 3
00059 std::string package = parent.filename().string();
00060 #else
00061 std::string package = parent.filename();
00062 #endif
00063 std::string package_path = ros::package::getPath(package);
00064 if (path.find(package_path) == 0)
00065 {
00066 package_name = package;
00067 break;
00068 }
00069 }
00070
00071 #if BOOST_FILESYSTEM_VERSION && BOOST_FILESYSTEM_VERSION == 3
00072 parent = parent.parent_path().string();
00073 #else
00074 parent = parent.parent_path();
00075 #endif
00076
00077 if (parent.string().empty())
00078 {
00079 return "";
00080 }
00081 }
00082
00083 return package_name;
00084 }
00085
00086
00087 }
00088
00089
00090 #endif //PLUGINLIB_BOOST_FS_WRAPPER_H