From 2c5ec0b132222131306514d578b6f604c00b61b1 Mon Sep 17 00:00:00 2001 From: Daniel Zaoui Date: Tue, 28 Apr 2015 14:27:01 +0300 Subject: [PATCH] Eolian: Add API to retrieve an event of a class by its name @feature --- src/lib/eolian/Eolian.h | 11 +++++++++++ src/lib/eolian/database_event_api.c | 20 ++++++++++++++++++++ src/tests/eolian/eolian_parsing.c | 3 +++ 3 files changed, 34 insertions(+) diff --git a/src/lib/eolian/Eolian.h b/src/lib/eolian/Eolian.h index d231782c81..d8c5e90965 100644 --- a/src/lib/eolian/Eolian.h +++ b/src/lib/eolian/Eolian.h @@ -1328,6 +1328,17 @@ EAPI Eolian_Object_Scope eolian_event_scope_get(const Eolian_Event *event); */ EAPI Eina_Stringshare *eolian_event_c_name_get(const Eolian_Event *event); +/* + * @brief Get an event in a class by its name + * + * @param[in] klass the class + * @param[in] event_name name of the event + * @return the Eolian_Event if found, NULL otherwise. + * + * @ingroup Eolian + */ +EAPI const Eolian_Event *eolian_class_event_get_by_name(const Eolian_Class *klass, const char *event_name); + /* * @brief Indicates if the class constructor has to invoke * a non-generated class constructor function. diff --git a/src/lib/eolian/database_event_api.c b/src/lib/eolian/database_event_api.c index f2c98a7133..0a6b22dcff 100644 --- a/src/lib/eolian/database_event_api.c +++ b/src/lib/eolian/database_event_api.c @@ -44,3 +44,23 @@ eolian_event_c_name_get(const Eolian_Event *event) while ((tmp = strpbrk(tmp, ".,"))) *tmp = '_'; return eina_stringshare_add(buf); } + +EAPI const Eolian_Event * +eolian_class_event_get_by_name(const Eolian_Class *klass, const char *event_name) +{ + Eina_List *itr; + Eolian_Event *event = NULL; + if (!klass) return NULL; + Eina_Stringshare *shr_ev = eina_stringshare_add(event_name); + + EINA_LIST_FOREACH(klass->events, itr, event) + { + if (event->name == shr_ev) + goto end; + } + + event = NULL; +end: + eina_stringshare_del(shr_ev); + return event; +} diff --git a/src/tests/eolian/eolian_parsing.c b/src/tests/eolian/eolian_parsing.c index f61434635c..8269c2c68e 100644 --- a/src/tests/eolian/eolian_parsing.c +++ b/src/tests/eolian/eolian_parsing.c @@ -129,6 +129,9 @@ START_TEST(eolian_events) fail_if(strcmp(type_name, "Evas_Event_Clicked_Double_Info")); fail_if(eina_iterator_next(iter, &dummy)); eina_iterator_free(iter); + /* Check eolian_class_event_get_by_name */ + fail_if(!eolian_class_event_get_by_name(class, "clicked,double")); + fail_if(eolian_class_event_get_by_name(class, "clicked,triple")); eolian_shutdown(); } -- 2.34.1