aboutsummaryrefslogtreecommitdiff
path: root/main.cpp
blob: 693a5d2b121756ee111029c68b19214e7978bdd3 (plain)
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
#include <cstdio>

#include "Exception.h"
#include "FileReader.h"
#include "Museum.h"
#include "Deserializer.h"
#include "Parser.h"
#include "View.h"
#include "ViewController.h"

using namespace std;

static unique_ptr<FileStrategy> open(const char * url) noexcept {
	try {
		unique_ptr<FileStrategy> file = FileReader::open(url);
		return file;
	} catch (Exception & e) {
		printf("file open error: %s\n", e.what());
		exit(EXIT_FAILURE);
	}
}

static void parse(FileStrategy & file, Deserializer & deserializer, const char * url) noexcept {
	try {
		Parser::parse(file, deserializer);
	} catch (Exception & e) {
		printf("parser error: %s (%s)\n", e.what(), url);
		exit(EXIT_FAILURE);
	}
}

int main(int argc, char** argv) {
	Museum museum {};
	museum.set_pause(true);

	Deserializer deserializer { museum };

	for (int i = 1; i < argc; i++) {
		char * url = argv[i];

		unique_ptr<FileStrategy> file = open(url);
		parse(*file, deserializer, url);
	}

	// printf("%s", museum.canvas.to_string(true).c_str());
	// printf("%s", museum.people.to_string().c_str());

	ViewController controller { museum };
	View view { controller };

	museum.set_pause(false);

	while (view.open);

	return EXIT_SUCCESS;
}