blob: e55005521bb8bc10db88fd37c9cd0e6c2c3d423f [file] [log] [blame]
This directory provides extensions of platform APIs that PlatformWindow
implementations can use to add support for more advanced APIs their
platform provides.
The sole intent of the extensions is to avoid casting from a PlatfromWindow
to the extensions and avoid polluting the PlatformWindow APIs with
unrelated methods.
In order to let clients to access APIs of the extensions that an
implementation of a PlatformWindow may have, one must set the
extension as a property of the PlatformWindow. Then, the client can
access the extension by providing the pointer to the PlatformWindow
to corresponding GetMyExtension() global method that will check
the properties of the PlatformWindow and return a pointer to the
extension if such a property exists.
For example,
class MyExtension {
virtual void MyExtensionMethod1() = 0;
virtual void MyExtensionMethod2() = 0;
virtual ~MyExtension();
void SetMyExtension(PlatformWindow* window, MyExtension* extension);
MyExtensions::~MyExtension() = default;
void MyExtension::SetMyExtension(PlatformWindow* window, MyExtension* extension) {
window->SetProperty(kMyExtensionKey, extension);
MyExtension* GetMyExtension(const PlatformWindow& window) {
return window.GetProperty(kMyExtensionKey);
class MyWindow : public PlatformWindow,
public MyExtension {
MyWindow() {
// Sets the MyExtension property of the PlatformWindow.
// Cast to MyExtension for a better readibility.
SetMyExtension(this, static_cast<MyExtension*>(this));
// PlatformWindow overrides:
void Method1() override {}
void Method2() override {}
// MyExtension overrides:
void MyExtensionMethod1() override {}
void MyExtensionMethod2() override {}
class Client {
void CreatePlatformWindow() {
auto window = std::make_unique<MyWindow>();
auto* extension = GetMyExtension(*window.get());