SAGA Adaptor CPI v.1.0
|
00001 // Copyright (c) 2005-2009 Hartmut Kaiser 00002 // 00003 // Distributed under the Boost Software License, Version 1.0. (See accompanying 00004 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 00005 00006 #ifndef SAGA_SAGA_PATH_LEAF_HPP 00007 #define SAGA_SAGA_PATH_LEAF_HPP 00008 00009 #include <string> 00010 #include <boost/version.hpp> 00011 #include <boost/filesystem/path.hpp> 00012 00013 namespace saga { namespace detail 00014 { 00015 inline SAGA_EXPORT std::string leaf(boost::filesystem::path const& p) 00016 { 00017 #if BOOST_FILESYSTEM_VERSION == 3 00018 return p.filename().string(); 00019 #else 00020 #if BOOST_VERSION >= 103600 00021 return p.empty() ? std::string() : *--p.end(); 00022 #else 00023 return p.leaf(); 00024 #endif 00025 #endif 00026 } 00027 00028 inline SAGA_EXPORT std::string parent(boost::filesystem::path const& p) 00029 { 00030 #if BOOST_VERSION >= 103600 00031 return p.parent_path().string(); 00032 #else 00033 return p.branch_path().string(); 00034 #endif 00035 } 00036 00037 // workaround for broken V1.44 filesystem library directory functions 00038 // canonize should have been called on the argument 00039 inline void remove_trailing_dot(boost::filesystem::path& p) 00040 { 00041 //#if BOOST_VERSION == 104400 00042 std::string str = p.string(); 00043 if (str[str.size()-1] == '.') 00044 p = boost::filesystem::path(str.substr(0, str.size()-1)); 00045 //#endif 00046 } 00047 00048 }} 00049 00050 #endif 00051