-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathloader.cpp
More file actions
28 lines (24 loc) · 776 Bytes
/
Copy pathloader.cpp
File metadata and controls
28 lines (24 loc) · 776 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include "loader.h"
#include <cstdio>
namespace qrqma {
TemplateLoader defaultLoader(std::filesystem::path const& template_directory) {
return [template_directory](std::string const& filename) {
auto pat = (template_directory / filename).native();
std::FILE* f = std::fopen(pat.c_str(), "r");
if (not f) {
throw std::runtime_error("cannot load template file \"" + filename + "\"");
}
std::string templ;
while (true) {
std::array<char, 4096> buf;
int r = std::fread(&buf[0], sizeof(buf[0]), buf.size(), f);
if (r == 0) {
break;
}
templ += std::string(buf.data(), r);
}
std::fclose(f);
return templ;
};
}
}