validation.cpp 1.17 KB
Newer Older
Matteo's avatar
update  
Matteo committed
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
#include <iostream>
#include <fstream>
#include "validation.h"
#include "colors.h"

using namespace std;
namespace fs = std::filesystem;

int checkJSON(fs::path irregularityFileInputPath, float speed, int tapeThresholdPercentual, int capstanThresholdPercentual) {
	// Input JSON check
	ifstream iJSON(irregularityFileInputPath);
	if (iJSON.fail()) {
		cerr << RED << BOLD << "config.json error!" << END << endl << RED << irregularityFileInputPath.string() << " cannot be found or opened." << END << endl;
		return -1;
	}
	if (speed != 7.5 && speed != 15) {
		cerr << RED << BOLD << "config.json error!" << END << endl << RED << "Speed parameter must be 7.5 or 15 ips." << END << endl;
		return -1;
	}
	if (tapeThresholdPercentual < 0 || tapeThresholdPercentual > 100) {
		cerr << RED << BOLD << "config.json error!" << END << endl << RED << "TapeThresholdPercentual parameter must be a percentage value." << END << endl;
		return -1;
	}
	if (capstanThresholdPercentual < 0 || capstanThresholdPercentual > 100) {
		cerr << RED << BOLD << "config.json error!" << END << endl << RED << "CapstanThresholdPercentual parameter must be a percentage value." << END << endl;
		return -1;
	}
	return 0;
}