Skip to content

[SUGGESTION] Question/Code Review Request: Simple implementation provider in cpp2 #604

@jazn

Description

@jazn

I started to play with cpp2 recently. I think this is great improvement in abstraction definition for C++.

I'm working on a simple rendering system and I would like to have the ability to select different implementations on different platforms.
I think that @interface is the way to go. I wonder what is the best way to select/initialize particular implementation. I use ImplementationProvider as a single point of change.

Here is a simplified example to show what I mean:

// defined in interface module
Surface: @interface type = {
    hello: (this);
}

SurfaceProvider: @interface type = {
    create_surface: (this) -> std::unique_ptr<Surface>;
}

// defined in implementation module
WVSurface: type = {
    this: Surface = ();
    hello: (this) = {
        std::cout << "Hello ." << std::endl;
    }
}
WVSurfaceProvider: type = {
    this: SurfaceProvider = ();
    create_surface: (this) -> std::unique_ptr<Surface> = {
        surf : std::unique_ptr<Surface>;
        surf = new<WVSurface>();
        return move(surf);
    }
}

// usage
main: () = {
    std::cout << "Begin." << std::endl;
    surf_prov: WVSurfaceProvider = (); // only this line need to be changed to select different implementation
    surf:_ = surf_prov.create_surface();
    surf*.hello();
}

What do you think about the code?
I'm open to suggestion about different ways to implement that function too.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions