eolian-cxx: Added example of Eo implementation in C++.
authorSavio Sena <savio@expertisesolutions.com.br>
Thu, 24 Jul 2014 19:47:35 +0000 (16:47 -0300)
committerSavio Sena <savio@expertisesolutions.com.br>
Thu, 24 Jul 2014 22:52:23 +0000 (19:52 -0300)
Instead of implementing Eo functions in C we do it in C++ simply.

src/examples/eolian_cxx/Makefile.am
src/examples/eolian_cxx/colourable.c
src/examples/eolian_cxx/colourable_cxx.cc [new file with mode: 0644]
src/examples/eolian_cxx/colourable_stub.c [new file with mode: 0644]
src/examples/eolian_cxx/colourable_stub.h [new file with mode: 0644]
src/examples/eolian_cxx/colourablesquare.c
src/examples/eolian_cxx/colourablesquare_cxx.cc [new file with mode: 0644]
src/examples/eolian_cxx/colourablesquare_stub.c [new file with mode: 0644]
src/examples/eolian_cxx/colourablesquare_stub.h [new file with mode: 0644]
src/examples/eolian_cxx/eolian_cxx_simple_01.cc
src/examples/eolian_cxx/eolian_cxx_simple_01_cxx_impl.cc [new file with mode: 0644]

index a163522..bfd8134 100644 (file)
@@ -74,7 +74,11 @@ EOS = \
 
 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 \
@@ -86,6 +90,7 @@ SRCS = \
 
 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 \
@@ -99,6 +104,14 @@ eolian_cxx_simple_01_SOURCES = \
        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 \
index 9bbcce2..5b33566 100644 (file)
@@ -17,16 +17,6 @@ static int _colourable_impl_logdomain;
 #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;
@@ -36,9 +26,6 @@ struct _Colourable_Data
 
 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)
 {
diff --git a/src/examples/eolian_cxx/colourable_cxx.cc b/src/examples/eolian_cxx/colourable_cxx.cc
new file mode 100644 (file)
index 0000000..8de02aa
--- /dev/null
@@ -0,0 +1,122 @@
+
+#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;
+}
+
diff --git a/src/examples/eolian_cxx/colourable_stub.c b/src/examples/eolian_cxx/colourable_stub.c
new file mode 100644 (file)
index 0000000..a427cc5
--- /dev/null
@@ -0,0 +1,12 @@
+#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"
diff --git a/src/examples/eolian_cxx/colourable_stub.h b/src/examples/eolian_cxx/colourable_stub.h
new file mode 100644 (file)
index 0000000..fbf913f
--- /dev/null
@@ -0,0 +1,31 @@
+#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
index 9ed046a..87bc419 100644 (file)
@@ -18,26 +18,12 @@ static int _colourablesquare_impl_logdomain;
 #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)
 {
diff --git a/src/examples/eolian_cxx/colourablesquare_cxx.cc b/src/examples/eolian_cxx/colourablesquare_cxx.cc
new file mode 100644 (file)
index 0000000..b98df67
--- /dev/null
@@ -0,0 +1,49 @@
+
+#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;
+}
+
diff --git a/src/examples/eolian_cxx/colourablesquare_stub.c b/src/examples/eolian_cxx/colourablesquare_stub.c
new file mode 100644 (file)
index 0000000..276130c
--- /dev/null
@@ -0,0 +1,12 @@
+#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"
diff --git a/src/examples/eolian_cxx/colourablesquare_stub.h b/src/examples/eolian_cxx/colourablesquare_stub.h
new file mode 100644 (file)
index 0000000..b653fe3
--- /dev/null
@@ -0,0 +1,23 @@
+#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
index 0a35f93..c64a93c 100644 (file)
@@ -22,7 +22,7 @@ main()
    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());
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 (file)
index 0000000..0a35f93
--- /dev/null
@@ -0,0 +1,36 @@
+// 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;
+}