diff options
author | Johan Klokkhammer Helsing <johan.helsing@qt.io> | 2018-11-15 10:01:16 +0100 |
---|---|---|
committer | Johan Helsing <johan.helsing@qt.io> | 2018-11-21 12:18:00 +0000 |
commit | 6b077d6cdb6f1131de47574c617360f44a0625e7 (patch) | |
tree | 95f0343500451f577084a518d55b7996fa40604b | |
parent | 00ee14a9456a1d69d3e352ebe41b5f2cf019c166 (diff) |
qtwaylandscanner: Generate Resource::object without interface prefix
This allows writing template functions like this
template<typename return_type>
return_type *fromResource(struct ::wl_resource *resource) {
if (auto *r = return_type::Resource::fromResource(resource))
return static_cast<return_type *>(r->object());
return nullptr;
}
Letting us easily cast a wl_resource to a wrapper type, i.e.:
wl_resource *resource = ...
auto *surfacePrivate = fromResource<QWaylandSurfacePrivate>(resource);
This can hopefully let us reduce some boilerplate in the future.
Change-Id: I41630f35b3472baa39d88d89c1c6503cc0e6584a
Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
-rw-r--r-- | src/qtwaylandscanner/qtwaylandscanner.cpp | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/src/qtwaylandscanner/qtwaylandscanner.cpp b/src/qtwaylandscanner/qtwaylandscanner.cpp index bc0262bc0..91a6d6eef 100644 --- a/src/qtwaylandscanner/qtwaylandscanner.cpp +++ b/src/qtwaylandscanner/qtwaylandscanner.cpp @@ -504,6 +504,7 @@ bool Scanner::process() printf(" virtual ~Resource() {}\n"); printf("\n"); printf(" %s *%s_object;\n", interfaceName, interfaceNameStripped); + printf(" %s *object() { return %s_object; } \n", interfaceName, interfaceNameStripped); printf(" struct ::wl_resource *handle;\n"); printf("\n"); printf(" struct ::wl_client *client() const { return wl_resource_get_client(handle); }\n"); |