-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_error.cpp
More file actions
83 lines (74 loc) · 1.92 KB
/
check_error.cpp
File metadata and controls
83 lines (74 loc) · 1.92 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <sstream>
#include <iostream>
#include <fstream>
#include <string>
#include <filesystem>
#include <vector>
#include "check_error.h"
ParseErrors check_error(int argc, char** argv, std::string& path, std::vector<double>& vx, std::vector<double>& vy, double& x, double& y)
{
//double x, y;
if(argc < 4)
{
return ParseErrors::INSUFFICIENT_ARGUMENTS;
}
if (argc > 4)
{
return ParseErrors::TO_MUCH_ARGUMENTS;
}
//std::string path;
path = argv[1];
try {
x = std::stod(argv[2]);
y = std::stod(argv[3]);
}
catch (std::logic_error)
{
//std::cerr << "Âû ïîäàëè íåâåðíûå àðãóìåíòû!" << std::endl;
return ParseErrors::WRONG_ARGUMENTS;
}
std::string x0, y0;
std::ifstream f;
f.open(path);
if (!f.is_open()) // ñ÷èòûâàíèÿ ôàéëà
{
//std::cerr << "error open file" << std::endl;
return ParseErrors::ERROR_OPEN_FILE;
}
std::cout << "file open" << std::endl;
try
{
while (!f.eof())
{
f >> x0 >> y0;
vx.push_back(std::stod(x0));
vy.push_back(std::stod(y0));
}
f.close();
}
catch (std::invalid_argument)
{
//std::cerr << "Âû ïîäàëè íåâåðíûå òî÷êè!" << std::endl;
return ParseErrors::INVALID_POLYGON;
}
return ParseErrors::SUCCESS;
}
std::string get_error_name(ParseErrors err_info)
{
switch (err_info)
{
case ParseErrors::INSUFFICIENT_ARGUMENTS:
return "Not enough arguments";
case ParseErrors::TO_MUCH_ARGUMENTS:
return "To much arguments";
case ParseErrors::WRONG_ARGUMENTS:
return "Wrong input: x and y must be double";
case ParseErrors::ERROR_OPEN_FILE:
return "Error open file";
case ParseErrors::INVALID_POLYGON:
return "Invalid polygon";
case ParseErrors::SUCCESS:
return "No error";
}
return "Unknown error";
}