bindings/cxx/eo_cxx/eo_init.hh \
bindings/cxx/eo_cxx/eo_ops.hh \
bindings/cxx/eo_cxx/eo_wref.hh \
-bindings/cxx/eo_cxx/eo_future.hh \
-bindings/cxx/eo_cxx/eo_promise.hh \
-bindings/cxx/eo_cxx/eo_promise_meta.hh \
bindings/cxx/eo_cxx/eo_private.hh \
bindings/cxx/eo_cxx/efl_object_impl.hh
tests_eo_cxx_eo_cxx_suite_SOURCES = \
tests/eo_cxx/eo_cxx_suite.cc \
-tests/eo_cxx/eo_cxx_suite.h \
-tests/eo_cxx/eo_cxx_test_promise.cc
+tests/eo_cxx/eo_cxx_suite.h
tests_eo_cxx_eo_cxx_suite_CPPFLAGS = -I$(top_builddir)/src/lib/efl \
-DTESTS_WD=\"`pwd`\" \
#include <eo_wref.hh>
//#include <eo_inherit.hh>
//#include <eo_own_ptr.hh>
-#include <eo_promise.hh>
#include <eo_cxx_interop.hh>
#include <eo_event.hh>
#include <utility>
#include <type_traits>
#include <initializer_list>
-#include <future>
#include <Eina.hh>
#include <Eo.hh>
struct out_traits<eina::optional<T&>> { typedef eina::optional<T&> type; };
template <>
struct out_traits<void*> { typedef void*& type; };
-template <typename T>
-struct out_traits<efl::shared_future<T>> { typedef efl::shared_future<T>& type; };
template <>
struct out_traits<efl::eina::strbuf> { typedef efl::eina::strbuf_wrapper& type; };
struct inout_traits { typedef T& type; };
template <>
struct inout_traits<void> { typedef void* type; };
-template <typename T>
-struct inout_traits<efl::shared_future<T>> { typedef efl::shared_future<T>& type; };
template <typename T>
struct return_traits { typedef T type; };
{
lhs._reset(const_cast<Eo*>(rhs));
}
-template <typename T>
-void assign_out_impl(efl::shared_future<T>& /*v*/, Efl_Future*, tag<efl::shared_future<T>&, Efl_Future*>)
-{
-}
template <typename Tag>
void assign_out_impl(efl::eina::string_view& view, const char* string, Tag)
{
{
return v._eo_ptr();
}
-template <typename T>
-Efl_Future* convert_inout_impl(efl::shared_future<T>& /*v*/, tag<efl::shared_future<T>, Efl_Future*>)
-{
- return nullptr;
-}
}
template <typename To, typename From, typename V>
{
return eina_stringshare_ref(x.c_str());
}
-template <typename T>
-Efl_Future* convert_to_c_impl(efl::shared_future<T> const&, tag<Efl_Future*, efl::shared_future<T>const&>)
-{
- std::abort();
-}
template <typename T, typename U, typename Deleter>
T* convert_to_c_impl(std::unique_ptr<U, Deleter>& v, tag<T*, std::unique_ptr<U, Deleter>>)
{
{
return eina::accessor<T>{ value };
}
-template <typename T>
-efl::shared_future<T> convert_to_return(Efl_Future* /*value*/, tag<Efl_Future*, efl::shared_future<T>>)
-{
- std::abort();
- return {};
-}
// Eina_Value*
inline efl::eina::value convert_to_return(Eina_Value* value, tag<Eina_Value*, efl::eina::value>)
{
+++ /dev/null
-///
-/// @file eo_future.hh
-///
-
-#ifndef EFL_CXX_EO_FUTURE_HH
-#define EFL_CXX_EO_FUTURE_HH
-
-#include <Efl.h>
-
-#include <Eina.hh>
-#include <Ecore_Manual.hh>
-
-#include <mutex>
-#include <condition_variable>
-
-#include <eina_tuple.hh>
-#include <eo_promise_meta.hh>
-
-namespace efl {
-
-template <typename...Args>
-struct shared_future;
-
-namespace _impl {
-
-template <typename V = char>
-struct wait_state
-{
- bool available = false;
- bool has_failed = false;
- std::mutex mutex;
- std::condition_variable cv;
- typename std::aligned_storage<sizeof(V), alignof(V)>::type storage;
- Eina_Error error;
-};
-
-inline void get_error_cb(void* data, Efl_Event const* event)
-{
- wait_state<>* wait_state_ = static_cast<wait_state<>*>(data);
- Efl_Future_Event_Failure* info = static_cast<Efl_Future_Event_Failure*>(event->info);
- std::unique_lock<std::mutex> l(wait_state_->mutex);
- wait_state_->error = info->error;
- wait_state_->has_failed = true;
- wait_state_->available = true;
- wait_state_->cv.notify_one();
-}
-
-struct shared_future_common
-{
- explicit shared_future_common(Efl_Future* future)
- : _future(future) {}
- shared_future_common()
- : _future(nullptr) {}
- ~shared_future_common()
- {
- if(_future)
- efl_unref(_future);
- }
- shared_future_common(shared_future_common const& future)
- : _future(efl_ref(future._future))
- {
- }
- shared_future_common& operator=(shared_future_common const& other)
- {
- _self_type tmp(other);
- tmp.swap(*this);
- return *this;
- }
- shared_future_common(shared_future_common&& future)
- : _future(future._future)
- {
- future._future = nullptr;
- }
- shared_future_common& operator=(shared_future_common&& other)
- {
- other.swap(*this);
- return *this;
- }
- void swap(shared_future_common& other)
- {
- std::swap(_future, other._future);
- }
- bool valid() const noexcept
- {
- return _future != nullptr;
- }
- void wait() const
- {
- if(eina_main_loop_is())
- throw std::runtime_error("Deadlock");
-
- struct wait_state<> wait_state;
-
- efl::ecore::main_loop_thread_safe_call_async
- ([&]
- {
- efl_future_then(this->_future, &wait_success, &wait_success, nullptr, &wait_state);
- });
-
- std::unique_lock<std::mutex> lock(wait_state.mutex);
- while(!wait_state.available)
- wait_state.cv.wait(lock);
- }
- static void wait_success(void* data, Efl_Event const*)
- {
- wait_state<>* wait_state_ = static_cast<wait_state<>*>(data);
- std::unique_lock<std::mutex> l(wait_state_->mutex);
- wait_state_->available = true;
- wait_state_->cv.notify_one();
- }
-
- typedef Efl_Future* native_handle_type;
- native_handle_type native_handle() const noexcept { return _future; }
-
- typedef shared_future_common _self_type;
- Efl_Future* _future;
-};
-
-template <typename T, typename Progress = void>
-struct shared_future_1_type : shared_future_common
-{
- typedef shared_future_common _base_type;
-
- using _base_type::_base_type;
- shared_future_1_type() = default;
- shared_future_1_type(shared_future_common const& other)
- : _base_type(other) {}
-
- T get() const
- {
- if(eina_main_loop_is())
- throw std::runtime_error("Deadlock");
-
- struct wait_state<T> wait_state;
-
- efl::ecore::main_loop_thread_safe_call_async
- ([&]
- {
- efl_future_then(this->_future, &get_success, &_impl::get_error_cb, nullptr, &wait_state);
- });
-
- {
- std::unique_lock<std::mutex> lock(wait_state.mutex);
- while(!wait_state.available)
- wait_state.cv.wait(lock);
- }
- if(wait_state.has_failed)
- EFL_CXX_THROW(eina::system_error(eina::error_code(wait_state.error, eina::eina_error_category()), "EFL Eina Error"));
- return *static_cast<T*>(static_cast<void*>(&wait_state.storage));
- }
-
- static void get_success(void* data, Efl_Event const* event)
- {
- wait_state<T>* wait_state_ = static_cast<wait_state<T>*>(data);
- Efl_Future_Event_Success* info = static_cast<Efl_Future_Event_Success*>(event->info);
-
- std::unique_lock<std::mutex> l(wait_state_->mutex);
- _impl::future_copy_traits<T>::copy(static_cast<T*>(static_cast<void*>(&wait_state_->storage)), info);
- wait_state_->available = true;
- wait_state_->cv.notify_one();
- }
-
- typedef shared_future_1_type<T, Progress> _self_type;
-};
-
-template <typename T>
-struct shared_race_future_1_type : shared_future_common
-{
- typedef shared_future_common _base_type;
-
- using _base_type::_base_type;
- shared_race_future_1_type(_base_type const& other)
- : _base_type(other) {}
-
- T get() const
- {
- if(eina_main_loop_is())
- throw std::runtime_error("Deadlock");
-
- struct wait_state<T> wait_state;
-
- efl::ecore::main_loop_thread_safe_call_async
- ([&]
- {
- efl_future_then(this->_future, &get_success, &_impl::get_error_cb, nullptr, &wait_state);
- });
-
- {
- std::unique_lock<std::mutex> lock(wait_state.mutex);
- while(!wait_state.available)
- wait_state.cv.wait(lock);
- }
- if(wait_state.has_failed)
- EFL_CXX_THROW(eina::system_error(eina::error_code(wait_state.error, eina::eina_error_category()), "EFL Eina Error"));
- return *static_cast<T*>(static_cast<void*>(&wait_state.storage));
- }
-
- static void get_success(void* data, Efl_Event const* event)
- {
- wait_state<T>* wait_state_ = static_cast<wait_state<T>*>(data);
- Efl_Future_Event_Success* info = static_cast<Efl_Future_Event_Success*>(event->info);
-
- std::unique_lock<std::mutex> l(wait_state_->mutex);
- _impl::future_copy_traits<T>::copy_race(static_cast<T*>(static_cast<void*>(&wait_state_->storage)), info);
- wait_state_->available = true;
- wait_state_->cv.notify_one();
- }
-
- typedef shared_race_future_1_type<T> _self_type;
-};
-
-template <typename...Args>
-struct shared_future_varargs_type : shared_future_common
-{
- typedef shared_future_common _base_type;
-
- using _base_type::_base_type;
- shared_future_varargs_type() = default;
- shared_future_varargs_type(_base_type const& other)
- : _base_type(other) {}
-
- typedef std::tuple<Args...> tuple_type;
-
- std::tuple<Args...> get() const
- {
- if(eina_main_loop_is())
- throw std::runtime_error("Deadlock");
-
- struct wait_state<tuple_type> wait_state;
-
- efl::ecore::main_loop_thread_safe_call_async
- ([&]
- {
- efl_future_then(this->_future, &get_success, &_impl::get_error_cb, nullptr, &wait_state);
- });
-
- {
- std::unique_lock<std::mutex> lock(wait_state.mutex);
- while(!wait_state.available)
- wait_state.cv.wait(lock);
- }
- if(wait_state.has_failed)
- EFL_CXX_THROW(eina::system_error(eina::error_code(wait_state.error, eina::eina_error_category()), "EFL Eina Error"));
- return *static_cast<tuple_type*>(static_cast<void*>(&wait_state.storage));
- }
-
- template <std::size_t N>
- static void read_accessor(Eina_Accessor* accessor
- , std::tuple<typename std::aligned_storage<sizeof(Args), alignof(Args)>::type...>& storage_tuple
- , wait_state<tuple_type>* wait_state
- , std::false_type)
- {
- typedef typename std::tuple_element<N, tuple_type>::type type;
- void* value;
- if(eina_accessor_data_get(accessor, N, &value))
- {
- eina::copy_from_c_traits<type>::copy_to_unitialized
- (static_cast<type*>(static_cast<void*>(&std::get<N>(storage_tuple))), value);
-
- _self_type::read_accessor<N+1>(accessor, storage_tuple, wait_state
- , std::integral_constant<bool, (N+1 == sizeof...(Args))>());
- }
- else
- {
- std::abort();
- // some error
- }
- }
-
- template <std::size_t N, std::size_t...I>
- static void read_accessor_end(std::tuple<typename std::aligned_storage<sizeof(Args), alignof(Args)>::type...>& storage_tuple
- , wait_state<tuple_type>* wait_state
- , eina::index_sequence<I...>)
- {
- std::unique_lock<std::mutex> l(wait_state->mutex);
-
- new (&wait_state->storage) tuple_type{(*static_cast<typename std::tuple_element<I, tuple_type>::type*>
- (static_cast<void*>(&std::get<I>(storage_tuple))))...};
-
- wait_state->available = true;
- wait_state->cv.notify_one();
- }
-
- template <std::size_t N>
- static void read_accessor(Eina_Accessor*
- , std::tuple<typename std::aligned_storage<sizeof(Args), alignof(Args)>::type...>& storage_tuple
- , wait_state<tuple_type>* wait_state
- , std::true_type)
- {
- _self_type::read_accessor_end<N>(storage_tuple, wait_state, eina::make_index_sequence<sizeof...(Args)>{});
- }
-
- static void get_success(void* data, Efl_Event const* event)
- {
- wait_state<tuple_type>* wait_state_ = static_cast<wait_state<tuple_type>*>(data);
- Efl_Future_Event_Success* info = static_cast<Efl_Future_Event_Success*>(event->info);
-
- Eina_Accessor* accessor = static_cast<Eina_Accessor*>(info->value);
- std::tuple<typename std::aligned_storage<sizeof(Args), alignof(Args)>::type...> storage_tuple;
-
- _self_type::read_accessor<0u>(accessor, storage_tuple, wait_state_, std::false_type());
- }
-
- typedef shared_future_varargs_type<Args...> _self_type;
-};
-
-}
-
-template <typename...Args>
-struct shared_future : private
- std::conditional
- <
- sizeof...(Args) == 1
- , _impl::shared_future_1_type<typename std::tuple_element<0u, std::tuple<Args...>>::type>
- , typename std::conditional
- <_impl::is_progress<typename std::tuple_element<sizeof...(Args) - 1, std::tuple<Args...>>::type>::value
- , typename std::conditional
- <sizeof...(Args) == 2
- , _impl::shared_future_1_type<Args...>
- , _impl::shared_future_varargs_type<Args...>
- >::type
- , _impl::shared_future_varargs_type<Args...>
- >::type
- >::type
-{
- typedef typename
- std::conditional
- <
- sizeof...(Args) == 1
- , _impl::shared_future_1_type<Args...>
- , typename std::conditional
- <_impl::is_progress<typename std::tuple_element<sizeof...(Args) - 1, std::tuple<Args...>>::type>::value
- , typename std::conditional
- <sizeof...(Args) == 2
- , _impl::shared_future_1_type<Args...>
- , _impl::shared_future_varargs_type<Args...>
- >::type
- , _impl::shared_future_varargs_type<Args...>
- >::type
- >::type
- _base_type;
- typedef typename _impl::progress_param<Args...>::type progress_param_type;
- typedef typename _impl::progress_type<progress_param_type>::type progress_type;
- typedef typename _base_type::native_handle_type native_handle_type;
- using _base_type::_base_type;
- using _base_type::swap;
- using _base_type::valid;
- using _base_type::get;
- using _base_type::wait;
- using _base_type::native_handle;
-
- shared_future() = default;
- template <typename...OtherArgs>
- shared_future(shared_future<OtherArgs...> const& other
- , typename std::enable_if<_impl::is_progress_param_compatible
- <progress_param_type, typename _impl::progress_param<OtherArgs...>::type>::value>::type* = nullptr)
- : _base_type(static_cast< _impl::shared_future_common const&>(other))
- {
- }
-
- template <typename...OtherArgs>
- friend struct shared_future;
-};
-
-template <typename...Args>
-struct shared_race_future : private std::conditional<sizeof...(Args) == 1, _impl::shared_race_future_1_type<typename std::tuple_element<0u, std::tuple<Args...>>::type>, void>::type
-{
- typedef typename std::conditional<sizeof...(Args) == 1, _impl::shared_race_future_1_type<typename std::tuple_element<0u, std::tuple<Args...>>::type>, void>::type _base_type;
-
- using _base_type::_base_type;
- using _base_type::swap;
- using _base_type::valid;
- using _base_type::get;
- using _base_type::wait;
- using _base_type::native_handle;
- typedef typename _base_type::native_handle_type native_handle_type;
-};
-
-namespace _impl {
-
-template <typename T>
-struct is_race_future : std::false_type {};
-
-template <typename...Args>
-struct is_race_future<shared_race_future<Args...>> : std::true_type {};
-
-}
-
-template <template <typename...> class Future, typename...Args, typename F>
-typename std::enable_if
-<
- !std::is_same<typename Future<Args...>::progress_type, void>::value
->::type on_progress(Future<Args...> future, F function)
-{
- struct private_data
- {
- F progress_cb;
- Future<Args...> future;
- };
- private_data* pdata = new private_data
- {std::move(function), std::move(future)};
-
- typedef typename Future<Args...>::progress_type progress_type;
-
- Efl_Event_Cb raw_progress_cb =
- [] (void* data, Efl_Event const* event)
- {
- private_data* pdata = static_cast<private_data*>(data);
- try
- {
- Efl_Future_Event_Progress const* info = static_cast<Efl_Future_Event_Progress const*>(event->info);
- pdata->progress_cb(*static_cast<progress_type const*>(info->progress));
- }
- catch(...)
- {
- // what should happen if progress_cb fails?
- }
- };
- Efl_Event_Cb raw_delete_cb =
- [] (void* data, Efl_Event const*)
- {
- private_data* pdata = static_cast<private_data*>(data);
- delete pdata;
- };
-
- assert(pdata->future.valid());
- efl_future_then(pdata->future.native_handle(), raw_delete_cb, raw_delete_cb, raw_progress_cb, pdata);
-}
-
-template <template <typename...> class Future, typename...Args, typename Success, typename Error>
-shared_future
-<
- typename std::enable_if
- <
- !std::is_same<void, typename std::tuple_element<0, std::tuple<Args...>>::type>::value
- && !std::is_same<void, typename std::result_of<Success(Args...)>::type>::value
- , typename std::result_of<Success(Args...)>::type
- >::type
-> then(Future<Args...> future, Success success_cb, Error error_cb)
-{
- struct private_data
- {
- Success success_cb;
- Error error_cb;
- Future<Args...> future;
- };
- private_data* pdata = new private_data
- {std::move(success_cb), std::move(error_cb), std::move(future)};
-
- Efl_Event_Cb raw_success_cb =
- [] (void* data, Efl_Event const* event)
- {
- private_data* pdata = static_cast<private_data*>(data);
- try
- {
- _impl::future_invoke<Args...>(pdata->success_cb, event, _impl::is_race_future<Future<Args...>>{});
- // should value_set the next promise
- }
- catch(...)
- {
- // should fail the next promise
- }
- delete pdata;
- };
- Efl_Event_Cb raw_error_cb =
- [] (void* data, Efl_Event const* event)
- {
- private_data* pdata = static_cast<private_data*>(data);
- Efl_Future_Event_Failure* info = static_cast<Efl_Future_Event_Failure*>(event->info);
- pdata->error_cb(eina::error_code(info->error, eina::eina_error_category()));
- // should error the next promise (or should the promise do that for me automatically?)
- delete pdata;
- };
-
- assert(pdata->future.valid());
- Efl_Future* new_future
- = efl_future_then(pdata->future.native_handle(), raw_success_cb, raw_error_cb, nullptr, pdata);
- return shared_future<typename std::result_of<Success(Args...)>::type>{efl_ref(new_future)};
-}
-
-// TODO:
-template <typename...Args, typename F>
-void then(shared_future<Args...> future, F function)
-{
- static_cast<void>(future);
- static_cast<void>(function);
-}
-
-template <typename...Args1, typename...Args2, typename...Futures>
-typename _impl::all_result_type<shared_future<Args1...>, shared_future<Args2...>, Futures...>::type
-all(shared_future<Args1...> future1, shared_future<Args2...> future2, Futures...futures)
-{
- return _impl::all_impl(future1, future2, futures...);
-}
-
-template <typename...Args1, typename...Args2, typename...Futures>
-typename _impl::race_result_type<shared_future<Args1...>, shared_future<Args2...>, Futures...>::type
-race(shared_future<Args1...> future1, shared_future<Args2...> future2, Futures...futures)
-{
- return _impl::race_impl(future1, future2, futures...);
-}
-
-}
-
-#endif
+++ /dev/null
-///
-/// @file eo_promise.hh
-///
-
-#ifndef EFL_CXX_EO_PROMISE_HH
-#define EFL_CXX_EO_PROMISE_HH
-
-#include <Efl.h>
-
-#include <Eina.hh>
-#include <Ecore_Manual.hh>
-
-#include <mutex>
-#include <condition_variable>
-
-#include <eina_tuple.hh>
-#include <eo_promise_meta.hh>
-#include <eo_future.hh>
-
-namespace efl {
-
-template <typename...Args>
-struct shared_future;
-
-namespace _impl {
-
-struct promise_common
-{
- explicit promise_common(Efl_Promise* _promise) : _promise(_promise) {}
- explicit promise_common(std::nullptr_t) : _promise(nullptr) {}
- promise_common()
- {
- _promise = efl_add(EFL_PROMISE_CLASS, efl_main_loop_get());
- }
- ~promise_common()
- {
- if(_promise)
- ::efl_unref(_promise);
- }
- promise_common(promise_common const& other)
- : _promise( ::efl_ref(other._promise))
- {
- }
- promise_common(promise_common&& other)
- : _promise(nullptr)
- {
- std::swap(*this, other);
- }
- promise_common& operator=(promise_common const& other)
- {
- _promise = ::efl_ref(other._promise);
- return *this;
- }
- promise_common& operator=(promise_common&& other)
- {
- std::swap(*this, other);
- return *this;
- }
- bool valid() const
- {
- return _promise != nullptr;
- }
- void swap(promise_common& other)
- {
- std::swap(*this, other);
- }
- void set_exception(std::exception_ptr /*p*/)
- {
- }
-
- Efl_Promise* _promise;
-};
-
-template <typename P>
-struct promise_progress : promise_common
-{
- void set_progress(P const& progress)
- {
- efl_promise_progress_set(this->_promise, &progress);
- }
-};
-
-template <>
-struct promise_progress<void> : promise_common
-{
- void set_progress()
- {
- efl_promise_progress_set(this->_promise, nullptr);
- }
-};
-
-template <typename T, typename Progress>
-struct promise_1_type : promise_progress<Progress>
-{
- void set_value(T const& v)
- {
- typedef typename eina::alloc_to_c_traits<T>::c_type c_type;
- c_type* c_value = eina::alloc_to_c_traits<T>::copy_alloc(v);
- efl_promise_value_set(this->_promise, c_value, & eina::alloc_to_c_traits<T>::free_alloc);
- }
- void set_value(T&& v)
- {
- typedef typename eina::alloc_to_c_traits<T>::c_type c_type;
- c_type* c_value = eina::alloc_to_c_traits<T>::copy_alloc(std::move(v));
- efl_promise_value_set(this->_promise, c_value, & eina::alloc_to_c_traits<T>::free_alloc);
- }
-};
-
-template <typename Progress>
-struct promise_1_type<void, Progress> : promise_progress<Progress>
-{
- void set_value()
- {
- efl_promise_value_set(this->_promise, nullptr, nullptr);
- }
-};
-
-}
-
-template <typename T, typename Progress = void>
-struct promise : private _impl::promise_1_type<T, Progress>
-{
- typedef _impl::promise_1_type<T, Progress> _base_type;
- using _base_type::_base_type;
- using _base_type::set_value;
- using _base_type::set_progress;
- using _base_type::set_exception;
-
- shared_future<T, progress<Progress>> get_future()
- {
- return shared_future<T, progress<Progress>>{ ::efl_ref( ::efl_promise_future_get(this->_promise)) };
- }
-
- void swap(promise<T, progress<Progress>>& other)
- {
- _base_type::swap(other);
- }
-};
-
-template <typename...Args>
-void swap(promise<Args...>& lhs, promise<Args...>& rhs)
-{
- lhs.swap(rhs);
-}
-
-}
-
-#endif
+++ /dev/null
-///
-/// @file eo_promise_meta.hh
-///
-
-#ifndef EFL_CXX_EO_PROMISE_META_HH
-#define EFL_CXX_EO_PROMISE_META_HH
-
-namespace efl {
-
-template <typename...Args>
-struct shared_future;
-
-template <typename...Args>
-struct shared_race_future;
-
-template <typename T>
-struct progress;
-
-namespace _impl {
-
-template <typename T>
-struct is_progress : std::false_type {};
-
-template <typename T>
-struct is_progress<progress<T>> : std::true_type {};
-
-template <typename L, typename R>
-struct is_progress_param_compatible : std::false_type {};
-
-template <typename T>
-struct is_progress_param_compatible<T, T> : std::true_type {};
-
-template <>
-struct is_progress_param_compatible<void, progress<void>> : std::true_type {};
-
-template <>
-struct is_progress_param_compatible<progress<void>, void> : std::true_type {};
-
-template <typename...Args>
-struct progress_param : std::conditional
- <is_progress<typename std::tuple_element<sizeof...(Args) - 1, std::tuple<Args...>>::type>::value
- , typename std::tuple_element<sizeof...(Args) - 1, std::tuple<Args...>>::type
- , void>
-{
-};
-
-template <typename T>
-struct progress_type;
-
-template <typename T>
-struct progress_type<progress<T>>
-{
- typedef T type;
-};
-
-template <>
-struct progress_type<void>
-{
- typedef void type;
-};
-
-template <typename...Futures>
-struct all_result_type;
-
-template <typename...Args>
-struct all_result_type<shared_future<Args...>>
-{
- typedef shared_future<Args...> type;
-};
-
-template <typename...Args1, typename...Args2>
-struct all_result_type<shared_future<Args1...>, shared_future<Args2...>>
-{
- typedef shared_future<Args1..., Args2...> type;
-};
-
-template <typename...Args1, typename...Args2, typename...OtherFutures>
-struct all_result_type<shared_future<Args1...>, shared_future<Args2...>, OtherFutures...>
-{
- typedef typename all_result_type<shared_future<Args1..., Args2...>, OtherFutures...>::type type;
-};
-
-template <typename...Futures>
-typename all_result_type<Futures...>::type
-all_impl(Futures const& ... futures)
-{
- Efl_Future* future = ::efl_future_all_internal(futures.native_handle()..., NULL);
- return typename all_result_type<Futures...>::type{ ::efl_ref(future)};
-}
-
-template <typename...Futures>
-struct race_result_type;
-
-template <typename...Args>
-struct race_result_type<shared_future<Args...>>
-{
- typedef shared_race_future<Args...> type;
-};
-
-template <typename T, typename...Args>
-struct race_compose_impl;
-
-template <typename T, typename A0, typename...Args>
-struct race_compose_impl<T, A0, Args...>
-{
- typedef typename std::conditional<eina::_mpl::tuple_contains<A0, T>::value
- , typename race_compose_impl<T, Args...>::type
- , typename race_compose_impl<typename eina::_mpl::push_back<T, A0>::type, Args...>::type
- >::type type;
-};
-
-template <typename T>
-struct race_compose_impl<T>
-{
- typedef T type;
-};
-
-template <typename T>
-struct variant_from_tuple;
-
-template <typename...Args>
-struct variant_from_tuple<std::tuple<Args...>>
-{
- typedef eina::variant<Args...> type;
-};
-
-template <typename...Args>
-struct race_variant
-{
- typedef typename variant_from_tuple<typename race_compose_impl<std::tuple<>, Args...>::type>::type type;
-};
-
-template <typename A0>
-struct race_result_type<shared_future<A0>>
-{
- typedef shared_race_future<A0> type;
-};
-
-template <typename A0>
-struct race_result_type<shared_future<eina::variant<A0>>>
-{
- typedef shared_race_future<A0> type;
-};
-
-template <typename...Args1, typename...Args2>
-struct race_result_type<shared_future<Args1...>, shared_future<Args2...>>
-{
- typedef typename race_result_type<shared_future<typename race_variant<Args1..., Args2...>::type>>::type type;
-};
-
-template <typename...Args1, typename...Args2, typename...OtherFutures>
-struct race_result_type<shared_future<Args1...>, shared_future<Args2...>, OtherFutures...>
-{
- typedef typename race_result_type<shared_future<typename race_variant<Args1..., Args2...>::type>
- , OtherFutures...>::type type;
-};
-
-template <typename...Futures>
-typename race_result_type<Futures...>::type
-race_impl(Futures const& ... futures)
-{
- Efl_Future* future = ::efl_future_race_internal(futures.native_handle()..., NULL);
- return typename race_result_type<Futures...>::type{ ::efl_ref(future)};
-}
-
-template <typename T, typename Enabler = void>
-struct future_copy_traits
-{
- static void copy(T* storage, Efl_Future_Event_Success const* info)
- {
- eina::copy_from_c_traits<T>::copy_to_unitialized
- (storage, info->value);
- }
- static void copy_race(T* storage, Efl_Future_Event_Success const* info)
- {
- Efl_Future_Race_Success const* race = static_cast<Efl_Future_Race_Success const*>(info->value);
- eina::copy_from_c_traits<T>::copy_to_unitialized
- (storage, race->value);
- }
-};
-
-template <typename...Args>
-struct future_copy_traits<eina::variant<Args...>>
-{
- template <std::size_t I>
- static void copy_impl(eina::variant<Args...>*, void const*, int, std::integral_constant<std::size_t, I>
- , std::integral_constant<std::size_t, I>)
- {
- std::abort();
- }
-
- template <std::size_t I, std::size_t N>
- static void copy_impl(eina::variant<Args...>* storage, void const* value, int index, std::integral_constant<std::size_t, I>
- , std::integral_constant<std::size_t, N> max
- , typename std::enable_if<I != N>::type* = 0)
- {
- if(I == index)
- {
- eina::copy_from_c_traits<eina::variant<Args...>>::copy_to_unitialized
- (storage, static_cast<typename std::tuple_element<I, std::tuple<Args...>>::type const*>
- (static_cast<void const*>(value)));
- }
- else
- copy_impl(storage, value, index, std::integral_constant<std::size_t, I+1>{}, max);
- }
- static void copy(eina::variant<Args...>*, Efl_Future_Event_Success const*)
- {
- std::abort();
- }
- static void copy_race(eina::variant<Args...>* storage, Efl_Future_Event_Success const* other_info)
- {
- Efl_Future_Race_Success const* info = static_cast<Efl_Future_Race_Success const*>
- (static_cast<void const*>(other_info->value));
- copy_impl(storage, info->value, info->index, std::integral_constant<std::size_t, 0ul>{}
- , std::integral_constant<std::size_t, sizeof...(Args)>{});
- }
-};
-
-template <typename A0, typename F, bool IsRace>
-typename std::enable_if
-<
- !std::is_same<A0, void>::value
- && !std::is_same<typename std::result_of<F(A0)>::type, void>::value
->::type
-future_invoke(F f, Efl_Event const* event, std::integral_constant<bool, IsRace> /* is_race */)
-{
- Efl_Future_Event_Success* info = static_cast<Efl_Future_Event_Success*>(event->info);
- try
- {
- typename std::aligned_storage<sizeof(A0), alignof(A0)>::type storage;
- if(IsRace)
- future_copy_traits<A0>::copy_race(static_cast<A0*>(static_cast<void*>(&storage)), info);
- else
- future_copy_traits<A0>::copy(static_cast<A0*>(static_cast<void*>(&storage)), info);
- auto r = f(*static_cast<A0*>(static_cast<void*>(&storage)));
- typedef decltype(r) result_type;
- typedef typename eina::alloc_to_c_traits<result_type>::c_type c_type;
- c_type* c_value = eina::alloc_to_c_traits<result_type>::copy_alloc(r);
- efl_promise_value_set(info->next, c_value, & eina::alloc_to_c_traits<result_type>::free_alloc);
- }
- catch(...)
- {
- }
-}
-
-template <typename A0, typename F, bool IsRace>
-typename std::enable_if<std::is_same<A0, void>::value>::type
-future_invoke(F f, Efl_Event const* event, std::integral_constant<bool, IsRace>)
-{
- Efl_Future_Event_Success* info = static_cast<Efl_Future_Event_Success*>(event->info);
- static_cast<void>(info);
- try
- {
- f();
- }
- catch(...)
- {
- }
-}
-
-template <std::size_t N, typename...Args, typename...StorageArgs>
-static void future_invoke_impl_read_accessor
- (Eina_Accessor*, std::tuple<StorageArgs...>&, std::tuple<Args...>*, std::true_type)
-{
-}
-
-template <std::size_t N, typename...Args, typename...StorageArgs>
-static void future_invoke_impl_read_accessor
- (Eina_Accessor* accessor
- , std::tuple<StorageArgs...>& storage_tuple
- , std::tuple<Args...>* args
- , std::false_type)
-{
- typedef std::tuple<Args...> tuple_type;
- typedef typename std::tuple_element<N, tuple_type>::type type;
- void* value;
- if(eina_accessor_data_get(accessor, N, &value))
- {
- eina::copy_from_c_traits<type>::copy_to_unitialized
- (static_cast<type*>(static_cast<void*>(&std::get<N>(storage_tuple))), value);
-
- _impl::future_invoke_impl_read_accessor<N+1>
- (accessor, storage_tuple, args
- , std::integral_constant<bool, (N+1 == sizeof...(Args))>());
- }
- else
- {
- std::abort();
- // some error
- }
-}
-
-template <typename F, typename...Args, std::size_t...I, bool IsRace>
-void future_invoke_impl(F f, Efl_Event const* event, std::tuple<Args...>* arguments_dummy, std::integral_constant<bool, IsRace>, eina::index_sequence<I...>)
-{
- Efl_Future_Event_Success* info = static_cast<Efl_Future_Event_Success*>(event->info);
- try
- {
- typedef std::tuple<Args...> arguments;
- typedef std::tuple<typename std::aligned_storage<sizeof(Args), alignof(Args)>::type...>
- storage_tuple_type;
- storage_tuple_type storage_tuple;
-
- future_invoke_impl_read_accessor<0ul>
- (static_cast<Eina_Accessor*>(info->value)
- , storage_tuple
- , arguments_dummy, std::false_type{});
-
- auto r = f(*static_cast<typename std::tuple_element<I, arguments>::type*>
- (static_cast<void*>(&std::get<I>(storage_tuple)))...);
-
- typedef decltype(r) result_type;
- typedef typename eina::alloc_to_c_traits<result_type>::c_type c_type;
- c_type* c_value = eina::alloc_to_c_traits<result_type>::copy_alloc(r);
- efl_promise_value_set(info->next, c_value, & eina::alloc_to_c_traits<result_type>::free_alloc);
- }
- catch(...)
- {
- }
-}
-
-template <typename A0, typename A1, typename...OtherArgs, typename F, bool IsRace>
-void
-future_invoke(F f, Efl_Event const* event, std::integral_constant<bool, IsRace> race)
-{
- std::tuple<A0, A1, OtherArgs...>* p = nullptr;
- _impl::future_invoke_impl(f, event, p, race, eina::make_index_sequence<sizeof...(OtherArgs) + 2>{});
-}
-
-} }
-
-#endif
--- /dev/null
+#ifndef EOLIAN_CXX_BLACKLIST_HH
+#define EOLIAN_CXX_BLACKLIST_HH
+
+#include <algorithm>
+#include "grammar/klass_def.hpp"
+
+namespace efl { namespace eolian { namespace grammar {
+
+namespace blacklist {
+
+bool is_blacklisted(attributes::type_def const& t);
+
+struct type_blacklisted_visitor
+{
+ typedef type_blacklisted_visitor visitor_type;
+ typedef bool result_type;
+
+ bool operator()(attributes::regular_type_def const&) const
+ {
+ return false;
+ }
+ bool operator()(attributes::klass_name const&) const
+ {
+ return false;
+ }
+ bool operator()(attributes::complex_type_def const& c) const
+ {
+ if (c.outer.base_type == "future")
+ return true;
+
+ return std::any_of(c.subtypes.begin(), c.subtypes.end(), is_blacklisted);
+ }
+};
+
+bool is_blacklisted(attributes::type_def const& t)
+{
+ return t.original_type.visit(type_blacklisted_visitor{});
+}
+
+bool is_blacklisted(attributes::function_def const& f)
+{
+ if (is_blacklisted(f.return_type))
+ return true;
+
+ return std::any_of(f.parameters.cbegin(), f.parameters.cend(), [](attributes::parameter_def const& p) { return is_blacklisted(p.type); });
+}
+
+
+} // namespace grammar
+} } } // namespace efl / eolian / grammar
+
+
+
+#endif
#include "grammar/type.hpp"
#include "grammar/parameter.hpp"
#include "grammar/keyword.hpp"
+#include "grammar/blacklist.hpp"
namespace efl { namespace eolian { namespace grammar {
template <typename OutputIterator, typename Context>
bool generate(OutputIterator sink, attributes::function_def const& f, Context const& ctx) const
{
+ if (blacklist::is_blacklisted(f))
+ return true;
+
std::string suffix, static_flag, const_flag;
switch(_klass_name.type)
{
#include "grammar/attribute_reorder.hpp"
#include "grammar/type_impl.hpp"
#include "grammar/eps.hpp"
+#include "grammar/blacklist.hpp"
namespace efl { namespace eolian { namespace grammar {
template <typename OutputIterator, typename Context>
bool generate(OutputIterator sink, attributes::function_def const& f, Context const& ctx) const
{
+ if (blacklist::is_blacklisted(f))
+ return true;
+
std::string suffix;
switch(_klass_name.type)
{
(complex, regular_type_def{" ::efl::promise", complex.outer.base_qualifier, {}});
}
}
- , {"future", nullptr, nullptr, [&]
- {
- return replace_outer
- (complex, regular_type_def{" ::efl::shared_future", complex.outer.base_qualifier, {}});
- }
- }
+ /* , {"future", nullptr, nullptr, [&] */
+ /* { */
+ /* return replace_outer */
+ /* (complex, regular_type_def{" ::efl::shared_future", complex.outer.base_qualifier, {}}); */
+ /* } */
+ /* } */
, {"iterator", nullptr, nullptr, [&]
{
return replace_outer
#include "../efl_check.h"
static const Efl_Test_Case etc[] = {
- { "Promise", eo_cxx_test_promise },
{ NULL, NULL }
};
#include <check.h>
#include "../efl_check.h"
-void eo_cxx_test_promise(TCase* tc);
#endif /* _EINA_CXX_SUITE_H */
+++ /dev/null
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <Eina.hh>
-#include <Eo.hh>
-#include <Ecore.hh>
-
-#include "eo_cxx_suite.h"
-
-void
-eo_cxx_test_promise(TCase* tc)
-{
-}