blob: d85feaccd35a1b1e76dc3a926f64695868eaef4a (
plain)
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
29
30
31
32
33
34
35
36
37
38
39
|
#include "CodegenOutput.hpp"
#include "CodegenUtils.hpp"
void CodegenOutput::AddRequestInclude(std::string_view include) {
if (!mRequestIncludes.contains(include)) {
mRequestIncludes.insert(std::string(include));
}
}
void CodegenOutput::AddOutputThing(CodegenOutputThing thing, int placementLocation) {
if (placementLocation < 0 || placementLocation >= mOutThings.size()) {
mOutThings.push_back(std::move(thing));
} else {
int maxIndex = (int)mOutThings.size() - 1;
if (placementLocation > maxIndex) {
placementLocation = maxIndex;
}
auto placementIter = mOutThings.begin() + placementLocation;
mOutThings.insert(placementIter, std::move(thing));
}
}
void CodegenOutput::MergeContents(CodegenOutput other) {
std::move(other.mOutThings.begin(), other.mOutThings.end(), std::back_inserter(this->mOutThings));
}
void CodegenOutput::Write(FILE* file) const {
for (auto& include : mRequestIncludes) {
// TODO how to resolve to the correct include paths?
WRITE_FMT_LN(file, "#include <%s>", include.c_str());
}
for (auto& thing : mOutThings) {
fwrite(thing.text.c_str(), sizeof(char), thing.text.size(), file);
WRITE_LIT(file, "\n");
}
}
|