filesystem_ext.hpp
Go to the documentation of this file.
00001 
00018 #ifndef FILESYSTEM_EXT_HPP_
00019 #define FILESYSTEM_EXT_HPP_
00020 
00021 #include <boost/filesystem.hpp>
00022 
00023 namespace boost {
00024         namespace filesystem {
00025                 class pathext {
00026                 public:
00032                         static path common_prefix(path& first, path& second) {
00033                                 // the resulting string.
00034                                 path result;
00035 
00036                                 // if it's a root path, append the "/" sign to the empty result
00037                                 if (first.string().find("/") == 0) {
00038                                         result /= "";
00039                                 }
00040 
00041                                 // get the first mismatching iterator
00042                                 std::pair<path::iterator, path::iterator> iteratorPair = std::mismatch(first.begin(), first.end(), second.begin());
00043                                 for (path::iterator iter = first.begin(); iter != iteratorPair.first; iter++) {
00044                                         result /= *iter;
00045                                 }
00046 
00047                                 return result;
00048                         };
00049 
00055                         static path relative_path(path& subject, path base = current_path()) {
00056                                 path result;
00057 
00058                                 std::pair<path::iterator, path::iterator> iteratorPair = std::mismatch(base.begin(), base.end(), subject.begin());
00059                                 for (path::iterator iter = iteratorPair.second; iter != subject.end(); iter++) {
00060                                         path subpath = *iter;
00061 
00062                                         if (subpath.string() == ".") {
00063                                                 continue;
00064                                         }
00065 
00066                                         result /= subpath;
00067                                 }
00068 
00069                                 return result;
00070                         };
00071                 };
00072         }
00073 }
00074 
00075 
00076 #endif /* FILESYSTEM_EXT_HPP_ */


asr_ros_uri
Author(s): Schleicher Ralf
autogenerated on Sat Jun 8 2019 20:46:59