Simplify signal code

0.8
Bruno Van de Velde 2015-05-07 14:46:16 +02:00
parent 6560b1ca07
commit 85aa8eb834
1 changed files with 2 additions and 69 deletions

View File

@ -108,8 +108,6 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Alternative code has to be used since VS2013 compiler crashed when trying to compile this
/*
/// @internal
template <typename Func, typename TypeA, typename TypeB, typename... Args>
struct isConvertible;
@ -117,9 +115,7 @@ namespace tgui
template <typename Func, typename... TypesA, typename... TypesB, typename... Args>
struct isConvertible<Func, TypeSet<TypesA...>, TypeSet<TypesB...>, Args...>
{
using type = typename std::conditional<std::is_convertible<decltype(
std::bind<Func, Args..., TypesA...>(std::declval<Func>(), std::declval<Args>()..., std::declval<TypesA>()...)),
std::function<void()>>::value, TypeSet<TypesA...>, TypeSet<TypesB...>>::type;
using type = typename std::conditional<std::is_convertible<Func, std::function<void(Args..., TypesA...)>>::value, TypeSet<TypesA...>, TypeSet<TypesB...>>::type;
};
template <typename Func, typename... Type>
@ -127,7 +123,7 @@ namespace tgui
{
using type = typename std::conditional<std::is_convertible<Func, std::function<void()>>::value, TypeSet<>, TypeSet<Type...>>::type;
};
*/
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @internal
@ -139,9 +135,6 @@ namespace tgui
Signal(std::vector<std::vector<std::string>>&& types);
// Alternative code has to be used since VS2013 compiler crashed when trying to compile this
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/*
template <typename Func, typename... Args>
void connect(unsigned int id, Func func, Args... args)
{
@ -163,66 +156,6 @@ namespace tgui
m_functions[id] = connectInternal(Type{}, func, args...);
}
*/
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
template <typename Func>
void connect(unsigned int id, Func func)
{
#define TGUI_CONDITINAL_0(TypeA, TypeB) typename std::conditional<std::is_convertible<Func, std::function<void()>>::value, TypeA, TypeB>::type
#define TGUI_CONDITINAL(TypeA, TypeB, ...) typename std::conditional<std::is_convertible<Func, std::function<void(__VA_ARGS__)>>::value, TypeA, TypeB>::type
using DoubleString = TypeSet<sf::String, sf::String>;
using Type = TGUI_CONDITINAL_0(
TypeSet<>,
TGUI_CONDITINAL(
TypeSet<int>,
TGUI_CONDITINAL(
TypeSet<sf::Vector2f>,
TGUI_CONDITINAL(
TypeSet<sf::String>,
TGUI_CONDITINAL(
DoubleString,
TGUI_CONDITINAL(TypeSet<std::vector<sf::String>>,
TGUI_CONDITINAL(TypeSet<std::shared_ptr<ChildWindow>>, TypeSet<void>, std::shared_ptr<ChildWindow>),
std::vector<sf::String>),
sf::String, sf::String),
sf::String),
sf::Vector2f),
int)
);
#undef TGUI_CONDITINAL_0
#undef TGUI_CONDITINAL
m_functions[id] = connectInternal(Type{}, func);
}
template <typename Func, typename... Args>
void connect(unsigned int id, Func func, Args... args)
{
#define TGUI_CONDITINAL(TypeA, TypeB, ...) typename std::conditional<std::is_convertible<Func, std::function<void(__VA_ARGS__)>>::value, TypeA, TypeB>::type
using DoubleString = TypeSet<sf::String, sf::String>;
using Type = TGUI_CONDITINAL(
TypeSet<>,
TGUI_CONDITINAL(
TypeSet<int>,
TGUI_CONDITINAL(
TypeSet<sf::Vector2f>,
TGUI_CONDITINAL(
TypeSet<sf::String>,
TGUI_CONDITINAL(
DoubleString,
TGUI_CONDITINAL(TypeSet<std::vector<sf::String>>,
TGUI_CONDITINAL(TypeSet<std::shared_ptr<ChildWindow>>, TypeSet<void>, Args..., std::shared_ptr<ChildWindow>),
Args..., std::vector<sf::String>),
Args..., sf::String, sf::String),
Args..., sf::String),
Args..., sf::Vector2f),
Args..., int),
Args...);
#undef TGUI_CONDITINAL
m_functions[id] = connectInternal(Type{}, func, args...);
}
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
template <typename Func, typename... Args>
void connectEx(unsigned int id, Func func, Args... args)