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 <memory>
13#include <vector>
14
15class QObject;
16
17namespace score
18{
19class SCORE_LIB_BASE_EXPORT RecursiveWatch
20{
21public:
22 struct Callbacks
23 {
24 std::function<void(std::string_view)> added;
25 std::function<void(std::string_view)> removed;
26 };
27
28 struct Watched
29 {
30 std::string ext;
31 Callbacks callbacks;
32 };
33
40 {
41 using Filter = smallfun::function<
42 std::function<void()>(std::string_view),
43#if defined(_MSC_VER) && !defined(NDEBUG)
44 128,
45#else
46 64,
47#endif
48 smallfun::DefaultAlign, smallfun::Methods::Move>;
49
50 Filter filter;
51 };
52
53 void setWatchedFolder(std::string root) { m_root = root; }
54
55 void registerWatch(std::string extension, Callbacks callbacks)
56 {
57 m_watched[extension].push_back(std::move(callbacks));
58 }
59
60 void registerWatch(std::string extension, AsyncCallbacks callbacks)
61 {
62 m_asyncWatched[extension].push_back(std::move(callbacks));
63 }
64
66 void scan() const;
67
71 void scanAsync(QObject* context);
72
76 void cancelAsync() noexcept;
77
78 void reset();
79
83 static void cancelAll() noexcept;
84
85 RecursiveWatch();
86 RecursiveWatch(const RecursiveWatch&) = delete;
87 RecursiveWatch& operator=(const RecursiveWatch&) = delete;
88 ~RecursiveWatch();
89
90 struct AsyncScan;
91
92private:
93 std::string m_root;
94 ossia::string_map<std::vector<Callbacks>> m_watched;
95 ossia::string_map<std::vector<AsyncCallbacks>> m_asyncWatched;
96 std::shared_ptr<AsyncScan> m_scan;
97};
98
99SCORE_LIB_BASE_EXPORT
100void for_all_files(std::string_view root, std::function<void(std::string_view)> f);
101}
Definition RecursiveWatch.hpp:20
Base toolkit upon which the software is built.
Definition Application.cpp:83
STL namespace.
Definition RecursiveWatch.hpp:40
Definition RecursiveWatch.hpp:23
Definition RecursiveWatch.hpp:29