blob: 0e786798e7569775eef0a6977ef6252f3b72d1ba (
plain)
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
|
#include <iostream>
#include <exception>
#include "tabOptions.h"
using namespace std;
TabOptions::TabOptions(): opts(), nb_opts(0) {}
void TabOptions::addOption(const Option &o) {
if (nb_opts == NMAX_OPTS) {
cerr << "Erreur: Impossible d'ajouter une nouvelle option." << endl
<< " Nombre maximum d'option atteint"<< " (" << NMAX_OPTS << ")."
<< endl;
terminate();
}
bool found = (getOptionIndex(o.getName()) != -1) || (getOptionIndex(o.getShortcut()) != -1);
if (found) {
cerr << "Avertissement: L'identifiant " << o.getId() << " est déjà utilisé."
<< endl;
} else {
opts[nb_opts] = o;
nb_opts++;
}
}
void TabOptions::print() const {
cout << "Options :" << endl;
for (size_t i = 0; i < nb_opts; i++) {
opts[i].print();
}
}
int TabOptions::getOptionIndex(const string &opt) const {
bool found = false;
size_t i = 0;
while (!found && (i < nb_opts)) {
found = ((opts[i].getName() == opt) || (opts[i].getShortcut() == opt));
i++;
}
return found ? i - 1 : -1;
}
// opt doit etre une option valide
int TabOptions::getOptionId(const std::string &opt) const {
int i = getOptionIndex(opt);
return (i>=0 ? opts[i].getId():-1);
}
// opt doit etre une option valide
bool TabOptions::optionHasArgument(const std::string &opt) const {
size_t i = getOptionIndex(opt);
return (opts[i].getType() != Option::AUCUN);
}
// opt doit etre une option valide
Option::Type TabOptions::optionArgumentType(const std::string &opt) const {
size_t i = getOptionIndex(opt);
return opts[i].getType();
}
|