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#include <smallfun.hpp>
10
11#include <functional>
12#include <vector>
13
14class QObject;
15
16namespace score
17{
18class SCORE_LIB_BASE_EXPORT RecursiveWatch
19{
20public:
21 struct Callbacks
22 {
23 std::function<void(std::string_view)> added;
24 std::function<void(std::string_view)> removed;
25 };
26
27 struct Watched
28 {
29 std::string ext;
30 Callbacks callbacks;
31 };
32
39 {
40 using Filter = smallfun::function<
41 std::function<void()>(std::string_view),
42#if defined(_MSC_VER) && !defined(NDEBUG)
43 128,
44#else
45 64,
46#endif
47 smallfun::DefaultAlign, smallfun::Methods::Move>;
48
49 Filter filter;
50 };
51
52 void setWatchedFolder(std::string root) { m_root = root; }
53
54 void registerWatch(std::string extension, Callbacks callbacks)
55 {
56 m_watched[extension].push_back(std::move(callbacks));
57 }
58
59 void registerWatch(std::string extension, AsyncCallbacks callbacks)
60 {
61 m_asyncWatched[extension].push_back(std::move(callbacks));
62 }
63
65 void scan() const;
66
70 void scanAsync(QObject* context);
71
72 void reset();
73
74private:
75 std::string m_root;
76 ossia::string_map<std::vector<Callbacks>> m_watched;
77 ossia::string_map<std::vector<AsyncCallbacks>> m_asyncWatched;
78};
79
80SCORE_LIB_BASE_EXPORT
81void for_all_files(std::string_view root, std::function<void(std::string_view)> f);
82}
Definition RecursiveWatch.hpp:19
Base toolkit upon which the software is built.
Definition Application.cpp:113
Definition RecursiveWatch.hpp:39
Definition RecursiveWatch.hpp:22
Definition RecursiveWatch.hpp:28