|
5 | 5 | #include <tbb/global_control.h> |
6 | 6 | #include <tbb/info.h> |
7 | 7 |
|
8 | | -namespace shapeworks { |
9 | | - |
10 | | -// Windows doesn't have S_ISDIR and S_ISREG macros |
11 | | -#if !defined(S_ISREG) && defined(S_IFMT) && defined(S_IFREG) |
12 | | -#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) |
13 | | -#endif |
| 8 | +#include <boost/filesystem.hpp> |
14 | 9 |
|
15 | | -#if !defined(S_ISDIR) && defined(S_IFMT) && defined(S_IFDIR) |
16 | | -#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) |
17 | | -#endif |
| 10 | +namespace shapeworks { |
18 | 11 |
|
19 | 12 | unsigned ShapeWorksUtils::rng_seed_ = std::chrono::system_clock::now().time_since_epoch().count(); |
20 | 13 | std::mt19937 ShapeWorksUtils::mt_; |
21 | 14 | std::unique_ptr<tbb::global_control> ShapeWorksUtils::tbb_global_control_; |
22 | 15 |
|
23 | | -//----------------------------------------------------------------------------- |
24 | | -/// looks at the pathname to see if it's a file or a directory or neither |
25 | | -static bool stat_path(const std::string& pathname, bool isdir = false) { |
26 | | - struct stat info; |
27 | | - if (stat(pathname.c_str(), &info) != 0) { |
28 | | - return false; |
29 | | - } else { |
30 | | - return isdir ? S_ISDIR(info.st_mode) : S_ISREG(info.st_mode); |
31 | | - } |
32 | | -} |
33 | | - |
34 | 16 | //----------------------------------------------------------------------------- |
35 | 17 | void ShapeWorksUtils::set_rng_seed(const unsigned seed) { |
36 | 18 | rng_seed_ = seed; |
37 | 19 | mt_.seed(rng_seed_); |
38 | 20 | } |
39 | 21 |
|
40 | 22 | //----------------------------------------------------------------------------- |
41 | | -bool ShapeWorksUtils::is_directory(const std::string& pathname) { return stat_path(pathname, true); } |
| 23 | +bool ShapeWorksUtils::is_directory(const std::string& pathname) { |
| 24 | + boost::system::error_code ec; |
| 25 | + return boost::filesystem::is_directory(pathname, ec); |
| 26 | +} |
42 | 27 |
|
43 | 28 | //----------------------------------------------------------------------------- |
44 | | -bool ShapeWorksUtils::file_exists(const std::string& filename) { return stat_path(filename, false); } |
| 29 | +bool ShapeWorksUtils::file_exists(const std::string& filename) { |
| 30 | + boost::system::error_code ec; |
| 31 | + return boost::filesystem::is_regular_file(filename, ec); |
| 32 | +} |
45 | 33 |
|
46 | 34 | //----------------------------------------------------------------------------- |
47 | 35 | void ShapeWorksUtils::setup_console_logging(bool show_progress, bool xml_status) { |
|
0 commit comments