Commit dfcbb117 authored by Marian Triebe's avatar Marian Triebe

Fix mixins to use derived type

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