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 
11 #ifndef BOOST_COMPUTE_DETAIL_PATH_HPP
12 #define BOOST_COMPUTE_DETAIL_PATH_HPP
13 
14 #include <boost/filesystem/path.hpp>
15 #include <boost/filesystem/operations.hpp>
16 #include <boost/compute/detail/getenv.hpp>
17 
18 namespace boost {
19 namespace compute {
20 namespace detail {
21 
22 // Path delimiter symbol for the current OS.
path_delim()23 static const std::string& path_delim()
24 {
25     static const std::string delim =
26         boost::filesystem::path("/").make_preferred().string();
27     return delim;
28 }
29 
30 // Path to appdata folder.
appdata_path()31 inline const std::string& appdata_path()
32 {
33     #ifdef _WIN32
34     static const std::string appdata = detail::getenv("APPDATA")
35         + path_delim() + "boost_compute";
36     #else
37     static const std::string appdata = detail::getenv("HOME")
38         + path_delim() + ".boost_compute";
39     #endif
40     return appdata;
41 }
42 
43 // Path to cached binaries.
program_binary_path(const std::string & hash,bool create=false)44 inline std::string program_binary_path(const std::string &hash, bool create = false)
45 {
46     std::string dir = detail::appdata_path() + path_delim()
47                     + hash.substr(0, 2) + path_delim()
48                     + hash.substr(2);
49 
50     if(create && !boost::filesystem::exists(dir)){
51         boost::filesystem::create_directories(dir);
52     }
53 
54     return dir + path_delim();
55 }
56 
57 // Path to parameter caches.
parameter_cache_path(bool create=false)58 inline std::string parameter_cache_path(bool create = false)
59 {
60     const static std::string dir = appdata_path() + path_delim() + "tune";
61 
62     if(create && !boost::filesystem::exists(dir)){
63         boost::filesystem::create_directories(dir);
64     }
65 
66     return dir + path_delim();
67 }
68 
69 } // end detail namespace
70 } // end compute namespace
71 } // end boost namespace
72 
73 #endif // BOOST_COMPUTE_DETAIL_PATH_HPP
74