-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDayOneParser.cpp
34 lines (26 loc) · 1015 Bytes
/
DayOneParser.cpp
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
//
// Created by Aidan Nagorcka-Smith on 27/12/2022.
//
#include "DayOneParser.h"
#include <iostream>
#include "InputFileReader.h"
namespace AdventOfCode::DayOne::Parser {
std::vector<Elf> parseFile(const std::filesystem::path &inputFilePath) {
std::vector<Elf> parsedElves{};
parseFile(inputFilePath, [&](auto &&elf) {
parsedElves.push_back(std::forward<decltype(elf)>(elf));
});
return parsedElves;
}
void parseFile(const std::filesystem::path &inputFilePath, const HandleElfCallbackFunction &&handleElfCallback) {
auto elfBuilder = Elf::builder();
InputFileReader::readLines(inputFilePath, [&](auto &&line) -> void {
if (!line.empty()) {
// TODO(aidanns): Handle the case where we have a malformed line.
elfBuilder.addFood(Food{std::stoi(line)});
} else {
handleElfCallback(elfBuilder.build());
}
});
}
} // AdventOfCode::DayOne::Parser