filesystem_compatibility.hpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. namespace boost { namespace wave { namespace util
  15. {
  16. ///////////////////////////////////////////////////////////////////////////////
  17. // filesystem wrappers allowing to handle different Boost versions
  18. #if !defined(BOOST_FILESYSTEM_NO_DEPRECATED)
  19. // interface wrappers for older Boost versions
  20. inline boost::filesystem::path initial_path()
  21. {
  22. return boost::filesystem::initial_path();
  23. }
  24. inline boost::filesystem::path current_path()
  25. {
  26. return boost::filesystem::current_path();
  27. }
  28. template <typename String>
  29. inline boost::filesystem::path create_path(String const& p)
  30. {
  31. #if BOOST_FILESYSTEM_VERSION >= 3
  32. return boost::filesystem::path(p);
  33. #else
  34. return boost::filesystem::path(p, boost::filesystem::native);
  35. #endif
  36. }
  37. inline std::string leaf(boost::filesystem::path const& p)
  38. {
  39. #if BOOST_FILESYSTEM_VERSION >= 3
  40. #if BOOST_VERSION >= 108400
  41. return p.filename().string();
  42. #else
  43. return p.leaf().string();
  44. #endif
  45. #else
  46. return p.leaf();
  47. #endif
  48. }
  49. inline boost::filesystem::path branch_path(boost::filesystem::path const& p)
  50. {
  51. #if BOOST_FILESYSTEM_VERSION >= 3 && BOOST_VERSION >= 108400
  52. return p.parent_path();
  53. #else
  54. return p.branch_path();
  55. #endif
  56. }
  57. inline boost::filesystem::path normalize(boost::filesystem::path& p)
  58. {
  59. #if BOOST_FILESYSTEM_VERSION >= 3 && BOOST_VERSION >= 108400
  60. return p.lexically_normal().make_preferred();
  61. #else
  62. return p.normalize().make_preferred();
  63. #endif
  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. inline boost::filesystem::path complete_path(
  74. boost::filesystem::path const& p)
  75. {
  76. #if BOOST_FILESYSTEM_VERSION >= 3
  77. #if BOOST_VERSION >= 108400
  78. return boost::filesystem::absolute(p, initial_path());
  79. #elif BOOST_VERSION >= 105000
  80. return boost::filesystem::complete(p, initial_path());
  81. #else
  82. return boost::filesystem3::complete(p, initial_path());
  83. #endif
  84. #else
  85. return boost::filesystem::complete(p, initial_path());
  86. #endif
  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 >= 108400
  93. return boost::filesystem::absolute(p, base);
  94. #elif BOOST_VERSION >= 105000
  95. return boost::filesystem::complete(p, base);
  96. #else
  97. return boost::filesystem3::complete(p, base);
  98. #endif
  99. #else
  100. return boost::filesystem::complete(p, base);
  101. #endif
  102. }
  103. #else
  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. inline boost::filesystem::path current_path()
  118. {
  119. #if BOOST_FILESYSTEM_VERSION >= 3
  120. #if BOOST_VERSION >= 105000
  121. return boost::filesystem::current_path();
  122. #else
  123. return boost::filesystem3::current_path();
  124. #endif
  125. #else
  126. return boost::filesystem::current_path<boost::filesystem::path>();
  127. #endif
  128. }
  129. template <typename String>
  130. inline boost::filesystem::path create_path(String const& p)
  131. {
  132. return boost::filesystem::path(p);
  133. }
  134. inline std::string leaf(boost::filesystem::path const& p)
  135. {
  136. #if BOOST_VERSION >= 104600 && BOOST_FILESYSTEM_VERSION >= 3
  137. return p.filename().string();
  138. #else
  139. return p.filename();
  140. #endif
  141. }
  142. inline boost::filesystem::path branch_path(boost::filesystem::path const& p)
  143. {
  144. return p.parent_path();
  145. }
  146. inline boost::filesystem::path normalize(boost::filesystem::path& p)
  147. {
  148. return p; // function doesn't exist anymore
  149. }
  150. inline std::string native_file_string(boost::filesystem::path const& p)
  151. {
  152. #if BOOST_VERSION >= 104600
  153. return p.string();
  154. #else
  155. return p.file_string();
  156. #endif
  157. }
  158. inline boost::filesystem::path complete_path(
  159. boost::filesystem::path const& p)
  160. {
  161. #if BOOST_VERSION >= 104600 && BOOST_FILESYSTEM_VERSION >= 3
  162. return boost::filesystem::absolute(p, initial_path());
  163. #else
  164. return boost::filesystem::complete(p, initial_path());
  165. #endif
  166. }
  167. inline boost::filesystem::path complete_path(
  168. boost::filesystem::path const& p, boost::filesystem::path const& base)
  169. {
  170. #if BOOST_VERSION >= 104600 && BOOST_FILESYSTEM_VERSION >= 3
  171. return boost::filesystem::absolute(p, base);
  172. #else
  173. return boost::filesystem::complete(p, base);
  174. #endif
  175. }
  176. #endif
  177. // starting withBoost V1.50 create_directories throws if given an empty path
  178. inline bool create_directories(boost::filesystem::path const& p)
  179. {
  180. if (p.string().empty())
  181. return true;
  182. return boost::filesystem::create_directories(p);
  183. }
  184. }}}
  185. #endif