MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Discovery.cpp
Go to the documentation of this file.
1#include "Discovery.hpp"
2
4
5namespace {
6
7 constexpr std::string_view default_marker = "MF_DESCRIBE";
8 constexpr std::string_view default_suffix = ".describe.hpp";
9
10 bool is_header(const std::filesystem::path& path)
11 {
12 const std::string name = path.filename().string();
13 if (name.ends_with(".describe.hpp") || name.ends_with(".signatures.hpp")) {
14 return false;
15 }
16 const std::string extension = path.extension().string();
17 return extension == ".hpp" || extension == ".h" || extension == ".hh" || extension == ".hxx";
18 }
19
20 bool has_request(const std::filesystem::path& path, std::string_view marker)
21 {
22 std::ifstream stream(path);
23 std::string line;
24 while (std::getline(stream, line)) {
25 std::string_view view(line);
26 while (!view.empty() && (view.front() == ' ' || view.front() == '\t' || view.front() == ';' || view.front() == '}')) {
27 view.remove_prefix(1);
28 }
29 if (!view.starts_with(marker)) {
30 continue;
31 }
32 view.remove_prefix(marker.size());
33 while (!view.empty() && (view.front() == ' ' || view.front() == '\t')) {
34 view.remove_prefix(1);
35 }
36 if (!view.empty() && view.front() == '(') {
37 return true;
38 }
39 }
40 return false;
41 }
42
43}
44
45std::vector<std::filesystem::path> discover_headers(const std::vector<std::filesystem::path>& roots)
46{
47 return discover_headers(roots, default_marker);
48}
49
50std::vector<std::filesystem::path> discover_headers(
51 const std::vector<std::filesystem::path>& roots, std::string_view marker)
52{
53 std::vector<std::filesystem::path> found;
54 std::error_code code;
55 for (const auto& root : roots) {
56 if (std::filesystem::is_regular_file(root, code)) {
57 if (is_header(root) && has_request(root, marker)) {
58 found.push_back(std::filesystem::canonical(root, code));
59 }
60 continue;
61 }
62 for (std::filesystem::recursive_directory_iterator it(root, code), end; it != end; it.increment(code)) {
63 if (code) {
64 break;
65 }
66 if (it->is_regular_file(code) && is_header(it->path()) && has_request(it->path(), marker)) {
67 found.push_back(std::filesystem::canonical(it->path(), code));
68 }
69 }
70 }
71 std::ranges::sort(found);
72 found.erase(std::ranges::unique(found).begin(), found.end());
73 return found;
74}
75
76std::vector<std::filesystem::path> discover_sidecars(const std::vector<std::filesystem::path>& roots)
77{
78 return discover_sidecars(roots, default_suffix);
79}
80
81std::vector<std::filesystem::path> discover_sidecars(
82 const std::vector<std::filesystem::path>& roots, std::string_view suffix)
83{
84 std::vector<std::filesystem::path> found;
85 std::error_code code;
86 for (const auto& root : roots) {
87 if (!std::filesystem::is_directory(root, code)) {
88 continue;
89 }
90 for (std::filesystem::recursive_directory_iterator it(root, code), end; it != end; it.increment(code)) {
91 if (code) {
92 break;
93 }
94 if (it->is_regular_file(code) && it->path().filename().string().ends_with(suffix)) {
95 found.push_back(std::filesystem::canonical(it->path(), code));
96 }
97 }
98 }
99 std::ranges::sort(found);
100 found.erase(std::ranges::unique(found).begin(), found.end());
101 return found;
102}
103
104}
Vruta::SoundRoutine line(float start_value, float end_value, float duration_seconds, uint32_t step_duration, bool restartable)
Creates a continuous interpolation generator between two values over time.
Definition Tasks.cpp:60
std::vector< std::filesystem::path > discover_headers(const std::vector< std::filesystem::path > &roots)
Finds headers under roots that contain an MF_DESCRIBE request.
Definition Discovery.cpp:45
std::vector< std::filesystem::path > discover_sidecars(const std::vector< std::filesystem::path > &roots)
Every Name.describe.hpp under the directories among roots, canonical and sorted.
Definition Discovery.cpp:76