/** * Inspired by: http://dbus-cplusplus.sourceforge.net/ */ #include #include #include #include "generator_utils.h" std::string underscorize(const std::string& str) { std::string res = str; for (unsigned int i = 0; i < res.length(); ++i) { if (!isalpha(res[i]) && !isdigit(res[i])) { res[i] = '_'; } } return res; } std::string stub_name(const std::string& name) { return "_" + underscorize(name) + "_stub"; } const char *atomic_type_to_string(char t) { static std::map atos { { 'y', "uint8_t" }, { 'b', "bool" }, { 'n', "int16_t" }, { 'q', "uint16_t" }, { 'i', "int32_t" }, { 'u', "uint32_t" }, { 'x', "int64_t" }, { 't', "uint64_t" }, { 'd', "double" }, { 's', "std::string" }, { 'o', "sdbus::ObjectPath" }, { 'g', "sdbus::Signature" }, { 'v', "sdbus::Variant" }, { 'h', "sdbus::UnixFd" }, { '\0', "" } }; if (atos.count(t)) { return atos[t]; } return nullptr; } static void _parse_signature(const std::string &signature, std::string &type, unsigned int &i, bool only_once = false) { for (; i < signature.length(); ++i) { switch (signature[i]) { case 'a': { switch (signature[++i]) { case '{': { type += "std::map<"; ++i; _parse_signature(signature, type, i); type += ">"; break; } case '(': { type += "std::vector