Reorganize inheritance example

Added circle to illustrate shape interface
Removed shape interface from square, since it inherits from rectangle.
Removed square private data and use its parent's data through the public accessors.
Do not overwrite rectangle's accessors in square, only define the new side.
Removed class cons/destructors which are not used (tutorial is complex enough)
Removed color property from interface (tutorial is complex enough)
This commit is contained in:
Xavi Artigas 2017-11-15 16:02:37 +01:00
parent 4380baece8
commit 1e380eace9
10 changed files with 73 additions and 79 deletions

View File

@ -13,5 +13,6 @@
#include "example_shape.eo.h"
#include "example_rectangle.eo.h"
#include "example_square.eo.h"
#include "example_circle.eo.h"
#endif

View File

@ -1,7 +1,7 @@
#include "eo_inherit.h"
Example_Shape *
_rect_create()
_rectangle_create()
{
Example_Rectangle *rectangle;
@ -25,6 +25,18 @@ _square_create()
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)
{
@ -36,12 +48,15 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
{
Eo *shape;
shape = _rect_create();
shape = _rectangle_create();
_shape_print(shape);
shape = _square_create();
_shape_print(shape);
shape = _circle_create();
_shape_print(shape);
efl_exit(0);
}
EFL_MAIN()

View File

@ -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"

View File

@ -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;
}
}

View File

@ -39,14 +39,4 @@ _example_rectangle_example_shape_area(Eo *obj EINA_UNUSED, Example_Rectangle_Dat
return pd->width * pd->height;
}
EOLIAN static void
_example_rectangle_class_constructor(Efl_Class *klass EINA_UNUSED)
{
}
EOLIAN static void
_example_rectangle_class_destructor(Efl_Class *klass EINA_UNUSED)
{
}
#include "example_rectangle.eo.c"

View File

@ -23,8 +23,6 @@ class Example.Rectangle (Efl.Object, Example.Shape) {
}
}
implements {
class.constructor;
class.destructor;
Example.Shape.area;
}
}

View File

@ -1,18 +1,6 @@
interface Example.Shape {
[[A generic shape object]]
methods {
@property color {
[[The colour that our shape should be filled with]]
set {
}
get {
}
values {
r: int; [[Red component color]]
g: int; [[Green component color]]
b: int; [[Blue component color]]
}
}
area {
[[Calculate the area of the shape.]]
params {

View File

@ -6,59 +6,20 @@
typedef struct
{
int size;
} Example_Square_Data;
EOLIAN static void
_example_square_side_set(Eo *obj EINA_UNUSED, Example_Square_Data *pd, int size)
_example_square_side_set(Eo *obj, Example_Square_Data *pd EINA_UNUSED, int size)
{
pd->size = size;
example_rectangle_width_set(obj, size);
example_rectangle_height_set(obj, size);
}
EOLIAN static int
_example_square_side_get(Eo *obj EINA_UNUSED, Example_Square_Data *pd)
{
return pd->size;
}
EOLIAN static void
_example_square_example_rectangle_width_set(Eo *obj EINA_UNUSED, Example_Square_Data *pd, int width)
{
pd->size = width;
}
EOLIAN static int
_example_square_example_rectangle_width_get(Eo *obj EINA_UNUSED, Example_Square_Data *pd)
{
return pd->size;
}
EOLIAN static void
_example_square_example_rectangle_height_set(Eo *obj EINA_UNUSED, Example_Square_Data *pd, int height)
{
pd->size = height;
}
EOLIAN static int
_example_square_example_rectangle_height_get(Eo *obj EINA_UNUSED, Example_Square_Data *pd)
{
return pd->size;
}
EOLIAN static int
_example_square_example_shape_area(Eo *obj EINA_UNUSED, Example_Square_Data *pd)
{
return pd->size * pd->size;
}
EOLIAN static void
_example_square_class_constructor(Efl_Class *klass EINA_UNUSED)
{
}
EOLIAN static void
_example_square_class_destructor(Efl_Class *klass EINA_UNUSED)
_example_square_side_get(Eo *obj, Example_Square_Data *pd EINA_UNUSED)
{
return example_rectangle_width_get(obj);
}
#include "example_square.eo.c"

View File

@ -12,11 +12,4 @@ class Example.Square (Example.Rectangle) {
}
}
}
implements {
class.constructor;
class.destructor;
Example.Shape.area;
Example.Rectangle.width {get; set;}
Example.Rectangle.height {get; set;}
}
}

View File

@ -1,6 +1,6 @@
eolian_gen = find_program('eolian_gen')
eo_src = ['example_shape', 'example_rectangle', 'example_square']
eo_src = ['example_shape', 'example_rectangle', 'example_square', 'example_circle']
eo_csrc = []
eo_gen = []