Input Files

1

Input Files

2
@Add(includes)
#include <iostream>
#include <vector>
#include <filesystem>
@End(includes)
3
@Add(inputs elements)
auto &cur() {
ASSERT (! open_.empty());
return open_.back();
}
auto &cur_input() {
return used_.find(cur().path())->second;
}
@End(inputs elements)
4
@Add(inputs elements)
auto begin() {
return used_.begin();
}
@End(inputs elements)
5
@Add(inputs elements)
auto end() {
return used_.end();
}
@End(inputs elements)
6
@Add(inputs elements)
auto size() const {
return used_.size();
}
@End(inputs elements)
7
@Add(inputs elements)
void push(const std::string &path) {
std::string prev;
if (open_.size()) {
auto got { used_.find(open_.back().path()) };
if (got != used_.end()) {
prev = open_.back().path();
}
}
used_.insert(std::move(
std::map<std::string, Input>::value_type(path, Input(prev))
));
open_.emplace_back(path);
}
const std::string open_head() const {
ASSERT(! open_.empty());
return open_.back().path();
}
Input &operator[](const std::string &name) {
return used_[name];
}
@End(inputs elements)
8
@Add(inputs elements)
void add(const std::string &path) {
roots_.push_back(path);
push(path);
}
@End(inputs elements)

Get next line

9

Get next line

10
@Add(inputs elements)
bool has(const std::string &name) const {
@put(has checks);
return false;
}
@End(inputs elements)
11
@def(has checks)
if (used_.find(name) != used_.end()) {
return true;
}
@end(has checks)

Local Frags

12

Local Frags

Line Numbers

13

Line Numbers

14
@Add(private open input els)
int line_ = 0;
@end(private open input els)
15
@Add(open input elements)
int line() const {
return line_;
}
@end(open input elements)
16
@Def(line read)
++line_;
@End(line read)
17
@Def(clear inputs)
used_.clear();
open_.clear();
if (roots_.empty()) {
@put(populate default file);
}
current_path_ = roots_.begin();
@End(clear inputs)
18
@def(populate default file)
if (std::filesystem::exists("index.md")) {
roots_.push_back("index.md");
} else if (std::filesystem::exists("index.x")) {
roots_.push_back("index.x");
} else {
std::cerr << "no input paths\n";
roots_.push_back("index.md");
}
@end(populate default file)