filesystem_compatibility.hpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /*=============================================================================
  2. Boost.Wave: A Standard compliant C++ preprocessor library
  3. http://www.boost.org/
  4. Copyright (c) 2001-2012 Hartmut Kaiser. Distributed under the Boost
  5. Software License, Version 1.0. (See accompanying file
  6. LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. =============================================================================*/
  8. #if !defined(BOOST_WAVE_FILESYSTEM_COMPATIBILITY_MAR_09_2009_0142PM)
  9. #define BOOST_WAVE_FILESYSTEM_COMPATIBILITY_MAR_09_2009_0142PM
  10. #include <string>
  11. #include <boost/version.hpp>
  12. #include <boost/filesystem/path.hpp>
  13. #include <boost/filesystem/operations.hpp>
  14. #include <boost/filesystem/directory.hpp>
  15. namespace boost { namespace wave { namespace util
  16. {
  17. ///////////////////////////////////////////////////////////////////////////////
  18. // filesystem wrappers allowing to handle different Boost versions
  19. #if !defined(BOOST_FILESYSTEM_NO_DEPRECATED)
  20. // interface wrappers for older Boost versions
  21. inline boost::filesystem::path initial_path()
  22. {
  23. return boost::filesystem::initial_path();
  24. }
  25. inline boost::filesystem::path current_path()
  26. {
  27. return boost::filesystem::current_path();
  28. }
  29. template <typename String>
  30. inline boost::filesystem::path create_path(String const& p)
  31. {
  32. #if BOOST_FILESYSTEM_VERSION >= 3
  33. return boost::filesystem::path(p);
  34. #else
  35. return boost::filesystem::path(p, boost::filesystem::native);
  36. #endif
  37. }
  38. inline std::string leaf(boost::filesystem::path const& p)
  39. {
  40. #if BOOST_FILESYSTEM_VERSION >= 3
  41. #if BOOST_VERSION >= 108400
  42. return p.filename().string();
  43. #else
  44. return p.leaf().string();
  45. #endif
  46. #else
  47. return p.leaf();
  48. #endif
  49. }
  50. inline boost::filesystem::path branch_path(boost::filesystem::path const& p)
  51. {
  52. #if BOOST_FILESYSTEM_VERSION >= 3 && BOOST_VERSION >= 108400
  53. return p.parent_path();
  54. #else
  55. return p.branch_path();
  56. #endif
  57. }
  58. inline boost::filesystem::path normalize(boost::filesystem::path& p)
  59. {
  60. #if BOOST_FILESYSTEM_VERSION >= 3 && BOOST_VERSION >= 108400
  61. return p.lexically_normal().make_preferred();
  62. #else
  63. return p.normalize().make_preferred();
  64. #endif
  65. }
  66. inline std::string native_file_string(boost::filesystem::path const& p)
  67. {
  68. #if BOOST_FILESYSTEM_VERSION >= 3
  69. return p.string();
  70. #else
  71. return p.native_file_string();
  72. #endif
  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 >= 108400
  79. return boost::filesystem::absolute(p, initial_path());
  80. #elif BOOST_VERSION >= 105000
  81. return boost::filesystem::complete(p, initial_path());
  82. #else
  83. return boost::filesystem3::complete(p, initial_path());
  84. #endif
  85. #else
  86. return boost::filesystem::complete(p, initial_path());
  87. #endif
  88. }
  89. inline boost::filesystem::path complete_path(
  90. boost::filesystem::path const& p, boost::filesystem::path const& base)
  91. {
  92. #if BOOST_FILESYSTEM_VERSION >= 3
  93. #if BOOST_VERSION >= 108400
  94. return boost::filesystem::absolute(p, base);
  95. #elif BOOST_VERSION >= 105000
  96. return boost::filesystem::complete(p, base);
  97. #else
  98. return boost::filesystem3::complete(p, base);
  99. #endif
  100. #else
  101. return boost::filesystem::complete(p, base);
  102. #endif
  103. }
  104. #else
  105. // interface wrappers if deprecated functions do not exist
  106. inline boost::filesystem::path initial_path()
  107. {
  108. #if BOOST_FILESYSTEM_VERSION >= 3
  109. #if BOOST_VERSION >= 105000
  110. return boost::filesystem::detail::initial_path();
  111. #else
  112. return boost::filesystem3::detail::initial_path();
  113. #endif
  114. #else
  115. return boost::filesystem::initial_path<boost::filesystem::path>();
  116. #endif
  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. template <typename String>
  131. inline boost::filesystem::path create_path(String const& p)
  132. {
  133. return boost::filesystem::path(p);
  134. }
  135. inline std::string leaf(boost::filesystem::path const& p)
  136. {
  137. #if BOOST_VERSION >= 104600 && BOOST_FILESYSTEM_VERSION >= 3
  138. return p.filename().string();
  139. #else
  140. return p.filename();
  141. #endif
  142. }
  143. inline boost::filesystem::path branch_path(boost::filesystem::path const& p)
  144. {
  145. return p.parent_path();
  146. }
  147. inline boost::filesystem::path normalize(boost::filesystem::path& p)
  148. {
  149. return p; // function doesn't exist anymore
  150. }
  151. inline std::string native_file_string(boost::filesystem::path const& p)
  152. {
  153. #if BOOST_VERSION >= 104600
  154. return p.string();
  155. #else
  156. return p.file_string();
  157. #endif
  158. }
  159. inline boost::filesystem::path complete_path(
  160. boost::filesystem::path const& p)
  161. {
  162. #if BOOST_VERSION >= 104600 && BOOST_FILESYSTEM_VERSION >= 3
  163. return boost::filesystem::absolute(p, initial_path());
  164. #else
  165. return boost::filesystem::complete(p, initial_path());
  166. #endif
  167. }
  168. inline boost::filesystem::path complete_path(
  169. boost::filesystem::path const& p, boost::filesystem::path const& base)
  170. {
  171. #if BOOST_VERSION >= 104600 && BOOST_FILESYSTEM_VERSION >= 3
  172. return boost::filesystem::absolute(p, base);
  173. #else
  174. return boost::filesystem::complete(p, base);
  175. #endif
  176. }
  177. #endif
  178. // starting withBoost V1.50 create_directories throws if given an empty path
  179. inline bool create_directories(boost::filesystem::path const& p)
  180. {
  181. if (p.string().empty())
  182. return true;
  183. return boost::filesystem::create_directories(p);
  184. }
  185. // starting with Boost 1.85 no_push was renamed to disable_recursion_pending for consistency
  186. // with std::filesystem (deprecated some point before that)
  187. inline void no_push(boost::filesystem::recursive_directory_iterator & it)
  188. {
  189. #if BOOST_VERSION >= 108400 && BOOST_FILESYSTEM_VERSION >= 3
  190. it.disable_recursion_pending();
  191. #else
  192. it.no_push();
  193. #endif
  194. }
  195. }}}
  196. #endif