1
1
#include " VariablesManagement.h"
2
2
#include " Types/MathType.h"
3
3
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 ) {
5
5
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;
6
11
}
7
12
8
13
std::string VariablesManagement::getVariableValue (std::string const & name) const {
9
14
std::unordered_map<std::string, std::string>::const_iterator got = m_variables.find (name);
10
15
if (got != m_variables.end ()) {
11
16
return got->second ;
12
17
}
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
+ }
13
28
else {
14
29
return " FPL Erreur : Variable non trouvé !" ;
15
30
}
16
31
}
17
32
18
33
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 ;
23
36
}
24
37
else {
25
- return false ;
38
+ return true ;
26
39
}
27
40
}
28
41
@@ -32,7 +45,7 @@ std::unordered_map<std::string, std::string> VariablesManagement::getContent() c
32
45
33
46
34
47
35
- void VariablesManagement::init (std::string& line) {
48
+ void VariablesManagement::variables_basics (std::string& line) {
36
49
std::string whatReplace = " variable " ;
37
50
std::string print_content = replaceFPL (line, whatReplace);
38
51
@@ -72,31 +85,78 @@ void VariablesManagement::init(std::string& line) {
72
85
value_indication = vec[2 ];
73
86
74
87
if (var_type == " texte" ) {
88
+ std::string const type = " texte" ;
75
89
var_type += " " ;
76
90
value_indication += " " ;
77
-
78
91
var_value = replaceFPL (line, var_name);
79
92
var_value = replaceFPL (line, var_type);
80
93
var_value = replaceFPL (line, value_indication);
81
-
82
- ajouterVariable (var_name, var_value);
94
+ ajouterVariable (var_name, var_value, type);
83
95
}
84
96
else if (var_type == " math" ) {
97
+ std::string const type = " math" ;
85
98
var_type += " " ;
86
99
value_indication += " " ;
87
-
88
100
var_value = replaceFPL (line, var_name);
89
101
var_value = replaceFPL (line, var_type);
90
102
var_value = replaceFPL (line, value_indication);
91
-
92
103
var_value = std::to_string (mathFinalValue (var_value));
93
-
94
- ajouterVariable (var_name, var_value);
104
+ ajouterVariable (var_name, var_value, type);
95
105
}
96
-
106
+
97
107
}
98
108
else {
99
109
error = " basic" ;
100
110
errorVariable (error);
101
111
}
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
+ }
102
162
}
0 commit comments