2014-07-16 17:29:47 -07:00
|
|
|
|
|
|
|
#ifndef EFL_EOLIAN_INTEROP_HH
|
|
|
|
#define EFL_EOLIAN_INTEROP_HH
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <tuple>
|
2015-01-12 06:00:59 -08:00
|
|
|
#include <utility>
|
2014-07-16 17:29:47 -07:00
|
|
|
#include <type_traits>
|
2015-03-26 07:48:09 -07:00
|
|
|
#include <initializer_list>
|
2016-06-05 22:54:36 -07:00
|
|
|
#include <future>
|
2014-07-16 17:29:47 -07:00
|
|
|
|
|
|
|
#include <Eina.hh>
|
|
|
|
#include <Eo.hh>
|
|
|
|
|
2015-03-26 07:48:09 -07:00
|
|
|
#include "eo_concrete.hh"
|
|
|
|
|
2014-07-16 17:29:47 -07:00
|
|
|
namespace efl { namespace eolian {
|
|
|
|
|
2016-06-05 22:54:36 -07:00
|
|
|
template <typename T, typename Enable = void>
|
|
|
|
struct in_traits { typedef T const& type; };
|
|
|
|
template <typename T>
|
|
|
|
struct in_traits<T, typename std::enable_if<eo::is_eolian_object<T>::value>::type> { typedef T type; };
|
|
|
|
template <typename T>
|
|
|
|
struct in_traits<T, typename std::enable_if<std::is_fundamental<T>::value>::type> { typedef T type; };
|
|
|
|
template <>
|
|
|
|
struct in_traits<eina::string_view> { typedef eina::string_view type; };
|
|
|
|
template <>
|
|
|
|
struct in_traits<eina::string_view const> { typedef eina::string_view const type; };
|
2016-06-21 12:35:09 -07:00
|
|
|
template <>
|
|
|
|
struct in_traits<eina::stringshare> { typedef eina::stringshare type; };
|
|
|
|
template <>
|
|
|
|
struct in_traits<eina::stringshare const> { typedef eina::stringshare const type; };
|
2016-06-05 22:54:36 -07:00
|
|
|
template <typename T>
|
|
|
|
struct in_traits<T&> { typedef T& type; };
|
|
|
|
template <typename T>
|
|
|
|
struct in_traits<T*> { typedef T* type; };
|
|
|
|
template <typename T, typename D>
|
|
|
|
struct in_traits<std::unique_ptr<T, D>> { typedef std::unique_ptr<T, D> type; };
|
2014-07-16 17:29:47 -07:00
|
|
|
|
2016-06-05 22:54:36 -07:00
|
|
|
template <typename T>
|
|
|
|
struct in_traits<eina::range_list<T>> { typedef eina::range_list<T> type; };
|
|
|
|
template <typename T>
|
|
|
|
struct in_traits<eina::range_array<T>> { typedef eina::range_array<T> type; };
|
|
|
|
|
|
|
|
template <typename T>
|
2016-06-08 13:31:46 -07:00
|
|
|
struct out_traits { typedef T& type; };
|
2016-06-16 17:48:07 -07:00
|
|
|
template <>
|
|
|
|
struct out_traits<void> { typedef void* type; };
|
2016-06-08 13:31:46 -07:00
|
|
|
template <typename T>
|
|
|
|
struct out_traits<T*> { typedef T* type; };
|
|
|
|
template <>
|
|
|
|
struct out_traits<Eina_Hash*> { typedef Eina_Hash*& type; };
|
|
|
|
template <typename T>
|
|
|
|
struct out_traits<eina::optional<T&>> { typedef eina::optional<T&> type; };
|
|
|
|
template <>
|
|
|
|
struct out_traits<void*> { typedef void*& type; };
|
2016-06-05 22:54:36 -07:00
|
|
|
template <typename T>
|
2016-08-07 12:52:48 -07:00
|
|
|
struct out_traits<efl::shared_future<T>> { typedef efl::shared_future<T>& type; };
|
2016-06-05 22:54:36 -07:00
|
|
|
|
|
|
|
template <typename T>
|
2016-06-08 13:31:46 -07:00
|
|
|
struct inout_traits { typedef T& type; };
|
2016-06-16 17:48:07 -07:00
|
|
|
template <>
|
|
|
|
struct inout_traits<void> { typedef void* type; };
|
2016-06-05 22:54:36 -07:00
|
|
|
template <typename T>
|
2016-08-07 12:52:48 -07:00
|
|
|
struct inout_traits<efl::shared_future<T>> { typedef efl::shared_future<T>& type; };
|
2016-06-05 22:54:36 -07:00
|
|
|
|
2016-07-05 12:31:35 -07:00
|
|
|
template <typename T>
|
|
|
|
struct return_traits { typedef T type; };
|
|
|
|
template <>
|
|
|
|
struct return_traits<eina::value_view&> { typedef eina::value_view type; };
|
|
|
|
template <>
|
|
|
|
struct return_traits<eina::value_view const&> { typedef eina::value_view type; };
|
|
|
|
|
2016-06-08 13:31:46 -07:00
|
|
|
template <typename To, typename From, bool Own = false, typename Lhs, typename Rhs>
|
|
|
|
void assign_out(Lhs& lhs, Rhs& rhs);
|
|
|
|
|
2016-06-05 22:54:36 -07:00
|
|
|
namespace impl {
|
|
|
|
|
2016-06-08 13:31:46 -07:00
|
|
|
template <typename From, typename To, bool Own = false>
|
2016-06-05 22:54:36 -07:00
|
|
|
struct tag
|
2014-07-16 17:29:47 -07:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
typedef To to;
|
|
|
|
typedef From from;
|
2016-06-08 13:31:46 -07:00
|
|
|
typedef std::integral_constant<bool, Own> own;
|
2016-06-05 22:54:36 -07:00
|
|
|
};
|
|
|
|
|
2017-06-18 07:30:00 -07:00
|
|
|
template <typename T>
|
|
|
|
void assign_out_impl(T*& lhs, T* rhs, tag<T*, T*>)
|
|
|
|
{
|
|
|
|
lhs = rhs;
|
|
|
|
}
|
2016-06-05 22:54:36 -07:00
|
|
|
template <typename T>
|
2016-11-03 12:59:20 -07:00
|
|
|
void assign_out_impl(T& lhs, T*& rhs, tag<T&, T*>, typename std::enable_if<!std::is_const<T>::value>::type* = 0)
|
2016-06-05 22:54:36 -07:00
|
|
|
{
|
2016-06-08 13:31:46 -07:00
|
|
|
lhs = *rhs;
|
2014-07-16 17:29:47 -07:00
|
|
|
}
|
2016-11-03 12:59:20 -07:00
|
|
|
template <typename T>
|
|
|
|
void assign_out_impl(T const& lhs, T const*& rhs, tag<T const&, T const*>)
|
|
|
|
{
|
|
|
|
const_cast<T&>(lhs) = *rhs;
|
|
|
|
}
|
2016-06-16 17:48:07 -07:00
|
|
|
inline void assign_out_impl(void*&, void*&, tag<void*, void*>)
|
|
|
|
{
|
|
|
|
std::abort(); // out parameter of void type?
|
|
|
|
}
|
|
|
|
inline void assign_out_impl(void*&, void*&, tag<void*, void>)
|
|
|
|
{
|
|
|
|
// do nothing, it is an inout parameter of void
|
|
|
|
}
|
2016-06-08 13:31:46 -07:00
|
|
|
template <typename U, typename T, typename D>
|
|
|
|
void assign_out_impl(std::unique_ptr<T, D>& lhs, U* rhs, tag<std::unique_ptr<T, D>&, U*, true>)
|
2015-01-05 09:41:37 -08:00
|
|
|
{
|
2016-06-08 13:31:46 -07:00
|
|
|
// with own
|
2016-06-05 22:54:36 -07:00
|
|
|
lhs.reset(rhs);
|
2015-01-05 09:41:37 -08:00
|
|
|
}
|
2016-06-05 22:54:36 -07:00
|
|
|
template <typename Tag>
|
|
|
|
void assign_out_impl(bool& lhs, Eina_Bool rhs, Tag)
|
2015-01-12 06:00:59 -08:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
lhs = rhs;
|
2015-01-12 06:00:59 -08:00
|
|
|
}
|
2016-06-05 22:54:36 -07:00
|
|
|
template <typename T>
|
|
|
|
void assign_out_impl(T& lhs, T& rhs, tag<T&, T>)
|
2015-01-12 06:00:59 -08:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
lhs = rhs;
|
2015-01-12 06:00:59 -08:00
|
|
|
}
|
2016-06-05 22:54:36 -07:00
|
|
|
template <typename T>
|
|
|
|
void assign_out_impl(T& lhs, Eo* rhs, tag<T&, Eo*>
|
|
|
|
, typename std::enable_if<eo::is_eolian_object<T>::value>::type* = 0)
|
2014-07-16 17:29:47 -07:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
lhs._reset(rhs);
|
2014-07-16 17:29:47 -07:00
|
|
|
}
|
2016-06-05 22:54:36 -07:00
|
|
|
template <typename T>
|
|
|
|
void assign_out_impl(T& lhs, Eo const* rhs, tag<T&, Eo const*>
|
|
|
|
, typename std::enable_if<eo::is_eolian_object<T>::value>::type* = 0)
|
2015-01-05 09:41:37 -08:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
lhs._reset(const_cast<Eo*>(rhs));
|
2015-01-05 09:41:37 -08:00
|
|
|
}
|
2016-06-05 22:54:36 -07:00
|
|
|
template <typename T>
|
2016-08-07 12:52:48 -07:00
|
|
|
void assign_out_impl(efl::shared_future<T>& /*v*/, Efl_Future*, tag<efl::shared_future<T>&, Efl_Future*>)
|
2014-07-16 17:29:47 -07:00
|
|
|
{
|
|
|
|
}
|
2016-06-05 22:54:36 -07:00
|
|
|
template <typename Tag>
|
|
|
|
void assign_out_impl(efl::eina::string_view& view, const char* string, Tag)
|
2014-09-30 14:08:06 -07:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
view = {string};
|
2014-09-30 14:08:06 -07:00
|
|
|
}
|
2016-06-08 13:31:46 -07:00
|
|
|
template <typename Tag>
|
|
|
|
void assign_out_impl(efl::eina::string_view* view, const char* string, Tag)
|
2014-11-25 10:18:08 -08:00
|
|
|
{
|
2016-06-08 13:31:46 -07:00
|
|
|
if(view)
|
|
|
|
*view = {string};
|
2014-11-25 10:18:08 -08:00
|
|
|
}
|
2016-06-21 12:35:09 -07:00
|
|
|
template <typename Tag>
|
|
|
|
void assign_out_impl(efl::eina::stringshare& to, const char* from, Tag)
|
|
|
|
{
|
2016-10-19 23:52:18 -07:00
|
|
|
to = from;
|
2016-06-21 12:35:09 -07:00
|
|
|
}
|
2016-06-08 13:31:46 -07:00
|
|
|
template <typename T>
|
|
|
|
void assign_out_impl(T*& lhs, T& rhs, tag<T*, T>) // optional
|
2015-01-05 09:41:37 -08:00
|
|
|
{
|
2016-06-08 13:31:46 -07:00
|
|
|
if(lhs)
|
|
|
|
*lhs = rhs;
|
2015-01-05 09:41:37 -08:00
|
|
|
}
|
2016-06-08 13:31:46 -07:00
|
|
|
template <typename T, typename Rhs, typename U, typename O, bool B>
|
|
|
|
void assign_out_impl(efl::eina::optional<T>& lhs, Rhs& rhs, tag<efl::eina::optional<U&>, O, B>)
|
2014-11-25 10:18:08 -08:00
|
|
|
{
|
2016-06-08 13:31:46 -07:00
|
|
|
if(lhs)
|
|
|
|
assign_out<U&, O, true>(*lhs, rhs);
|
2014-11-25 10:18:08 -08:00
|
|
|
}
|
2016-06-05 22:54:36 -07:00
|
|
|
template <typename Tag>
|
2016-07-05 12:31:35 -07:00
|
|
|
void assign_out_impl(eina::value& lhs, Eina_Value& rhs, Tag)
|
|
|
|
{
|
|
|
|
Eina_Value* v = eina_value_new(EINA_VALUE_TYPE_CHAR);
|
|
|
|
eina_value_flush(v);
|
|
|
|
eina_value_copy(&rhs, v);
|
2016-10-19 23:52:18 -07:00
|
|
|
lhs.reset(v);
|
2016-07-05 12:31:35 -07:00
|
|
|
eina_value_flush(&rhs);
|
|
|
|
}
|
|
|
|
// This is a invalid use-case that is used in EFL. This leaks
|
|
|
|
template <typename Tag>
|
|
|
|
void assign_out_impl(eina::value_view& lhs, Eina_Value& rhs, Tag)
|
2014-11-25 10:18:08 -08:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
Eina_Value* v = eina_value_new(EINA_VALUE_TYPE_CHAR);
|
|
|
|
eina_value_flush(v);
|
|
|
|
eina_value_copy(&rhs, v);
|
2016-10-19 23:52:18 -07:00
|
|
|
lhs.reset(v);
|
2014-11-25 10:18:08 -08:00
|
|
|
}
|
2016-06-08 13:31:46 -07:00
|
|
|
template <typename T>
|
|
|
|
void assign_out_impl(efl::eina::list<T>& lhs, Eina_List* rhs, tag<efl::eina::list<T>&, Eina_List*, true>)
|
2015-01-05 09:41:37 -08:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
lhs = efl::eina::list<T>{rhs};
|
2015-01-05 09:41:37 -08:00
|
|
|
}
|
2016-06-08 13:31:46 -07:00
|
|
|
template <typename T>
|
|
|
|
void assign_out_impl(efl::eina::range_list<T>& lhs, Eina_List* rhs, tag<efl::eina::range_list<T>&, Eina_List*>)
|
|
|
|
{
|
|
|
|
lhs = efl::eina::range_list<T>{rhs};
|
|
|
|
}
|
|
|
|
template <typename T>
|
|
|
|
void assign_out_impl(efl::eina::array<T>& lhs, Eina_Array* rhs, tag<efl::eina::array<T>&, Eina_Array*, true>)
|
|
|
|
{
|
|
|
|
lhs = efl::eina::array<T>{rhs};
|
|
|
|
}
|
|
|
|
template <typename T>
|
|
|
|
void assign_out_impl(efl::eina::range_array<T>& lhs, Eina_Array* rhs, tag<efl::eina::range_array<T>&, Eina_Array*>)
|
|
|
|
{
|
|
|
|
lhs = efl::eina::range_array<T>{rhs};
|
|
|
|
}
|
|
|
|
inline void assign_out_impl(Eina_Hash*& lhs, Eina_Hash*& rhs, tag<Eina_Hash*&, Eina_Hash*, true>)
|
|
|
|
{
|
|
|
|
lhs = rhs;
|
|
|
|
}
|
|
|
|
template <typename T>
|
|
|
|
void assign_out_impl(efl::eina::iterator<T>& /*lhs*/, Eina_Iterator* /*rhs*/, tag<efl::eina::iterator<T>&, Eina_Iterator*>)
|
|
|
|
{
|
|
|
|
// Must copy here
|
|
|
|
std::abort();
|
|
|
|
}
|
|
|
|
template <typename T>
|
|
|
|
void assign_out_impl(efl::eina::iterator<T>& lhs, Eina_Iterator* rhs, tag<efl::eina::iterator<T>&, Eina_Iterator*, true>)
|
|
|
|
{
|
|
|
|
lhs = efl::eina::iterator<T>{rhs};
|
|
|
|
}
|
|
|
|
template <typename T>
|
|
|
|
void assign_out_impl(efl::eina::accessor<T>& lhs, Eina_Accessor* rhs, tag<efl::eina::accessor<T>&, Eina_Accessor*>)
|
|
|
|
{
|
|
|
|
lhs = efl::eina::accessor<T>{ ::eina_accessor_clone(rhs) };
|
|
|
|
}
|
|
|
|
template <typename T>
|
|
|
|
void assign_out_impl(efl::eina::accessor<T>& lhs, Eina_Accessor* rhs, tag<efl::eina::accessor<T>&, Eina_Accessor*, true>)
|
|
|
|
{
|
|
|
|
lhs = efl::eina::accessor<T>{rhs};
|
|
|
|
}
|
2016-06-05 22:54:36 -07:00
|
|
|
}
|
|
|
|
|
2016-06-08 13:31:46 -07:00
|
|
|
template <typename To, typename From, bool Own, typename Lhs, typename Rhs>
|
2016-06-05 22:54:36 -07:00
|
|
|
void assign_out(Lhs& lhs, Rhs& rhs)
|
2014-11-25 10:18:08 -08:00
|
|
|
{
|
2016-06-08 13:31:46 -07:00
|
|
|
return impl::assign_out_impl(lhs, rhs, impl::tag<To, From, Own>{});
|
2014-11-25 10:18:08 -08:00
|
|
|
}
|
2014-07-17 10:05:19 -07:00
|
|
|
|
2016-06-05 22:54:36 -07:00
|
|
|
namespace impl {
|
2014-07-16 17:29:47 -07:00
|
|
|
|
|
|
|
template <typename T>
|
2016-06-05 22:54:36 -07:00
|
|
|
T* convert_inout_impl(T& v, tag<T, T*>)
|
2014-07-16 17:29:47 -07:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
return v;
|
2014-07-16 17:29:47 -07:00
|
|
|
}
|
2017-07-27 09:19:49 -07:00
|
|
|
inline Eina_Bool convert_inout_impl(bool v, tag<bool, Eina_Bool>)
|
|
|
|
{
|
|
|
|
return v ? EINA_TRUE : EINA_FALSE;
|
|
|
|
}
|
2016-06-16 17:48:07 -07:00
|
|
|
inline void* convert_inout_impl(void* v, tag<void, void>)
|
|
|
|
{
|
|
|
|
return v;
|
|
|
|
}
|
2016-06-05 22:54:36 -07:00
|
|
|
template <typename T>
|
|
|
|
T& convert_inout_impl(T& v, tag<T, T>)
|
2014-07-16 17:29:47 -07:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
return v;
|
2014-07-16 17:29:47 -07:00
|
|
|
}
|
|
|
|
template <typename T>
|
2016-06-05 22:54:36 -07:00
|
|
|
Eo* convert_inout_impl(T& v, tag<T, Eo*>
|
|
|
|
, typename std::enable_if<eo::is_eolian_object<T>::value>::type* = 0)
|
2014-07-16 17:29:47 -07:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
return v._eo_ptr();
|
2014-07-16 17:29:47 -07:00
|
|
|
}
|
|
|
|
template <typename T>
|
2016-06-05 22:54:36 -07:00
|
|
|
Eo const* convert_inout_impl(T v, tag<T, Eo const*>
|
|
|
|
, typename std::enable_if<eo::is_eolian_object<T>::value>::type* = 0)
|
2014-07-16 17:29:47 -07:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
return v._eo_ptr();
|
2014-07-16 17:29:47 -07:00
|
|
|
}
|
2015-01-05 09:41:37 -08:00
|
|
|
template <typename T>
|
2016-08-07 12:52:48 -07:00
|
|
|
Efl_Future* convert_inout_impl(efl::shared_future<T>& /*v*/, tag<efl::shared_future<T>, Efl_Future*>)
|
2016-06-05 22:54:36 -07:00
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename To, typename From, typename V>
|
|
|
|
auto convert_inout(V& object) -> decltype(impl::convert_inout_impl(object, impl::tag<From, To>{}))
|
2015-01-05 09:41:37 -08:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
return impl::convert_inout_impl(object, impl::tag<From, To>{});
|
2015-01-05 09:41:37 -08:00
|
|
|
}
|
2016-06-05 22:54:36 -07:00
|
|
|
|
2016-06-08 13:31:46 -07:00
|
|
|
template <typename T, typename U, bool Own = false, typename V>
|
2016-06-05 22:54:36 -07:00
|
|
|
T convert_to_c(V&& object);
|
|
|
|
|
|
|
|
namespace impl {
|
2015-01-05 09:41:37 -08:00
|
|
|
|
2017-01-18 16:25:02 -08:00
|
|
|
template <typename U, typename T, typename V>
|
2016-06-05 22:54:36 -07:00
|
|
|
auto convert_to_c_impl
|
2017-01-18 16:25:02 -08:00
|
|
|
(V&& v, tag<U, T>, typename std::enable_if<std::is_same<typename std::remove_reference<T>::type, U>::value>::type* =0) -> decltype(std::forward<V>(v))
|
2015-01-05 09:41:37 -08:00
|
|
|
{
|
2017-01-18 16:25:02 -08:00
|
|
|
return std::forward<V>(v);
|
2015-01-05 09:41:37 -08:00
|
|
|
}
|
|
|
|
|
2016-06-08 13:31:46 -07:00
|
|
|
template <typename T>
|
|
|
|
T convert_to_c_impl(T& /*v*/, tag<T, T, true>)
|
|
|
|
{
|
|
|
|
std::abort();
|
|
|
|
}
|
|
|
|
template <typename T>
|
|
|
|
T* convert_to_c_impl(T& v, tag<T*, T&>)
|
|
|
|
{
|
|
|
|
return &v;
|
|
|
|
}
|
|
|
|
template <typename T>
|
2016-06-15 13:47:19 -07:00
|
|
|
T* convert_to_c_impl(T& /*v*/, tag<T*, T&, true>)
|
2016-06-08 13:31:46 -07:00
|
|
|
{
|
|
|
|
std::abort();
|
|
|
|
}
|
|
|
|
template <typename T>
|
|
|
|
T* convert_to_c_impl(T const& v, tag<T*, T const&>) // not own
|
|
|
|
{
|
|
|
|
return const_cast<T*>(&v);
|
|
|
|
}
|
|
|
|
template <typename T>
|
|
|
|
T* convert_to_c_impl(T const& v, tag<T*, T const&, true>) // with own
|
|
|
|
{
|
|
|
|
T* r = static_cast<T*>(malloc(sizeof(T)));
|
|
|
|
*r = v;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
template <typename T>
|
|
|
|
T const* convert_to_c_impl(T& v, tag<T const*, T&>)
|
|
|
|
{
|
|
|
|
return &v;
|
|
|
|
}
|
|
|
|
template <typename T>
|
|
|
|
T const* convert_to_c_impl(T* v, tag<T const*, T*>)
|
|
|
|
{
|
|
|
|
return v;
|
|
|
|
}
|
2014-12-30 15:18:40 -08:00
|
|
|
template <typename T>
|
2016-06-05 22:54:36 -07:00
|
|
|
T const& convert_to_c_impl(T const& v, tag<T, T const&>)
|
2014-12-30 15:18:40 -08:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
return v;
|
2014-12-30 15:18:40 -08:00
|
|
|
}
|
2014-07-16 17:29:47 -07:00
|
|
|
template <typename T>
|
2016-06-05 22:54:36 -07:00
|
|
|
Eo* convert_to_c_impl(T v, tag<Eo*, T>
|
|
|
|
, typename std::enable_if<eo::is_eolian_object<T>::value>::type* = 0)
|
2014-07-16 17:29:47 -07:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
return v._eo_ptr();
|
2014-07-16 17:29:47 -07:00
|
|
|
}
|
2016-06-05 22:54:36 -07:00
|
|
|
template <typename T>
|
2016-06-08 13:31:46 -07:00
|
|
|
Eo* convert_to_c_impl(T v, tag<Eo*, T, true>
|
|
|
|
, typename std::enable_if<eo::is_eolian_object<T>::value>::type* = 0)
|
|
|
|
{
|
2016-08-15 11:14:53 -07:00
|
|
|
return ::efl_ref(v._eo_ptr());
|
2016-06-08 13:31:46 -07:00
|
|
|
}
|
|
|
|
template <typename T>
|
2016-06-05 22:54:36 -07:00
|
|
|
Eo const* convert_to_c_impl(T v, tag<Eo const*, T>
|
|
|
|
, typename std::enable_if<eo::is_eolian_object<T>::value>::type* = 0)
|
2014-07-16 17:29:47 -07:00
|
|
|
{
|
2016-06-08 13:31:46 -07:00
|
|
|
return const_cast<Eo const*>(v._eo_ptr());
|
2014-07-16 17:29:47 -07:00
|
|
|
}
|
2016-07-05 12:31:35 -07:00
|
|
|
template <typename T>
|
|
|
|
Eo** convert_to_c_impl(T& v, tag<Eo**, T&>
|
|
|
|
, typename std::enable_if<eo::is_eolian_object<T>::value>::type* = 0)
|
|
|
|
{
|
|
|
|
return reinterpret_cast<Eo**>(static_cast<void*>(&v));
|
|
|
|
}
|
2016-06-05 22:54:36 -07:00
|
|
|
inline const char* convert_to_c_impl( ::efl::eina::string_view v, tag<const char*, ::efl::eina::string_view>)
|
2014-07-16 17:29:47 -07:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
return v.c_str();
|
2014-07-16 17:29:47 -07:00
|
|
|
}
|
2016-06-08 13:31:46 -07:00
|
|
|
inline const char* convert_to_c_impl( ::efl::eina::string_view v, tag<const char*, ::efl::eina::string_view, true>)
|
|
|
|
{
|
|
|
|
char* string = static_cast<char*>(malloc(v.size() + 1));
|
|
|
|
std::strcpy(string, v.c_str());
|
|
|
|
return string;
|
|
|
|
}
|
2016-06-05 22:54:36 -07:00
|
|
|
inline const char** convert_to_c_impl(efl::eina::string_view* /*view*/, tag<const char **, efl::eina::string_view*>)
|
2015-01-05 09:41:37 -08:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
std::abort();
|
2015-01-05 09:41:37 -08:00
|
|
|
}
|
2016-06-05 22:54:36 -07:00
|
|
|
inline const char* convert_to_c_impl( std::string const& v, tag<const char*, std::string const&>)
|
2015-01-12 06:00:59 -08:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
std::size_t len = v.size()+1;
|
|
|
|
char* buffer = static_cast<char*>(malloc(len));
|
|
|
|
std::memcpy(buffer, v.data(), len);
|
|
|
|
return buffer;
|
2015-01-12 06:00:59 -08:00
|
|
|
}
|
2016-06-05 22:54:36 -07:00
|
|
|
inline const char** convert_to_c_impl(std::string* /*view*/, tag<const char **, std::string*>)
|
2015-01-12 06:00:59 -08:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
std::abort();
|
2015-01-12 06:00:59 -08:00
|
|
|
}
|
2016-06-05 22:54:36 -07:00
|
|
|
inline Eina_Value* convert_to_c_impl( ::efl::eina::value v, tag<Eina_Value*, in_traits<eina::value>::type>)
|
2014-07-16 17:29:47 -07:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
Eina_Value* nv = eina_value_new(v.type_info());
|
|
|
|
eina_value_copy(v.native_handle(), nv);
|
|
|
|
return nv;
|
|
|
|
}
|
2016-07-05 12:31:35 -07:00
|
|
|
inline Eina_Value const* convert_to_c_impl( ::efl::eina::value& v, tag<Eina_Value const*, in_traits<eina::value>::type>)
|
2016-06-05 22:54:36 -07:00
|
|
|
{
|
|
|
|
Eina_Value* nv = eina_value_new(v.type_info());
|
|
|
|
eina_value_copy(v.native_handle(), nv);
|
|
|
|
return nv;
|
|
|
|
}
|
2016-07-05 12:31:35 -07:00
|
|
|
inline Eina_Value const* convert_to_c_impl( ::efl::eina::value_view const& v, tag<Eina_Value const*, in_traits<eina::value_view const&>::type>)
|
|
|
|
{
|
|
|
|
return v.native_handle();
|
|
|
|
}
|
|
|
|
inline Eina_Value* convert_to_c_impl( ::efl::eina::value_view& v, tag<Eina_Value*, in_traits<eina::value_view&>::type>)
|
|
|
|
{
|
|
|
|
return v.native_handle();
|
|
|
|
}
|
|
|
|
inline Eina_Value* convert_to_c_impl( ::efl::eina::value_view const& v, tag<Eina_Value*, in_traits<eina::value_view const&>::type>)
|
|
|
|
{
|
|
|
|
return const_cast<Eina_Value*>(v.native_handle());
|
|
|
|
}
|
2016-06-05 22:54:36 -07:00
|
|
|
inline Eina_Bool convert_to_c_impl( bool b, tag<Eina_Bool, bool>)
|
|
|
|
{
|
|
|
|
return b;
|
|
|
|
}
|
2014-07-16 17:29:47 -07:00
|
|
|
template <typename T>
|
2016-06-05 22:54:36 -07:00
|
|
|
T convert_to_c_impl(efl::eina::optional<T> const& optional, tag<T, efl::eina::optional<T>const&>)
|
2014-07-16 17:29:47 -07:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
return optional ? *optional : T{};
|
|
|
|
}
|
2016-06-08 13:31:46 -07:00
|
|
|
template <typename T>
|
|
|
|
T* convert_to_c_impl(efl::eina::optional<T const&>const& optional, tag<T*, efl::eina::optional<T const&>const&, true>)
|
|
|
|
{
|
|
|
|
if(optional)
|
|
|
|
{
|
|
|
|
T* r = static_cast<T*>(malloc(sizeof(T)));
|
|
|
|
*r = *optional;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-06-05 22:54:36 -07:00
|
|
|
template <typename U, typename T>
|
|
|
|
U convert_to_c_impl(efl::eina::optional<T> const& optional, tag<U, efl::eina::optional<T>const&>)
|
|
|
|
{
|
|
|
|
return impl::convert_to_c_impl(optional ? *optional : T{}, tag<U, typename in_traits<T>::type>{});
|
|
|
|
}
|
2014-07-16 17:29:47 -07:00
|
|
|
template <typename T>
|
2016-06-05 22:54:36 -07:00
|
|
|
Eina_List* convert_to_c_impl(efl::eina::range_list<T> range, tag<Eina_List *, efl::eina::range_list<T>>)
|
2014-07-16 17:29:47 -07:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
return range.native_handle();
|
|
|
|
}
|
2015-01-12 06:00:59 -08:00
|
|
|
template <typename T>
|
2016-06-05 22:54:36 -07:00
|
|
|
Eina_List const* convert_to_c_impl(efl::eina::range_list<T> range, tag<Eina_List const *, efl::eina::range_list<T>>)
|
2015-01-12 06:00:59 -08:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
return range.native_handle();
|
|
|
|
}
|
|
|
|
template <typename T>
|
2016-06-08 13:31:46 -07:00
|
|
|
Eina_List* convert_to_c_impl(efl::eina::list<T>const& c, tag<Eina_List *, efl::eina::list<T>const&, true>)
|
2014-07-16 17:29:47 -07:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
return const_cast<Eina_List*>(c.native_handle());
|
2014-07-16 17:29:47 -07:00
|
|
|
}
|
2016-06-05 22:54:36 -07:00
|
|
|
template <typename T>
|
2016-06-08 13:31:46 -07:00
|
|
|
Eina_List const* convert_to_c_impl(efl::eina::list<T>const& c, tag<Eina_List const *, efl::eina::list<T>const&, true>)
|
2015-01-05 09:41:37 -08:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
return c.native_handle();
|
2015-01-05 09:41:37 -08:00
|
|
|
}
|
2016-06-08 13:31:46 -07:00
|
|
|
|
2016-06-05 22:54:36 -07:00
|
|
|
template <typename T>
|
|
|
|
Eina_Array* convert_to_c_impl(efl::eina::range_array<T> range, tag<Eina_Array *, efl::eina::range_array<T>>)
|
2014-07-17 17:46:13 -07:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
return range.native_handle();
|
2014-07-16 17:29:47 -07:00
|
|
|
}
|
2016-06-05 22:54:36 -07:00
|
|
|
template <typename T>
|
|
|
|
Eina_Array const* convert_to_c_impl(efl::eina::range_array<T> range, tag<Eina_Array const *, efl::eina::range_array<T>>)
|
2015-01-05 09:41:37 -08:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
return range.native_handle();
|
2015-01-05 09:41:37 -08:00
|
|
|
}
|
2016-06-05 22:54:36 -07:00
|
|
|
template <typename T>
|
2016-06-08 13:31:46 -07:00
|
|
|
Eina_Array* convert_to_c_impl(efl::eina::array<T>const& c, tag<Eina_Array *, efl::eina::array<T>const&, true>)
|
2014-07-17 17:46:13 -07:00
|
|
|
{
|
2016-06-08 13:31:46 -07:00
|
|
|
return const_cast<Eina_Array*>(c.native_handle());
|
2014-07-16 17:29:47 -07:00
|
|
|
}
|
2016-06-05 22:54:36 -07:00
|
|
|
template <typename T>
|
2016-06-08 13:31:46 -07:00
|
|
|
Eina_Array const* convert_to_c_impl(efl::eina::array<T>const& c, tag<Eina_Array const *, efl::eina::array<T>const&, true>)
|
2015-01-05 09:41:37 -08:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
return c.native_handle();
|
2015-01-05 09:41:37 -08:00
|
|
|
}
|
2016-06-08 13:31:46 -07:00
|
|
|
template <typename T>
|
|
|
|
Eina_Iterator* convert_to_c_impl(efl::eina::iterator<T>const& i, tag<Eina_Iterator *, efl::eina::iterator<T>const&>)
|
|
|
|
{
|
|
|
|
return const_cast<Eina_Iterator*>(i.native_handle());
|
|
|
|
}
|
|
|
|
template <typename T>
|
|
|
|
Eina_Iterator const* convert_to_c_impl(efl::eina::iterator<T>const& i, tag<Eina_Iterator const*, efl::eina::iterator<T>const&>)
|
|
|
|
{
|
|
|
|
return i.native_handle();
|
|
|
|
}
|
|
|
|
template <typename T>
|
|
|
|
Eina_Iterator* convert_to_c_impl(efl::eina::iterator<T>const& /*i*/, tag<Eina_Iterator *, efl::eina::iterator<T>const&, true>)
|
|
|
|
{
|
|
|
|
// Eina Iterator must be copied
|
|
|
|
std::abort();
|
|
|
|
}
|
|
|
|
template <typename T>
|
|
|
|
Eina_Accessor* convert_to_c_impl(efl::eina::accessor<T>const& i, tag<Eina_Accessor *, efl::eina::accessor<T>const&>)
|
|
|
|
{
|
|
|
|
return const_cast<Eina_Accessor*>(i.native_handle());
|
|
|
|
}
|
|
|
|
template <typename T>
|
|
|
|
Eina_Accessor const* convert_to_c_impl(efl::eina::accessor<T>const& i, tag<Eina_Accessor const*, efl::eina::accessor<T>const&>)
|
|
|
|
{
|
|
|
|
return i.native_handle();
|
|
|
|
}
|
|
|
|
template <typename T>
|
|
|
|
Eina_Accessor* convert_to_c_impl(efl::eina::accessor<T>const& i, tag<Eina_Accessor *, efl::eina::accessor<T>const&, true>)
|
|
|
|
{
|
|
|
|
return ::eina_accessor_clone(const_cast<Eina_Accessor*>(i.native_handle()));
|
|
|
|
}
|
2016-06-05 22:54:36 -07:00
|
|
|
inline const char** convert_to_c_impl(efl::eina::string_view /*view*/, tag<char const **, efl::eina::string_view>)
|
2016-05-23 13:34:50 -07:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
std::abort();
|
2016-05-23 13:34:50 -07:00
|
|
|
}
|
2016-06-08 13:31:46 -07:00
|
|
|
inline const char** convert_to_c_impl(efl::eina::string_view /*view*/, tag<char const **, efl::eina::string_view, true>)
|
|
|
|
{
|
|
|
|
std::abort();
|
|
|
|
}
|
2016-06-05 22:54:36 -07:00
|
|
|
inline const char* convert_to_c_impl(efl::eina::stringshare x, tag<const char*, efl::eina::stringshare>)
|
2016-05-23 13:34:50 -07:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
return x.c_str();
|
2016-05-23 13:34:50 -07:00
|
|
|
}
|
2016-06-21 12:35:09 -07:00
|
|
|
inline const char* convert_to_c_impl(efl::eina::stringshare x, tag<const char*, efl::eina::stringshare, true>)
|
|
|
|
{
|
|
|
|
return eina_stringshare_ref(x.c_str());
|
|
|
|
}
|
2016-06-05 22:54:36 -07:00
|
|
|
template <typename T>
|
2016-08-07 12:52:48 -07:00
|
|
|
Efl_Future* convert_to_c_impl(efl::shared_future<T> const&, tag<Efl_Future*, efl::shared_future<T>const&>)
|
2016-05-23 13:34:50 -07:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
std::abort();
|
2016-05-23 13:34:50 -07:00
|
|
|
}
|
2016-06-05 22:54:36 -07:00
|
|
|
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>>)
|
2016-05-23 13:34:50 -07:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
return convert_to_c<T*, U*>(v.release());
|
2016-05-23 13:34:50 -07:00
|
|
|
}
|
2016-06-05 22:54:36 -07:00
|
|
|
template <typename T>
|
2016-06-08 08:55:19 -07:00
|
|
|
Eina_Array** convert_to_c_impl(efl::eina::array<T>& /*c*/, tag<Eina_Array **, efl::eina::array<T>&>)
|
2016-05-23 13:34:50 -07:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
std::abort();
|
2016-05-23 13:34:50 -07:00
|
|
|
}
|
2016-06-05 22:54:36 -07:00
|
|
|
template <typename T>
|
2016-06-08 08:55:19 -07:00
|
|
|
Eina_Array** convert_to_c_impl(efl::eina::range_array<T>& /*c*/, tag<Eina_Array **, efl::eina::range_array<T>&>)
|
2016-05-23 13:34:50 -07:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
std::abort();
|
|
|
|
}
|
2017-06-18 07:30:00 -07:00
|
|
|
template <typename T>
|
|
|
|
T* convert_to_c_impl(T const* p, tag<T*, T const*>) // needed for property_get
|
|
|
|
{
|
|
|
|
return const_cast<T*>(p);
|
2016-05-23 13:34:50 -07:00
|
|
|
}
|
2017-06-18 07:30:00 -07:00
|
|
|
}
|
|
|
|
|
2016-06-08 13:31:46 -07:00
|
|
|
template <typename T, typename U, bool Own, typename V>
|
2016-06-05 22:54:36 -07:00
|
|
|
T convert_to_c(V&& object)
|
2014-07-16 17:29:47 -07:00
|
|
|
{
|
2016-06-08 13:31:46 -07:00
|
|
|
return impl::convert_to_c_impl(std::forward<V>(object), impl::tag<T, U, Own>{});
|
2014-07-16 17:29:47 -07:00
|
|
|
}
|
2016-06-05 22:54:36 -07:00
|
|
|
namespace impl {
|
|
|
|
template <typename T>
|
|
|
|
struct is_range : std::false_type {};
|
|
|
|
template <typename T>
|
|
|
|
struct is_range<efl::eina::range_list<T>> : std::true_type {};
|
|
|
|
template <typename T>
|
|
|
|
struct is_range<efl::eina::range_array<T>> : std::true_type {};
|
2014-07-16 17:29:47 -07:00
|
|
|
|
2016-06-05 22:54:36 -07:00
|
|
|
template <typename T>
|
|
|
|
struct is_container : std::false_type {};
|
|
|
|
template <typename T>
|
|
|
|
struct is_container<efl::eina::list<T>> : std::true_type {};
|
|
|
|
template <typename T>
|
|
|
|
struct is_container<efl::eina::array<T>> : std::true_type {};
|
|
|
|
|
|
|
|
// event
|
|
|
|
template <typename T>
|
|
|
|
T convert_to_event(void* value, typename std::enable_if< eo::is_eolian_object<T>::value>::type* = 0)
|
2015-01-05 09:41:37 -08:00
|
|
|
{
|
2016-08-15 11:14:53 -07:00
|
|
|
return T{::efl_ref(static_cast<Eo*>(value))};
|
2015-01-05 09:41:37 -08:00
|
|
|
}
|
2016-06-05 22:54:36 -07:00
|
|
|
template <typename T>
|
|
|
|
T convert_to_event(void* value, typename std::enable_if< is_container<T>::value
|
|
|
|
|| is_range<T>::value>::type* = 0)
|
2014-07-16 17:29:47 -07:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
return T{static_cast<typename T::native_handle_type>(value)};
|
2014-07-16 17:29:47 -07:00
|
|
|
}
|
2016-06-05 22:54:36 -07:00
|
|
|
template <typename T>
|
|
|
|
T convert_to_event(void* value, typename std::enable_if< !std::is_pointer<T>::value
|
|
|
|
&& !is_container<T>::value && !is_range<T>::value
|
|
|
|
&& !eo::is_eolian_object<T>::value>::type* = 0)
|
2015-01-05 09:41:37 -08:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
return *static_cast<T*>(value);
|
2015-01-05 09:41:37 -08:00
|
|
|
}
|
2016-06-05 22:54:36 -07:00
|
|
|
template <typename T>
|
|
|
|
T convert_to_event(void* value, typename std::enable_if<std::is_same<T, bool>::value>::type* = 0)
|
2014-07-16 17:29:47 -07:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
return *static_cast<Eina_Bool*>(value);
|
2014-07-16 17:29:47 -07:00
|
|
|
}
|
2016-06-05 22:54:36 -07:00
|
|
|
}
|
|
|
|
template <typename T>
|
|
|
|
T convert_to_event(void* value) { return impl::convert_to_event<T>(value); }
|
|
|
|
namespace impl {
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
T convert_to_return(T value, tag<T, T>)
|
2015-01-05 09:41:37 -08:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
return value;
|
2015-01-05 09:41:37 -08:00
|
|
|
}
|
2017-08-10 11:52:25 -07:00
|
|
|
template <typename U, typename T>
|
|
|
|
T convert_to_return(U const value, tag<U const, T>)
|
|
|
|
{
|
|
|
|
return value;
|
|
|
|
}
|
2016-06-05 22:54:36 -07:00
|
|
|
template <typename T>
|
2016-06-08 13:31:46 -07:00
|
|
|
T& convert_to_return(T* value, tag<T*, T&>)
|
|
|
|
{
|
|
|
|
return *value;
|
|
|
|
}
|
|
|
|
template <typename T>
|
2016-06-05 22:54:36 -07:00
|
|
|
T convert_to_return(Eo* value, tag<Eo*, T>, typename std::enable_if< eo::is_eolian_object<T>::value>::type* = 0)
|
2014-07-17 17:46:13 -07:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
return T{value};
|
2014-07-17 17:46:13 -07:00
|
|
|
}
|
2016-06-05 22:54:36 -07:00
|
|
|
template <typename T>
|
|
|
|
T convert_to_return(Eo const* value, tag<Eo const*, T>, typename std::enable_if<eo::is_eolian_object<T>::value>::type* = 0)
|
2015-01-05 09:41:37 -08:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
return T{const_cast<Eo*>(value)};
|
2015-01-05 09:41:37 -08:00
|
|
|
}
|
2016-06-05 22:54:36 -07:00
|
|
|
template <typename T>
|
|
|
|
eina::list<T> convert_to_return(Eina_List* value, tag<Eina_List*, eina::list<T>>)
|
2014-07-17 17:46:13 -07:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
return eina::list<T>{value};
|
2014-07-17 17:46:13 -07:00
|
|
|
}
|
2016-06-05 22:54:36 -07:00
|
|
|
template <typename T>
|
|
|
|
eina::list<T> convert_to_return(Eina_List const* value, tag<Eina_List const*, eina::list<T>>)
|
2015-01-05 09:41:37 -08:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
return eina::list<T>{const_cast<Eina_List*>(value)};
|
2015-01-05 09:41:37 -08:00
|
|
|
}
|
2016-06-05 22:54:36 -07:00
|
|
|
template <typename T>
|
|
|
|
eina::range_list<T> convert_to_return(Eina_List* value, tag<Eina_List*, eina::range_list<T>>)
|
2014-07-16 17:29:47 -07:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
return eina::range_list<T>{value};
|
2014-07-16 17:29:47 -07:00
|
|
|
}
|
2016-06-05 22:54:36 -07:00
|
|
|
template <typename T>
|
|
|
|
eina::range_list<T> convert_to_return(Eina_List const* value, tag<Eina_List const*, eina::range_list<T>>)
|
2014-07-16 17:29:47 -07:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
return eina::range_list<T>{const_cast<Eina_List*>(value)};
|
2014-07-16 17:29:47 -07:00
|
|
|
}
|
|
|
|
template <typename T>
|
2016-06-05 22:54:36 -07:00
|
|
|
eina::array<T> convert_to_return(Eina_Array* value, tag<Eina_Array*, eina::array<T>>)
|
2014-07-16 17:29:47 -07:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
return eina::array<T>{value};
|
|
|
|
}
|
|
|
|
template <typename T>
|
|
|
|
eina::array<T> convert_to_return(Eina_Array const* value, tag<Eina_Array const*, eina::array<T>>)
|
2014-07-16 17:29:47 -07:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
return eina::array<T>{const_cast<Eina_Array*>(value)};
|
|
|
|
}
|
|
|
|
template <typename T>
|
|
|
|
eina::range_array<T> convert_to_return(Eina_Array* value, tag<Eina_Array*, eina::range_array<T>>)
|
2014-07-16 17:29:47 -07:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
return eina::range_array<T>{value};
|
2014-07-16 17:29:47 -07:00
|
|
|
}
|
2016-06-05 22:54:36 -07:00
|
|
|
template <typename T>
|
|
|
|
eina::range_array<T> convert_to_return(Eina_Array const* value, tag<Eina_Array const*, eina::range_array<T>>)
|
2014-07-16 17:29:47 -07:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
return eina::range_array<T>{const_cast<Eina_Array*>(value)};
|
2014-07-16 17:29:47 -07:00
|
|
|
}
|
2016-06-05 22:54:36 -07:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
eina::iterator<T> convert_to_return(Eina_Iterator* value, tag<Eina_Iterator*, eina::iterator<T>>)
|
2014-11-19 07:59:21 -08:00
|
|
|
{
|
2016-06-12 21:17:18 -07:00
|
|
|
return eina::iterator<T>{ value };
|
|
|
|
}
|
|
|
|
template <typename T>
|
|
|
|
eina::accessor<T> convert_to_return(Eina_Accessor* value, tag<Eina_Accessor*, eina::accessor<T>>)
|
|
|
|
{
|
|
|
|
return eina::accessor<T>{ value };
|
2014-11-19 07:59:21 -08:00
|
|
|
}
|
2016-06-05 22:54:36 -07:00
|
|
|
template <typename T>
|
2016-08-07 12:52:48 -07:00
|
|
|
efl::shared_future<T> convert_to_return(Efl_Future* /*value*/, tag<Efl_Future*, efl::shared_future<T>>)
|
2015-03-26 07:48:09 -07:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
std::abort();
|
|
|
|
return {};
|
2015-03-26 07:48:09 -07:00
|
|
|
}
|
2016-06-05 22:54:36 -07:00
|
|
|
// Eina_Value*
|
|
|
|
inline efl::eina::value convert_to_return(Eina_Value* value, tag<Eina_Value*, efl::eina::value>)
|
|
|
|
{
|
|
|
|
return efl::eina::value{value};
|
|
|
|
}
|
2016-07-05 12:31:35 -07:00
|
|
|
inline efl::eina::value_view convert_to_return(Eina_Value* value, tag<Eina_Value*, efl::eina::value_view>)
|
|
|
|
{
|
|
|
|
return efl::eina::value_view{value};
|
|
|
|
}
|
2016-06-05 22:54:36 -07:00
|
|
|
template <typename T, typename U>
|
|
|
|
T convert_to_return(U* value, tag<T, U*>, typename std::enable_if<is_range<T>::value || is_container<T>::value>::type* = 0)
|
|
|
|
{
|
|
|
|
// const should be to the type if value is const
|
|
|
|
return T{const_cast<typename std::remove_const<U>::type*>(value)};
|
|
|
|
}
|
2016-06-21 12:35:09 -07:00
|
|
|
inline eina::stringshare convert_to_return(const Eina_Stringshare* value, tag<const char*, efl::eina::stringshare>)
|
|
|
|
{
|
|
|
|
return efl::eina::stringshare(value);
|
|
|
|
}
|
2016-06-05 22:54:36 -07:00
|
|
|
template <typename T>
|
|
|
|
T convert_to_return(const char** /*value*/, tag<const char**, T>, typename std::enable_if<std::is_same<T, efl::eina::string_view*>::value>::type* = 0)
|
|
|
|
{
|
|
|
|
std::abort();
|
|
|
|
}
|
|
|
|
inline eina::string_view convert_to_return(const char* value, tag<const char*, efl::eina::string_view>)
|
2015-01-12 06:00:59 -08:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
return {value};
|
|
|
|
}
|
2016-06-08 13:31:46 -07:00
|
|
|
inline eina::string_view convert_to_return(const char** value, tag<const char**, efl::eina::string_view>)
|
|
|
|
{
|
|
|
|
return {*value};
|
|
|
|
}
|
2016-06-05 22:54:36 -07:00
|
|
|
inline std::string convert_to_return(const char* value, tag<const char*, std::string>)
|
|
|
|
{
|
2016-06-08 13:31:46 -07:00
|
|
|
if(value)
|
|
|
|
{
|
|
|
|
std::string r{value};
|
|
|
|
free((void*)value);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
inline std::string convert_to_return(const char** value, tag<const char**, std::string>)
|
|
|
|
{
|
|
|
|
if(value)
|
|
|
|
{
|
|
|
|
std::string r{*value};
|
|
|
|
free((void*)*value);
|
|
|
|
free((void*)value);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return {};
|
2016-06-05 22:54:36 -07:00
|
|
|
}
|
|
|
|
inline bool convert_to_return(Eina_Bool value, tag<Eina_Bool, bool>)
|
|
|
|
{
|
|
|
|
return !!value;
|
|
|
|
}
|
2016-06-08 13:31:46 -07:00
|
|
|
template <typename T, typename D>
|
|
|
|
std::unique_ptr<T, D> convert_to_return(T* value, tag<T*, std::unique_ptr<T, D>>)
|
2016-06-05 22:54:36 -07:00
|
|
|
{
|
2016-06-08 13:31:46 -07:00
|
|
|
return std::unique_ptr<T, D>{value, {}};
|
2016-06-05 22:54:36 -07:00
|
|
|
}
|
2016-06-08 13:31:46 -07:00
|
|
|
template <typename T, typename U, typename D>
|
|
|
|
std::unique_ptr<T, D> convert_to_return(U* value, tag<U*, std::unique_ptr<T, D>>)
|
2016-06-05 22:54:36 -07:00
|
|
|
{
|
2016-06-08 13:31:46 -07:00
|
|
|
return std::unique_ptr<T, D>{convert_to_return(value, tag<U*, T*>{}), {}};
|
2016-06-05 22:54:36 -07:00
|
|
|
}
|
2015-01-12 06:00:59 -08:00
|
|
|
}
|
|
|
|
|
2016-06-05 22:54:36 -07:00
|
|
|
template <typename T, typename U>
|
|
|
|
T convert_to_return(U& object)
|
2015-01-12 06:00:59 -08:00
|
|
|
{
|
2016-06-05 22:54:36 -07:00
|
|
|
return impl::convert_to_return(object, impl::tag<U, T>{});
|
2015-01-12 06:00:59 -08:00
|
|
|
}
|
|
|
|
|
2015-03-26 07:48:09 -07:00
|
|
|
/// Miscellaneous
|
2016-06-05 22:54:36 -07:00
|
|
|
template <typename T, typename Enable = void>
|
|
|
|
struct is_callable : std::false_type {};
|
|
|
|
template <typename T>
|
|
|
|
struct is_callable<T, decltype(std::declval<T>() ())> : std::true_type {};
|
2015-03-26 07:48:09 -07:00
|
|
|
|
2016-06-05 22:54:36 -07:00
|
|
|
inline void do_eo_add(Eo*& object, efl::eo::concrete const& parent
|
2016-08-11 12:24:15 -07:00
|
|
|
, Efl_Class const* klass)
|
2016-06-05 22:54:36 -07:00
|
|
|
{
|
2016-08-15 11:14:53 -07:00
|
|
|
object = ::_efl_add_internal_start(__FILE__, __LINE__, klass, parent._eo_ptr(), EINA_TRUE, EINA_FALSE);
|
|
|
|
object = ::_efl_add_end(object, EINA_FALSE, EINA_FALSE);
|
2016-06-05 22:54:36 -07:00
|
|
|
}
|
|
|
|
template <typename F>
|
2016-08-11 12:24:15 -07:00
|
|
|
void do_eo_add(Eo*& object, efl::eo::concrete const& parent, Efl_Class const* klass, F f)
|
2015-03-26 07:48:09 -07:00
|
|
|
{
|
2016-08-15 11:14:53 -07:00
|
|
|
object = ::_efl_add_internal_start(__FILE__, __LINE__, klass, parent._eo_ptr(), EINA_TRUE, EINA_FALSE);
|
2016-06-05 22:54:36 -07:00
|
|
|
f();
|
2016-08-15 11:14:53 -07:00
|
|
|
object = ::_efl_add_end(object, EINA_FALSE, EINA_FALSE);
|
2015-03-26 07:48:09 -07:00
|
|
|
}
|
|
|
|
|
2016-06-05 22:54:36 -07:00
|
|
|
template <typename D, typename T>
|
|
|
|
struct light_address_of_operator
|
|
|
|
{
|
|
|
|
operator T* () const { return static_cast<T*>(static_cast<void*>(static_cast<D const*>(this)->p)); }
|
|
|
|
};
|
|
|
|
template <typename D, typename T>
|
|
|
|
struct light_address_of_operator<D, T const>
|
|
|
|
{
|
|
|
|
operator T const* () const { return static_cast<T const*>(static_cast<void const*>(static_cast<D const*>(this)->p)); }
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T, typename...Args>
|
|
|
|
struct address_of_operator : light_address_of_operator<address_of_operator<T, Args...>, Args>...
|
|
|
|
{
|
|
|
|
operator T* () { return p; };
|
|
|
|
address_of_operator(T* p) : p(p) {}
|
|
|
|
T* p;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T, typename...Args>
|
|
|
|
struct address_of_operator<T const, Args...> : light_address_of_operator<address_of_operator<T const, Args...>, Args>...
|
|
|
|
{
|
|
|
|
operator T const* () { return p; };
|
|
|
|
address_of_operator(T const* p) : p(p) {}
|
|
|
|
T const* p;
|
|
|
|
};
|
|
|
|
|
2014-07-16 17:29:47 -07:00
|
|
|
} } // namespace efl { namespace eolian {
|
|
|
|
|
|
|
|
#endif // EFL_EOLIAN_INTEROP_HH
|