Commit dfcbb117 authored by Marian Triebe's avatar Marian Triebe

Fix mixins to use derived type

parent 00d77d3b
...@@ -38,14 +38,14 @@ namespace mixin { ...@@ -38,14 +38,14 @@ namespace mixin {
/// A `behavior_changer` is an actor that supports /// A `behavior_changer` is an actor that supports
/// `self->become(...)` and `self->unbecome()`. /// `self->become(...)` and `self->unbecome()`.
template <class Base, class Derived> template <class Base, class Subtype>
class behavior_changer : public Base { class behavior_changer : public Base {
public: public:
// -- member types ----------------------------------------------------------- // -- member types -----------------------------------------------------------
using extended_base = behavior_changer; using extended_base = behavior_changer;
using behavior_type = typename behavior_type_of<Derived>::type; using behavior_type = typename behavior_type_of<Subtype>::type;
// -- constructors, destructors, and assignment operators -------------------- // -- constructors, destructors, and assignment operators --------------------
...@@ -57,11 +57,11 @@ public: ...@@ -57,11 +57,11 @@ public:
// -- behavior management ---------------------------------------------------- // -- behavior management ----------------------------------------------------
void become(behavior_type bhvr) { void become(behavior_type bhvr) {
this->do_become(std::move(bhvr.unbox()), true); dptr()->do_become(std::move(bhvr.unbox()), true);
} }
void become(const keep_behavior_t&, behavior_type bhvr) { void become(const keep_behavior_t&, behavior_type bhvr) {
this->do_become(std::move(bhvr.unbox()), false); dptr()->do_become(std::move(bhvr.unbox()), false);
} }
template <class T0, class T1, class... Ts> template <class T0, class T1, class... Ts>
...@@ -72,7 +72,7 @@ public: ...@@ -72,7 +72,7 @@ public:
behavior_type bhvr{std::forward<T0>(x0), behavior_type bhvr{std::forward<T0>(x0),
std::forward<T1>(x1), std::forward<T1>(x1),
std::forward<Ts>(xs)...}; std::forward<Ts>(xs)...};
this->do_become(std::move(bhvr.unbox()), true); dptr()->do_become(std::move(bhvr.unbox()), true);
} }
template <class T0, class T1, class... Ts> template <class T0, class T1, class... Ts>
...@@ -80,11 +80,16 @@ public: ...@@ -80,11 +80,16 @@ public:
behavior_type bhvr{std::forward<T0>(x0), behavior_type bhvr{std::forward<T0>(x0),
std::forward<T1>(x1), std::forward<T1>(x1),
std::forward<Ts>(xs)...}; std::forward<Ts>(xs)...};
this->do_become(std::move(bhvr.unbox()), false); dptr()->do_become(std::move(bhvr.unbox()), false);
} }
void unbecome() { void unbecome() {
this->bhvr_stack_.pop_back(); dptr()->bhvr_stack_.pop_back();
}
private:
Subtype* dptr() {
return static_cast<Subtype*>(this);
} }
}; };
......
...@@ -77,8 +77,8 @@ public: ...@@ -77,8 +77,8 @@ public:
typename res_t::type typename res_t::type
>::valid, >::valid,
"this actor does not accept the response message"); "this actor does not accept the response message");
dest->eq_impl(message_id::make(P), this->ctrl(), dest->eq_impl(message_id::make(P), dptr()->ctrl(),
this->context(), std::forward<Ts>(xs)...); dptr()->context(), std::forward<Ts>(xs)...);
} }
template <message_priority P = message_priority::normal, template <message_priority P = message_priority::normal,
...@@ -96,7 +96,7 @@ public: ...@@ -96,7 +96,7 @@ public:
>::valid, >::valid,
"receiver does not accept given message"); "receiver does not accept given message");
dest->eq_impl(message_id::make(P), nullptr, dest->eq_impl(message_id::make(P), nullptr,
this->context(), std::forward<Ts>(xs)...); dptr()->context(), std::forward<Ts>(xs)...);
} }
template <message_priority P = message_priority::normal, template <message_priority P = message_priority::normal,
......
...@@ -57,7 +57,7 @@ public: ...@@ -57,7 +57,7 @@ public:
// -- overridden functions of monitorable_actor ------------------------------ // -- overridden functions of monitorable_actor ------------------------------
bool cleanup(error&& fail_state, execution_unit* ptr) override { bool cleanup(error&& fail_state, execution_unit* ptr) override {
auto me = this->ctrl(); auto me = dptr()->ctrl();
for (auto& subscription : subscriptions_) for (auto& subscription : subscriptions_)
subscription->unsubscribe(me); subscription->unsubscribe(me);
subscriptions_.clear(); subscriptions_.clear();
...@@ -72,7 +72,7 @@ public: ...@@ -72,7 +72,7 @@ public:
CAF_LOG_TRACE(CAF_ARG(what)); CAF_LOG_TRACE(CAF_ARG(what));
if (what == invalid_group) if (what == invalid_group)
return; return;
if (what->subscribe(this->ctrl())) if (what->subscribe(dptr()->ctrl()))
subscriptions_.emplace(what); subscriptions_.emplace(what);
} }
...@@ -80,7 +80,7 @@ public: ...@@ -80,7 +80,7 @@ public:
void leave(const group& what) { void leave(const group& what) {
CAF_LOG_TRACE(CAF_ARG(what)); CAF_LOG_TRACE(CAF_ARG(what));
if (subscriptions_.erase(what) > 0) if (subscriptions_.erase(what) > 0)
what->unsubscribe(this->ctrl()); what->unsubscribe(dptr()->ctrl());
} }
/// Returns all subscribed groups. /// Returns all subscribed groups.
...@@ -89,6 +89,10 @@ public: ...@@ -89,6 +89,10 @@ public:
} }
private: private:
Subtype* dptr() {
return static_cast<Subtype*>(this);
}
// -- data members ----------------------------------------------------------- // -- data members -----------------------------------------------------------
/// Stores all subscribed groups. /// Stores all subscribed groups.
......
...@@ -71,6 +71,10 @@ public: ...@@ -71,6 +71,10 @@ public:
* miscellaneous actor operations * * miscellaneous actor operations *
****************************************************************************/ ****************************************************************************/
execution_unit* context() const {
return self_->context();
}
actor_system& system() const { actor_system& system() const {
return self_->system(); return self_->system();
} }
......
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