sanitize_typename.cpp
Go to the documentation of this file.
1 #include "sanitize_typename.h"
2 
3 #include <sstream>
4 
5 #include <SimoxUtility/algorithm/string.h>
6 
7 #include <RobotAPI/libraries/armem/aron/MemoryID.aron.generated.h>
8 
9 
11  armarx::armem::arondto::MemoryID::ToAronType()->getFullName();
13 
14 namespace
15 {
16  std::string
17  remove_wrap(const std::string& string, const std::string& prefix, const std::string& suffix)
18  {
19  if (simox::alg::starts_with(string, prefix) && simox::alg::ends_with(string, suffix))
20  {
21  return string.substr(prefix.size(), string.size() - prefix.size() - suffix.size());
22  }
23  else
24  {
25  return string;
26  }
27  }
28 } // namespace
29 
30 std::string
32 {
33  if (typeName == rawMemoryIDTypeName)
34  {
36  }
37 
38  namespace s = simox::alg;
39  std::string n = typeName;
40  n = s::replace_all(n, "armarx::aron::type::", "");
41  n = s::replace_all(n, "armarx::aron::data::", "");
42 
43  if (s::starts_with(n, "Object<"))
44  {
45  n = remove_wrap(n, "Object<", ">");
46  const std::string del = "::"; // remove namespace
47  size_t find = n.rfind(del);
48  if (find != n.npos)
49  {
50  find += del.size(); // include del
51  std::stringstream ss;
52  ss << n.substr(find) << " (" << n.substr(0, find - del.size()) << ")";
53  n = ss.str();
54  }
55  }
56  else
57  {
58  if (s::contains(n, "<")) // another containertype
59  {
60  std::string container = n.substr(0, n.find("<"));
61  std::string subtype = remove_wrap(n, (container + "<"), ">");
63  n = n.substr(0, n.find("<") + 1) + subtype + ">";
64  }
65  }
66 
67  return n;
68 }
sanitize_typename.h
armarx::armem::gui::instance::sanitizeTypeName
std::string sanitizeTypeName(const std::string &typeName)
Definition: sanitize_typename.cpp:31
simox::alg
Definition: Impl.cpp:40
magic_enum::detail::subtype
constexpr enum_subtype subtype(std::true_type) noexcept
Definition: magic_enum.hpp:749
magic_enum::detail::n
constexpr auto n() noexcept
Definition: magic_enum.hpp:418
armarx::starts_with
bool starts_with(const std::string &haystack, const std::string &needle)
Definition: StringHelpers.cpp:47
armarx::armem::contains
bool contains(const MemoryID &general, const MemoryID &specific)
Indicates whether general is "less specific" than, or equal to, specific, i.e.
Definition: MemoryID.cpp:563
armarx::armem::gui::instance::rawMemoryIDTypeName
const std::string rawMemoryIDTypeName
Definition: sanitize_typename.cpp:10
magic_enum::detail::find
constexpr std::size_t find(string_view str, char_type c) noexcept
Definition: magic_enum.hpp:309
armarx::ends_with
bool ends_with(const std::string &haystack, const std::string &needle)
Definition: StringHelpers.cpp:53
armarx::armem::gui::instance::sanitizedMemoryIDTypeName
const std::string sanitizedMemoryIDTypeName
Definition: sanitize_typename.cpp:12
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33