82{
84
86
87 bool ok = false;
88 int typecount = 0;
89 std::string originalinputtext = inputtext;
90 std::map<std::string, std::string> typesdict;
91 std::map<std::string, std::string> typesdict_content;
92
93
94
95
96 while (!ok)
97 {
98
99
100
101 const char * simpletypeRE = "[^\\<\\>,\\s]+\\<[^\\<\\>]+\\>";
102
103
104
105 std::smatch matches;
106 std::regex regex(simpletypeRE);
107
108 std::regex_search(inputtext, matches, regex);
109
110
111 if (matches.size() == 0)
112 {
113 if (typesdict.size() == 0)
114 {
115 auto tkey =
"$T" + std::to_string(typecount);
116 typesdict[
tkey] = inputtext;
117 }
118 break;
119 }
120 else
121 {
122
123 int i = 0;
124 for (auto & m : matches)
125 {
126 std::string tstr = m;
127 auto tkey =
"$T" + std::to_string(typecount);
129
130 typecount++;
131 typesdict[
tkey] = tstr;
132
133 i++;
134 }
135 }
136 }
137
138
139 std::vector<std::pair<std::string, std::string>> orderedTypedict;
140 for (const auto & item : typesdict)
141 {
142 orderedTypedict.emplace_back(item);
143 }
144
145 std::sort(
146 orderedTypedict.begin(), orderedTypedict.end(),
147 [](auto & a, auto & b) { return std::stoi(a.first.substr(2)) > std::stoi(b.first.substr(2)); });
148
149
150 std::set<std::string> allbasetypes;
151 for (auto & typeentry : orderedTypedict )
152 {
153 auto flat = typeentry.second;
154
155 size_t startindex = flat.find("<");
156 size_t endindex = flat.find(">");
157 if (startindex != std::string::npos)
158 {
159 flat = flat.substr(
160 startindex + 1,
161 endindex - startindex - 1);
162
163 typesdict_content[typeentry.first] = flat;
164 std::vector<std::string> localbasetypes;
165
166 std::istringstream iss(flat);
167 std::string token;
168 while (std::getline(iss, token, ','))
169 {
170 boost::trim(token);
171 localbasetypes.push_back(token);
172 }
173
174 for (auto & b : localbasetypes)
175 {
176 size_t found = b.find("$");
177
178 if (found == std::string::npos)
179 {
180 allbasetypes.insert(b);
181 }
182 }
183 }
184
185
186
187
188
189 for (auto & b : allbasetypes)
190 {
191 typesdict[b] = b;
192 }
193 }
194
195
196
197
198
199
200
201
202
203 for (auto & b : allbasetypes)
204 {
205 orderedTypedict.push_back({b, b});
206 }
207
208
209 std::vector<TypeInfo::Ptr> types;
210 std::vector<std::string> tokens;
211
212 for (auto t : orderedTypedict)
213 {
214
215 auto &
tkey = t.first;
216 auto & tval = t.second;
218 auto tinfo = std::make_shared<TypeInfo>(
tkey, tval,
finaltype);
219 types.push_back(tinfo);
220 tokens.push_back(
tkey);
221
222
223 }
224
225
227 for (auto & t : types)
228 {
229
230 if (t->finaltype == originalinputtext)
231 {
232 roottype = t;
233 break;
234 }
235 }
236
237 if (roottype ==
nullptr &&
globalNh_ !=
nullptr)
238 {
239 std::stringstream ss;
240 ss << "---------------" << std::endl;
241 ss << "TYPE STRING WALKER, type was not properly interpreted: " << std::endl
242 << " - " << inputtext.c_str() << std::endl
243 << " - " << originalinputtext << std::endl;
244
245 auto strmsg = ss.str();
246 RCLCPP_WARN_STREAM(
globalNh_->get_logger(), strmsg);
247 }
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271 for (size_t i = 0; i < types.size(); i++)
272 {
273 auto t = types[i];
274 auto ttoken = tokens[i];
275
276
277 std::vector<std::pair<int, TypeInfo::Ptr>> unorderedTemplateParameters;
278
279
280
281
282 auto codedtypecopy = typesdict_content[ttoken];
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297 for (auto & t2 : types)
298
299 {
300
301
302
303 if (t == t2) continue;
304
305 auto index = codedtypecopy.find(t2->tkey);
306 if (index != std::string::npos)
307 {
308 auto pair = std::make_pair(index, t2);
309
310
311 unorderedTemplateParameters.push_back(pair);
312 replace(codedtypecopy, t2->tkey,
"");
313
314 }
315 }
316
317 std::sort(
318 unorderedTemplateParameters.begin(), unorderedTemplateParameters.end(),
319 [](auto & a, auto & b) -> bool { return a.first <= b.first; });
320
321
322
323
324 for (auto & item : unorderedTemplateParameters)
325 {
326
327 t->templateParameters.push_back(item.second);
328 }
329
330 }
331
332
333
335 {
336 if (
globalNh_ !=
nullptr) RCLCPP_DEBUG_STREAM(
globalNh_->get_logger(),
"- " << en.first);
337 }
338
340
341 if (roottype ==
nullptr &&
globalNh_ !=
nullptr)
342 {
343 std::stringstream ss;
344 ss << "---------------" << std::endl;
345 ss << "TYPE STRING WALKER, type was not properly interpreted: " << std::endl
346 << " - " << inputtext.c_str() << std::endl
347 << " - " << originalinputtext << std::endl;
348
349 ss << "---- current type (ordered types)" << std::endl;
350
351 for (auto & en : orderedTypedict)
352 {
353 ss << "- " << en.first << ": " << en.second << std::endl;
354 }
355 ss << "---------------" << std::endl;
356
357 ss << "------current type types --------" << std::endl;
358
359 for (auto & t : types)
360 {
361 ss << t->finaltype << std::endl;
362 }
363
364 ss << "----total typeinfo database" << std::endl;
365
367 {
368 ss << "- " << en.first << ": " << en.second << std::endl;
369 }
370
371 auto strmsg = ss.str();
372 RCLCPP_WARN_STREAM(
globalNh_->get_logger(), strmsg);
373 }
374
375 return roottype;
376}
std::shared_ptr< TypeInfo > Ptr
static std::map< std::string, Ptr > typeInfoDatabase
rclcpp::Node::SharedPtr globalNh_
bool replace(std::string &str, const std::string &from, const std::string &to)
std::string replace_back(std::string roottype, std::vector< std::pair< std::string, std::string > > &orderedtypesdict)