summaryrefslogtreecommitdiff
path: root/src/files_finder.hh
blob: 2928efae7b3899a88670f99f388c70c22d1bf80d (plain)
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#ifndef FILES_FINDER_HH
#define FILES_FINDER_HH

#include <memory>
#include <filesystem>

class Logger;
class TaskRunner;

class FilesFinder {
public:
  class Delegate {
  public:
    virtual ~Delegate() = default;

    // Called on any thread, default implementation
    // returns true for files not hidden.
    // Depth is counted from root, files in root have depth zero.
    virtual bool include_file(std::string_view name, uint16_t depth) const;

    // Called on any thread, default implementation
    // returns true for dirs not hidden.
    // Depth is counted from root, files in root have depth zero.
    virtual bool include_dir(std::string_view name, uint16_t depth) const;

    // Called for each file found. Called on runner.
    virtual void file(std::filesystem::path path) = 0;

    // Called after all files have been found. Called on runner.
    // Default implementation does nothing.
    virtual void done();

  protected:
    Delegate() = default;
  };

  virtual ~FilesFinder() = default;

  static std::unique_ptr<FilesFinder> create(std::shared_ptr<Logger> logger,
                                             std::shared_ptr<TaskRunner> runner,
                                             std::filesystem::path root,
                                             Delegate* delegate,
                                             size_t threads = 1);

protected:
  FilesFinder() = default;
  FilesFinder(FilesFinder const&) = delete;
  FilesFinder& operator=(FilesFinder const&) = delete;
};

#endif  // FILES_HH