Loading...
Searching...
No Matches
RecursiveWatch.hpp
1#pragma once
2#include <ossia/detail/string_map.hpp>
3
4#include <QDebug>
5#include <QDir>
6#include <QString>
7
8#include <score_lib_base_export.h>
9
10#include <functional>
11#include <vector>
12
13class QObject;
14
15namespace score
16{
17class SCORE_LIB_BASE_EXPORT RecursiveWatch
18{
19public:
20 struct Callbacks
21 {
22 std::function<void(std::string_view)> added;
23 std::function<void(std::string_view)> removed;
24 };
25
26 struct Watched
27 {
28 std::string ext;
29 Callbacks callbacks;
30 };
31
38 {
39 std::function<std::function<void()>(std::string_view path)> filter;
40 };
41
42 void setWatchedFolder(std::string root) { m_root = root; }
43
44 void registerWatch(std::string extension, Callbacks callbacks)
45 {
46 m_watched[extension].push_back(std::move(callbacks));
47 }
48
49 void registerWatch(std::string extension, AsyncCallbacks callbacks)
50 {
51 m_asyncWatched[extension].push_back(std::move(callbacks));
52 }
53
55 void scan() const;
56
60 void scanAsync(QObject* context);
61
62 void reset()
63 {
64 m_root.clear();
65 m_watched.clear();
66 m_asyncWatched.clear();
67 }
68
69private:
70 std::string m_root;
71 ossia::string_map<std::vector<Callbacks>> m_watched;
72 ossia::string_map<std::vector<AsyncCallbacks>> m_asyncWatched;
73};
74
75SCORE_LIB_BASE_EXPORT
76void for_all_files(std::string_view root, std::function<void(std::string_view)> f);
77}
Definition RecursiveWatch.hpp:18
Base toolkit upon which the software is built.
Definition Application.cpp:113
Definition RecursiveWatch.hpp:38
Definition RecursiveWatch.hpp:21
Definition RecursiveWatch.hpp:27