-
Notifications
You must be signed in to change notification settings - Fork 0
/
sharedAoC.h
45 lines (39 loc) · 902 Bytes
/
sharedAoC.h
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
40
41
42
43
44
45
#pragma once
#include "./../../shared/rtpcore.h"
namespace AoC{
auto init(int argc, char** argv, bool extra = false){
char* file;
if(argc == 2 || (argc >= 2 && extra)){
file = argv[1];
} else if(argc < 2){
print("A path is required.\n");
exit(-1);
} else{
print("Too many arguments only a path is required.");
exit(-1);
}
std::ifstream infile(file); //std::ios::binary | std::ios::ate);
if(!infile){
print("Bad file path: {}\n", file);
exit(-1);
} else if(infile.peek() == std::ifstream::traits_type::eof()){
print("Empty file: {}", file);
exit(0);
}
return infile;
};
template <typename T>
auto toArray(size_t prealloc, std::ifstream& infile){
string s{30};
Array<T> res(prealloc);
do{
//s.erase();
std::getline(infile, s);
if(s.empty()){
} else{
res.push_back(atoi(s.data()));
}
} while(infile);
return res;
};
};