Commit 3d596c39 authored by Dominik Charousset's avatar Dominik Charousset

Allow functor attachables to have one or two args

parent 7478b485
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include "caf/abstract_channel.hpp" #include "caf/abstract_channel.hpp"
#include "caf/detail/type_traits.hpp" #include "caf/detail/type_traits.hpp"
#include "caf/detail/functor_attachable.hpp"
namespace caf { namespace caf {
...@@ -90,16 +91,7 @@ class abstract_actor : public abstract_channel { ...@@ -90,16 +91,7 @@ class abstract_actor : public abstract_channel {
*/ */
template <class F> template <class F>
void attach_functor(F f) { void attach_functor(F f) {
struct functor_attachable : attachable { attach(attachable_ptr{new detail::functor_attachable<F>(std::move(f))});
F m_functor;
functor_attachable(F arg) : m_functor(std::move(arg)) {
// nop
}
void actor_exited(abstract_actor*, uint32_t reason) {
m_functor(reason);
}
};
attach(attachable_ptr{new functor_attachable(std::move(f))});
} }
/** /**
......
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright (C) 2011 - 2014 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENCE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#ifndef CAF_FUNCTOR_ATTACHABLE_HPP
#define CAF_FUNCTOR_ATTACHABLE_HPP
#include "caf/attachable.hpp"
#include "caf/detail/type_list.hpp"
#include "caf/detail/type_traits.hpp"
namespace caf {
namespace detail {
template <class F,
int Args = tl_size<typename get_callable_trait<F>::arg_types>::value>
struct functor_attachable : attachable {
static_assert(Args == 2, "Only 1 and 2 arguments for F are supported");
F m_functor;
functor_attachable(F arg) : m_functor(std::move(arg)) {
// nop
}
void actor_exited(abstract_actor* self, uint32_t reason) override {
m_functor(self, reason);
}
};
template <class F>
struct functor_attachable<F, 1> : attachable {
F m_functor;
functor_attachable(F arg) : m_functor(std::move(arg)) {
// nop
}
void actor_exited(abstract_actor*, uint32_t reason) override {
m_functor(reason);
}
};
} // namespace detail
} // namespace caf
#endif // CAF_FUNCTOR_ATTACHABLE_HPP
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment