MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Check.cpp
Go to the documentation of this file.
1#include "Check.hpp"
2
3#include "Sidecar.hpp"
4
6
7namespace {
8
9 using Members = std::map<std::string, std::vector<std::string>>;
10
11 constexpr std::string_view record_marker = "struct Description<::";
12
13 Members parse_sidecar(const std::string& text)
14 {
15 Members parsed;
16 auto current = parsed.end();
17 std::istringstream lines(text);
18 std::string line;
19 while (std::getline(lines, line)) {
20 if (const auto at = line.find(record_marker); at != std::string::npos) {
21 const auto begin = at + record_marker.size();
22 const auto end = line.find('>', begin);
23 if (end != std::string::npos) {
24 current = parsed.try_emplace(line.substr(begin, end - begin)).first;
25 }
26 continue;
27 }
28 if (current == parsed.end() || line.find("Member<&::") == std::string::npos) {
29 continue;
30 }
31 const auto open = line.find('"');
32 const auto close = open == std::string::npos ? open : line.find('"', open + 1);
33 if (close != std::string::npos) {
34 current->second.push_back(line.substr(open + 1, close - open - 1));
35 }
36 }
37 return parsed;
38 }
39
40 std::string joined(const std::vector<std::string>& names)
41 {
42 std::string out;
43 for (const auto& name : names) {
44 out += out.empty() ? name : ", " + name;
45 }
46 return out;
47 }
48
49 std::vector<std::string> missing_from(const std::vector<std::string>& names, const std::vector<std::string>& other)
50 {
51 std::vector<std::string> out;
52 for (const auto& name : names) {
53 if (std::ranges::find(other, name) == other.end()) {
54 out.push_back(name);
55 }
56 }
57 return out;
58 }
59
60 std::vector<std::string> drift(const std::string& where, const std::string& have_text, const std::string& want_text)
61 {
62 const Members have = parse_sidecar(have_text);
63 const Members want = parse_sidecar(want_text);
64 std::vector<std::string> messages;
65
66 for (const auto& [name, members] : want) {
67 const auto found = have.find(name);
68 if (found == have.end()) {
69 messages.push_back(where + name + " is not described in the sidecar");
70 continue;
71 }
72 if (found->second == members) {
73 continue;
74 }
75 const auto added = missing_from(members, found->second);
76 const auto removed = missing_from(found->second, members);
77 std::string change = where + name + ":";
78 if (!added.empty()) {
79 change += " add " + joined(added);
80 }
81 if (!removed.empty()) {
82 change += " remove " + joined(removed);
83 }
84 if (added.empty() && removed.empty()) {
85 change += " member order changed";
86 }
87 messages.push_back(change);
88 }
89 for (const auto& [name, members] : have) {
90 if (!want.contains(name)) {
91 messages.push_back(where + name + " is in the sidecar but no longer requested");
92 }
93 }
94 if (messages.empty()) {
95 messages.push_back(where + "the sidecar text differs from the generator output");
96 }
97 return messages;
98 }
99
100}
101
102std::vector<std::string> check_sidecars(
103 const RequestMap& requests,
104 const std::vector<std::filesystem::path>& headers,
105 const std::vector<std::filesystem::path>& existing)
106{
107 std::vector<std::string> problems;
108 std::vector<std::filesystem::path> expected;
109
110 for (const auto& header : headers) {
111 const auto found = requests.find(header);
112 if (found == requests.end()) {
113 problems.push_back(header.string() + ": contains MF_DESCRIBE text but produced no request");
114 continue;
115 }
116
117 const std::filesystem::path sidecar = sidecar_path(header);
118 expected.push_back(sidecar);
119 const std::string where = sidecar.string() + ": ";
120 const std::string want = render_sidecar(found->second);
121
122 if (auto have = read_text(sidecar)) {
123 for (auto at = have->find("\r\n"); at != std::string::npos; at = have->find("\r\n", at + 1)) {
124 have->erase(at, 1);
125 }
126 if (*have != want) {
127 const auto messages = drift(where, *have, want);
128 problems.insert(problems.end(), messages.begin(), messages.end());
129 }
130 } else {
131 problems.push_back(where + "missing, expected " + std::to_string(found->second.records.size()) + " record(s)");
132 }
133
134 if (const auto problem = check_include(found->second)) {
135 problems.push_back(*problem);
136 }
137 }
138
139 for (const auto& sidecar : existing) {
140 if (std::ranges::find(expected, sidecar) == expected.end()) {
141 problems.push_back(sidecar.string() + ": orphaned, its header has no MF_DESCRIBE left");
142 }
143 }
144 return problems;
145}
146
147}
Cycle Behavior: The for_cycles(N) configuration controls how many times the capture operation execute...
void close(std::span< const float > mask, std::span< float > tmp, std::span< float > dst, uint32_t w, uint32_t h, uint32_t radius)
Morphological closing writing into dst.
void open(std::span< const float > mask, std::span< float > tmp, std::span< float > dst, uint32_t w, uint32_t h, uint32_t radius)
Morphological opening writing into dst.
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
auto at(const B &anchor, F &&factory, Args &&... args) -> decltype(std::forward< F >(factory)(Kinesis::bounds_of(anchor), std::forward< Args >(args)...))
Call a bounds-taking factory with an anchor's region.
Definition Geometry.hpp:154
std::map< std::filesystem::path, HeaderRequests > RequestMap
Definition Request.hpp:30
std::string render_sidecar(const HeaderRequests &requests)
Text of the sidecar for one header, with its records sorted by name.
Definition Sidecar.cpp:95
std::optional< std::string > read_text(const std::filesystem::path &path)
The whole content of path, or nullopt when it cannot be read.
Definition Sidecar.cpp:30
std::filesystem::path sidecar_path(const std::filesystem::path &header)
Path of the sidecar for header: Name.hpp becomes Name.describe.hpp beside it.
Definition Sidecar.cpp:85
std::vector< std::string > check_sidecars(const RequestMap &requests, const std::vector< std::filesystem::path > &headers, const std::vector< std::filesystem::path > &existing)
Compares the sidecars on disk with what the generator would write, touching nothing.
Definition Check.cpp:102
std::optional< std::string > check_include(const HeaderRequests &requests)
Checks that the header includes its sidecar exactly once, after its last marker.
Definition Sidecar.cpp:161