eclipse-zenoh / zenoh-cpp

C++ API for zenoh
Other
51 stars 31 forks source link

make keyexpr functions (join, concat, equals, insersect, etc) standalone #63

Closed milyin closed 1 year ago

milyin commented 1 year ago

Describe the feature

There are two key expresssion support classes in zenoh-cpp: KeyExpr and KeyExprView, which corresponds to zenoh-c z_keyexpr_t and z_owned_keyexpr_t structures.

Both these classes supports operatons like equals, join, etc. Currently these operations are implemented as methods. This leads to code duplication: all real functionality is implemented in KeyExprView, but to provide convenient API the KeyExpr repeats all these methods by just proxying them to it's KeyExprView representation.

Taking into account that each of these methods exists in two variants (with and without error code support), the amount of boilerplate code becomes too big. This also unnecessarily increases size of documentation.

Fix for issue https://github.com/eclipse-zenoh/zenoh-cpp/issues/20 adds even more duplicated code (variants of these functions with Session parameter).

I propose to remove these methods and replace them with standalone functions named keyexpr_equals, keyexpr_join, etc. These functions should accept const KeyExprView& type, so they will automatically accept KeyExpr, const char*, std::string_view.

It will be possible to write code like this:

if(keyexpr_includes("FOO/*", keyexpr)) {
...
}

instead of

if(KeyExprView("FOO/*").includes(keyexpr)) {
...
}

But more important that the code duplication between KeyExprView and KeyExpr will be removed

milyin commented 1 year ago

On second thought it's better to just add standalone funcitons without removing the methods. Closing the issue