Instead of implementing Eo functions in C we do it in C++ simply.
IMPL = \
colourable.c \
- colourablesquare.c
+ colourable_cxx.cc \
+ colourablesquare.c \
+ colourablesquare_cxx.cc \
+ colourable_stub.c \
+ colourablesquare_stub.c
SRCS = \
eolian_cxx_simple_01.cc \
EXTRA_PROGRAMS = \
eolian_cxx_simple_01 \
+ eolian_cxx_simple_01_cxx_impl \
eolian_cxx_inherit_01 \
eolian_cxx_callbacks_01 \
eolian_cxx_eo_events_01 \
colourablesquare.c
eolian_cxx_simple_01.$(OBJEXT): $(GENERATED)
+eolian_cxx_simple_01_cxx_impl_SOURCES = \
+ eolian_cxx_simple_01.cc \
+ colourable_stub.c \
+ colourablesquare_stub.c \
+ colourable_cxx.cc \
+ colourablesquare_cxx.cc
+eolian_cxx_simple_01_cxx_impl.$(OBJEXT): $(GENERATED)
+
eolian_cxx_inherit_01_SOURCES = \
eolian_cxx_inherit_01.cc \
colourable.c \
#endif
#define DBG(...) EINA_LOG_DOM_DBG(_colourable_impl_logdomain, __VA_ARGS__)
-#ifdef INFO
-#undef INFO
-#endif
-#define INFO(...) EINA_LOG_DOM_INFO(_colourable_impl_logdomain, __VA_ARGS__)
-
-#ifdef ERR
-#undef ERR
-#endif
-#define ERR(...) EINA_LOG_DOM_ERR(_colourable_impl_logdomain, __VA_ARGS__)
-
struct _Colourable_Data
{
int r;
typedef struct _Colourable_Data Colourable_Data;
-#define COLOURABLE_DATA_GET(o, wd) \
- Colourable_Data *wd = eo_data_scope_get(o, MY_CLASS)
-
void
_colourable_constructor(Eo *obj, Colourable_Data *self EINA_UNUSED)
{
--- /dev/null
+
+#include <iostream>
+#include <iomanip>
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "Eo.hh"
+#include "Eina.hh"
+
+extern "C"
+{
+#include "colourable_stub.h"
+#include "colourable.eo.h"
+}
+
+#define MY_CLASS COLOURABLE_CLASS
+
+static efl::eina::log_domain domain("colourable");
+
+void
+_colourable_constructor(Eo *obj, Colourable_Data *self)
+{
+ EINA_CXX_DOM_LOG_DBG(domain) << __func__ << std::endl;
+ self->r = self->g = self->b = 0;
+ eo_do_super(obj, MY_CLASS, eo_constructor());
+}
+
+void
+_colourable_destructor(Eo *obj, Colourable_Data *self EINA_UNUSED)
+{
+ EINA_CXX_DOM_LOG_DBG(domain) << __func__ << std::endl;
+ eo_do_super(obj, MY_CLASS, eo_destructor());
+}
+
+void
+_colourable_rgb_composite_constructor(Eo *obj, Colourable_Data *self, int r, int g, int b)
+{
+ EINA_CXX_DOM_LOG_DBG(domain) << std::showbase << std::hex
+ << __func__ << " [ (r, g, b) = ("
+ << r << ", " << g << ", " << b << ") ]" << std::endl;
+ self->r = r;
+ self->g = g;
+ self->b = b;
+ eo_do_super(obj, MY_CLASS, eo_constructor());
+}
+
+void
+_colourable_rgb_24bits_constructor(Eo *obj, Colourable_Data *self, int rgb)
+{
+ EINA_CXX_DOM_LOG_DBG(domain) << std::showbase << std::hex
+ << __func__ << " [ rgb = " << rgb <<" ]" << std::endl;
+ self->r = (rgb & 0x00ff0000) >> 16;
+ self->g = (rgb & 0x0000ff00) >> 8;
+ self->b = rgb & 0x000000ff;
+ eo_do_super(obj, MY_CLASS, eo_constructor());
+}
+
+void
+_colourable_print_colour(Eo *obj EINA_UNUSED, Colourable_Data *self EINA_UNUSED)
+{
+ EINA_CXX_DOM_LOG_DBG(domain) << __func__ << std::endl;
+}
+
+int
+_colourable_colour_mask(Eo *obj EINA_UNUSED, Colourable_Data *self, int mask)
+{
+ int masked_rgb =
+ (((self->r << 16)& 0x00ff0000) |
+ ((self->g << 8) & 0x0000ff00) |
+ (self->b & 0x000000ff)) & mask;
+ EINA_CXX_DOM_LOG_DBG(domain) << std::showbase << std::hex
+ << __func__ << " [ mask = " << masked_rgb << " ]" << std::endl;
+ return masked_rgb;
+}
+
+void
+_colourable_composite_colour_get(Eo *obj EINA_UNUSED, Colourable_Data *self, int* r, int* g, int* b)
+{
+ *r = self->r;
+ *g = self->g;
+ *b = self->b;
+ EINA_CXX_DOM_LOG_DBG(domain) << std::showbase << std::hex
+ << __func__ << " [ (r, g, b) = (" << *r << ", " << *g << ", " << *b << ") ]" << std::endl;
+ return;
+}
+
+void
+_colourable_composite_colour_set(Eo *obj EINA_UNUSED, Colourable_Data *self, int r, int g, int b)
+{
+ EINA_CXX_DOM_LOG_DBG(domain) << std::showbase << std::hex
+ << __func__ << " [ (r, g, b) = (" << r << ", " << g << ", " << b << ") ]" << std::endl;
+ self->r = r;
+ self->g = g;
+ self->b = b;
+ return;
+}
+
+int
+_colourable_colour_get(Eo *obj EINA_UNUSED, Colourable_Data *self)
+{
+ int rgb =
+ ((self->r << 16)& 0x00ff0000) |
+ ((self->g << 8) & 0x0000ff00) |
+ (self->b & 0x000000ff);
+ EINA_CXX_DOM_LOG_DBG(domain) << std::showbase << std::hex
+ << __func__ << " [ rgb = " << rgb <<" ]" << std::endl;
+ return rgb;
+}
+
+void
+_colourable_colour_set(Eo *obj EINA_UNUSED, Colourable_Data *self, int rgb)
+{
+ EINA_CXX_DOM_LOG_DBG(domain) << std::showbase << std::hex
+ << __func__ << " [ rgb = " << rgb <<" ]" << std::endl;
+ self->r = (rgb & 0x00ff0000) >> 16;
+ self->g = (rgb & 0x0000ff00) >> 8;
+ self->b = rgb & 0x000000ff;
+ return;
+}
+
--- /dev/null
+#include <stdio.h>
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "Eo.h"
+#include "Eina.h"
+
+#include "colourable_stub.h"
+#include "colourable.eo.h"
+#include "colourable.eo.c"
--- /dev/null
+#ifndef EFL_EXAMPLE_EOLIAN_CXX_COLOURABLE_STUB_H
+#define EFL_EXAMPLE_EOLIAN_CXX_COLOURABLE_STUB_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct _Colourable_Data
+{
+ int r;
+ int g;
+ int b;
+};
+typedef struct _Colourable_Data Colourable_Data;
+
+void _colourable_constructor(Eo *obj, Colourable_Data *self);
+void _colourable_rgb_composite_constructor(Eo *obj, Colourable_Data *self, int r, int g, int b);
+void _colourable_rgb_24bits_constructor(Eo *obj, Colourable_Data *self, int rgb);
+void _colourable_print_colour(Eo *obj, Colourable_Data *self);
+void _colourable_print_colour(Eo *obj, Colourable_Data *self);
+int _colourable_colour_mask(Eo *obj, Colourable_Data *self, int mask);
+void _colourable_composite_colour_get(Eo *obj, Colourable_Data *self, int* r, int* g, int* b);
+void _colourable_composite_colour_set(Eo *obj, Colourable_Data *self, int r, int g, int b);
+int _colourable_colour_get(Eo *obj, Colourable_Data *self);
+void _colourable_colour_set(Eo *obj, Colourable_Data *self, int rgb);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // EFL_EXAMPLE_EOLIAN_CXX_COLOURABLE_STUB_H
#endif
#define DBG(...) EINA_LOG_DOM_DBG(_colourablesquare_impl_logdomain, __VA_ARGS__)
-#ifdef INFO
-#undef INFO
-#endif
-#define INFO(...) EINA_LOG_DOM_INFO(_colourablesquare_impl_logdomain, __VA_ARGS__)
-
-#ifdef ERR
-#undef ERR
-#endif
-#define ERR(...) EINA_LOG_DOM_ERR(_colourablesquare_impl_logdomain, __VA_ARGS__)
-
struct _ColourableSquare_Data
{
int size;
};
-
typedef struct _ColourableSquare_Data ColourableSquare_Data;
-#define COLOURABLESQUARE_DATA_GET(o, wd) \
- ColourableSquare_Data *wd = eo_data_scope_get(o, MY_CLASS)
-
static void
_colourablesquare_size_constructor(Eo *obj, ColourableSquare_Data *self, int size)
{
--- /dev/null
+
+#include <iostream>
+#include <iomanip>
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "Eo.hh"
+#include "Eina.hh"
+
+extern "C"
+{
+#include "colourablesquare_stub.h"
+#include "colourable.eo.h"
+#include "colourablesquare.eo.h"
+}
+
+#define MY_CLASS COLOURABLESQUARE_CLASS
+
+static efl::eina::log_domain domain("colourablesquare");
+
+void
+_colourablesquare_size_constructor(Eo *obj, ColourableSquare_Data *self, int size)
+{
+ self->size = size;
+ EINA_CXX_DOM_LOG_DBG(domain) << __func__ << " [ size = " << size << " ]" << std::endl;
+ eo_do_super(obj, MY_CLASS, eo_constructor());
+}
+
+int
+_colourablesquare_size_get(Eo *obj EINA_UNUSED, ColourableSquare_Data *self)
+{
+ EINA_CXX_DOM_LOG_DBG(domain) << __func__ << " [ size = " << self->size << " ]" << std::endl;
+ return self->size;
+}
+
+void
+_colourablesquare_size_print(Eo *obj EINA_UNUSED, ColourableSquare_Data *self)
+{
+ EINA_CXX_DOM_LOG_DBG(domain) << __func__ << " [ size = " << self->size << " ]" << std::endl;
+}
+
+void
+_colourablesquare_size_set(Eo *obj EINA_UNUSED, ColourableSquare_Data *self EINA_UNUSED, int size)
+{
+ EINA_CXX_DOM_LOG_DBG(domain) << __func__ << " [ size = " << self->size << " ]" << std::endl;
+}
+
--- /dev/null
+#include <stdio.h>
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "Eo.h"
+
+#include "colourablesquare_stub.h"
+#include "colourable.eo.h"
+#include "colourablesquare.eo.h"
+#include "colourablesquare.eo.c"
--- /dev/null
+#ifndef EFL_EXAMPLE_EOLIAN_CXX_COLOURABLE_SQUARE_STUB_H
+#define EFL_EXAMPLE_EOLIAN_CXX_COLOURABLE_SQUARE_STUB_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct _ColourableSquare_Data
+{
+ int size;
+};
+typedef struct _ColourableSquare_Data ColourableSquare_Data;
+
+void _colourablesquare_size_constructor(Eo *obj, ColourableSquare_Data *self, int size);
+int _colourablesquare_size_get(Eo *obj, ColourableSquare_Data *self);
+void _colourablesquare_size_print(Eo *obj, ColourableSquare_Data *self);
+void _colourablesquare_size_set(Eo *obj, ColourableSquare_Data *self, int size);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // EFL_EXAMPLE_EOLIAN_CXX_COLOURABLE_SQUARE_STUB_H
obj1.colour_set(0xc0ffee);
obj1.composite_colour_get(&r, &g, &b);
- ::colourablesquare obj2(0x123456);
+ ::colourablesquare obj2(10);
obj2.composite_colour_set(r, g, b);
obj2.size_set(11);
assert(obj1.colour_get() == obj2.colour_get());
--- /dev/null
+// EINA_LOG_LEVELS=colourable:4,colourablesquare:4 ./eolian_cxx_simple_01
+
+#include <iostream>
+#include <cassert>
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "colourable.eo.hh"
+#include "colourablesquare.eo.hh"
+
+int
+main()
+{
+ efl::eo::eo_init init;
+ eina_log_domain_level_set("colourable", EINA_LOG_LEVEL_DBG);
+ eina_log_domain_level_set("colourablesquare", EINA_LOG_LEVEL_DBG);
+
+ int r, g, b;
+ ::colourable obj1(0x123456);
+ obj1.colour_set(0xc0ffee);
+ obj1.composite_colour_get(&r, &g, &b);
+
+ ::colourablesquare obj2(0x123456);
+ obj2.composite_colour_set(r, g, b);
+ obj2.size_set(11);
+ assert(obj1.colour_get() == obj2.colour_get());
+
+ efl::eo::wref<::colourable> ref = obj1;
+ efl::eina::optional<::colourable> obj3 = ref.lock();
+ assert(obj3);
+ obj3->colour_set(0x00);
+
+ return 0;
+}