refactor: enable compile-time D-Bus signature generation (#425)

Since sdbus-c++ knows types of D-Bus call/signal/property input/output parameters at compile time, why not assemble the D-Bus signature strings at compile time, too, instead of assembling them at run time as std::string with likely cost of (unnecessary) heap allocations...

std::array is well supported constexpr type in C++20, so we harness it to build the D-Bus signature string and store it into the binary at compile time.
This commit is contained in:
Stanislav Angelovič
2024-04-24 20:20:29 +02:00
parent 32a97f214f
commit d856969051
9 changed files with 294 additions and 319 deletions
+2 -2
View File
@@ -51,7 +51,7 @@ namespace sdbus {
template <typename _ElementType>
sdbus::Message& operator<<(sdbus::Message& msg, const std::list<_ElementType>& items)
{
msg.openContainer(sdbus::signature_of<_ElementType>::str());
msg.openContainer<_ElementType>();
for (const auto& item : items)
msg << item;
@@ -64,7 +64,7 @@ namespace sdbus {
template <typename _ElementType>
sdbus::Message& operator>>(sdbus::Message& msg, std::list<_ElementType>& items)
{
if(!msg.enterContainer(sdbus::signature_of<_ElementType>::str()))
if(!msg.enterContainer<_ElementType>())
return msg;
while (true)