cxx: Add define EFL_CXXPERIMENTAL for testing
authorJean-Philippe Andre <jp.andre@samsung.com>
Wed, 22 Nov 2017 08:17:04 +0000 (17:17 +0900)
committerJean-Philippe Andre <jp.andre@samsung.com>
Tue, 5 Dec 2017 01:14:03 +0000 (10:14 +0900)
I'll hide some controversial features behind this, until we come to an
agreement with @felipealmeida and people who actually know C++ (iow: not
just me^^).

Features protected:
 - easy wref (using -> without locking)
 - xxx_event_cb_add() functions in object classes
 - instantiate(obj) to create a new object
 - add as a synonym for instantiate (both in efl::eo)

src/bindings/cxx/eo_cxx/eo_concrete.hh
src/bindings/cxx/eo_cxx/eo_wref.hh
src/examples/elementary/bg_cxx_example_02.cc
src/examples/elementary/button_cxx_example_00.cc
src/examples/elementary/button_cxx_example_01.cc
src/examples/elementary/calendar_cxx_example_02.cc
src/examples/elementary/radio_cxx_example_01.cc
src/lib/eolian_cxx/grammar/class_definition.hpp

index adc3398..47013dc 100644 (file)
@@ -32,6 +32,7 @@ namespace efl { namespace eo {
 /// @{
 
 struct instantiate_t {
+#ifdef EFL_CXXPERIMENTAL
    /// @brief A helper to create objects with a different syntax
    ///
    /// @param obj The object to instantiate
@@ -49,6 +50,7 @@ struct instantiate_t {
       obj = T(*this);
       return obj;
    }
+#endif
 };
 
 /// @brief The handle to use to create real EFL objects
@@ -57,6 +59,10 @@ struct instantiate_t {
 /// to trigger a real EFL object creation. The following syntax is preferred:
 ///   T obj(instantiate, ...);
 instantiate_t const instantiate = {};
+
+#ifdef EFL_CXXPERIMENTAL
+instantiate_t const add = {};
+#endif
     
 /// @brief Creates concrete versions for <em>Eo</em> wrappers.
 ///
index e28409c..aed6d69 100644 (file)
@@ -123,7 +123,7 @@ struct wref
       return *this;
    }
 
-#ifdef EFL_CXX_WREF_EASY
+#ifdef EFL_CXXPERIMENTAL
    T operator->() const {
       if (!_eo_wref) return T(nullptr);
       return T(detail::ref(_eo_wref));
index 34016b6..8ef33a8 100644 (file)
@@ -5,6 +5,8 @@
  * ./bg_cxx_example_02
  */
 
+#define EFL_CXXPERIMENTAL
+
 #include <Elementary.hh>
 
 #include <sstream>
@@ -16,7 +18,7 @@ efl::ui::Win win;
 EAPI_MAIN void
 efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
 {
-   instantiate(win);
+   win = efl::ui::Win(instantiate);
    ::efl_ref(win._eo_ptr()); // FIXME: Window is doing BAD THINGSā„¢!
    win.text_set("Bg Image");
    win.autohide_set(true);
index 5e899e1..d44f18a 100644 (file)
@@ -1,6 +1,6 @@
 // g++ -g `pkg-config --cflags --libs elementary-cxx efl-cxx eina-cxx eo-cxx ecore-cxx evas-cxx edje-cxx` button_cxx_example_00.cc -o button_cxx_example_00
 
-#define EFL_CXX_WREF_EASY
+#define EFL_CXXPERIMENTAL
 #include <Elementary.hh>
 #include <iostream>
 
index e6b5147..7de67d3 100644 (file)
@@ -1,6 +1,6 @@
 // g++ -g `pkg-config --cflags --libs elementary-cxx efl-cxx eina-cxx eo-cxx ecore-cxx evas-cxx edje-cxx` button_cxx_example_01.cc -o button_cxx_example_01
 
-#define EFL_CXX_WREF_EASY
+#define EFL_CXXPERIMENTAL
 #include <Elementary.hh>
 
 using efl::eo::instantiate;
index d6cb766..fd001f7 100644 (file)
@@ -1,9 +1,9 @@
-#define EFL_CXX_WREF_EASY
+#define EFL_CXXPERIMENTAL
 
 #include <Elementary.hh>
 
-using efl::eo::instantiate;
 using namespace std::placeholders;
+using efl::eo::add;
 
 struct appData
 {
@@ -16,11 +16,11 @@ struct appData
    void create() {
       std::cout << "Hello!" << std::endl;
 
-      instantiate(m_win);
+      add(m_win);
       m_win.text_set("Calendar Layout Formatting Example");
       m_win.delete_request_event_cb_add([&](){ destroy(); });
 
-      efl::ui::Calendar cal(instantiate, m_win);
+      efl::ui::Calendar cal(add, m_win);
       m_win.content_set(cal);
 
       auto wcal(cal._get_wref());
index 7150794..6fb410c 100644 (file)
@@ -1,6 +1,6 @@
 // g++ -g `pkg-config --cflags --libs elementary-cxx efl-cxx eina-cxx eo-cxx ecore-cxx evas-cxx edje-cxx` radio_cxx_example_01.cc -o radio_cxx_example_01
 
-#define EFL_CXX_WREF_EASY
+#define EFL_CXXPERIMENTAL
 #include <Elementary.hh>
 #include <iostream>
 
index 295662f..d5810da 100644 (file)
@@ -156,6 +156,10 @@ struct class_definition_generator
                 << scope_tab << "} const " << string_replace(',', '_') << "_event;\n"
              ))).generate(sink, std::vector<attributes::event_def>{e}, context))
             return false;
+
+          /* EXPERIMENTAL: event_cb_add */
+          if (!as_generator("#ifdef EFL_CXXPERIMENTAL\n").generate(sink, attributes::unused, context))
+            return false;
           if (!as_generator(
                  scope_tab << "template <typename F>\n"
                  << scope_tab << "typename std::enable_if<std::is_bind_expression<F>::value, ::efl::eolian::signal_connection>::type\n"
@@ -174,6 +178,9 @@ struct class_definition_generator
                  << scope_tab << "}\n")
               .generate(sink, std::make_tuple(e.name, e.name), context))
             return false;
+          if (!as_generator("#endif\n").generate(sink, attributes::unused, context))
+            return false;
+
           if (e.beta && !as_generator("#endif\n").generate(sink, attributes::unused, context))
             return false;
           if (e.protect && !as_generator("#endif\n").generate(sink, attributes::unused, context))
@@ -192,12 +199,13 @@ struct class_definition_generator
                          "return ::efl::eo::wref<" << string << ">(*this); }\n"
                      ).generate(sink, std::make_tuple(cls.cxx_name, cls.cxx_name), context)) return false;
 
-     if(!as_generator("#ifdef EFL_CXX_WREF_EASY\n").generate(sink, attributes::unused, context)) return false;
+     // EXPERIMENTAL
+     if(!as_generator("#ifdef EFL_CXXPERIMENTAL\n").generate(sink, attributes::unused, context)) return false;
      if(!as_generator(   scope_tab << "const " << string << "* operator->() const { return this; }\n"
                      ).generate(sink, std::make_tuple(cls.cxx_name, cls.cxx_name), context)) return false;
      if(!as_generator(   scope_tab << string << "* operator->() { return this; }\n"
                      ).generate(sink, std::make_tuple(cls.cxx_name, cls.cxx_name), context)) return false;
-          if(!as_generator("#endif \n").generate(sink, attributes::unused, context)) return false;
+     if(!as_generator("#endif \n").generate(sink, attributes::unused, context)) return false;
 
      if(!as_generator(   scope_tab << "::efl::eo::concrete const& _get_concrete() const { return *this; }\n"
                       << scope_tab << "::efl::eo::concrete& _get_concrete() { return *this; }\n"