summaryrefslogtreecommitdiff
path: root/src/examples/eolian_cxx/colourable.c
diff options
context:
space:
mode:
authorSavio Sena <savio@expertisesolutions.com.br>2014-05-03 00:55:51 +0200
committerCedric Bail <cedric.bail@free.fr>2014-05-03 00:56:32 +0200
commit46b6e8a563bd429690e7bffba4e98d06aa40798d (patch)
treeb7a2aebfc32bcc6d7a2600072a00d69a9f68d9a1 /src/examples/eolian_cxx/colourable.c
parent64c6c63725d96f03baf34b660ca71e13b29078c1 (diff)
eolian_cxx: initial version of the EFL C++ Bindings Generator.
Summary: This patch adds 'eolian_cxx' -- a C++ bindings generator -- to the EFL tree. Eolian Cxx uses Eolian API to read .eo files and generate .eo.hh. It relies/depends on Eo Cxx and Eina Cxx (both non-generated bindings). src/bin/eolian_cxx: The eolian_cxx program. src/lib/eolian_cxx: A header-only library that implements the C++ code generation that binds the .eo classes. =Examples= src/examples/eolian_cxx/eolian_cxx_simple_01.cc: The simplest example, it just uses some "dummy" generated C++ classes. src/examples/eolian_cxx/eolian_cxx_inherit_01.cc: Illustrates how pure C++ classes inherit from .eo generated classes. src/examples/evas/evas_cxx_rectangle.cc: More realistic example using the generated bindings Evas Cxx. Still a bit shallow because we don't have full fledged .eo descriptions yet, but will be improved. =Important= The generated code is not supported and not a stable API/ABI. It is here to gather people interest and get review before we set things in stone for release 1.11. @feature Reviewers: cedric, smohanty, raster, stefan_schmidt CC: felipealmeida, JackDanielZ, cedric, stefan Differential Revision: https://phab.enlightenment.org/D805 Signed-off-by: Cedric Bail <cedric.bail@free.fr>
Diffstat (limited to 'src/examples/eolian_cxx/colourable.c')
-rw-r--r--src/examples/eolian_cxx/colourable.c165
1 files changed, 165 insertions, 0 deletions
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"