Example #1
0
boost::filesystem::path naive_uncomplete(boost::filesystem::path const path, 
    boost::filesystem::path const base) {
    if (path.has_root_path()){
        if (path.root_path() != base.root_path()) {
            return path;
        } else {
            return naive_uncomplete(path.relative_path(), base.relative_path());
        }
    } else {
        if (base.has_root_path()) {
            throw "cannot uncomplete a path relative path from a rooted base";
        } else {
            typedef boost::filesystem::path::const_iterator path_iterator;
            path_iterator path_it = path.begin();
            path_iterator base_it = base.begin();
            while ( path_it != path.end() && base_it != base.end() ) {
                if (*path_it != *base_it) break;
                ++path_it; ++base_it;
            }
            boost::filesystem::path result;
            for (; base_it != base.end(); ++base_it) {
                result /= "..";
            }
            for (; path_it != path.end(); ++path_it) {
                result /= *path_it;
            }
            return result;
        }
    }
}
Example #2
0
 boost::filesystem::path MultiresImagePlugin::MakePathRelative(boost::filesystem::path path, boost::filesystem::path base)
 {
   // Borrowed from: https://svn.boost.org/trac/boost/ticket/1976#comment:2
   if (path.has_root_path())
   {
     if (path.root_path() != base.root_path())
     {
       return path;
     }
     else
     {
       return MakePathRelative(path.relative_path(), base.relative_path());
     }
   }
   else
   {
     if (base.has_root_path())
     {
       ROS_WARN("Cannot uncomplete a path relative path from a rooted base.");
       return path;
     }
     else
     {
       typedef boost::filesystem::path::const_iterator path_iterator;
       path_iterator path_it = path.begin();
       path_iterator base_it = base.begin();
       while (path_it != path.end() && base_it != base.end())
       {
         if (*path_it != *base_it)
           break;
         ++path_it;
         ++base_it;
       }
       boost::filesystem::path result;
       for (; base_it != base.end(); ++base_it)
       {
         result /= "..";
       }
       for (; path_it != path.end(); ++path_it)
       {
         result /= *path_it;
       }
       return result;
     }
   }
 }