From 1acb71b216dfbd6d2a2ac38ab7721a38a9e28b50 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Fri, 17 Nov 2017 16:46:59 +0000 Subject: [PATCH] Add a colored mixin so we can talk about multiple inheritance --- .../src/{eo_inherit.h => eo_multiinherit.h} | 1 + ..._inherit_main.c => eo_multiinherit_main.c} | 70 +++++++++++-------- .../c/eo-multiinherit/src/example_circle.c | 2 +- .../c/eo-multiinherit/src/example_colored.c | 33 +++++++++ .../c/eo-multiinherit/src/example_colored.eo | 18 +++++ .../c/eo-multiinherit/src/example_rectangle.c | 2 +- .../eo-multiinherit/src/example_rectangle.eo | 2 +- .../c/eo-multiinherit/src/example_shape.c | 2 +- .../c/eo-multiinherit/src/example_square.c | 2 +- tutorial/c/eo-multiinherit/src/meson.build | 7 +- 10 files changed, 101 insertions(+), 38 deletions(-) rename tutorial/c/eo-multiinherit/src/{eo_inherit.h => eo_multiinherit.h} (90%) rename tutorial/c/eo-multiinherit/src/{eo_inherit_main.c => eo_multiinherit_main.c} (79%) create mode 100644 tutorial/c/eo-multiinherit/src/example_colored.c create mode 100644 tutorial/c/eo-multiinherit/src/example_colored.eo diff --git a/tutorial/c/eo-multiinherit/src/eo_inherit.h b/tutorial/c/eo-multiinherit/src/eo_multiinherit.h similarity index 90% rename from tutorial/c/eo-multiinherit/src/eo_inherit.h rename to tutorial/c/eo-multiinherit/src/eo_multiinherit.h index 4c9fe633..04d05452 100644 --- a/tutorial/c/eo-multiinherit/src/eo_inherit.h +++ b/tutorial/c/eo-multiinherit/src/eo_multiinherit.h @@ -10,6 +10,7 @@ #include #include "example_shape.eo.h" +#include "example_colored.eo.h" #include "example_rectangle.eo.h" #include "example_square.eo.h" #include "example_circle.eo.h" diff --git a/tutorial/c/eo-multiinherit/src/eo_inherit_main.c b/tutorial/c/eo-multiinherit/src/eo_multiinherit_main.c similarity index 79% rename from tutorial/c/eo-multiinherit/src/eo_inherit_main.c rename to tutorial/c/eo-multiinherit/src/eo_multiinherit_main.c index eb6091fc..ccb65f7a 100644 --- a/tutorial/c/eo-multiinherit/src/eo_inherit_main.c +++ b/tutorial/c/eo-multiinherit/src/eo_multiinherit_main.c @@ -1,29 +1,4 @@ -#include "eo_inherit.h" - -Example_Shape * -_rectangle_create() -{ - Example_Rectangle *rectangle; - - rectangle = efl_add(EXAMPLE_RECTANGLE_CLASS, NULL, - efl_name_set(efl_added, "Rectangle"), - example_rectangle_width_set(efl_added, 5), - example_rectangle_height_set(efl_added, 10)); - - return rectangle; -} - -Example_Shape * -_square_create() -{ - Example_Square *square; - - square = efl_add(EXAMPLE_SQUARE_CLASS, NULL, - efl_name_set(efl_added, "Square"), - example_rectangle_width_set(efl_added, 7)); - - return square; -} +#include "eo_multiinherit.h" Example_Shape * _circle_create() @@ -37,10 +12,45 @@ _circle_create() return circle; } +Example_Shape * +_rectangle_create() +{ + Example_Rectangle *rectangle; + + rectangle = efl_add(EXAMPLE_RECTANGLE_CLASS, NULL, + efl_name_set(efl_added, "Rectangle"), + example_rectangle_width_set(efl_added, 5), + example_rectangle_height_set(efl_added, 10)); + + example_colored_color_set(rectangle, 255, 0, 0); + return rectangle; +} + +Example_Shape * +_square_create() +{ + Example_Square *square; + + square = efl_add(EXAMPLE_SQUARE_CLASS, NULL, + efl_name_set(efl_added, "Square"), + example_rectangle_width_set(efl_added, 7)); + + example_colored_color_set(square, 64, 64, 64); + return square; +} + void _shape_print(Example_Shape *shape) { printf("Shape named %s has area %d\n", efl_name_get(shape), example_shape_area(shape)); + + if (efl_isa(shape, EXAMPLE_COLORED_MIXIN)) + { + int red, green, blue; + + example_colored_color_get(shape, &red, &green, &blue); + printf(" Colored %d, %d, %d\n", red, green, blue); + } } EAPI_MAIN void @@ -48,6 +58,10 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED) { Eo *shape; + shape = _circle_create(); + _shape_print(shape); + efl_unref(shape); + shape = _rectangle_create(); _shape_print(shape); efl_unref(shape); @@ -56,10 +70,6 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED) _shape_print(shape); efl_unref(shape); - shape = _circle_create(); - _shape_print(shape); - efl_unref(shape); - efl_exit(0); } EFL_MAIN() diff --git a/tutorial/c/eo-multiinherit/src/example_circle.c b/tutorial/c/eo-multiinherit/src/example_circle.c index 2051a809..74541fb2 100644 --- a/tutorial/c/eo-multiinherit/src/example_circle.c +++ b/tutorial/c/eo-multiinherit/src/example_circle.c @@ -2,7 +2,7 @@ #include #include "example_circle.eo.h" -#include "eo_inherit.h" +#include "eo_multiinherit.h" typedef struct { diff --git a/tutorial/c/eo-multiinherit/src/example_colored.c b/tutorial/c/eo-multiinherit/src/example_colored.c new file mode 100644 index 00000000..49d08149 --- /dev/null +++ b/tutorial/c/eo-multiinherit/src/example_colored.c @@ -0,0 +1,33 @@ +#define EFL_BETA_API_SUPPORT +#include +#include "example_colored.eo.h" + +#include "eo_multiinherit.h" + +typedef struct +{ + int red, green, blue; +} Example_Colored_Data; + +EOLIAN static void +_example_colored_color_set(Eo *obj EINA_UNUSED, Example_Colored_Data *pd, + int red, int green, int blue) +{ + pd->red = red; + pd->green = green; + pd->blue = blue; +} + +EOLIAN static void +_example_colored_color_get(Eo *obj EINA_UNUSED, Example_Colored_Data *pd, + int *red, int *green, int *blue) +{ + if (red) + *red = pd->red; + if (green) + *green = pd->green; + if (blue) + *blue = pd->blue; +} + +#include "example_colored.eo.c" diff --git a/tutorial/c/eo-multiinherit/src/example_colored.eo b/tutorial/c/eo-multiinherit/src/example_colored.eo new file mode 100644 index 00000000..80fa8de0 --- /dev/null +++ b/tutorial/c/eo-multiinherit/src/example_colored.eo @@ -0,0 +1,18 @@ +mixin Example.Colored { + [[A mixin for providing APIs for managing colour properties]] + methods { + @property color { + [[The colour to associate with the class we are coloring. + We use RGB to manage the colour, so have 3 in and out parameters.]] + get { + } + set { + } + values { + red: int; [[The red colour channel]] + green: int; [[The green colour channel]] + blue: int; [[The blue colour channel]] + } + } + } +} diff --git a/tutorial/c/eo-multiinherit/src/example_rectangle.c b/tutorial/c/eo-multiinherit/src/example_rectangle.c index f2128bd1..3062f90b 100644 --- a/tutorial/c/eo-multiinherit/src/example_rectangle.c +++ b/tutorial/c/eo-multiinherit/src/example_rectangle.c @@ -2,7 +2,7 @@ #include #include "example_rectangle.eo.h" -#include "eo_inherit.h" +#include "eo_multiinherit.h" typedef struct { diff --git a/tutorial/c/eo-multiinherit/src/example_rectangle.eo b/tutorial/c/eo-multiinherit/src/example_rectangle.eo index 957f09b4..82cdc84e 100644 --- a/tutorial/c/eo-multiinherit/src/example_rectangle.eo +++ b/tutorial/c/eo-multiinherit/src/example_rectangle.eo @@ -1,4 +1,4 @@ -class Example.Rectangle (Efl.Object, Example.Shape) { +class Example.Rectangle (Efl.Object, Example.Shape, Example.Colored) { [[A rectangle shape object]] methods { @property width { diff --git a/tutorial/c/eo-multiinherit/src/example_shape.c b/tutorial/c/eo-multiinherit/src/example_shape.c index 1fc8dd00..5fa2226f 100644 --- a/tutorial/c/eo-multiinherit/src/example_shape.c +++ b/tutorial/c/eo-multiinherit/src/example_shape.c @@ -2,6 +2,6 @@ #include #include "example_shape.eo.h" -#include "eo_inherit.h" +#include "eo_multiinherit.h" #include "example_shape.eo.c" diff --git a/tutorial/c/eo-multiinherit/src/example_square.c b/tutorial/c/eo-multiinherit/src/example_square.c index 8ebb6969..da5120f7 100644 --- a/tutorial/c/eo-multiinherit/src/example_square.c +++ b/tutorial/c/eo-multiinherit/src/example_square.c @@ -2,7 +2,7 @@ #include #include "example_square.eo.h" -#include "eo_inherit.h" +#include "eo_multiinherit.h" typedef struct { diff --git a/tutorial/c/eo-multiinherit/src/meson.build b/tutorial/c/eo-multiinherit/src/meson.build index 26fffb7e..23cf36be 100644 --- a/tutorial/c/eo-multiinherit/src/meson.build +++ b/tutorial/c/eo-multiinherit/src/meson.build @@ -1,6 +1,7 @@ eolian_gen = find_program('eolian_gen') -eo_src = ['example_shape', 'example_rectangle', 'example_square', 'example_circle'] +eo_src = ['example_shape', 'example_colored', 'example_rectangle', + 'example_square', 'example_circle'] eo_csrc = [] eo_gen = [] @@ -19,8 +20,8 @@ foreach eo : eo_src endforeach src = files([ - 'eo_inherit.h', - 'eo_inherit_main.c', + 'eo_multiinherit.h', + 'eo_multiinherit_main.c', ]) deps = [eina, efl]