-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
65 lines (58 loc) · 1.82 KB
/
main.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <Windows.h>
#include <tchar.h>
#include "console.hpp"
#include "argparser.hpp"
#include "output_writer.hpp"
#include "input_reader.hpp"
#include "fizz_buzz_persistent_cache.hpp"
// Welcome to 2024, where open source projects have a copyright.
TCHAR copyrightMessage[] = {
TEXT("FizzBuzz Enterprise Edition.\nEnterpriseQualityCoding - the most serious and not satire or fake company in the universe.\n")
};
ArgumentParser argParser;
BaseInputReader* inputReader;
BaseOutputWriter* outputWriter;
FizzBuzzCacheLoader* cacheLoader;
int _tmain(unsigned int argc, TCHAR* argv[]) {
argParser.parse(argc, argv);
if (argParser.shouldShowSplash()) console.writeOutput(copyrightMessage);
if (argParser.shouldShowHelp()) {
console.writeOutput(helpMessage);
return (argParser.isExplicitHelp()) ? 0 : -1;
}
if (argParser.shouldUseTestInput()) {
inputReader = new TestInputReader();
}
else if (argParser.getInputFile() == TEXT("")) {
inputReader = new ConsoleInputReader();
}
else {
inputReader = new FileInputReader(argParser.getInputFile());
}
if (argParser.getOutputFilename() != TEXT("")) {
outputWriter = new FileOutputWriter(argParser.getOutputFilename());
}
else {
outputWriter = new ConsoleOutputWriter();
}
if (argParser.getCacheFile() != TEXT("")) {
cacheLoader = new FizzBuzzCacheLoader(argParser.getCacheFile());
cacheLoader->loadCache(fizzbuzzer.cache);
}
while (!inputReader->getIsInputExhausted()) {
try {
unsigned long long int value = inputReader->read();
outputWriter->writeOne(value, fizzbuzzer.fizzBuzz(value));
}
catch (std::exception e) { // Just in case something goes wrong (is the input stream empty?).
continue;
}
}
if (argParser.getCacheFile() != TEXT("")) {
cacheLoader->dumpCache(fizzbuzzer.cache);
}
delete cacheLoader;
delete outputWriter;
delete inputReader;
return 0;
}