ajwillia-ms pushed a commit to branch master. http://git.enlightenment.org/tools/examples.git/commit/?id=6e78b6caa3358ec953906de807cd6a5196639299
commit 6e78b6caa3358ec953906de807cd6a5196639299 Author: Andy Williams <a...@andywilliams.me> Date: Fri Nov 17 15:37:35 2017 +0000 eo-multiinherit: Clone from eo-inherit before interface removal Mixins still to come --- tutorial/c/eo-multiinherit/meson.build | 13 +++++ tutorial/c/eo-multiinherit/src/eo_inherit.h | 17 ++++++ tutorial/c/eo-multiinherit/src/eo_inherit_main.c | 66 ++++++++++++++++++++++ tutorial/c/eo-multiinherit/src/example_circle.c | 30 ++++++++++ tutorial/c/eo-multiinherit/src/example_circle.eo | 18 ++++++ tutorial/c/eo-multiinherit/src/example_rectangle.c | 42 ++++++++++++++ .../c/eo-multiinherit/src/example_rectangle.eo | 28 +++++++++ tutorial/c/eo-multiinherit/src/example_shape.c | 7 +++ tutorial/c/eo-multiinherit/src/example_shape.eo | 11 ++++ tutorial/c/eo-multiinherit/src/example_square.c | 26 +++++++++ tutorial/c/eo-multiinherit/src/example_square.eo | 7 +++ tutorial/c/eo-multiinherit/src/meson.build | 33 +++++++++++ 12 files changed, 298 insertions(+) diff --git a/tutorial/c/eo-multiinherit/meson.build b/tutorial/c/eo-multiinherit/meson.build new file mode 100644 index 0000000..3aff71b --- /dev/null +++ b/tutorial/c/eo-multiinherit/meson.build @@ -0,0 +1,13 @@ +project( + 'efl-example-eo-multiinherit', 'c', + version : '0.0.1', + default_options: [ 'c_std=gnu99', 'warning_level=2' ], + meson_version : '>= 0.38.0') + +eina = dependency('eina', version : '>=1.20.99') +efl = dependency('efl-core', version : '>=1.20.99') +dependency('eolian', version : '>=1.20.99') + +inc = include_directories('.') +subdir('src') + diff --git a/tutorial/c/eo-multiinherit/src/eo_inherit.h b/tutorial/c/eo-multiinherit/src/eo_inherit.h new file mode 100644 index 0000000..4c9fe63 --- /dev/null +++ b/tutorial/c/eo-multiinherit/src/eo_inherit.h @@ -0,0 +1,17 @@ +#ifndef _EO_CLASSES_H +#define _EO_CLASSES_H 1 + +#define EFL_EO_API_SUPPORT 1 +#ifndef EFL_BETA_API_SUPPORT +#define EFL_BETA_API_SUPPORT 1 +#endif + +#include <Eina.h> +#include <Efl_Core.h> + +#include "example_shape.eo.h" +#include "example_rectangle.eo.h" +#include "example_square.eo.h" +#include "example_circle.eo.h" + +#endif diff --git a/tutorial/c/eo-multiinherit/src/eo_inherit_main.c b/tutorial/c/eo-multiinherit/src/eo_inherit_main.c new file mode 100644 index 0000000..eb6091f --- /dev/null +++ b/tutorial/c/eo-multiinherit/src/eo_inherit_main.c @@ -0,0 +1,66 @@ +#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; +} + +Example_Shape * +_circle_create() +{ + Example_Circle *circle; + + circle = efl_add(EXAMPLE_CIRCLE_CLASS, NULL, + efl_name_set(efl_added, "Circle"), + example_circle_radius_set(efl_added, 5)); + + return circle; +} + +void +_shape_print(Example_Shape *shape) +{ + printf("Shape named %s has area %d\n", efl_name_get(shape), example_shape_area(shape)); +} + +EAPI_MAIN void +efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED) +{ + Eo *shape; + + shape = _rectangle_create(); + _shape_print(shape); + efl_unref(shape); + + shape = _square_create(); + _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 new file mode 100644 index 0000000..2051a80 --- /dev/null +++ b/tutorial/c/eo-multiinherit/src/example_circle.c @@ -0,0 +1,30 @@ +#define EFL_BETA_API_SUPPORT +#include <Eo.h> +#include "example_circle.eo.h" + +#include "eo_inherit.h" + +typedef struct +{ + int radius; +} Example_Circle_Data; + +EOLIAN static void +_example_circle_radius_set(Eo *obj EINA_UNUSED, Example_Circle_Data *pd, int radius) +{ + pd->radius = radius; +} + +EOLIAN static int +_example_circle_radius_get(Eo *obj EINA_UNUSED , Example_Circle_Data *pd) +{ + return pd->radius; +} + +EOLIAN static int +_example_circle_example_shape_area(Eo *obj EINA_UNUSED, Example_Circle_Data *pd) +{ + return (int)(pd->radius * pd->radius * 3.14159f); +} + +#include "example_circle.eo.c" diff --git a/tutorial/c/eo-multiinherit/src/example_circle.eo b/tutorial/c/eo-multiinherit/src/example_circle.eo new file mode 100644 index 0000000..6a91fac --- /dev/null +++ b/tutorial/c/eo-multiinherit/src/example_circle.eo @@ -0,0 +1,18 @@ +class Example.Circle (Efl.Object, Example.Shape) { + [[A circle shape object]] + methods { + @property radius { + [[The radius of this circle]] + set { + } + get { + } + values { + radius: int; + } + } + } + implements { + Example.Shape.area; + } +} diff --git a/tutorial/c/eo-multiinherit/src/example_rectangle.c b/tutorial/c/eo-multiinherit/src/example_rectangle.c new file mode 100644 index 0000000..f2128bd --- /dev/null +++ b/tutorial/c/eo-multiinherit/src/example_rectangle.c @@ -0,0 +1,42 @@ +#define EFL_BETA_API_SUPPORT +#include <Eo.h> +#include "example_rectangle.eo.h" + +#include "eo_inherit.h" + +typedef struct +{ + int width, height; +} Example_Rectangle_Data; + +EOLIAN static void +_example_rectangle_width_set(Eo *obj EINA_UNUSED, Example_Rectangle_Data *pd, int width) +{ + pd->width = width; +} + +EOLIAN static int +_example_rectangle_width_get(Eo *obj EINA_UNUSED, Example_Rectangle_Data *pd) +{ + return pd->width; +} + +EOLIAN static void +_example_rectangle_height_set(Eo *obj EINA_UNUSED, Example_Rectangle_Data *pd, int height) +{ + pd->height = height; +} + +EOLIAN static int +_example_rectangle_height_get(Eo *obj EINA_UNUSED, Example_Rectangle_Data *pd) +{ + return pd->height; +} + +EOLIAN static int +_example_rectangle_example_shape_area(Eo *obj EINA_UNUSED, Example_Rectangle_Data *pd) +{ + return pd->width * pd->height; +} + +#include "example_rectangle.eo.c" diff --git a/tutorial/c/eo-multiinherit/src/example_rectangle.eo b/tutorial/c/eo-multiinherit/src/example_rectangle.eo new file mode 100644 index 0000000..957f09b --- /dev/null +++ b/tutorial/c/eo-multiinherit/src/example_rectangle.eo @@ -0,0 +1,28 @@ +class Example.Rectangle (Efl.Object, Example.Shape) { + [[A rectangle shape object]] + methods { + @property width { + [[The width of this rectangle]] + set { + } + get { + } + values { + width: int; [[Rectangle width]] + } + } + @property height { + [[The height of this rectangle]] + set { + } + get { + } + values { + height: int; [[Rectangle height]] + } + } + } + implements { + Example.Shape.area; + } +} diff --git a/tutorial/c/eo-multiinherit/src/example_shape.c b/tutorial/c/eo-multiinherit/src/example_shape.c new file mode 100644 index 0000000..1fc8dd0 --- /dev/null +++ b/tutorial/c/eo-multiinherit/src/example_shape.c @@ -0,0 +1,7 @@ +#define EFL_BETA_API_SUPPORT +#include <Eo.h> +#include "example_shape.eo.h" + +#include "eo_inherit.h" + +#include "example_shape.eo.c" diff --git a/tutorial/c/eo-multiinherit/src/example_shape.eo b/tutorial/c/eo-multiinherit/src/example_shape.eo new file mode 100644 index 0000000..d2ee74d --- /dev/null +++ b/tutorial/c/eo-multiinherit/src/example_shape.eo @@ -0,0 +1,11 @@ +interface Example.Shape { + [[A generic shape object]] + methods { + area { + [[Calculate the area of the shape.]] + params { + } + return: int; + } + } +} diff --git a/tutorial/c/eo-multiinherit/src/example_square.c b/tutorial/c/eo-multiinherit/src/example_square.c new file mode 100644 index 0000000..8ebb696 --- /dev/null +++ b/tutorial/c/eo-multiinherit/src/example_square.c @@ -0,0 +1,26 @@ +#define EFL_BETA_API_SUPPORT +#include <Eo.h> +#include "example_square.eo.h" + +#include "eo_inherit.h" + +typedef struct +{ + +} Example_Square_Data; + +EOLIAN static void +_example_square_example_rectangle_width_set(Eo *obj, Example_Square_Data *pd EINA_UNUSED, int width) +{ + example_rectangle_width_set(efl_super(obj, EXAMPLE_SQUARE_CLASS), width); + example_rectangle_height_set(efl_super(obj, EXAMPLE_SQUARE_CLASS), width); +} + +EOLIAN static void +_example_square_example_rectangle_height_set(Eo *obj, Example_Square_Data *pd EINA_UNUSED, int height) +{ + example_rectangle_width_set(efl_super(obj, EXAMPLE_SQUARE_CLASS), height); + example_rectangle_height_set(efl_super(obj, EXAMPLE_SQUARE_CLASS), height); +} + +#include "example_square.eo.c" diff --git a/tutorial/c/eo-multiinherit/src/example_square.eo b/tutorial/c/eo-multiinherit/src/example_square.eo new file mode 100644 index 0000000..ea1ea94 --- /dev/null +++ b/tutorial/c/eo-multiinherit/src/example_square.eo @@ -0,0 +1,7 @@ +class Example.Square (Example.Rectangle) { + [[A square shape object]] + implements { + Example.Rectangle.width {set;} + Example.Rectangle.height {set;} + } +} diff --git a/tutorial/c/eo-multiinherit/src/meson.build b/tutorial/c/eo-multiinherit/src/meson.build new file mode 100644 index 0000000..26fffb7 --- /dev/null +++ b/tutorial/c/eo-multiinherit/src/meson.build @@ -0,0 +1,33 @@ +eolian_gen = find_program('eolian_gen') + +eo_src = ['example_shape', 'example_rectangle', 'example_square', 'example_circle'] +eo_csrc = [] +eo_gen = [] + +foreach eo : eo_src + eo_file = eo + '.eo' + eo_csrc += eo + '.c' + + eo_gen += custom_target('eolian_gen_' + eo_file, + input : eo_file, + output : [eo_file + '.h'], + command : [eolian_gen, '-I', meson.current_source_dir(), + '-gchi', + '-o', 'i:' + join_paths(meson.current_source_dir(), eo + '.c'), + '-o', 'h:' + join_paths(meson.current_build_dir(), eo_file + '.h'), + '-o', 'c:' + join_paths(meson.current_build_dir(), eo_file + '.c'), '@INPUT@']) +endforeach + +src = files([ + 'eo_inherit.h', + 'eo_inherit_main.c', +]) + +deps = [eina, efl] + +executable('efl_example_eo_multiinherit', src, eo_csrc, eo_gen, + dependencies : deps, + include_directories : inc, + install : true +) + --