1 /*=============================================================================
2     Boost.Wave: A Standard compliant C++ preprocessor library
3 
4     http://www.boost.org/
5 
6     Copyright (c) 2001-2011 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 =============================================================================*/
10 
11 #if !defined(BOOST_WAVE_FILESYSTEM_COMPATIBILITY_MAR_09_2009_0142PM)
12 #define BOOST_WAVE_FILESYSTEM_COMPATIBILITY_MAR_09_2009_0142PM
13 
14 #include <string>
15 
16 #include <boost/version.hpp>
17 #include <boost/filesystem/path.hpp>
18 #include <boost/filesystem/operations.hpp>
19 
20 namespace boost { namespace wave { namespace util
21 {
22 ///////////////////////////////////////////////////////////////////////////////
23 // filesystem wrappers allowing to handle different Boost versions
24 #if !defined(BOOST_FILESYSTEM_NO_DEPRECATED)
25 // interface wrappers for older Boost versions
initial_path()26     inline boost::filesystem::path initial_path()
27     {
28         return boost::filesystem::initial_path();
29     }
30 
current_path()31     inline boost::filesystem::path current_path()
32     {
33         return boost::filesystem::current_path();
34     }
35 
36     template <typename String>
create_path(String const & p)37     inline boost::filesystem::path create_path(String const& p)
38     {
39 #if BOOST_FILESYSTEM_VERSION >= 3
40         return boost::filesystem::path(p);
41 #else
42         return boost::filesystem::path(p, boost::filesystem::native);
43 #endif
44     }
45 
leaf(boost::filesystem::path const & p)46     inline std::string leaf(boost::filesystem::path const& p)
47     {
48 #if BOOST_FILESYSTEM_VERSION >= 3
49         return p.leaf().string();
50 #else
51         return p.leaf();
52 #endif
53     }
54 
branch_path(boost::filesystem::path const & p)55     inline boost::filesystem::path branch_path(boost::filesystem::path const& p)
56     {
57         return p.branch_path();
58     }
59 
normalize(boost::filesystem::path & p)60     inline boost::filesystem::path normalize(boost::filesystem::path& p)
61     {
62         return p.normalize();
63     }
64 
native_file_string(boost::filesystem::path const & p)65     inline std::string native_file_string(boost::filesystem::path const& p)
66     {
67 #if BOOST_FILESYSTEM_VERSION >= 3
68         return p.string();
69 #else
70         return p.native_file_string();
71 #endif
72     }
73 
complete_path(boost::filesystem::path const & p)74     inline boost::filesystem::path complete_path(
75         boost::filesystem::path const& p)
76     {
77 #if BOOST_FILESYSTEM_VERSION >= 3
78         return boost::filesystem3::complete(p, initial_path());
79 #else
80         return boost::filesystem::complete(p, initial_path());
81 #endif
82     }
83 
complete_path(boost::filesystem::path const & p,boost::filesystem::path const & base)84     inline boost::filesystem::path complete_path(
85         boost::filesystem::path const& p, boost::filesystem::path const& base)
86     {
87 #if BOOST_FILESYSTEM_VERSION >= 3
88         return boost::filesystem3::complete(p, base);
89 #else
90         return boost::filesystem::complete(p, base);
91 #endif
92     }
93 
94 #else
95 
96 // interface wrappers if deprecated functions do not exist
97     inline boost::filesystem::path initial_path()
98     {
99 #if BOOST_FILESYSTEM_VERSION >= 3
100         return boost::filesystem3::detail::initial_path();
101 #else
102         return boost::filesystem::initial_path<boost::filesystem::path>();
103 #endif
104     }
105 
106     inline boost::filesystem::path current_path()
107     {
108 #if BOOST_FILESYSTEM_VERSION >= 3
109         return boost::filesystem3::current_path();
110 #else
111         return boost::filesystem::current_path<boost::filesystem::path>();
112 #endif
113     }
114 
115     template <typename String>
116     inline boost::filesystem::path create_path(String const& p)
117     {
118         return boost::filesystem::path(p);
119     }
120 
121     inline std::string leaf(boost::filesystem::path const& p)
122     {
123 #if BOOST_VERSION >= 104600 && BOOST_FILESYSTEM_VERSION >= 3
124         return p.filename().string();
125 #else
126         return p.filename();
127 #endif
128     }
129 
130     inline boost::filesystem::path branch_path(boost::filesystem::path const& p)
131     {
132         return p.parent_path();
133     }
134 
135     inline boost::filesystem::path normalize(boost::filesystem::path& p)
136     {
137         return p; // function doesn't exist anymore
138     }
139 
140     inline std::string native_file_string(boost::filesystem::path const& p)
141     {
142 #if BOOST_VERSION >= 104600
143         return p.string();
144 #else
145         return p.file_string();
146 #endif
147     }
148 
149     inline boost::filesystem::path complete_path(
150         boost::filesystem::path const& p)
151     {
152 #if BOOST_VERSION >= 104600 && BOOST_FILESYSTEM_VERSION >= 3
153         return boost::filesystem::absolute(p, initial_path());
154 #else
155         return boost::filesystem::complete(p, initial_path());
156 #endif
157     }
158 
159     inline boost::filesystem::path complete_path(
160         boost::filesystem::path const& p, boost::filesystem::path const& base)
161     {
162 #if BOOST_VERSION >= 104600 && BOOST_FILESYSTEM_VERSION >= 3
163         return boost::filesystem::absolute(p, base);
164 #else
165         return boost::filesystem::complete(p, base);
166 #endif
167     }
168 #endif
169 
170 }}}
171 
172 #endif
173