Zappy - Year end project
2
This is a project that Epitech asked us to create in order to allow us to reveiw the notions of the current year.
Loading...
Searching...
No Matches
src
gui_client
src
Parsing.cpp
Go to the documentation of this file.
1
/*
2
** EPITECH PROJECT, 2024
3
** my_zappy
4
** File description:
5
** Parsing.cpp
6
*/
7
8
#include <cstring>
9
#include "
Parsing.hpp
"
10
#include "
ArgumentHandling.hpp
"
11
12
namespace
Gui
13
{
14
Parsing::Parsing
() : _port(
""
), _machine(
""
)
15
{}
16
17
void
Parsing::help
()
const
18
{
19
std::cout <<
"USAGE: ./zappy_gui -p port -h machine"
<< std::endl;
20
}
21
22
bool
Parsing::parse_args
(
int
ac,
char
**av)
23
{
24
for
(
int
i = 1; i < ac; ++i) {
25
if
(std::strcmp(av[i],
"-p"
) == 0 && i + 1 < ac) {
26
_port = av[++i];
27
if
(check_valid_port(_port) !=
true
)
28
throw
Exception::ArgumentHandling
(
"Invalid port number."
);
29
}
else
if
(std::strcmp(av[i],
"-h"
) == 0 && i + 1 < ac) {
30
_machine = av[++i];
31
}
else
{
32
throw
Exception::ArgumentHandling
(
"Invalid argument: "
+ std::string(av[i]));
33
}
34
}
35
return
true
;
36
}
37
38
bool
Parsing::validate_args
()
const
39
{
40
if
(_port.empty() || _machine.empty()) {
41
throw
Exception::ArgumentHandling
(
"Missing arguments."
);
42
}
43
return
true
;
44
}
45
46
void
Parsing::print_args
()
const
47
{
48
std::cout <<
"Port : "
<< _port << std::endl;
49
std::cout <<
"Machine : "
<< _machine << std::endl;
50
}
51
52
bool
Parsing::check_valid_port(
const
std::string &port)
53
{
54
55
for
(
size_t
i = 0; i < port.size(); ++i) {
56
char
c = port[i];
57
if
(std::isdigit(c) == 0)
58
return
false
;
59
}
60
return
true
;
61
}
62
}
ArgumentHandling.hpp
Parsing.hpp
Exception::ArgumentHandling
Definition
ArgumentHandling.hpp:16
Gui::Parsing::print_args
void print_args() const
Definition
Parsing.cpp:46
Gui::Parsing::help
void help() const
Definition
Parsing.cpp:17
Gui::Parsing::parse_args
bool parse_args(int ac, char **av)
Definition
Parsing.cpp:22
Gui::Parsing::Parsing
Parsing()
Definition
Parsing.cpp:14
Gui::Parsing::validate_args
bool validate_args() const
Definition
Parsing.cpp:38
Gui
Definition
Parsing.hpp:13