From 057e01d67fdcbb715580a4e34af52f09de4e0e29 Mon Sep 17 00:00:00 2001 From: Daniel Kolesa Date: Wed, 13 Aug 2014 12:06:48 +0100 Subject: [PATCH] eolian: API refactoring Start getting rid of the terrible _information_get APIs, starting with events. --- src/bin/eolian/eo_generator.c | 13 ++++------- src/bin/eolian_cxx/eolian_wrappers.hh | 6 ++--- src/lib/eolian/Eolian.h | 33 ++++++++++++++++++++------- src/lib/eolian/database_event_api.c | 27 +++++++++++++++------- src/lib/eolian/database_print.c | 10 ++++---- 5 files changed, 56 insertions(+), 33 deletions(-) diff --git a/src/bin/eolian/eo_generator.c b/src/bin/eolian/eo_generator.c index 505072ef77..3e34e24bf0 100644 --- a/src/bin/eolian/eo_generator.c +++ b/src/bin/eolian/eo_generator.c @@ -275,9 +275,8 @@ eo_header_generate(const Eolian_Class *class, Eina_Strbuf *buf) itr = eolian_class_events_get(class); EINA_ITERATOR_FOREACH(itr, event) { - const char *evname = NULL; - const char *evdesc = NULL; - eolian_class_event_information_get(event, &evname, NULL, &evdesc); + const char *evname = eolian_event_name_get(event); + const char *evdesc = eolian_event_description_get(event); if (!evdesc) evdesc = "No description"; eina_strbuf_reset(tmpbuf); @@ -556,13 +555,12 @@ eo_source_beginning_generate(const Eolian_Class *class, Eina_Strbuf *buf) itr = eolian_class_events_get(class); EINA_ITERATOR_FOREACH(itr, event) { - const char *evname; - const char *evdesc; + const char *evname = eolian_event_name_get(event); + const char *evdesc = eolian_event_description_get(event); char *evdesc_line1; char *p; eina_strbuf_reset(str_ev); - eolian_class_event_information_get(event, &evname, NULL, &evdesc); evdesc_line1 = _source_desc_get(evdesc); eina_strbuf_append_printf(str_ev, "%s_EVENT_%s", class_env.upper_classname, evname); p = (char *)eina_strbuf_string_get(str_ev); @@ -776,11 +774,10 @@ eo_source_end_generate(const Eolian_Class *class, Eina_Strbuf *buf) itr = eolian_class_events_get(class); EINA_ITERATOR_FOREACH(itr, event) { - const char *evname; + const char *evname = eolian_event_name_get(event); char *p; eina_strbuf_reset(tmpbuf); - eolian_class_event_information_get(event, &evname, NULL, NULL); eina_strbuf_append_printf(tmpbuf, "%s_EVENT_%s", class_env.upper_classname, evname); p = (char *)eina_strbuf_string_get(tmpbuf); eina_str_toupper(&p); diff --git a/src/bin/eolian_cxx/eolian_wrappers.hh b/src/bin/eolian_cxx/eolian_wrappers.hh index 6269f37fef..7f10b49e0d 100644 --- a/src/bin/eolian_cxx/eolian_wrappers.hh +++ b/src/bin/eolian_cxx/eolian_wrappers.hh @@ -351,8 +351,8 @@ inline efl::eolian::eo_event event_create(Eolian_Class const& klass, const Eolian_Event *event_) { efl::eolian::eo_event event; - const char *name, *comment; - if(::eolian_class_event_information_get(event_, &name, NULL, &comment)) + const char *name = ::eolian_event_name_get(event_); + if (name) { std::string name_ = safe_str(name); std::transform(name_.begin(), name_.end(), name_.begin(), @@ -360,7 +360,7 @@ event_create(Eolian_Class const& klass, const Eolian_Event *event_) event.name = normalize_spaces(name_); event.eo_name = safe_upper (find_replace(class_full_name(klass), ".", "_") + "_EVENT_" + event.name); - event.comment = safe_str(comment); + event.comment = safe_str(eolian_event_description_get(event_)); } return event; } diff --git a/src/lib/eolian/Eolian.h b/src/lib/eolian/Eolian.h index e5c72f30e4..c57f3df482 100644 --- a/src/lib/eolian/Eolian.h +++ b/src/lib/eolian/Eolian.h @@ -873,17 +873,34 @@ EAPI Eina_Iterator *eolian_class_implements_get(const Eolian_Class *klass); EAPI Eina_Iterator *eolian_class_events_get(const Eolian_Class *klass); /* - * @brief Get information about an event. + * @brief Get the name of an event. * - * @param[in] event handle of the event - * @param[out] event_name name of the event - * @param[out] event_type type of the event - * @param[out] event_desc description of the event - * @return EINA_TRUE on success, EINA_FALSE otherwise. + * @param[in] event the event handle + * @return the name or NULL + * + * @ingroup Eolian + */ +EAPI Eina_Stringshare *eolian_event_name_get(const Eolian_Event *event); + +/* + * @brief Get the type of an event. + * + * @param[in] event the event handle + * @return the type or NULL + * + * @ingroup Eolian + */ +EAPI Eolian_Type *eolian_event_type_get(const Eolian_Event *event); + +/* + * @brief Get the description of an event. + * + * @param[in] event the event handle + * @return the description or NULL * * @ingroup Eolian */ -EAPI Eina_Bool eolian_class_event_information_get(const Eolian_Event *event, const char **event_name, const Eolian_Type **event_type, const char **event_desc); +EAPI Eina_Stringshare *eolian_event_description_get(const Eolian_Event *event); /* * @brief Returns the scope of an event @@ -893,7 +910,7 @@ EAPI Eina_Bool eolian_class_event_information_get(const Eolian_Event *event, con * * @ingroup Eolian */ -EAPI Eolian_Object_Scope eolian_class_event_scope_get(const Eolian_Event *event); +EAPI Eolian_Object_Scope eolian_event_scope_get(const Eolian_Event *event); /* * @brief Indicates if the class constructor has to invoke diff --git a/src/lib/eolian/database_event_api.c b/src/lib/eolian/database_event_api.c index 877932e1f8..29169786cf 100644 --- a/src/lib/eolian/database_event_api.c +++ b/src/lib/eolian/database_event_api.c @@ -1,18 +1,29 @@ #include #include "eolian_database.h" -EAPI Eina_Bool -eolian_class_event_information_get(const Eolian_Event *event, const char **event_name, const Eolian_Type **event_type, const char **event_comment) +EAPI Eina_Stringshare * +eolian_event_name_get(const Eolian_Event *event) { - EINA_SAFETY_ON_NULL_RETURN_VAL(event, EINA_FALSE); - if (event_name) *event_name = event->name; - if (event_type) *event_type = event->type; - if (event_comment) *event_comment = event->comment; - return EINA_TRUE; + EINA_SAFETY_ON_NULL_RETURN_VAL(event, NULL); + return event->name; +} + +EAPI Eolian_Type * +eolian_event_type_get(const Eolian_Event *event) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(event, NULL); + return event->type; +} + +EAPI Eina_Stringshare * +eolian_event_description_get(const Eolian_Event *event) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(event, NULL); + return event->comment; } EAPI Eolian_Object_Scope -eolian_class_event_scope_get(const Eolian_Event *event) +eolian_event_scope_get(const Eolian_Event *event) { EINA_SAFETY_ON_NULL_RETURN_VAL(event, EOLIAN_SCOPE_PUBLIC); return event->scope; diff --git a/src/lib/eolian/database_print.c b/src/lib/eolian/database_print.c index 7b110d8e65..8addd8d746 100644 --- a/src/lib/eolian/database_print.c +++ b/src/lib/eolian/database_print.c @@ -29,13 +29,11 @@ _implements_print(Eolian_Implement *impl, int nb_spaces) static void _event_print(Eolian_Event *ev, int nb_spaces) { - const char *name, *comment; - const Eolian_Type *type; - - eolian_class_event_information_get(ev, &name, &type, &comment); - printf("%*s <%s> <", nb_spaces + 5, "", name); + const Eolian_Type *type = eolian_event_type_get(ev); + const char *desc = eolian_event_description_get(ev); + printf("%*s <%s> <", nb_spaces + 5, "", eolian_event_name_get(ev)); if (type) database_type_print((Eolian_Type*)type); - printf("> <%s>\n", comment); + printf("> <%s>\n", desc ? desc : ""); } static Eina_Bool _function_print(const Eolian_Function *fid, int nb_spaces) -- 2.34.1