1 /*=============================================================================
2 Boost.Wave: A Standard compliant C++ preprocessor library
6 Copyright (c) 2001-2012 Hartmut Kaiser. Distributed under the Boost
7 Software License, Version 1.0. (See accompanying file
8 LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 =============================================================================*/
11 #if !defined(BOOST_WAVE_FILESYSTEM_COMPATIBILITY_MAR_09_2009_0142PM)
12 #define BOOST_WAVE_FILESYSTEM_COMPATIBILITY_MAR_09_2009_0142PM
16 #include <boost/version.hpp>
17 #include <boost/filesystem/path.hpp>
18 #include <boost/filesystem/operations.hpp>
20 namespace boost { namespace wave { namespace util
22 ///////////////////////////////////////////////////////////////////////////////
23 // filesystem wrappers allowing to handle different Boost versions
24 #if !defined(BOOST_FILESYSTEM_NO_DEPRECATED)
25 // interface wrappers for older Boost versions
26 inline boost::filesystem::path initial_path()
28 return boost::filesystem::initial_path();
31 inline boost::filesystem::path current_path()
33 return boost::filesystem::current_path();
36 template <typename String>
37 inline boost::filesystem::path create_path(String const& p)
39 #if BOOST_FILESYSTEM_VERSION >= 3
40 return boost::filesystem::path(p);
42 return boost::filesystem::path(p, boost::filesystem::native);
46 inline std::string leaf(boost::filesystem::path const& p)
48 #if BOOST_FILESYSTEM_VERSION >= 3
49 return p.leaf().string();
55 inline boost::filesystem::path branch_path(boost::filesystem::path const& p)
57 return p.branch_path();
60 inline boost::filesystem::path normalize(boost::filesystem::path& p)
65 inline std::string native_file_string(boost::filesystem::path const& p)
67 #if BOOST_FILESYSTEM_VERSION >= 3
70 return p.native_file_string();
74 inline boost::filesystem::path complete_path(
75 boost::filesystem::path const& p)
77 #if BOOST_FILESYSTEM_VERSION >= 3
78 #if BOOST_VERSION >= 105000
79 return boost::filesystem::complete(p, initial_path());
81 return boost::filesystem3::complete(p, initial_path());
84 return boost::filesystem::complete(p, initial_path());
88 inline boost::filesystem::path complete_path(
89 boost::filesystem::path const& p, boost::filesystem::path const& base)
91 #if BOOST_FILESYSTEM_VERSION >= 3
92 #if BOOST_VERSION >= 105000
93 return boost::filesystem::complete(p, base);
95 return boost::filesystem3::complete(p, base);
98 return boost::filesystem::complete(p, base);
104 // interface wrappers if deprecated functions do not exist
105 inline boost::filesystem::path initial_path()
107 #if BOOST_FILESYSTEM_VERSION >= 3
108 #if BOOST_VERSION >= 105000
109 return boost::filesystem::detail::initial_path();
111 return boost::filesystem3::detail::initial_path();
114 return boost::filesystem::initial_path<boost::filesystem::path>();
118 inline boost::filesystem::path current_path()
120 #if BOOST_FILESYSTEM_VERSION >= 3
121 #if BOOST_VERSION >= 105000
122 return boost::filesystem::current_path();
124 return boost::filesystem3::current_path();
127 return boost::filesystem::current_path<boost::filesystem::path>();
131 template <typename String>
132 inline boost::filesystem::path create_path(String const& p)
134 return boost::filesystem::path(p);
137 inline std::string leaf(boost::filesystem::path const& p)
139 #if BOOST_VERSION >= 104600 && BOOST_FILESYSTEM_VERSION >= 3
140 return p.filename().string();
146 inline boost::filesystem::path branch_path(boost::filesystem::path const& p)
148 return p.parent_path();
151 inline boost::filesystem::path normalize(boost::filesystem::path& p)
153 return p; // function doesn't exist anymore
156 inline std::string native_file_string(boost::filesystem::path const& p)
158 #if BOOST_VERSION >= 104600
161 return p.file_string();
165 inline boost::filesystem::path complete_path(
166 boost::filesystem::path const& p)
168 #if BOOST_VERSION >= 104600 && BOOST_FILESYSTEM_VERSION >= 3
169 return boost::filesystem::absolute(p, initial_path());
171 return boost::filesystem::complete(p, initial_path());
175 inline boost::filesystem::path complete_path(
176 boost::filesystem::path const& p, boost::filesystem::path const& base)
178 #if BOOST_VERSION >= 104600 && BOOST_FILESYSTEM_VERSION >= 3
179 return boost::filesystem::absolute(p, base);
181 return boost::filesystem::complete(p, base);
186 // starting withBoost V1.50 create_directories throws if given an empty path
187 inline bool create_directories(boost::filesystem::path const& p)
189 if (p.string().empty())
191 return boost::filesystem::create_directories(p);