path.hpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //---------------------------------------------------------------------------//
  2. // Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
  3. //
  4. // Distributed under the Boost Software License, Version 1.0
  5. // See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt
  7. //
  8. // See http://boostorg.github.com/compute for more information.
  9. //---------------------------------------------------------------------------//
  10. #ifndef BOOST_COMPUTE_DETAIL_PATH_HPP
  11. #define BOOST_COMPUTE_DETAIL_PATH_HPP
  12. #include <boost/filesystem/path.hpp>
  13. #include <boost/filesystem/operations.hpp>
  14. #include <boost/compute/detail/getenv.hpp>
  15. namespace boost {
  16. namespace compute {
  17. namespace detail {
  18. // Path delimiter symbol for the current OS.
  19. static const std::string& path_delim()
  20. {
  21. static const std::string delim =
  22. boost::filesystem::path("/").make_preferred().string();
  23. return delim;
  24. }
  25. // Path to appdata folder.
  26. inline const std::string& appdata_path()
  27. {
  28. #ifdef _WIN32
  29. static const std::string appdata = detail::getenv("APPDATA")
  30. + path_delim() + "boost_compute";
  31. #else
  32. static const std::string appdata = detail::getenv("HOME")
  33. + path_delim() + ".boost_compute";
  34. #endif
  35. return appdata;
  36. }
  37. // Path to cached binaries.
  38. inline std::string program_binary_path(const std::string &hash, bool create = false)
  39. {
  40. std::string dir = detail::appdata_path() + path_delim()
  41. + hash.substr(0, 2) + path_delim()
  42. + hash.substr(2);
  43. if(create && !boost::filesystem::exists(dir)){
  44. boost::filesystem::create_directories(dir);
  45. }
  46. return dir + path_delim();
  47. }
  48. // Path to parameter caches.
  49. inline std::string parameter_cache_path(bool create = false)
  50. {
  51. const static std::string dir = appdata_path() + path_delim() + "tune";
  52. if(create && !boost::filesystem::exists(dir)){
  53. boost::filesystem::create_directories(dir);
  54. }
  55. return dir + path_delim();
  56. }
  57. } // end detail namespace
  58. } // end compute namespace
  59. } // end boost namespace
  60. #endif // BOOST_COMPUTE_DETAIL_PATH_HPP