70{
72
75
76 bool ok = false;
77 int typecount = 0;
78 std::string originalinputtext = inputtext;
79 std::map<std::string, std::string> typesdict;
80 std::map<std::string, std::string> typesdict_content;
81
82 while (!ok)
83 {
84
85
86
87 const char* simpletypeRE = "[^\\<\\>,\\s]+\\<[^\\<\\>]+\\>";
88
89
90
91 std::smatch matches;
92 std::regex regex(simpletypeRE);
93
94
95 std::regex_search(inputtext, matches, regex);
96
97
98
99
100
101
102
103 if (matches.size() == 0)
104 {
105 if (typesdict.size() == 0)
106 {
107 auto tkey =
"$T" + std::to_string(typecount);
108 typesdict[
tkey] = inputtext;
109 }
110 break;
111 }
112
113
114
115
116
117
118
119
120
121
122 int i = 0;
123 for (auto& m : matches)
124 {
125 std::string tstr = m;
126 auto tkey =
"$T" + std::to_string(typecount);
128
129
130
131 typecount++;
132 typesdict[
tkey] = tstr;
133
134 i++;
135 }
136 }
137
138
139
140
141
142
143
144
145
146
147
148
149
150 std::vector<std::pair<std::string, std::string>> orderedTypedict;
151 for (const auto& item : typesdict)
152 {
153 orderedTypedict.emplace_back(item);
154 }
155
156 std::sort(orderedTypedict.begin(), orderedTypedict.end(),
157 [](auto& a, auto& b) { return std::stoi(a.first.substr(2)) < std::stoi(b.first.substr(2)); });
158
159 std::set<std::string> allbasetypes;
160 for (auto& typeentry : orderedTypedict )
161 {
162 auto flat = typeentry.second;
163
164
165 size_t startindex = flat.find("<");
166 size_t endindex = flat.find(">");
167 if (startindex != std::string::npos)
168 {
169 flat = flat.substr(startindex + 1,
170 endindex - startindex - 1);
171
172
173 typesdict_content[typeentry.first] = flat;
174 std::vector<std::string> localbasetypes;
175
176 std::istringstream iss(flat);
177 std::string token;
178 while (std::getline(iss, token, ','))
179 {
180 boost::trim(token);
181 localbasetypes.push_back(token);
182
183 }
184
185 for (auto& b : localbasetypes)
186 {
187 size_t found = b.find("$");
188
189 if (found == std::string::npos)
190 {
191 allbasetypes.insert(b);
192 }
193 }
194 }
195
196
197
198
199
200 for (auto& b : allbasetypes)
201 {
202 typesdict[b] = b;
203 }
204 }
205
206
207
208
209
210
211
212
213
214 for (auto& b : allbasetypes)
215 {
216 orderedTypedict.push_back({ b, b });
217 }
218
219
220 std::vector<TypeInfo::Ptr> types;
221 std::vector<std::string> tokens;
222
223 for (auto t : orderedTypedict)
224 {
225
226 auto&
tkey = t.first;
227 auto& tval = t.second;
229 auto tinfo = std::make_shared<TypeInfo>(
tkey, tval,
finaltype);
230 types.push_back(tinfo);
231 tokens.push_back(
tkey);
232
233
234 }
235
237 for (auto& t : types)
238 {
239
240 if (t->finaltype == originalinputtext)
241 {
242 roottype = t;
243 break;
244 }
245 }
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268 for (size_t i = 0; i < types.size(); i++)
269 {
270 auto t = types[i];
271 auto ttoken = tokens[i];
272
273
274 std::vector<std::pair<int, TypeInfo::Ptr>> unorderedTemplateParameters;
275
276
277
278
279 auto codedtypecopy = typesdict_content[ttoken];
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294 for (auto& t2 : types)
295
296 {
297
298
299
300 if (t == t2)
301 continue;
302
303 auto index = codedtypecopy.find(t2->tkey);
304 if (index != std::string::npos)
305 {
306 auto pair = std::make_pair(index, t2);
307
308
309 unorderedTemplateParameters.push_back(pair);
310 replace(codedtypecopy, t2->tkey,
"");
311
312 }
313 }
314
315 std::sort(unorderedTemplateParameters.begin(), unorderedTemplateParameters.end(),
316 [](auto& a, auto& b) -> bool { return a.first <= b.first; });
317
318 ROS_DEBUG_STREAM("------------------");
319 ROS_DEBUG_STREAM("CREATING TYPE:" << t->getFullName());
320
321 for (auto& item : unorderedTemplateParameters)
322 {
323 ROS_DEBUG_STREAM(" - template parameter: " << item.second->getFullName());
324 t->templateParameters.push_back(item.second);
325 }
326 ROS_DEBUG_STREAM("------------------");
327 }
328
329 ROS_DEBUG_STREAM("ADDING TYPE TO DATABASE: " << inputtext);
330 ROS_DEBUG_STREAM("Current Database");
332 {
333 ROS_DEBUG_STREAM("- " << en.first);
334 }
335
337 return roottype;
338}
std::shared_ptr< TypeInfo > Ptr
static std::map< std::string, Ptr > typeInfoDatabase
std::string replace_back(std::string roottype, std::vector< std::pair< std::string, std::string > > &orderedtypesdict)
bool replace(std::string &str, const std::string &from, const std::string &to)