-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArgParser.cpp
89 lines (79 loc) · 2.26 KB
/
ArgParser.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//
// Created by vincenzo on 27/10/22.
//
#include "ArgParser.h"
#include <string>
#include <iostream>
#include <filesystem>
void ArgParser::parse() {
const std::vector<std::string_view> args(argvPointer+1,argvPointer+argumentLength);
if(args.size() < 2){
std::cerr<<"Missing required parameters!";
printUsage();
exit(1);
}
for (auto& arg : args){
if(arg == "--rom" ){
romPath= nextArgument(arg);
if(std::filesystem::exists(romPath))
isRom= true;
else
isRom= false;
}
if(arg == "--freq" ){
frequency= std::stoi(nextArgument(arg));
}
if(arg == "--scanH"){
horizontalScanLinesEnabled= true;
}
if(arg == "--scanV"){
verticalScanLinesEnabled= true;
}
if(arg == "--scanX"){
horizontalScanLinesEnabled= true;
verticalScanLinesEnabled= true;
}
if(arg == "--crossDir"){
crossingLineEnabled = true;
std::string crossDir= nextArgument(arg);
if(crossDir == "V"){
crossingLineDirection= false;
} else if (crossDir == "H"){
crossingLineDirection= true;
}else{
std::cerr<<"\n"<<"invalid crossing line direction";
printUsage();
}
}
}
if(!isRom){
std::cerr<<"\n"<<"Path to rom is either missing or invalid!";
printUsage();
exit(1);
}
}
const std::string &ArgParser::getRomPath() const {
return romPath;
}
int ArgParser::getFrequency() const {
return frequency;
}
std::string ArgParser::nextArgument(const std::string_view &stringView) {
auto res=(*(&stringView+1)).data();
return res;
}
void ArgParser::printUsage() {
std::cerr<<"\n"<<"Usage: ChipInterpreter --rom PathToYourRom [--freq InterpreterFrequency]";
}
bool ArgParser::isHorizontalScanLinesEnabled() const {
return horizontalScanLinesEnabled;
}
bool ArgParser::isVerticalScanLinesEnabled() const {
return verticalScanLinesEnabled;
}
bool ArgParser::isCrossingLineEnabled() const {
return crossingLineEnabled;
}
bool ArgParser::isCrossingLineDirection() const {
return crossingLineDirection;
}