]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /*============================================================================= |
2 | Boost.Wave: A Standard compliant C++ preprocessor library | |
3 | ||
4 | http://www.boost.org/ | |
5 | ||
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 | =============================================================================*/ | |
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 | |
26 | inline boost::filesystem::path initial_path() | |
27 | { | |
28 | return boost::filesystem::initial_path(); | |
29 | } | |
30 | ||
31 | inline boost::filesystem::path current_path() | |
32 | { | |
33 | return boost::filesystem::current_path(); | |
34 | } | |
35 | ||
36 | template <typename String> | |
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 | ||
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 | ||
55 | inline boost::filesystem::path branch_path(boost::filesystem::path const& p) | |
56 | { | |
57 | return p.branch_path(); | |
58 | } | |
59 | ||
60 | inline boost::filesystem::path normalize(boost::filesystem::path& p) | |
61 | { | |
11fdf7f2 | 62 | return p.normalize().make_preferred(); |
7c673cae FG |
63 | } |
64 | ||
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 | ||
74 | inline boost::filesystem::path complete_path( | |
75 | boost::filesystem::path const& p) | |
76 | { | |
77 | #if BOOST_FILESYSTEM_VERSION >= 3 | |
78 | #if BOOST_VERSION >= 105000 | |
79 | return boost::filesystem::complete(p, initial_path()); | |
80 | #else | |
81 | return boost::filesystem3::complete(p, initial_path()); | |
82 | #endif | |
83 | #else | |
84 | return boost::filesystem::complete(p, initial_path()); | |
85 | #endif | |
86 | } | |
87 | ||
88 | inline boost::filesystem::path complete_path( | |
89 | boost::filesystem::path const& p, boost::filesystem::path const& base) | |
90 | { | |
91 | #if BOOST_FILESYSTEM_VERSION >= 3 | |
92 | #if BOOST_VERSION >= 105000 | |
93 | return boost::filesystem::complete(p, base); | |
94 | #else | |
95 | return boost::filesystem3::complete(p, base); | |
96 | #endif | |
97 | #else | |
98 | return boost::filesystem::complete(p, base); | |
99 | #endif | |
100 | } | |
101 | ||
102 | #else | |
103 | ||
104 | // interface wrappers if deprecated functions do not exist | |
105 | inline boost::filesystem::path initial_path() | |
106 | { | |
107 | #if BOOST_FILESYSTEM_VERSION >= 3 | |
108 | #if BOOST_VERSION >= 105000 | |
109 | return boost::filesystem::detail::initial_path(); | |
110 | #else | |
111 | return boost::filesystem3::detail::initial_path(); | |
112 | #endif | |
113 | #else | |
114 | return boost::filesystem::initial_path<boost::filesystem::path>(); | |
115 | #endif | |
116 | } | |
117 | ||
118 | inline boost::filesystem::path current_path() | |
119 | { | |
120 | #if BOOST_FILESYSTEM_VERSION >= 3 | |
121 | #if BOOST_VERSION >= 105000 | |
122 | return boost::filesystem::current_path(); | |
123 | #else | |
124 | return boost::filesystem3::current_path(); | |
125 | #endif | |
126 | #else | |
127 | return boost::filesystem::current_path<boost::filesystem::path>(); | |
128 | #endif | |
129 | } | |
130 | ||
131 | template <typename String> | |
132 | inline boost::filesystem::path create_path(String const& p) | |
133 | { | |
134 | return boost::filesystem::path(p); | |
135 | } | |
136 | ||
137 | inline std::string leaf(boost::filesystem::path const& p) | |
138 | { | |
139 | #if BOOST_VERSION >= 104600 && BOOST_FILESYSTEM_VERSION >= 3 | |
140 | return p.filename().string(); | |
141 | #else | |
142 | return p.filename(); | |
143 | #endif | |
144 | } | |
145 | ||
146 | inline boost::filesystem::path branch_path(boost::filesystem::path const& p) | |
147 | { | |
148 | return p.parent_path(); | |
149 | } | |
150 | ||
151 | inline boost::filesystem::path normalize(boost::filesystem::path& p) | |
152 | { | |
153 | return p; // function doesn't exist anymore | |
154 | } | |
155 | ||
156 | inline std::string native_file_string(boost::filesystem::path const& p) | |
157 | { | |
158 | #if BOOST_VERSION >= 104600 | |
159 | return p.string(); | |
160 | #else | |
161 | return p.file_string(); | |
162 | #endif | |
163 | } | |
164 | ||
165 | inline boost::filesystem::path complete_path( | |
166 | boost::filesystem::path const& p) | |
167 | { | |
168 | #if BOOST_VERSION >= 104600 && BOOST_FILESYSTEM_VERSION >= 3 | |
169 | return boost::filesystem::absolute(p, initial_path()); | |
170 | #else | |
171 | return boost::filesystem::complete(p, initial_path()); | |
172 | #endif | |
173 | } | |
174 | ||
175 | inline boost::filesystem::path complete_path( | |
176 | boost::filesystem::path const& p, boost::filesystem::path const& base) | |
177 | { | |
178 | #if BOOST_VERSION >= 104600 && BOOST_FILESYSTEM_VERSION >= 3 | |
179 | return boost::filesystem::absolute(p, base); | |
180 | #else | |
181 | return boost::filesystem::complete(p, base); | |
182 | #endif | |
183 | } | |
184 | #endif | |
185 | ||
186 | // starting withBoost V1.50 create_directories throws if given an empty path | |
187 | inline bool create_directories(boost::filesystem::path const& p) | |
188 | { | |
189 | if (p.string().empty()) | |
190 | return true; | |
191 | return boost::filesystem::create_directories(p); | |
192 | } | |
193 | }}} | |
194 | ||
195 | #endif |