summaryrefslogtreecommitdiff
path: root/src/bin/eolian_cxx
diff options
context:
space:
mode:
authorVitor Sousa <vitorsousasilva@gmail.com>2015-01-06 15:39:44 -0200
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2015-04-14 01:06:57 -0300
commit9eb19f8852faf1b5cc7d64bd28eefb9307c78baf (patch)
tree7d89c52dfe77a22e07e635ab5f1bd136b267cf73 /src/bin/eolian_cxx
parent4b950b55c08d220d9b26d4a5a479d11ca4ea3e9b (diff)
eolian_cxx: Declaring all inherited events on the concrete C++ wrapper
Added declaration of all inherited events on the concrete type to avoid unnecessary type conversion on event callbacks. Note that when two events happens to have the same name, only the event of the derived class is declared in the concrete class. Access to such events should be made through the base class type specification. Fix on forwarding callback object (changed std::move to std::forward). Additional line break at the end of event handling methods in the generated headers to improve readability.
Diffstat (limited to 'src/bin/eolian_cxx')
-rw-r--r--src/bin/eolian_cxx/convert.cc56
1 files changed, 54 insertions, 2 deletions
diff --git a/src/bin/eolian_cxx/convert.cc b/src/bin/eolian_cxx/convert.cc
index fab4c1608c..d029999411 100644
--- a/src/bin/eolian_cxx/convert.cc
+++ b/src/bin/eolian_cxx/convert.cc
@@ -1,6 +1,7 @@
1 1
2#include <vector> 2#include <vector>
3#include <set> 3#include <set>
4#include <map>
4#include <algorithm> 5#include <algorithm>
5#include <cassert> 6#include <cassert>
6#include <cstddef> 7#include <cstddef>
@@ -22,6 +23,7 @@
22namespace eolian_cxx { 23namespace eolian_cxx {
23 24
24extern efl::eina::log_domain domain; 25extern efl::eina::log_domain domain;
26typedef std::map<efl::eolian::eo_event, bool> event_map;
25 27
26void 28void
27add_ancestor_recursive(const char* klass_name, std::set<std::string>& ancestor) 29add_ancestor_recursive(const char* klass_name, std::set<std::string>& ancestor)
@@ -48,6 +50,40 @@ add_ancestor_recursive(const char* klass_name, std::set<std::string>& ancestor)
48 eina_iterator_free(inheritances); 50 eina_iterator_free(inheritances);
49} 51}
50 52
53void
54add_events_recursive(event_map& events, Eolian_Class const& klass, std::set<std::string>& ancestors)
55{
56 for (efl::eolian::eo_event const& e : event_list(klass))
57 {
58 auto it = events.find(e);
59 if (it == events.end())
60 events[e] = true;
61 else
62 it->second = false;
63 }
64
65 Eina_Iterator* inheritances = ::eolian_class_inherits_get(&klass);
66 void* curr = 0;
67
68 EINA_ITERATOR_FOREACH(inheritances, curr)
69 {
70 const char* ancestor_name = static_cast<const char*>(curr);
71 if (!ancestor_name || ancestors.find(ancestor_name) != ancestors.end())
72 continue;
73
74 Eolian_Class const* ancestor_klass = ::eolian_class_get_by_name(ancestor_name);
75 if (!ancestor_klass)
76 {
77 std::cerr << "Error: could not get eolian class name `" << ancestor_name << "'" << std::endl;
78 continue;
79 }
80 ancestors.insert(ancestor_name);
81 add_events_recursive(events, *ancestor_klass, ancestors);
82 }
83
84 eina_iterator_free(inheritances);
85}
86
51static efl::eolian::parameters_container_type 87static efl::eolian::parameters_container_type
52_convert_eolian_parameters(Eina_Iterator *parameters, 88_convert_eolian_parameters(Eina_Iterator *parameters,
53 Eolian_Function_Type func_type) 89 Eolian_Function_Type func_type)
@@ -199,8 +235,24 @@ void
199convert_eolian_events(efl::eolian::eo_class& cls, Eolian_Class const& klass) 235convert_eolian_events(efl::eolian::eo_class& cls, Eolian_Class const& klass)
200{ 236{
201 efl::eolian::events_container_type events = event_list(klass); 237 efl::eolian::events_container_type events = event_list(klass);
202 cls.events.reserve(cls.events.size() + events.size()); 238 cls.own_events.reserve(cls.own_events.size() + events.size());
203 cls.events.insert(cls.events.end(), events.begin(), events.end()); 239 cls.own_events.insert(cls.own_events.end(), events.begin(), events.end());
240
241 event_map concrete_events;
242 std::set<std::string> ancestors;
243
244 add_events_recursive(concrete_events, klass, ancestors);
245
246 for (auto const& e : events)
247 {
248 concrete_events[e] = true;
249 }
250
251 for (auto const& pair : concrete_events)
252 {
253 if (pair.second)
254 cls.concrete_events.push_back(pair.first);
255 }
204} 256}
205 257
206efl::eolian::eo_class 258efl::eolian::eo_class