forked from Kistler-Group/sdbus-cpp
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:
@@ -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)
|
||||
|
||||
@@ -170,7 +170,8 @@ namespace
|
||||
|
||||
TYPED_TEST(Type2DBusTypeSignatureConversion, ConvertsTypeToProperDBusSignature)
|
||||
{
|
||||
ASSERT_THAT(sdbus::signature_of<TypeParam>::str(), Eq(this->dbusTypeSignature_));
|
||||
constexpr auto signature = sdbus::as_null_terminated(sdbus::signature_of_v<TypeParam>);
|
||||
ASSERT_THAT(signature.data(), Eq(this->dbusTypeSignature_));
|
||||
}
|
||||
|
||||
TEST(FreeFunctionTypeTraits, DetectsTraitsOfTrivialSignatureFunction)
|
||||
|
||||
Reference in New Issue
Block a user