summaryrefslogtreecommitdiff
path: root/src/examples/eolian_cxx
diff options
context:
space:
mode:
Diffstat (limited to 'src/examples/eolian_cxx')
-rw-r--r--src/examples/eolian_cxx/.gitignore3
-rw-r--r--src/examples/eolian_cxx/Makefile.am114
-rw-r--r--src/examples/eolian_cxx/colourable.c165
-rw-r--r--src/examples/eolian_cxx/colourable.eo63
-rw-r--r--src/examples/eolian_cxx/colourablesquare.c91
-rw-r--r--src/examples/eolian_cxx/colourablesquare.eo23
-rw-r--r--src/examples/eolian_cxx/eolian_cxx_inherit_01.cc69
-rw-r--r--src/examples/eolian_cxx/eolian_cxx_simple_01.cc35
8 files changed, 563 insertions, 0 deletions
diff --git a/src/examples/eolian_cxx/.gitignore b/src/examples/eolian_cxx/.gitignore
new file mode 100644
index 0000000000..6ae19365d7
--- /dev/null
+++ b/src/examples/eolian_cxx/.gitignore
@@ -0,0 +1,3 @@
1/eolian_cxx_simple_01
2/eolian_cxx_inherit_01
3/eolian_cxx_evas_images
diff --git a/src/examples/eolian_cxx/Makefile.am b/src/examples/eolian_cxx/Makefile.am
new file mode 100644
index 0000000000..eec68a6a7f
--- /dev/null
+++ b/src/examples/eolian_cxx/Makefile.am
@@ -0,0 +1,114 @@
1
2AUTOMAKE_OPTIONS = subdir-objects
3
4MAINTAINERCLEANFILES = Makefile.in
5
6AM_CXXFLAGS = \
7 -I. \
8 -I$(top_builddir)/src/lib/efl \
9 -I$(top_srcdir)/src/lib/eina \
10 -I$(top_builddir)/src/lib/eina \
11 -I$(top_srcdir)/src/lib/eo \
12 -I$(top_builddir)/src/lib/eo \
13 -I$(top_srcdir)/src/bindings/eo_cxx \
14 -I$(top_builddir)/src/bindings/eo_cxx \
15 -I$(top_srcdir)/src/bindings/eina_cxx \
16 -I$(top_builddir)/src/bindings/eina_cxx \
17 -I$(top_srcdir)/src/lib/evas/ \
18 -I$(top_builddir)/src/lib/evas/ \
19 -I$(top_srcdir)/src/lib/evas/common \
20 -I$(top_builddir)/src/lib/evas/common \
21 -I$(top_srcdir)/src/lib/evas/canvas \
22 -I$(top_builddir)/src/lib/evas/canvas \
23 -I$(top_srcdir)/src/lib/ecore \
24 -I$(top_builddir)/src/lib/ecore \
25 -I$(top_srcdir)/src/lib/ecore_evas \
26 -I$(top_builddir)/src/lib/ecore_evas
27
28AM_CFLAGS = $(AM_CXXFLAGS)
29
30AM_LDFLAGS = \
31 -L$(top_builddir)/src/lib/efl \
32 -L$(top_builddir)/src/lib/eina \
33 -L$(top_builddir)/src/lib/eo \
34 -L$(top_builddir)/src/lib/evas \
35 -L$(top_builddir)/src/lib/ecore \
36 -L$(top_builddir)/src/lib/ecore_evas \
37 -leina -levas -leo -lecore -lecore_evas
38
39LDADD = \
40 $(top_builddir)/src/lib/eo/libeo.la \
41 $(top_builddir)/src/lib/eina/libeina.la \
42 $(top_builddir)/src/lib/evas/libevas.la \
43 $(top_builddir)/src/lib/ecore_evas/libecore_evas.la
44
45GENERATED = \
46 colourable.eo.c \
47 colourable.eo.h \
48 colourable.eo.hh \
49 colourablesquare.eo.c \
50 colourablesquare.eo.h \
51 colourablesquare.eo.hh
52
53EOS = \
54 colourable.eo \
55 colourablesquare.eo
56
57SRCS = \
58 eolian_cxx_simple_01.cc \
59 eolian_cxx_inherit_01.cc
60
61EXTRA_PROGRAMS = \
62 eolian_cxx_simple_01 \
63 eolian_cxx_inherit_01
64
65DATA_FILES = Makefile.examples
66CLEANFILES =
67
68eolian_cxx_simple_01_SOURCES = \
69 eolian_cxx_simple_01.cc \
70 colourable.c \
71 colourablesquare.c
72
73eolian_cxx_inherit_01_SOURCES = \
74 eolian_cxx_inherit_01.cc \
75 colourable.c \
76 colourablesquare.c
77
78EOLIAN_GEN = $(top_builddir)/src/bin/eolian/eolian_gen${EXEEXT}
79EOLIAN_CXX = $(top_builddir)/src/bin/eolian_cxx/eolian_cxx${EXEEXT}
80EOLIAN_FLAGS = \
81-I. \
82-I$(top_builddir)/src/lib/eo \
83-I$(top_builddir)/src/lib/evas/canvas \
84-I$(top_builddir)/src/lib/edje \
85-I$(top_builddir)/src/lib/ecore_audio
86
87SUFFIXES = .eo .eo.c .eo.h .eo.hh
88
89%.eo.hh: %.eo $(EOLIAN_CXX)
90 $(AM_V_EOLCXX)$(EOLIAN_CXX) $(EOLIAN_FLAGS) -I./$< -o $@
91
92%.eo.c: %.eo $(EOLIAN_GEN)
93 $(AM_V_EOL)$(EOLIAN_GEN) --eo --legacy $(EOLIAN_FLAGS) --gc -o $@ $<
94
95%.eo.h: %.eo $(EOLIAN_GEN)
96 $(AM_V_EOL)$(EOLIAN_GEN) --eo $(EOLIAN_FLAGS) --gh -o $@ $<
97
98examples: $(EOS) $(GENERATED) $(EXTRA_PROGRAMS)
99
100clean-local:
101 rm -f $(EXTRA_PROGRAMS) $(GENERATED)
102
103install-examples:
104 mkdir -p $(datadir)/eolian_cxx/examples
105 $(install_sh_DATA) -c $(SRCS) $(DATA_FILES) $(datadir)/eolian_cxx/examples
106
107uninstall-local:
108 for f in $(SRCS) $(DATA_FILES); do \
109 rm -f $(datadir)/eolian_cxx/examples/$$f ; \
110 done
111
112if ALWAYS_BUILD_EXAMPLES
113noinst_PROGRAMS = $(EXTRA_PROGRAMS)
114endif
diff --git a/src/examples/eolian_cxx/colourable.c b/src/examples/eolian_cxx/colourable.c
new file mode 100644
index 0000000000..3e289583dd
--- /dev/null
+++ b/src/examples/eolian_cxx/colourable.c
@@ -0,0 +1,165 @@
1#include <stdio.h>
2
3#ifdef HAVE_CONFIG_H
4# include <config.h>
5#endif
6
7#include "Eo.h"
8#include "Eina.h"
9#include "colourable.eo.h"
10
11#define MY_CLASS COLOURABLE_CLASS
12
13static int _colourable_impl_logdomain;
14
15#ifdef DBG
16#undef DBG
17#endif
18#define DBG(...) EINA_LOG_DOM_DBG(_colourable_impl_logdomain, __VA_ARGS__)
19
20#ifdef INFO
21#undef INFO
22#endif
23#define INFO(...) EINA_LOG_DOM_INFO(_colourable_impl_logdomain, __VA_ARGS__)
24
25#ifdef ERR
26#undef ERR
27#endif
28#define ERR(...) EINA_LOG_DOM_ERR(_colourable_impl_logdomain, __VA_ARGS__)
29
30struct _Colourable_Data
31{
32 int r;
33 int g;
34 int b;
35};
36
37typedef struct _Colourable_Data Colourable_Data;
38
39#define COLOURABLE_DATA_GET(o, wd) \
40 Colourable_Data *wd = eo_data_scope_get(o, MY_CLASS)
41
42void
43_colourable_constructor(Eo *obj, Colourable_Data *self)
44{
45 if(!_colourable_impl_logdomain)
46 {
47 _colourable_impl_logdomain
48 = eina_log_domain_register("colourable", EINA_COLOR_BLUE);
49 }
50 DBG("_colourable_constructor(%p, %p)\n", obj, MY_CLASS);
51 eo_do_super(obj, MY_CLASS, eo_constructor());
52}
53
54void
55_colourable_destructor(Eo *obj, Colourable_Data *self)
56{
57 if(_colourable_impl_logdomain)
58 {
59 eina_log_domain_unregister(_colourable_impl_logdomain);
60 _colourable_impl_logdomain = 0;
61 }
62 DBG("_colourable_destructor()\n");
63 eo_do_super(obj, MY_CLASS, eo_destructor());
64}
65
66void
67_colourable_rgb_composite_constructor(Eo *obj, Colourable_Data *self, int r, int g, int b)
68{
69 if(!_colourable_impl_logdomain)
70 {
71 _colourable_impl_logdomain
72 = eina_log_domain_register("colourable", EINA_COLOR_BLUE);
73 }
74 self->r = r;
75 self->g = g;
76 self->b = b;
77 DBG("_colourable_rgb_composite_constructor(0x%2.x, %0x2.x, %0x2.x)\n",
78 (unsigned int)self->r,
79 (unsigned int)self->g,
80 (unsigned int)self->b);
81 eo_do_super(obj, MY_CLASS, eo_constructor());
82}
83
84void
85_colourable_rgb_24bits_constructor(Eo *obj, Colourable_Data *self, int rgb)
86{
87 if(!_colourable_impl_logdomain)
88 {
89 _colourable_impl_logdomain
90 = eina_log_domain_register("colourable", EINA_COLOR_BLUE);
91 }
92
93 self->r = (rgb & 0x00ff0000) >> 16;
94 self->g = (rgb & 0x0000ff00) >> 8;
95 self->b = rgb & 0x000000ff;
96 DBG("_colourable_rgb_24bits_constructor(0x%.6x)\n", (int)rgb);
97 eo_do_super(obj, MY_CLASS, eo_constructor());
98}
99
100void
101_colourable_print_colour(Eo *obj, Colourable_Data *self)
102{
103 DBG("_colourable_print_colour() ==> 0x%2.x 0x%2.x 0x%2.x\n", self->r, self->g, self->b);
104}
105
106int
107_colourable_colour_mask(Eo *obj, Colourable_Data *self, int mask)
108{
109 int masked_rgb =
110 (((self->r << 16)& 0x00ff0000) |
111 ((self->g << 8) & 0x0000ff00) |
112 (self->b & 0x000000ff)) & mask;
113 DBG("_colourable_colour_mask() ==> 0x%2.x\n", (unsigned int)masked_rgb);
114 return masked_rgb;
115}
116
117void
118_colourable_composite_colour_get(Eo *obj, Colourable_Data *self, int* r, int* g, int* b)
119{
120 *r = self->r;
121 *g = self->g;
122 *b = self->b;
123 DBG("_colourable_composite_colour_get() ==> 0x%2.x 0x%2.x 0x%2.x\n", *r, *g, *b);
124 return;
125}
126
127void
128_colourable_composite_colour_set(Eo *obj, Colourable_Data *self, int r, int g, int b)
129{
130 self->r = r;
131 self->g = g;
132 self->b = b;
133 DBG("_colourable_composite_colour_set(0x%2.x, 0x%2.x, 0x%2.x)\n",
134 (int)self->r, (int)self->g, (int)self->b);
135 return;
136}
137
138int
139_colourable_colour_get(Eo *obj, Colourable_Data *self)
140{
141 int rgb =
142 ((self->r << 16)& 0x00ff0000) |
143 ((self->g << 8) & 0x0000ff00) |
144 (self->b & 0x000000ff);
145 DBG("_colourable_colour_get() ==> 0x%.6x\n", (unsigned int)rgb);
146 return rgb;
147}
148
149void
150_colourable_colour_set(Eo *obj, Colourable_Data *self, int rgb)
151{
152 self->r = (rgb & 0x00ff0000) >> 16;
153 self->g = (rgb & 0x0000ff00) >> 8;
154 self->b = rgb & 0x000000ff;
155 DBG("_colourable_colour_set(0x%.6x)\n", (unsigned int)rgb);
156 return;
157}
158
159static void
160_user_colourable_class_constructor(Eo_Class *klass)
161{
162 DBG("_colourable_class_constructor()\n");
163}
164
165#include "colourable.eo.c"
diff --git a/src/examples/eolian_cxx/colourable.eo b/src/examples/eolian_cxx/colourable.eo
new file mode 100644
index 0000000000..a708217a39
--- /dev/null
+++ b/src/examples/eolian_cxx/colourable.eo
@@ -0,0 +1,63 @@
1class Colourable (Eo_Base)
2{
3 /*@ Colourable class. */
4 legacy_prefix: legacy;
5 constructors {
6 constructor {
7 /*@ Default constructor. */
8 }
9 rgb_composite_constructor {
10 /*@ Composite RGB Constructor. */
11 params {
12 @in int r; /*@ The red component. */
13 @in int g; /*@ The green component. */
14 @in int b; /*@ The blue component. */
15 };
16 };
17 rgb_24bits_constructor {
18 /*@ RGB Constructor. */
19 params {
20 @in int rgb; /*@ 24-bit RGB Component. */
21 };
22 };
23 };
24 methods {
25 print_colour { /*@ Print the RGB colour. */ };
26 colour_mask {
27 /*@ The masked RGB value. */
28 return int;
29 params {
30 @in int mask; /*@ The colour mask to be applied to current RGB value. */
31 };
32 };
33 };
34 properties {
35 colour {
36 set {
37 /*@ Sets a 24-bit RGB colour. */
38 };
39 get {
40 /*@ Gets the 24-bit RGB colour. */
41 };
42 values {
43 int rgb; /*@ The RGB colour value. */
44 };
45 };
46 composite_colour {
47 set {
48 /*@ Sets a composite RGB colour. */
49 };
50 get {
51 /*@ Gets the composite RGB colour. */
52 };
53 values {
54 int r; /*@ The red component. */
55 int g; /*@ The green component. */
56 int b; /*@ The blue component. */
57 };
58 };
59 };
60 events {
61 colour_changed(int);
62 };
63};
diff --git a/src/examples/eolian_cxx/colourablesquare.c b/src/examples/eolian_cxx/colourablesquare.c
new file mode 100644
index 0000000000..1eb190cf85
--- /dev/null
+++ b/src/examples/eolian_cxx/colourablesquare.c
@@ -0,0 +1,91 @@
1#include <stdio.h>
2
3#ifdef HAVE_CONFIG_H
4# include <config.h>
5#endif
6
7#include "Eo.h"
8
9#include "colourable.eo.h"
10#include "colourablesquare.eo.h"
11
12#define MY_CLASS COLOURABLESQUARE_CLASS
13
14static int _colourablesquare_impl_logdomain;
15
16#ifdef DBG
17#undef DBG
18#endif
19#define DBG(...) EINA_LOG_DOM_DBG(_colourablesquare_impl_logdomain, __VA_ARGS__)
20
21#ifdef INFO
22#undef INFO
23#endif
24#define INFO(...) EINA_LOG_DOM_INFO(_colourablesquare_impl_logdomain, __VA_ARGS__)
25
26#ifdef ERR
27#undef ERR
28#endif
29#define ERR(...) EINA_LOG_DOM_ERR(_colourablesquare_impl_logdomain, __VA_ARGS__)
30
31struct _ColourableSquare_Data
32{
33 int size;
34};
35
36typedef struct _ColourableSquare_Data ColourableSquare_Data;
37
38#define COLOURABLESQUARE_DATA_GET(o, wd) \
39 ColourableSquare_Data *wd = eo_data_scope_get(o, MY_CLASS)
40
41static void
42_colourablesquare_size_constructor(Eo *obj, ColourableSquare_Data *self, int size)
43{
44 if(!_colourablesquare_impl_logdomain)
45 {
46 _colourablesquare_impl_logdomain
47 = eina_log_domain_register
48 ("colourablesquare", EINA_COLOR_LIGHTBLUE);
49 }
50 self->size = size;
51 DBG("_colourablesquare_constructor(%d)\n", size);
52 eo_do_super(obj, MY_CLASS, eo_constructor());
53}
54
55static void
56_colourablesquare_destructor(Eo *obj, ColourableSquare_Data *self)
57{
58 eo_do_super(obj, MY_CLASS, eo_destructor());
59 if(_colourablesquare_impl_logdomain)
60 {
61 eina_log_domain_unregister(_colourablesquare_impl_logdomain);
62 _colourablesquare_impl_logdomain = 0;
63 }
64}
65
66static int
67_colourablesquare_size_get(Eo *obj, ColourableSquare_Data *self)
68{
69 DBG("_colourablesquare_size_get() => %d\n", self->size);
70 return self->size;
71}
72
73static void
74_colourablesquare_size_print(Eo *obj, ColourableSquare_Data *self)
75{
76 DBG("_colourablesquare_size_print() ==> %d\n", self->size);
77}
78
79static void
80_colourablesquare_size_set(Eo *obj, ColourableSquare_Data *self, int size)
81{
82 DBG("_colourablesquare_size_set(%d)\n", size);
83}
84
85static void
86_user_colourablesquare_class_constructor(Eo_Class *klass)
87{
88 DBG("_colourablesquare_class_constructor()\n");
89}
90
91#include "colourablesquare.eo.c"
diff --git a/src/examples/eolian_cxx/colourablesquare.eo b/src/examples/eolian_cxx/colourablesquare.eo
new file mode 100644
index 0000000000..d254151152
--- /dev/null
+++ b/src/examples/eolian_cxx/colourablesquare.eo
@@ -0,0 +1,23 @@
1class ColourableSquare (Colourable)
2{
3 constructors {
4 size_constructor { params { @in int size; } }
5 };
6 legacy_prefix: legacy;
7 properties {
8 size {
9 values {
10 int size;
11 };
12 set {
13 /*@ Sets size. */
14 };
15 get {
16 /*@ Gets size. */
17 };
18 };
19 };
20 methods {
21 size_print { /*@ Show the square. */ };
22 };
23};
diff --git a/src/examples/eolian_cxx/eolian_cxx_inherit_01.cc b/src/examples/eolian_cxx/eolian_cxx_inherit_01.cc
new file mode 100644
index 0000000000..798b3a8cf5
--- /dev/null
+++ b/src/examples/eolian_cxx/eolian_cxx_inherit_01.cc
@@ -0,0 +1,69 @@
1
2#include <iostream>
3
4#ifdef HAVE_CONFIG_H
5# include <config.h>
6#endif
7
8#include "colourable.eo.hh"
9#include "colourablesquare.eo.hh"
10
11#include <eo_inherit.hh>
12
13using namespace efl;
14
15struct ColourableCircle
16 : efl::eo::inherit<ColourableCircle, ::colourable>
17{
18 ColourableCircle(int r, int g, int b)
19 : inherit_base(r, g, b)
20 {}
21
22 ColourableCircle(int rgb)
23 : inherit_base(efl::eo::args<::colourable>(rgb))
24 {}
25
26 int colour_get()
27 {
28 int rgb = 0;
29 eo_do_super(_eo_ptr(), _eo_class(), rgb = ::colourable_colour_get());
30 std::cout << "ColourableCircle::colour_get(" << this << ") ==> "
31 << std::hex << rgb << std::endl;
32 return rgb;
33 }
34};
35
36
37struct ColourableFoo
38 : efl::eo::inherit<ColourableFoo,
39 ::colourable,
40 ::colourablesquare>
41{
42 ColourableFoo(int size, int rgb)
43 : inherit_base(efl::eo::args<::colourable>(size)
44 , efl::eo::args<::colourablesquare>(rgb))
45 {}
46};
47
48int
49main()
50{
51 efl::eo::eo_init init;
52 eina_log_domain_level_set("colourable", EINA_LOG_LEVEL_DBG);
53
54 ColourableCircle obj1(0xc0, 0xff, 0xee);
55
56 ColourableCircle obj2(0xc0ffee);
57 int r, g, b;
58 obj2.composite_colour_get(&r, &g, &b);
59
60 assert(r == 0xc0);
61 assert(g == 0xff);
62 assert(b == 0xee);
63
64 assert(obj1.colour_get() == obj2.colour_get());
65
66 // ColourableFoo obj3(10, 0xc0ffee);
67
68 return 0;
69}
diff --git a/src/examples/eolian_cxx/eolian_cxx_simple_01.cc b/src/examples/eolian_cxx/eolian_cxx_simple_01.cc
new file mode 100644
index 0000000000..363073a259
--- /dev/null
+++ b/src/examples/eolian_cxx/eolian_cxx_simple_01.cc
@@ -0,0 +1,35 @@
1// EINA_LOG_LEVELS=colourable:4,colourablesquare:4 ./eolian_cxx_simple_01
2
3#include <iostream>
4
5#ifdef HAVE_CONFIG_H
6# include <config.h>
7#endif
8
9#include "colourable.eo.hh"
10#include "colourablesquare.eo.hh"
11
12int
13main()
14{
15 efl::eo::eo_init init;
16 eina_log_domain_level_set("colourable", EINA_LOG_LEVEL_DBG);
17 eina_log_domain_level_set("colourablesquare", EINA_LOG_LEVEL_DBG);
18
19 int r, g, b;
20 ::colourable obj1(0x123456);
21 obj1.colour_set(0xc0ffee);
22 obj1.composite_colour_get(&r, &g, &b);
23
24 ::colourablesquare obj2(0x123456);
25 obj2.composite_colour_set(r, g, b);
26 obj2.size_set(11);
27 assert(obj1.colour_get() == obj2.colour_get());
28
29 efl::eo::wref<::colourable> ref = obj1;
30 efl::eina::optional<::colourable> obj3 = ref.lock();
31 assert(obj3);
32 obj3->colour_set(0x00);
33
34 return 0;
35}