some changes

This commit is contained in:
Naios 2015-06-10 16:24:20 +02:00
parent facb6c852d
commit 06df1c4313
3 changed files with 39 additions and 9 deletions

View File

@ -80,6 +80,7 @@ using shared_callback_of_t = typename detail::unwrap_callback<_CTy>::SharedCallb
template<typename _CTy>
using weak_callback_of_t = typename detail::unwrap_callback<_CTy>::WeakCallbackType;
template<typename _CTy>
inline shared_callback_of_t<_CTy>
make_shared_callback(_CTy&& callback)
@ -88,6 +89,7 @@ inline shared_callback_of_t<_CTy>
(std::forward<callback_of_t<_CTy>>(callback));
}
/* Disabled due to clang errors
template<typename... Args>
inline auto make_weak_wrapped_callback(WeakCallback<Args...> const& weak_callback)
-> Callback<Args...>
@ -103,5 +105,6 @@ inline auto make_weak_wrapped_callback(SharedCallback<Args...> const& shared_cal
// Some workarounds for clang...
return detail::WeakProxyFactory<Args...>::CreateProxyFromShared(shared_callback);
}
*/
#endif /// _CALLBACK_H_

View File

@ -20,25 +20,38 @@
#include "Callback.h"
template <typename _MTy>
class ContinuableBase
{
};
template <typename _ATy, typename _WTy = void>
template <typename _CTy, typename _WTy = void>
class Continuable;
template <typename... _ATy>
class Continuable<Callback<_ATy...>, void>
{
public:
typedef bool type;
};
template <typename... _ATy, typename _WTy>
class Continuable<Callback<_ATy...>, _WTy>
{
static_assert(false, "");
public:
typedef int type;
};
/*
template <typename _CTy>
auto make_continuable(_CTy&& callback)
->
{
}
*/
#endif /// _CONTINUABLE_H_

View File

@ -8,6 +8,16 @@
#include <iostream>
#include <exception>
enum SpellCastResult
{
SPELL_FAILED_SUCCESS = 0,
SPELL_FAILED_AFFECTING_COMBAT = 1,
SPELL_FAILED_ALREADY_AT_FULL_HEALTH = 2,
SPELL_FAILED_ALREADY_AT_FULL_MANA = 3,
SPELL_FAILED_ALREADY_AT_FULL_POWER = 4,
SPELL_FAILED_ALREADY_BEING_TAMED = 5
};
ProtoContinueable CastSpell(int id)
{
std::cout << "Cast " << id << std::endl;
@ -24,12 +34,12 @@ ProtoContinueable MoveTo(int point)
return ProtoContinueable();
}
void CastSpell(int id, Callback<bool> const& callback)
void CastSpell(int id, Callback<SpellCastResult> const& callback)
{
std::cout << "Cast " << id << std::endl;
// on success call true
callback(true);
// on success call the callback with SPELL_FAILED_SUCCESS
callback(SPELL_FAILED_SUCCESS);
}
void MoveTo(int point, Callback<bool> const& callback)
@ -42,9 +52,9 @@ void MoveTo(int point, Callback<bool> const& callback)
int main(int argc, char** argv)
{
make_waterfall<Callback<bool>>()
make_waterfall<Callback<SpellCastResult>>()
// .then(std::bind(&CastSpell, 71382, std::placeholders::_1))
.then([](bool success, Callback<bool> const& callback)
.then([](SpellCastResult result, Callback<bool> const& callback)
{
MoveTo(1, callback);
})
@ -141,14 +151,18 @@ int main(int argc, char** argv)
std::cout << "huhu" << std::endl;
});
/*
auto wrapped = make_weak_wrapped_callback(weak_2);
auto wrapped2 = make_weak_wrapped_callback(WeakCallback<>(weak_2));
wrapped();
wrapped2();
*/
typedef Continuable<Callback<bool>> cont;
typedef Continuable<Callback<bool>>::type myty1;
typedef Continuable<Callback<bool>, float>::type myty2;
return 0;
}