customcanvas.C
gives an example of creating a custom subclass of
x::w::canvasObj::implObj
and two mixin templates:
struct fore_color_tag; class my_canvas_implObj : public x::w::scratch_and_mask_buffer_draw< x::w::background_color_elementObj<x::w::canvasObj::implObj, fore_color_tag>> { typedef x::w::scratch_and_mask_buffer_draw< x::w::background_color_elementObj<x::w::canvasObj::implObj, fore_color_tag>> superclass_t; // ... my_canvas_implObj( /* parameters */ ) : superclass_t{ /* parameters */ } // ...
LibCXXW's mixin templates follow this general design pattern:
The template defines a class that inherits from the class
specified by the first parameter. In this example,
my_canvas_implObj
inherits from
x::w::scratch_and_mask_buffer_draw
,
which inherits from
x::w::background_color_elementObj
,
which inherits from
x::w::canvasObj::implObj
.
Some mixin templates may have their own, specific, additional
template parameters. Their purpose depends on the mixin.
x::w::background_color_elementObj
has
an additional fore_color_tag
parameter in
this example.
Mixin template constructors have variadic parameters. Depending on the mixin template, its constructors' initial parameters apply to the mixin template itself, and the remaining constructor parameters get universally-forwarded to the superclass.
Some mixin templates do not need any constructor parameters. Those mixin templates directly delegate their constructor to their superclass.
The
x::w::scratch_and_mask_buffer_draw
template mixin's constructor requires one parameter.
x::w::background_color_elementObj
's
constructor requires one.
This means that my_canvas_implObj
passes the following parameters to its parent class:
Its immediate parent class is the
x::w::scratch_and_mask_buffer_draw
mixin. This mixin's constructor uses its first parameter
and forwards
the rest to its parent class.
Its parent class is the
x::w::background_color_elementObj
mixin, handling one color. Therefore,
its constructor uses its first parameter, and forwards
the rest to its parent class.
The remaining constructor parameters reach the
x::w::canvasObj::implObj
's constructor.