Skip to content

Commit 6c419e1

Browse files
committed
Fix des problèmes + ajouts
1 parent 25268fd commit 6c419e1

File tree

1 file changed

+75
-15
lines changed

1 file changed

+75
-15
lines changed

headers/VariablesManagement.cpp

Lines changed: 75 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,41 @@
11
#include "VariablesManagement.h"
22
#include "Types/MathType.h"
33

4-
void VariablesManagement::ajouterVariable(std::string const& name, std::string const& value) {
4+
void VariablesManagement::ajouterVariable(std::string const& name, std::string const& value, std::string const& type) {
55
m_variables.insert({ name, value });
6+
types_variables.insert({ name, type });
7+
}
8+
9+
void VariablesManagement::setValueVariable(std::string const& name, std::string const& value) {
10+
m_variables[name] = value;
611
}
712

813
std::string VariablesManagement::getVariableValue(std::string const& name) const {
914
std::unordered_map<std::string, std::string>::const_iterator got = m_variables.find(name);
1015
if (got != m_variables.end()) {
1116
return got->second;
1217
}
18+
else {
19+
return "FPL Erreur : Variable non trouve !";
20+
}
21+
}
22+
23+
std::string VariablesManagement::getTypeVariable(std::string const& name) const {
24+
std::unordered_map<std::string, std::string>::const_iterator got = types_variables.find(name);
25+
if (got != types_variables.end()) {
26+
return got->second;
27+
}
1328
else {
1429
return "FPL Erreur : Variable non trouvé !";
1530
}
1631
}
1732

1833
bool VariablesManagement::isVariable(std::string& name) {
19-
std::unordered_map<std::string, std::string>::const_iterator got = m_variables.find(name);
20-
21-
if (got != m_variables.end()) {
22-
return true;
34+
if (m_variables.find(name) == m_variables.end()) {
35+
return false;
2336
}
2437
else {
25-
return false;
38+
return true;
2639
}
2740
}
2841

@@ -32,7 +45,7 @@ std::unordered_map<std::string, std::string> VariablesManagement::getContent() c
3245

3346

3447

35-
void VariablesManagement::init(std::string& line) {
48+
void VariablesManagement::variables_basics(std::string& line) {
3649
std::string whatReplace = "variable ";
3750
std::string print_content = replaceFPL(line, whatReplace);
3851

@@ -72,31 +85,78 @@ void VariablesManagement::init(std::string& line) {
7285
value_indication = vec[2];
7386

7487
if (var_type == "texte") {
88+
std::string const type = "texte";
7589
var_type += " ";
7690
value_indication += " ";
77-
7891
var_value = replaceFPL(line, var_name);
7992
var_value = replaceFPL(line, var_type);
8093
var_value = replaceFPL(line, value_indication);
81-
82-
ajouterVariable(var_name, var_value);
94+
ajouterVariable(var_name, var_value, type);
8395
}
8496
else if (var_type == "math") {
97+
std::string const type = "math";
8598
var_type += " ";
8699
value_indication += " ";
87-
88100
var_value = replaceFPL(line, var_name);
89101
var_value = replaceFPL(line, var_type);
90102
var_value = replaceFPL(line, value_indication);
91-
92103
var_value = std::to_string(mathFinalValue(var_value));
93-
94-
ajouterVariable(var_name, var_value);
104+
ajouterVariable(var_name, var_value, type);
95105
}
96-
106+
97107
}
98108
else {
99109
error = "basic";
100110
errorVariable(error);
101111
}
112+
}
113+
114+
void VariablesManagement::variables_update(std::string& line) {
115+
std::string whatReplace = "changer ";
116+
std::string print_content = replaceFPL(line, whatReplace);
117+
118+
std::vector<std::string> vec = split(print_content);
119+
120+
std::string name, new_value, INDICATION, TYPE, error;
121+
bool normalContent = false;
122+
123+
if (vec.size() == 0) {
124+
error = "name";
125+
errorUpdateVariable(error);
126+
normalContent = false;
127+
}
128+
else if (vec.size() == 1) {
129+
error = "indication";
130+
errorUpdateVariable(error);
131+
normalContent = false;
132+
}
133+
else if (vec.size() == 2) {
134+
error = "value";
135+
errorUpdateVariable(error);
136+
normalContent = false;
137+
}
138+
else {
139+
normalContent = true;
140+
}
141+
142+
if (normalContent) {
143+
name = vec[0];
144+
INDICATION = vec[1];
145+
TYPE = getTypeVariable(name);
146+
new_value = replaceFPL(line, name);
147+
new_value = replaceFPL(line, INDICATION);
148+
149+
if (TYPE == "math") {
150+
std::string const type = "math";
151+
new_value = std::to_string(mathFinalValue(new_value));
152+
setValueVariable(name, new_value);
153+
}
154+
else if (TYPE == "texte") {
155+
setValueVariable(name, new_value);
156+
}
157+
}
158+
else {
159+
error = "basic";
160+
errorUpdateVariable(error);
161+
}
102162
}

0 commit comments

Comments
 (0)