2018-04-08 12:18:16 +00:00
|
|
|
#ifndef LLARP_FS_HPP
|
|
|
|
#define LLARP_FS_HPP
|
2018-08-26 12:51:22 +00:00
|
|
|
#include <functional>
|
2018-06-14 07:48:42 +00:00
|
|
|
#if defined(WIN32) || defined(_WIN32)
|
2018-06-14 19:22:26 +00:00
|
|
|
#define PATH_SEP "\\"
|
2018-06-14 07:48:42 +00:00
|
|
|
#else
|
2018-06-14 19:22:26 +00:00
|
|
|
#define PATH_SEP "/"
|
2018-06-14 07:48:42 +00:00
|
|
|
#endif
|
|
|
|
|
2018-06-14 19:22:26 +00:00
|
|
|
#include "filesystem.h"
|
2018-07-30 04:38:14 +00:00
|
|
|
#if defined(CPP17) && defined(USE_CXX17_FILESYSTEM)
|
|
|
|
// win32 is the only one that doesn't use cpp17::filesystem
|
|
|
|
// because cpp17::filesystem is unimplemented for Windows
|
|
|
|
// -despair86
|
2018-08-16 22:36:15 +00:00
|
|
|
#if defined(__MINGW32__) || defined(_MSC_VER) || defined(__sun)
|
2018-07-26 01:00:15 +00:00
|
|
|
namespace fs = std::experimental::filesystem;
|
2018-07-26 08:52:27 +00:00
|
|
|
#else
|
2018-09-06 11:46:19 +00:00
|
|
|
namespace fs = std::experimental::filesystem;
|
2018-07-30 04:38:14 +00:00
|
|
|
#endif // end win32
|
|
|
|
#else
|
2018-07-26 08:52:27 +00:00
|
|
|
// not CPP17 needs this
|
|
|
|
// openbsd needs this
|
|
|
|
// linux gcc 7.2 needs this
|
|
|
|
namespace fs = cpp17::filesystem;
|
2018-07-30 04:38:14 +00:00
|
|
|
#endif
|
2018-06-14 19:28:27 +00:00
|
|
|
|
2018-08-26 12:51:22 +00:00
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace util
|
|
|
|
{
|
|
|
|
typedef std::function< bool(const fs::path &) > PathVisitor;
|
|
|
|
typedef std::function< void(const fs::path &, PathVisitor) > PathIter;
|
|
|
|
#if defined(CPP17) && defined(USE_CXX17_FILESYSTEM)
|
|
|
|
static PathIter IterDir = [](const fs::path &path, PathVisitor visit) {
|
|
|
|
fs::directory_iterator i(path);
|
|
|
|
auto itr = fs::begin(i);
|
|
|
|
while(itr != fs::end(i))
|
|
|
|
{
|
|
|
|
fs::path p = path / *itr;
|
|
|
|
if(!visit(p))
|
|
|
|
return;
|
|
|
|
++itr;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
#else
|
|
|
|
static PathIter IterDir = [](const fs::path &path, PathVisitor visit) {
|
|
|
|
fs::directory_iterator i(path);
|
|
|
|
auto itr = i.begin();
|
|
|
|
while(itr != itr.end())
|
|
|
|
{
|
|
|
|
fs::path p = path / *itr;
|
|
|
|
if(!visit(p))
|
|
|
|
return;
|
|
|
|
++itr;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
} // namespace util
|
|
|
|
} // namespace llarp
|
2018-07-27 03:41:55 +00:00
|
|
|
#endif // end LLARP_FS_HPP
|