-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
43 lines (38 loc) · 1.08 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
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <stdexcept>
#include "parse_descriptor.h"
/*
Contains the user interface. A descriptor can be provided to the program by
providing the path to a text file or entering the descriptor directly.
*/
std::stringstream input_to_ss(const std::string raw_user_input)
{
std::string raw_descriptor;
std::ifstream ist {raw_user_input};
if (ist)
{
ist>>raw_descriptor;
} else {
raw_descriptor = raw_user_input;
}
std::stringstream ss{raw_descriptor};
return ss;
}
int main()
{
try {
std::cout << "Please enter a descriptor directly or enter the path to a file containing a descriptor: ";
std::string raw_user_input;
std::cin>>raw_user_input;
Descriptor descriptor = ss_to_descriptor(input_to_ss(raw_user_input));
print_descriptor_info(descriptor);
} catch (std::runtime_error& error) {
std::cerr << error.what() << '\n';
} catch (...) {
std::cerr << "An unknown error occured" << '\n';
}
return 0;
}