-
Notifications
You must be signed in to change notification settings - Fork 265
Closed
Labels
Description
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.