diff options
author | Lauro Moura <lauromoura@expertisesolutions.com.br> | 2019-12-10 14:01:26 -0300 |
---|---|---|
committer | Lauro Moura <lauromoura@expertisesolutions.com.br> | 2019-12-10 15:05:43 -0300 |
commit | 271b56889fed170cc05f048e63c44b4e928d7964 (patch) | |
tree | cd11ee951559c7ad1a05daab9f572b5b432d82f3 | |
parent | 4318fe1254c23257fd96224b5d74a71a38330df5 (diff) | |
download | efl-271b56889fed170cc05f048e63c44b4e928d7964.tar.gz |
csharp: Removed duplicated call_match implementations
Summary:
Small refactor. Keep it in a single header that other files could use.
Ref T8515
Reviewers: brunobelo, felipealmeida, jptiz
Reviewed By: jptiz
Subscribers: cedric, #reviewers, #committers
Tags: #efl
Maniphest Tasks: T8515
Differential Revision: https://phab.enlightenment.org/D10852
-rw-r--r-- | src/bin/eolian_mono/eolian/mono/events.hh | 12 | ||||
-rw-r--r-- | src/bin/eolian_mono/eolian/mono/marshall_annotation.hh | 16 | ||||
-rw-r--r-- | src/bin/eolian_mono/eolian/mono/marshall_type_impl.hh | 5 | ||||
-rw-r--r-- | src/bin/eolian_mono/eolian/mono/type_impl.hh | 20 | ||||
-rw-r--r-- | src/bin/eolian_mono/eolian/mono/type_match.hh | 46 |
5 files changed, 63 insertions, 36 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/events.hh b/src/bin/eolian_mono/eolian/mono/events.hh index a4289af559..f0367c31dc 100644 --- a/src/bin/eolian_mono/eolian/mono/events.hh +++ b/src/bin/eolian_mono/eolian/mono/events.hh @@ -18,14 +18,18 @@ #include <iterator> +#include <Eina.hh> + #include "grammar/generator.hpp" #include "grammar/klass_def.hpp" -#include "type_impl.hh" // For call_match +#include "type_match.hh" #include "name_helpers.hh" #include "using_decl.hh" namespace eolian_mono { +namespace eina = efl::eina; + template<typename OutputIterator, typename Context> struct unpack_event_args_visitor { @@ -114,7 +118,7 @@ struct unpack_event_args_visitor return as_generator(conversion).generate(sink, attributes::unused, *context); }; - if (eina::optional<bool> b = call_match(match_table, filter_func, accept_func)) + if (eina::optional<bool> b = type_match::get_match(match_table, filter_func, accept_func)) return *b; else { @@ -188,7 +192,7 @@ struct pack_event_info_and_call_visitor ).generate(sink, attributes::unused, *context); }; - if (eina::optional<bool> b = call_match(str_table, filter_func, str_accept_func)) + if (eina::optional<bool> b = type_match::get_match(str_table, filter_func, str_accept_func)) return *b; match const value_table [] = @@ -206,7 +210,7 @@ struct pack_event_info_and_call_visitor ).generate(sink, attributes::unused, *context); }; - if (eina::optional<bool> b = call_match(value_table, filter_func, value_accept_func)) + if (eina::optional<bool> b = type_match::get_match(value_table, filter_func, value_accept_func)) return *b; return value_accept_func("e.args"); diff --git a/src/bin/eolian_mono/eolian/mono/marshall_annotation.hh b/src/bin/eolian_mono/eolian/mono/marshall_annotation.hh index 90da376a73..a9fc45d7da 100644 --- a/src/bin/eolian_mono/eolian/mono/marshall_annotation.hh +++ b/src/bin/eolian_mono/eolian/mono/marshall_annotation.hh @@ -21,25 +21,13 @@ #include "grammar/case.hpp" #include "name_helpers.hh" #include "type_impl.hh" +#include "type_match.hh" namespace eolian_mono { namespace eina = efl::eina; namespace detail { - -template <typename Array, typename SelectionPredicate, int N, typename AcceptFunc> -eina::optional<bool> call_annotation_match(Array const (&array)[N], SelectionPredicate predicate, AcceptFunc acceptFunc) -{ - typedef Array const* iterator_type; - iterator_type match_iterator = &array[0], match_last = match_iterator + N; - match_iterator = std::find_if(match_iterator, match_last, predicate); - if(match_iterator != match_last) - { - return acceptFunc(match_iterator->function()); - } - return {nullptr}; -} template <typename OutputIterator, typename Context> struct marshall_annotation_visitor_generate @@ -157,7 +145,7 @@ struct marshall_annotation_visitor_generate const auto& match_table = is_return ? return_match_table : parameter_match_table; - if(eina::optional<bool> b = call_annotation_match(match_table, predicate, acceptCb)) + if(eina::optional<bool> b = type_match::get_match(match_table, predicate, acceptCb)) { return *b; } diff --git a/src/bin/eolian_mono/eolian/mono/marshall_type_impl.hh b/src/bin/eolian_mono/eolian/mono/marshall_type_impl.hh index 69b4a9afc1..4d1e188997 100644 --- a/src/bin/eolian_mono/eolian/mono/marshall_type_impl.hh +++ b/src/bin/eolian_mono/eolian/mono/marshall_type_impl.hh @@ -21,6 +21,7 @@ #include "grammar/case.hpp" #include "helpers.hh" #include "name_helpers.hh" +#include "type_match.hh" #include "type_impl.hh" #include "generation_contexts.hh" #include "blacklist.hh" @@ -192,7 +193,7 @@ struct marshall_type_visitor_generate return as_generator(string << ".NativeStruct") .generate(sink, name_helpers::type_full_managed_name(regular), *context); } - else if (eina::optional<bool> b = call_match + else if (eina::optional<bool> b = type_match::get_match (match_table , [&] (match const& m) { @@ -296,7 +297,7 @@ struct marshall_type_visitor_generate && as_generator("<" << (type(false, false, true) % ", ") << ">").generate(sink, complex.subtypes, *context); }; - if(eina::optional<bool> b = call_match + if(eina::optional<bool> b = type_match::get_match (matches , [&] (match const& m) { diff --git a/src/bin/eolian_mono/eolian/mono/type_impl.hh b/src/bin/eolian_mono/eolian/mono/type_impl.hh index 2dd2c34ae9..fb521f273e 100644 --- a/src/bin/eolian_mono/eolian/mono/type_impl.hh +++ b/src/bin/eolian_mono/eolian/mono/type_impl.hh @@ -20,6 +20,7 @@ #include "grammar/klass_def.hpp" #include "grammar/case.hpp" #include "name_helpers.hh" +#include "type_match.hh" namespace eolian_mono { @@ -69,19 +70,6 @@ attributes::complex_type_def replace_outer(attributes::complex_type_def v, attri v.outer = regular; return v; } - -template <typename Array, typename F, int N, typename A> -eina::optional<bool> call_match(Array const (&array)[N], F f, A a) -{ - typedef Array const* iterator_type; - iterator_type match_iterator = &array[0], match_last = match_iterator + N; - match_iterator = std::find_if(match_iterator, match_last, f); - if(match_iterator != match_last) - { - return a(match_iterator->function()); - } - return {nullptr}; -} template <typename OutputIterator, typename Context> struct visitor_regular_type_def_printer @@ -248,7 +236,7 @@ struct visitor_generate }} // FIXME add proper support for any_value_ref }; std::string full_type_name = name_helpers::type_full_eolian_name(regular); - if(eina::optional<bool> b = call_match + if(eina::optional<bool> b = type_match::get_match (optional_match_table , [&] (match const& m) { @@ -271,7 +259,7 @@ struct visitor_generate is_optional = false; return (*this)(r); } - else if(eina::optional<bool> b = call_match + else if(eina::optional<bool> b = type_match::get_match (match_table , [&] (match const& m) { @@ -441,7 +429,7 @@ struct visitor_generate // && detail::generate_pointers(sink, pointers, *context, false); }; - if(eina::optional<bool> b = call_match + if(eina::optional<bool> b = type_match::get_match (matches , [&] (match const& m) { diff --git a/src/bin/eolian_mono/eolian/mono/type_match.hh b/src/bin/eolian_mono/eolian/mono/type_match.hh new file mode 100644 index 0000000000..b42fb43190 --- /dev/null +++ b/src/bin/eolian_mono/eolian/mono/type_match.hh @@ -0,0 +1,46 @@ +/* + * Copyright 2019 by its authors. See AUTHORS. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef EOLIAN_MONO_TYPE_MATCH_HH +#define EOLIAN_MONO_TYPE_MATCH_HH + +#include <Eina.hh> + +namespace eolian_mono { + +namespace type_match { + +namespace eina = efl::eina; + +/** + * Apply the given AcceptFunction to the first element that matches the SelectionPredicate. + */ +template <typename Array, typename SelectionPredicate, int N, typename AcceptFunc> +eina::optional<bool> get_match(Array const (&array)[N], SelectionPredicate predicate, AcceptFunc acceptFunc) +{ + typedef Array const* iterator_type; + iterator_type match_iterator = &array[0], match_last = match_iterator + N; + match_iterator = std::find_if(match_iterator, match_last, predicate); + if(match_iterator != match_last) + { + return acceptFunc(match_iterator->function()); + } + return {nullptr}; +} + +} // type_match + +} // eolian_mono +#endif |