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>
This commit is contained in:
Johan Klokkhammer Helsing 2018-11-15 10:01:16 +01:00 committed by Johan Helsing
parent e4c13a174a
commit a544de1bc0

View File

@ -504,6 +504,7 @@ bool Scanner::process()
printf(" virtual ~Resource() {}\n"); printf(" virtual ~Resource() {}\n");
printf("\n"); printf("\n");
printf(" %s *%s_object;\n", interfaceName, interfaceNameStripped); printf(" %s *%s_object;\n", interfaceName, interfaceNameStripped);
printf(" %s *object() { return %s_object; } \n", interfaceName, interfaceNameStripped);
printf(" struct ::wl_resource *handle;\n"); printf(" struct ::wl_resource *handle;\n");
printf("\n"); printf("\n");
printf(" struct ::wl_client *client() const { return wl_resource_get_client(handle); }\n"); printf(" struct ::wl_client *client() const { return wl_resource_get_client(handle); }\n");