15#include <boost/algorithm/string.hpp>
17#include <boost/algorithm/string/find_iterator.hpp>
19#include <boost/algorithm/string/trim.hpp>
25namespace introspection
27bool replace(std::string& str,
const std::string& from,
const std::string& to)
29 size_t start_pos = str.find(from);
30 if (start_pos == std::string::npos)
32 str.replace(start_pos, from.length(), to);
36std::string
replace_back(std::string roottype, std::vector<std::pair<std::string, std::string>>& orderedtypesdict)
38 while (roottype.find(
"$") != std::string::npos)
40 for (
auto& t : orderedtypesdict)
43 auto& tval = t.second;
78 std::string originalinputtext = inputtext;
79 std::map<std::string, std::string> typesdict;
80 std::map<std::string, std::string> typesdict_content;
87 const char* simpletypeRE =
"[^\\<\\>,\\s]+\\<[^\\<\\>]+\\>";
92 std::regex regex(simpletypeRE);
95 std::regex_search(inputtext, matches, regex);
103 if (matches.size() == 0)
105 if (typesdict.size() == 0)
107 auto tkey =
"$T" + std::to_string(typecount);
108 typesdict[
tkey] = inputtext;
123 for (
auto& m : matches)
125 std::string tstr = m;
126 auto tkey =
"$T" + std::to_string(typecount);
132 typesdict[
tkey] = tstr;
150 std::vector<std::pair<std::string, std::string>> orderedTypedict;
151 for (
const auto& item : typesdict)
153 orderedTypedict.emplace_back(item);
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)); });
159 std::set<std::string> allbasetypes;
160 for (
auto& typeentry : orderedTypedict )
162 auto flat = typeentry.second;
165 size_t startindex = flat.find(
"<");
166 size_t endindex = flat.find(
">");
167 if (startindex != std::string::npos)
169 flat = flat.substr(startindex + 1,
170 endindex - startindex - 1);
173 typesdict_content[typeentry.first] = flat;
174 std::vector<std::string> localbasetypes;
176 std::istringstream iss(flat);
178 while (std::getline(iss, token,
','))
181 localbasetypes.push_back(token);
185 for (
auto& b : localbasetypes)
187 size_t found = b.find(
"$");
189 if (found == std::string::npos)
191 allbasetypes.insert(b);
200 for (
auto& b : allbasetypes)
214 for (
auto& b : allbasetypes)
216 orderedTypedict.push_back({ b, b });
220 std::vector<TypeInfo::Ptr> types;
221 std::vector<std::string> tokens;
223 for (
auto t : orderedTypedict)
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);
237 for (
auto& t : types)
240 if (t->finaltype == originalinputtext)
268 for (
size_t i = 0; i < types.size(); i++)
271 auto ttoken = tokens[i];
274 std::vector<std::pair<int, TypeInfo::Ptr>> unorderedTemplateParameters;
279 auto codedtypecopy = typesdict_content[ttoken];
294 for (
auto& t2 : types)
303 auto index = codedtypecopy.find(t2->tkey);
304 if (index != std::string::npos)
306 auto pair = std::make_pair(index, t2);
309 unorderedTemplateParameters.push_back(pair);
310 replace(codedtypecopy, t2->tkey,
"");
315 std::sort(unorderedTemplateParameters.begin(), unorderedTemplateParameters.end(),
316 [](
auto& a,
auto& b) ->
bool { return a.first <= b.first; });
318 ROS_DEBUG_STREAM(
"------------------");
319 ROS_DEBUG_STREAM(
"CREATING TYPE:" << t->getFullName());
321 for (
auto& item : unorderedTemplateParameters)
323 ROS_DEBUG_STREAM(
" - template parameter: " << item.second->getFullName());
324 t->templateParameters.push_back(item.second);
326 ROS_DEBUG_STREAM(
"------------------");
329 ROS_DEBUG_STREAM(
"ADDING TYPE TO DATABASE: " << inputtext);
330 ROS_DEBUG_STREAM(
"Current Database");
333 ROS_DEBUG_STREAM(
"- " << en.first);
static TypeInfo::Ptr getTypeInfoFromString(std::string inputtext)
std::shared_ptr< TypeInfo > Ptr
static std::map< std::string, Ptr > typeInfoDatabase
static TypeInfo::Ptr getFromStdTypeInfo(const std::type_info &tid)
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)
std::string demangleSymbol()