diff --git a/src/01/Day01.h b/src/01/Day01.h index 351f212..4aaa86f 100644 --- a/src/01/Day01.h +++ b/src/01/Day01.h @@ -8,8 +8,6 @@ class Day01 : public Day { protected: Result Task1() override; Result Task2() override; -public: - explicit Day01(Input &input) : Day(input) {} }; diff --git a/src/02/Day02.h b/src/02/Day02.h index 92ebcd5..a9f5203 100644 --- a/src/02/Day02.h +++ b/src/02/Day02.h @@ -8,8 +8,6 @@ class Day02 : public Day { protected: Result Task1() override; Result Task2() override; -public: - explicit Day02(Input &input) : Day(input) {} }; diff --git a/src/03/Day03.h b/src/03/Day03.h index 79cf08a..250f212 100644 --- a/src/03/Day03.h +++ b/src/03/Day03.h @@ -8,8 +8,6 @@ class Day03 : public Day { protected: Result Task1() override; Result Task2() override; -public: - explicit Day03(Input &input) : Day(input) {} }; diff --git a/src/Day.h b/src/Day.h index 3bcd487..f66b086 100644 --- a/src/Day.h +++ b/src/Day.h @@ -1,11 +1,8 @@ #ifndef ADVENTOFCODE2022_DAY_H #define ADVENTOFCODE2022_DAY_H -#include -#include -#include +#include "util.h" #include -#include using namespace std::chrono; typedef std::string Result; @@ -17,8 +14,11 @@ protected: virtual Result Task1() { return ""; } virtual Result Task2() { return ""; } public: - explicit Day(Input &input) : input(input) {} - int run() { + explicit Day() = default; + ~Day() = default; + int run(Input &_input) { + this->input = _input; + auto start = high_resolution_clock::now(); std::cout << "Task 1" << std::endl; diff --git a/src/days.h b/src/days.h index fa9d6ab..78676a4 100644 --- a/src/days.h +++ b/src/days.h @@ -6,22 +6,12 @@ #include "02/Day02.h" #include "03/Day03.h" -Day* getDay(int dayNum, std::vector &input){ - Day* day; - switch (dayNum){ - case 1: - day = new Day01(input); - break; - case 2: - day = new Day02(input); - break; - case 3: - day = new Day03(input); - break; - default: - day = nullptr; - } - return day; +std::vector getAllDays(){ + return std::vector { + new Day01(), + new Day02(), + new Day03() + }; } #endif diff --git a/src/main.cpp b/src/main.cpp index 8efcdaf..21ed1f5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -46,24 +46,23 @@ std::string getSessionKey(){ int main(int argc, char *argv[]) { - std::string key = getSessionKey(); + auto key = getSessionKey(); bool useTestInput = false; + auto days = getAllDays(); for (int i = 1; i < argc; i++){ int dayNum = std::stoi(argv[i]); std::cout << "Running day " << dayNum << std::endl; auto input = getInput(dayNum, key, useTestInput); - auto day = getDay(dayNum, input); - if (day == nullptr){ - std::cout << "Could not run day " << dayNum << std::endl; - continue; - } - - int code = day->run(); + auto day = days[dayNum - 1]; + int code = day->run(input); if (code != 0) return code; } + for (Day* day : days) + delete day; + return 0; } diff --git a/src/util.h b/src/util.h new file mode 100644 index 0000000..8cbda41 --- /dev/null +++ b/src/util.h @@ -0,0 +1,11 @@ + +#ifndef ADVENTOFCODE2022_UTIL_H +#define ADVENTOFCODE2022_UTIL_H + +#include +#include +#include +#include +#include + +#endif