filesystem_compatibility.hpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. return p.leaf().string();
  41. #else
  42. return p.leaf();
  43. #endif
  44. }
  45. inline boost::filesystem::path branch_path(boost::filesystem::path const& p)
  46. {
  47. return p.branch_path();
  48. }
  49. inline boost::filesystem::path normalize(boost::filesystem::path& p)
  50. {
  51. return p.normalize().make_preferred();
  52. }
  53. inline std::string native_file_string(boost::filesystem::path const& p)
  54. {
  55. #if BOOST_FILESYSTEM_VERSION >= 3
  56. return p.string();
  57. #else
  58. return p.native_file_string();
  59. #endif
  60. }
  61. inline boost::filesystem::path complete_path(
  62. boost::filesystem::path const& p)
  63. {
  64. #if BOOST_FILESYSTEM_VERSION >= 3
  65. #if BOOST_VERSION >= 105000
  66. return boost::filesystem::complete(p, initial_path());
  67. #else
  68. return boost::filesystem3::complete(p, initial_path());
  69. #endif
  70. #else
  71. return boost::filesystem::complete(p, initial_path());
  72. #endif
  73. }
  74. inline boost::filesystem::path complete_path(
  75. boost::filesystem::path const& p, boost::filesystem::path const& base)
  76. {
  77. #if BOOST_FILESYSTEM_VERSION >= 3
  78. #if BOOST_VERSION >= 105000
  79. return boost::filesystem::complete(p, base);
  80. #else
  81. return boost::filesystem3::complete(p, base);
  82. #endif
  83. #else
  84. return boost::filesystem::complete(p, base);
  85. #endif
  86. }
  87. #else
  88. // interface wrappers if deprecated functions do not exist
  89. inline boost::filesystem::path initial_path()
  90. {
  91. #if BOOST_FILESYSTEM_VERSION >= 3
  92. #if BOOST_VERSION >= 105000
  93. return boost::filesystem::detail::initial_path();
  94. #else
  95. return boost::filesystem3::detail::initial_path();
  96. #endif
  97. #else
  98. return boost::filesystem::initial_path<boost::filesystem::path>();
  99. #endif
  100. }
  101. inline boost::filesystem::path current_path()
  102. {
  103. #if BOOST_FILESYSTEM_VERSION >= 3
  104. #if BOOST_VERSION >= 105000
  105. return boost::filesystem::current_path();
  106. #else
  107. return boost::filesystem3::current_path();
  108. #endif
  109. #else
  110. return boost::filesystem::current_path<boost::filesystem::path>();
  111. #endif
  112. }
  113. template <typename String>
  114. inline boost::filesystem::path create_path(String const& p)
  115. {
  116. return boost::filesystem::path(p);
  117. }
  118. inline std::string leaf(boost::filesystem::path const& p)
  119. {
  120. #if BOOST_VERSION >= 104600 && BOOST_FILESYSTEM_VERSION >= 3
  121. return p.filename().string();
  122. #else
  123. return p.filename();
  124. #endif
  125. }
  126. inline boost::filesystem::path branch_path(boost::filesystem::path const& p)
  127. {
  128. return p.parent_path();
  129. }
  130. inline boost::filesystem::path normalize(boost::filesystem::path& p)
  131. {
  132. return p; // function doesn't exist anymore
  133. }
  134. inline std::string native_file_string(boost::filesystem::path const& p)
  135. {
  136. #if BOOST_VERSION >= 104600
  137. return p.string();
  138. #else
  139. return p.file_string();
  140. #endif
  141. }
  142. inline boost::filesystem::path complete_path(
  143. boost::filesystem::path const& p)
  144. {
  145. #if BOOST_VERSION >= 104600 && BOOST_FILESYSTEM_VERSION >= 3
  146. return boost::filesystem::absolute(p, initial_path());
  147. #else
  148. return boost::filesystem::complete(p, initial_path());
  149. #endif
  150. }
  151. inline boost::filesystem::path complete_path(
  152. boost::filesystem::path const& p, boost::filesystem::path const& base)
  153. {
  154. #if BOOST_VERSION >= 104600 && BOOST_FILESYSTEM_VERSION >= 3
  155. return boost::filesystem::absolute(p, base);
  156. #else
  157. return boost::filesystem::complete(p, base);
  158. #endif
  159. }
  160. #endif
  161. // starting withBoost V1.50 create_directories throws if given an empty path
  162. inline bool create_directories(boost::filesystem::path const& p)
  163. {
  164. if (p.string().empty())
  165. return true;
  166. return boost::filesystem::create_directories(p);
  167. }
  168. }}}
  169. #endif