-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDirectoryWalker.hpp
More file actions
34 lines (27 loc) · 1.05 KB
/
Copy pathDirectoryWalker.hpp
File metadata and controls
34 lines (27 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <boost/filesystem.hpp>
#include <boost/lockfree/queue.hpp>
#include <optional>
#include <thread>
class DirectoryWalker {
public:
DirectoryWalker(const std::string directoryName);
// Starts the asynchronous directory traversal in a separate thread.
// Directory entries can immediately be retrieved using GetNext();
void Traverse(const bool descend);
// GetNext returns a pair of values -
// an optional next path that has been retrieved from filesystem
// traversal, and a bool indicating if the overall traversal process
// has completed or not.
std::pair<std::optional<boost::filesystem::path>, bool> GetNext();
// Ensures the asynchronous worker has completed before returning.
void Finish();
private:
boost::filesystem::path Directory;
boost::lockfree::queue<boost::filesystem::path *,
boost::lockfree::fixed_sized<false>>
Queue;
// Semaphore indicating that directory traversal has completed
bool Completed = false;
// Reference to thread running the directory traversal
std::thread Worker;
};