eo-classes: Add an example using eolian to define a class heirarchy

This commit is contained in:
Andy Williams 2017-11-07 17:35:34 +00:00
parent 84383a46c4
commit c2fd813ea6
9 changed files with 301 additions and 0 deletions

14
c-eo-classes/meson.build Normal file
View File

@ -0,0 +1,14 @@
project(
'efl-example-eo-classes', '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', version : '>=1.20.99')
elm = dependency('elementary', version : '>=1.20.99')
eolian = dependency('eolian', version : '>=1.20.99')
inc = include_directories('.')
subdir('src')

View File

@ -0,0 +1,57 @@
#define EFL_EO_API_SUPPORT 1
#define EFL_BETA_API_SUPPORT 1
#include <Eina.h>
#include <Efl.h>
#include <Elementary.h>
#include "example_shape.eo.h"
#include "example_rectangle.eo.h"
#include "example_square.eo.h"
Example_Shape *
_rect_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_square_side_set(efl_added, 7));
return square;
}
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 = _rect_create();
_shape_print(shape);
shape = _square_create();
_shape_print(shape);
efl_exit(0);
}
EFL_MAIN()

View File

@ -0,0 +1,51 @@
#define EFL_BETA_API_SUPPORT
#include <Eo.h>
#include "example_rectangle.eo.h"
#include "example_shape.eo.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;
}
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

@ -0,0 +1,31 @@
class Example.Rectangle (Efl.Object, Example.Shape) {
[[A rectangle shape object]]
eo_prefix: example_rectangle;
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 {
class.constructor;
class.destructor;
Example.Shape.area;
}
}

View File

@ -0,0 +1,5 @@
#define EFL_BETA_API_SUPPORT
#include <Eo.h>
#include "example_shape.eo.h"
#include "example_shape.eo.c"

View File

@ -0,0 +1,24 @@
interface Example.Shape {
[[A generic shape object]]
eo_prefix: example_shape;
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 {
}
return: int;
}
}
}

View File

@ -0,0 +1,64 @@
#define EFL_BETA_API_SUPPORT
#include <Eo.h>
#include "example_square.eo.h"
#include "example_rectangle.eo.h"
#include "example_shape.eo.h"
typedef struct
{
int size;
} Example_Square_Data;
EOLIAN static void
_example_square_side_set(Eo *obj EINA_UNUSED, Example_Square_Data *pd, int size)
{
pd->size = 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)
{
}
#include "example_square.eo.c"

View File

@ -0,0 +1,23 @@
class Example.Square (Example.Rectangle) {
[[A square shape object]]
eo_prefix: example_square;
methods {
@property side {
[[The length of both sides of this square]]
set {
}
get {
}
values {
size: int; [[Square side length]]
}
}
}
implements {
class.constructor;
class.destructor;
Example.Shape.area;
Example.Rectangle.width {get; set;}
Example.Rectangle.height {get; set;}
}
}

View File

@ -0,0 +1,32 @@
eolian_gen = find_program('eolian_gen')
eo_src = ['example_shape', 'example_rectangle', 'example_square']
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', eolian.get_pkgconfig_variable('eoincludedir'),
'-I', '../src',
'-gchi', '-o', 'h:' + eo_file + '.h',
'-o', 'i:../src/' + eo + '.c',
'-o', 'c:' + eo_file + '.c', '@INPUT@'])
endforeach
src = files([
'eo_classes_main.c',
])
deps = [eina, efl, elm]
executable('efl_example_eo_classes', src, eo_csrc, eo_gen,
dependencies : deps,
include_directories : inc,
install : true
)