MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ read_signature_entries()

std::optional< std::vector< SignatureEntry > > MayaFlux::Reflect::Tool::read_signature_entries ( const std::filesystem::path & registry,
const std::filesystem::path & source_root,
std::string & error )
nodiscard

Reads the N, W and B registrations of the registry header and finds each class's header.

A registration is a line of the form N(Name, MayaFlux::Qualified::Type), with an optional trailing backslash. The header of a class is the one file named after it under source_root / MayaFlux that declares it as a class or struct with a body.

Parameters
errorReceives the reason when nullopt is returned: an unreadable registry, an empty or duplicated registration list, or a class with no header or more than one.

Definition at line 37 of file SignatureEntries.cpp.

39{
40 std::ifstream stream(registry);
41 if (!stream) {
42 error = "cannot read " + registry.string();
43 return std::nullopt;
44 }
45
46 const std::regex entry(R"(^\s*([NWB])\‍((\w+),\s*(MayaFlux::[\w:]+)\)\s*\\?\s*$)");
47 std::vector<SignatureEntry> entries;
48 std::set<std::string> names;
49 std::string line;
50 while (std::getline(stream, line)) {
51 if (!line.empty() && line.back() == '\r') {
52 line.pop_back();
53 }
54 std::smatch match;
55 if (!std::regex_match(line, match, entry)) {
56 continue;
57 }
58 if (!names.insert(match[2].str()).second) {
59 error = "registry is empty or contains duplicate factory names: " + match[2].str();
60 return std::nullopt;
61 }
62 entries.push_back(SignatureEntry { .name = match[2].str(), .type_name = match[3].str(), .header = {} });
63 }
64 if (entries.empty()) {
65 error = "registry is empty or contains duplicate factory names";
66 return std::nullopt;
67 }
68
69 const auto headers = headers_by_name(source_root / "MayaFlux");
70 for (SignatureEntry& item : entries) {
71 const std::string class_name = item.type_name.substr(item.type_name.rfind("::") + 2);
72 std::vector<std::filesystem::path> matches;
73 const auto range = headers.equal_range(class_name + ".hpp");
74 for (auto it = range.first; it != range.second; ++it) {
75 if (declares_class(it->second, class_name)) {
76 matches.push_back(it->second);
77 }
78 }
79 if (matches.size() != 1) {
80 error = item.name + ": expected one defining class header, found " + std::to_string(matches.size());
81 return std::nullopt;
82 }
83 item.header = matches.front();
84 }
85 return entries;
86}
void error(Component component, Context context, std::source_location location, std::string_view message)
Log an error message and optionally throw an exception.
std::vector< double > range(std::span< const double > data, size_t n_windows, uint32_t hop_size, uint32_t window_size)
Value range (max - min) per window.
Definition Analysis.cpp:473
One class of the Creator registry: the method name, its qualified type and its header.

Referenced by run_creator_build().

Here is the caller graph for this function: