filesystem_ext.hpp
Go to the documentation of this file.
1 
18 #ifndef FILESYSTEM_EXT_HPP_
19 #define FILESYSTEM_EXT_HPP_
20 
21 #include <boost/filesystem.hpp>
22 
23 namespace boost {
24  namespace filesystem {
25  class pathext {
26  public:
32  static path common_prefix(path& first, path& second) {
33  // the resulting string.
34  path result;
35 
36  // if it's a root path, append the "/" sign to the empty result
37  if (first.string().find("/") == 0) {
38  result /= "";
39  }
40 
41  // get the first mismatching iterator
42  std::pair<path::iterator, path::iterator> iteratorPair = std::mismatch(first.begin(), first.end(), second.begin());
43  for (path::iterator iter = first.begin(); iter != iteratorPair.first; iter++) {
44  result /= *iter;
45  }
46 
47  return result;
48  };
49 
55  static path relative_path(path& subject, path base = current_path()) {
56  path result;
57 
58  std::pair<path::iterator, path::iterator> iteratorPair = std::mismatch(base.begin(), base.end(), subject.begin());
59  for (path::iterator iter = iteratorPair.second; iter != subject.end(); iter++) {
60  path subpath = *iter;
61 
62  if (subpath.string() == ".") {
63  continue;
64  }
65 
66  result /= subpath;
67  }
68 
69  return result;
70  };
71  };
72  }
73 }
74 
75 
76 #endif /* FILESYSTEM_EXT_HPP_ */
static path relative_path(path &subject, path base=current_path())
static path common_prefix(path &first, path &second)


asr_ros_uri
Author(s): Schleicher Ralf
autogenerated on Fri Dec 6 2019 03:24:27