Synopsis - Cross-Reference
File: /src/Support/fspath.hh1// 2// Copyright (C) 2007 Bernhard Fischer 3// All rights reserved. 4// Licensed to the public under the terms of the GNU LGPL (>= 2), 5// see the file COPYING for details. 6// 7// 8 9#ifndef Support_fspath_hh_ 10#define Support_fspath_hh_ 11 12#include <boost/filesystem/operations.hpp> 13 14namespace Synopsis 15{ 16 17//. Get normalized absolute path of a filename. 18inline boost::filesystem::path get_path(std::string const &filename) 19{ 20 using namespace boost::filesystem; 21 return system_complete(path(filename, native)).normalize(); 22} 23 24//. Return true if base_path is set and path p contains base_path. 25inline bool matches_path(std::string const &p, std::string const &base_path) 26{ 27 return !base_path.empty() && p.substr(0,base_path.size()) == base_path; 28} 29 30//. Return the string representation of file in native path 31//. nomenclature. 32inline std::string make_full_path(std::string const &p) 33{ 34 return get_path(p).native_file_string(); 35} 36 37//. Given a path, strip the base_path. 38inline std::string make_short_path(std::string const &p, std::string const &base_path) 39{ 40 std::string short_fname = make_full_path(p); 41 if (matches_path(short_fname, base_path)) 42 short_fname.erase(0, base_path.size()); 43 return short_fname; 44} 45 46} 47 48#endif