aocpp/lib/src/Startup.cpp

37 lines
690 B
C++
Raw Normal View History

#include <aocpp/Startup.hpp>
#include <cstdlib>
#include <iostream>
2022-11-07 21:00:14 -08:00
#include <optional>
#include <memory>
#include <fstream>
2022-11-13 11:42:40 -08:00
#include <utility>
#define DOCTEST_CONFIG_IMPLEMENT
#include <doctest.h>
namespace aocpp {
auto Startup(int argc, char ** argv) -> std::unique_ptr<std::istream, ConditionalDeleter> {
bool should_delete;
std::istream* result_ptr;
2022-11-13 11:42:40 -08:00
2022-11-07 21:00:14 -08:00
switch (argc) {
case 2:
should_delete = true;
result_ptr = new std::ifstream{argv[1]};
break;
case 1:
should_delete = false;
result_ptr = &std::cin;
break;
default:
std::cerr << "bad arguments\n";
exit(EXIT_FAILURE);
}
return {result_ptr, should_delete};
}
}