summaryrefslogtreecommitdiff
path: root/src/examples/eolian_cxx
diff options
context:
space:
mode:
authorSavio Sena <savio@expertisesolutions.com.br>2014-07-24 16:47:35 -0300
committerSavio Sena <savio@expertisesolutions.com.br>2014-07-24 19:52:23 -0300
commit3e43bb57d85ab172f0d68e42f4c94f616ebf1d3f (patch)
treeefd31e885ac5c71d1cd6015ae2ccaadbcc343411 /src/examples/eolian_cxx
parentfb82d67ab13b12534468a39ac29eb31d0d04cee5 (diff)
eolian-cxx: Added example of Eo implementation in C++.
Instead of implementing Eo functions in C we do it in C++ simply.
Diffstat (limited to 'src/examples/eolian_cxx')
-rw-r--r--src/examples/eolian_cxx/Makefile.am15
-rw-r--r--src/examples/eolian_cxx/colourable.c13
-rw-r--r--src/examples/eolian_cxx/colourable_cxx.cc122
-rw-r--r--src/examples/eolian_cxx/colourable_stub.c12
-rw-r--r--src/examples/eolian_cxx/colourable_stub.h31
-rw-r--r--src/examples/eolian_cxx/colourablesquare.c14
-rw-r--r--src/examples/eolian_cxx/colourablesquare_cxx.cc49
-rw-r--r--src/examples/eolian_cxx/colourablesquare_stub.c12
-rw-r--r--src/examples/eolian_cxx/colourablesquare_stub.h23
-rw-r--r--src/examples/eolian_cxx/eolian_cxx_simple_01.cc2
-rw-r--r--src/examples/eolian_cxx/eolian_cxx_simple_01_cxx_impl.cc36
11 files changed, 300 insertions, 29 deletions
diff --git a/src/examples/eolian_cxx/Makefile.am b/src/examples/eolian_cxx/Makefile.am
index a163522..bfd8134 100644
--- a/src/examples/eolian_cxx/Makefile.am
+++ b/src/examples/eolian_cxx/Makefile.am
@@ -74,7 +74,11 @@ EOS = \
74 74
75IMPL = \ 75IMPL = \
76 colourable.c \ 76 colourable.c \
77 colourablesquare.c 77 colourable_cxx.cc \
78 colourablesquare.c \
79 colourablesquare_cxx.cc \
80 colourable_stub.c \
81 colourablesquare_stub.c
78 82
79SRCS = \ 83SRCS = \
80 eolian_cxx_simple_01.cc \ 84 eolian_cxx_simple_01.cc \
@@ -86,6 +90,7 @@ SRCS = \
86 90
87EXTRA_PROGRAMS = \ 91EXTRA_PROGRAMS = \
88 eolian_cxx_simple_01 \ 92 eolian_cxx_simple_01 \
93 eolian_cxx_simple_01_cxx_impl \
89 eolian_cxx_inherit_01 \ 94 eolian_cxx_inherit_01 \
90 eolian_cxx_callbacks_01 \ 95 eolian_cxx_callbacks_01 \
91 eolian_cxx_eo_events_01 \ 96 eolian_cxx_eo_events_01 \
@@ -99,6 +104,14 @@ eolian_cxx_simple_01_SOURCES = \
99 colourablesquare.c 104 colourablesquare.c
100eolian_cxx_simple_01.$(OBJEXT): $(GENERATED) 105eolian_cxx_simple_01.$(OBJEXT): $(GENERATED)
101 106
107eolian_cxx_simple_01_cxx_impl_SOURCES = \
108 eolian_cxx_simple_01.cc \
109 colourable_stub.c \
110 colourablesquare_stub.c \
111 colourable_cxx.cc \
112 colourablesquare_cxx.cc
113eolian_cxx_simple_01_cxx_impl.$(OBJEXT): $(GENERATED)
114
102eolian_cxx_inherit_01_SOURCES = \ 115eolian_cxx_inherit_01_SOURCES = \
103 eolian_cxx_inherit_01.cc \ 116 eolian_cxx_inherit_01.cc \
104 colourable.c \ 117 colourable.c \
diff --git a/src/examples/eolian_cxx/colourable.c b/src/examples/eolian_cxx/colourable.c
index 9bbcce2..5b33566 100644
--- a/src/examples/eolian_cxx/colourable.c
+++ b/src/examples/eolian_cxx/colourable.c
@@ -17,16 +17,6 @@ static int _colourable_impl_logdomain;
17#endif 17#endif
18#define DBG(...) EINA_LOG_DOM_DBG(_colourable_impl_logdomain, __VA_ARGS__) 18#define DBG(...) EINA_LOG_DOM_DBG(_colourable_impl_logdomain, __VA_ARGS__)
19 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 20struct _Colourable_Data
31{ 21{
32 int r; 22 int r;
@@ -36,9 +26,6 @@ struct _Colourable_Data
36 26
37typedef struct _Colourable_Data Colourable_Data; 27typedef struct _Colourable_Data Colourable_Data;
38 28
39#define COLOURABLE_DATA_GET(o, wd) \
40 Colourable_Data *wd = eo_data_scope_get(o, MY_CLASS)
41
42void 29void
43_colourable_constructor(Eo *obj, Colourable_Data *self EINA_UNUSED) 30_colourable_constructor(Eo *obj, Colourable_Data *self EINA_UNUSED)
44{ 31{
diff --git a/src/examples/eolian_cxx/colourable_cxx.cc b/src/examples/eolian_cxx/colourable_cxx.cc
new file mode 100644
index 0000000..8de02aa
--- /dev/null
+++ b/src/examples/eolian_cxx/colourable_cxx.cc
@@ -0,0 +1,122 @@
1
2#include <iostream>
3#include <iomanip>
4
5#ifdef HAVE_CONFIG_H
6# include <config.h>
7#endif
8
9#include "Eo.hh"
10#include "Eina.hh"
11
12extern "C"
13{
14#include "colourable_stub.h"
15#include "colourable.eo.h"
16}
17
18#define MY_CLASS COLOURABLE_CLASS
19
20static efl::eina::log_domain domain("colourable");
21
22void
23_colourable_constructor(Eo *obj, Colourable_Data *self)
24{
25 EINA_CXX_DOM_LOG_DBG(domain) << __func__ << std::endl;
26 self->r = self->g = self->b = 0;
27 eo_do_super(obj, MY_CLASS, eo_constructor());
28}
29
30void
31_colourable_destructor(Eo *obj, Colourable_Data *self EINA_UNUSED)
32{
33 EINA_CXX_DOM_LOG_DBG(domain) << __func__ << std::endl;
34 eo_do_super(obj, MY_CLASS, eo_destructor());
35}
36
37void
38_colourable_rgb_composite_constructor(Eo *obj, Colourable_Data *self, int r, int g, int b)
39{
40 EINA_CXX_DOM_LOG_DBG(domain) << std::showbase << std::hex
41 << __func__ << " [ (r, g, b) = ("
42 << r << ", " << g << ", " << b << ") ]" << std::endl;
43 self->r = r;
44 self->g = g;
45 self->b = b;
46 eo_do_super(obj, MY_CLASS, eo_constructor());
47}
48
49void
50_colourable_rgb_24bits_constructor(Eo *obj, Colourable_Data *self, int rgb)
51{
52 EINA_CXX_DOM_LOG_DBG(domain) << std::showbase << std::hex
53 << __func__ << " [ rgb = " << rgb <<" ]" << std::endl;
54 self->r = (rgb & 0x00ff0000) >> 16;
55 self->g = (rgb & 0x0000ff00) >> 8;
56 self->b = rgb & 0x000000ff;
57 eo_do_super(obj, MY_CLASS, eo_constructor());
58}
59
60void
61_colourable_print_colour(Eo *obj EINA_UNUSED, Colourable_Data *self EINA_UNUSED)
62{
63 EINA_CXX_DOM_LOG_DBG(domain) << __func__ << std::endl;
64}
65
66int
67_colourable_colour_mask(Eo *obj EINA_UNUSED, Colourable_Data *self, int mask)
68{
69 int masked_rgb =
70 (((self->r << 16)& 0x00ff0000) |
71 ((self->g << 8) & 0x0000ff00) |
72 (self->b & 0x000000ff)) & mask;
73 EINA_CXX_DOM_LOG_DBG(domain) << std::showbase << std::hex
74 << __func__ << " [ mask = " << masked_rgb << " ]" << std::endl;
75 return masked_rgb;
76}
77
78void
79_colourable_composite_colour_get(Eo *obj EINA_UNUSED, Colourable_Data *self, int* r, int* g, int* b)
80{
81 *r = self->r;
82 *g = self->g;
83 *b = self->b;
84 EINA_CXX_DOM_LOG_DBG(domain) << std::showbase << std::hex
85 << __func__ << " [ (r, g, b) = (" << *r << ", " << *g << ", " << *b << ") ]" << std::endl;
86 return;
87}
88
89void
90_colourable_composite_colour_set(Eo *obj EINA_UNUSED, Colourable_Data *self, int r, int g, int b)
91{
92 EINA_CXX_DOM_LOG_DBG(domain) << std::showbase << std::hex
93 << __func__ << " [ (r, g, b) = (" << r << ", " << g << ", " << b << ") ]" << std::endl;
94 self->r = r;
95 self->g = g;
96 self->b = b;
97 return;
98}
99
100int
101_colourable_colour_get(Eo *obj EINA_UNUSED, Colourable_Data *self)
102{
103 int rgb =
104 ((self->r << 16)& 0x00ff0000) |
105 ((self->g << 8) & 0x0000ff00) |
106 (self->b & 0x000000ff);
107 EINA_CXX_DOM_LOG_DBG(domain) << std::showbase << std::hex
108 << __func__ << " [ rgb = " << rgb <<" ]" << std::endl;
109 return rgb;
110}
111
112void
113_colourable_colour_set(Eo *obj EINA_UNUSED, Colourable_Data *self, int rgb)
114{
115 EINA_CXX_DOM_LOG_DBG(domain) << std::showbase << std::hex
116 << __func__ << " [ rgb = " << rgb <<" ]" << std::endl;
117 self->r = (rgb & 0x00ff0000) >> 16;
118 self->g = (rgb & 0x0000ff00) >> 8;
119 self->b = rgb & 0x000000ff;
120 return;
121}
122
diff --git a/src/examples/eolian_cxx/colourable_stub.c b/src/examples/eolian_cxx/colourable_stub.c
new file mode 100644
index 0000000..a427cc5
--- /dev/null
+++ b/src/examples/eolian_cxx/colourable_stub.c
@@ -0,0 +1,12 @@
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
10#include "colourable_stub.h"
11#include "colourable.eo.h"
12#include "colourable.eo.c"
diff --git a/src/examples/eolian_cxx/colourable_stub.h b/src/examples/eolian_cxx/colourable_stub.h
new file mode 100644
index 0000000..fbf913f
--- /dev/null
+++ b/src/examples/eolian_cxx/colourable_stub.h
@@ -0,0 +1,31 @@
1#ifndef EFL_EXAMPLE_EOLIAN_CXX_COLOURABLE_STUB_H
2#define EFL_EXAMPLE_EOLIAN_CXX_COLOURABLE_STUB_H
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8struct _Colourable_Data
9{
10 int r;
11 int g;
12 int b;
13};
14typedef struct _Colourable_Data Colourable_Data;
15
16void _colourable_constructor(Eo *obj, Colourable_Data *self);
17void _colourable_rgb_composite_constructor(Eo *obj, Colourable_Data *self, int r, int g, int b);
18void _colourable_rgb_24bits_constructor(Eo *obj, Colourable_Data *self, int rgb);
19void _colourable_print_colour(Eo *obj, Colourable_Data *self);
20void _colourable_print_colour(Eo *obj, Colourable_Data *self);
21int _colourable_colour_mask(Eo *obj, Colourable_Data *self, int mask);
22void _colourable_composite_colour_get(Eo *obj, Colourable_Data *self, int* r, int* g, int* b);
23void _colourable_composite_colour_set(Eo *obj, Colourable_Data *self, int r, int g, int b);
24int _colourable_colour_get(Eo *obj, Colourable_Data *self);
25void _colourable_colour_set(Eo *obj, Colourable_Data *self, int rgb);
26
27#ifdef __cplusplus
28}
29#endif
30
31#endif // EFL_EXAMPLE_EOLIAN_CXX_COLOURABLE_STUB_H
diff --git a/src/examples/eolian_cxx/colourablesquare.c b/src/examples/eolian_cxx/colourablesquare.c
index 9ed046a..87bc419 100644
--- a/src/examples/eolian_cxx/colourablesquare.c
+++ b/src/examples/eolian_cxx/colourablesquare.c
@@ -18,26 +18,12 @@ static int _colourablesquare_impl_logdomain;
18#endif 18#endif
19#define DBG(...) EINA_LOG_DOM_DBG(_colourablesquare_impl_logdomain, __VA_ARGS__) 19#define DBG(...) EINA_LOG_DOM_DBG(_colourablesquare_impl_logdomain, __VA_ARGS__)
20 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 21struct _ColourableSquare_Data
32{ 22{
33 int size; 23 int size;
34}; 24};
35
36typedef struct _ColourableSquare_Data ColourableSquare_Data; 25typedef struct _ColourableSquare_Data ColourableSquare_Data;
37 26
38#define COLOURABLESQUARE_DATA_GET(o, wd) \
39 ColourableSquare_Data *wd = eo_data_scope_get(o, MY_CLASS)
40
41static void 27static void
42_colourablesquare_size_constructor(Eo *obj, ColourableSquare_Data *self, int size) 28_colourablesquare_size_constructor(Eo *obj, ColourableSquare_Data *self, int size)
43{ 29{
diff --git a/src/examples/eolian_cxx/colourablesquare_cxx.cc b/src/examples/eolian_cxx/colourablesquare_cxx.cc
new file mode 100644
index 0000000..b98df67
--- /dev/null
+++ b/src/examples/eolian_cxx/colourablesquare_cxx.cc
@@ -0,0 +1,49 @@
1
2#include <iostream>
3#include <iomanip>
4
5#ifdef HAVE_CONFIG_H
6# include <config.h>
7#endif
8
9#include "Eo.hh"
10#include "Eina.hh"
11
12extern "C"
13{
14#include "colourablesquare_stub.h"
15#include "colourable.eo.h"
16#include "colourablesquare.eo.h"
17}
18
19#define MY_CLASS COLOURABLESQUARE_CLASS
20
21static efl::eina::log_domain domain("colourablesquare");
22
23void
24_colourablesquare_size_constructor(Eo *obj, ColourableSquare_Data *self, int size)
25{
26 self->size = size;
27 EINA_CXX_DOM_LOG_DBG(domain) << __func__ << " [ size = " << size << " ]" << std::endl;
28 eo_do_super(obj, MY_CLASS, eo_constructor());
29}
30
31int
32_colourablesquare_size_get(Eo *obj EINA_UNUSED, ColourableSquare_Data *self)
33{
34 EINA_CXX_DOM_LOG_DBG(domain) << __func__ << " [ size = " << self->size << " ]" << std::endl;
35 return self->size;
36}
37
38void
39_colourablesquare_size_print(Eo *obj EINA_UNUSED, ColourableSquare_Data *self)
40{
41 EINA_CXX_DOM_LOG_DBG(domain) << __func__ << " [ size = " << self->size << " ]" << std::endl;
42}
43
44void
45_colourablesquare_size_set(Eo *obj EINA_UNUSED, ColourableSquare_Data *self EINA_UNUSED, int size)
46{
47 EINA_CXX_DOM_LOG_DBG(domain) << __func__ << " [ size = " << self->size << " ]" << std::endl;
48}
49
diff --git a/src/examples/eolian_cxx/colourablesquare_stub.c b/src/examples/eolian_cxx/colourablesquare_stub.c
new file mode 100644
index 0000000..276130c
--- /dev/null
+++ b/src/examples/eolian_cxx/colourablesquare_stub.c
@@ -0,0 +1,12 @@
1#include <stdio.h>
2
3#ifdef HAVE_CONFIG_H
4# include <config.h>
5#endif
6
7#include "Eo.h"
8
9#include "colourablesquare_stub.h"
10#include "colourable.eo.h"
11#include "colourablesquare.eo.h"
12#include "colourablesquare.eo.c"
diff --git a/src/examples/eolian_cxx/colourablesquare_stub.h b/src/examples/eolian_cxx/colourablesquare_stub.h
new file mode 100644
index 0000000..b653fe3
--- /dev/null
+++ b/src/examples/eolian_cxx/colourablesquare_stub.h
@@ -0,0 +1,23 @@
1#ifndef EFL_EXAMPLE_EOLIAN_CXX_COLOURABLE_SQUARE_STUB_H
2#define EFL_EXAMPLE_EOLIAN_CXX_COLOURABLE_SQUARE_STUB_H
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8struct _ColourableSquare_Data
9{
10 int size;
11};
12typedef struct _ColourableSquare_Data ColourableSquare_Data;
13
14void _colourablesquare_size_constructor(Eo *obj, ColourableSquare_Data *self, int size);
15int _colourablesquare_size_get(Eo *obj, ColourableSquare_Data *self);
16void _colourablesquare_size_print(Eo *obj, ColourableSquare_Data *self);
17void _colourablesquare_size_set(Eo *obj, ColourableSquare_Data *self, int size);
18
19#ifdef __cplusplus
20}
21#endif
22
23#endif // EFL_EXAMPLE_EOLIAN_CXX_COLOURABLE_SQUARE_STUB_H
diff --git a/src/examples/eolian_cxx/eolian_cxx_simple_01.cc b/src/examples/eolian_cxx/eolian_cxx_simple_01.cc
index 0a35f93..c64a93c 100644
--- a/src/examples/eolian_cxx/eolian_cxx_simple_01.cc
+++ b/src/examples/eolian_cxx/eolian_cxx_simple_01.cc
@@ -22,7 +22,7 @@ main()
22 obj1.colour_set(0xc0ffee); 22 obj1.colour_set(0xc0ffee);
23 obj1.composite_colour_get(&r, &g, &b); 23 obj1.composite_colour_get(&r, &g, &b);
24 24
25 ::colourablesquare obj2(0x123456); 25 ::colourablesquare obj2(10);
26 obj2.composite_colour_set(r, g, b); 26 obj2.composite_colour_set(r, g, b);
27 obj2.size_set(11); 27 obj2.size_set(11);
28 assert(obj1.colour_get() == obj2.colour_get()); 28 assert(obj1.colour_get() == obj2.colour_get());
diff --git a/src/examples/eolian_cxx/eolian_cxx_simple_01_cxx_impl.cc b/src/examples/eolian_cxx/eolian_cxx_simple_01_cxx_impl.cc
new file mode 100644
index 0000000..0a35f93
--- /dev/null
+++ b/src/examples/eolian_cxx/eolian_cxx_simple_01_cxx_impl.cc
@@ -0,0 +1,36 @@
1// EINA_LOG_LEVELS=colourable:4,colourablesquare:4 ./eolian_cxx_simple_01
2
3#include <iostream>
4#include <cassert>
5
6#ifdef HAVE_CONFIG_H
7# include <config.h>
8#endif
9
10#include "colourable.eo.hh"
11#include "colourablesquare.eo.hh"
12
13int
14main()
15{
16 efl::eo::eo_init init;
17 eina_log_domain_level_set("colourable", EINA_LOG_LEVEL_DBG);
18 eina_log_domain_level_set("colourablesquare", EINA_LOG_LEVEL_DBG);
19
20 int r, g, b;
21 ::colourable obj1(0x123456);
22 obj1.colour_set(0xc0ffee);
23 obj1.composite_colour_get(&r, &g, &b);
24
25 ::colourablesquare obj2(0x123456);
26 obj2.composite_colour_set(r, g, b);
27 obj2.size_set(11);
28 assert(obj1.colour_get() == obj2.colour_get());
29
30 efl::eo::wref<::colourable> ref = obj1;
31 efl::eina::optional<::colourable> obj3 = ref.lock();
32 assert(obj3);
33 obj3->colour_set(0x00);
34
35 return 0;
36}