Commit fe7fe943 authored by Dominik Charousset's avatar Dominik Charousset

Fix cppcheck warnings

parent 5aa56598
// having an explicit constructor for attachable would
// make it harder to use and its a library internal anyways
noExplicitConstructor:libcaf_core/caf/attachable.hpp
// cppcheck has all kinds of false positives in the optional header,
// mostly const and static suggestions that are flat out wrong and
// would cause compiler error (const optional::destroy?, wtf?)
*:libcaf_core/caf/optional.hpp
// cppcheck fails to recognize the pattern of converting
// `intrusive_ptr<T>` from `intrusive_ptr<U>`
noExplicitConstructor:libcaf_core/caf/intrusive_ptr.hpp
// cppcheck complains about `node_id(const invalid_node_id_t&)`,
// which must not be explicit because `invalid_node_id_t` would
// be completely useless otherwise, the same is true for
// - `message_id(invalid_message_id_t)`
noExplicitConstructor:libcaf_core/caf/node_id.hpp
noExplicitConstructor:libcaf_core/caf/message_id.hpp
// the ctor `duration(std::chrono::duration<Rep, Period> d)`
// is not explicit on purpose
noExplicitConstructor:libcaf_core/caf/duration.hpp
// `operator=(const ref_counted&)` does not assign `rc_`
// on purpose because this would corrupt reference counting
operatorEqVarError:libcaf_core/src/ref_counted.cpp
// cppcheck complains about not initializing the pad members
uninitMemberVar:libcaf_core/caf/detail/double_ended_queue.hpp
// making the policy functions static is technically possible,
// but conceptionally questionable
functionStatic:libcaf_core/caf/policy/work_stealing.hpp
// 6 false positives
*:libcaf_core/caf/detail/limited_vector.hpp
// `test_struct::test_value` is unused since this file tests `announce`
unusedStructMember:libcaf_io/test/uniform_type.cpp
// `exit_reason::as_string` is unused in this .cpp file, but part of the API,
// same is true for other falsely reported unused functions
unusedFunction:libcaf_core/src/exit_reason.cpp
unusedFunction:libcaf_core/src/shared_spinlock.cpp
unusedFunction:libcaf_io/src/interfaces.cpp
unusedFunction:libcaf_io/src/max_msg_size.cpp
...@@ -87,7 +87,7 @@ protected: ...@@ -87,7 +87,7 @@ protected:
private: private:
// can only be called from abstract_actor and abstract_group // can only be called from abstract_actor and abstract_group
abstract_channel(int init_flags); explicit abstract_channel(int init_flags);
abstract_channel(int init_flags, node_id nid); abstract_channel(int init_flags, node_id nid);
/* /*
......
...@@ -109,7 +109,7 @@ public: ...@@ -109,7 +109,7 @@ public:
/// Returns the name of this module implementation. /// Returns the name of this module implementation.
/// @threadsafe /// @threadsafe
const std::string& name(); const std::string& name() const;
/// Returns a pointer to the group associated with the name `group_name`. /// Returns a pointer to the group associated with the name `group_name`.
/// @threadsafe /// @threadsafe
......
...@@ -79,23 +79,27 @@ protected: ...@@ -79,23 +79,27 @@ protected:
private: private:
template <class C> template <class C>
typename std::enable_if<std::is_empty<C>::value, bool>::type static typename std::enable_if<std::is_empty<C>::value, bool>::type
eq(const C&, const C&) const { eq(const C&, const C&) {
return true; return true;
} }
template <class C> template <class C>
typename std::enable_if<! std::is_empty<C>::value && static typename std::enable_if<
detail::is_comparable<C, C>::value, ! std::is_empty<C>::value && detail::is_comparable<C, C>::value,
bool>::type bool
eq(const C& lhs, const C& rhs) const { >::type
eq(const C& lhs, const C& rhs) {
return lhs == rhs; return lhs == rhs;
} }
template <class C> template <class C>
typename std::enable_if<! std::is_empty<C>::value && std::is_pod<C>::value && typename std::enable_if<
! detail::is_comparable<C, C>::value, ! std::is_empty<C>::value
bool>::type && ! detail::is_comparable<C, C>::value
&& std::is_pod<C>::value,
bool
>::type
eq(const C& lhs, const C& rhs) const { eq(const C& lhs, const C& rhs) const {
return pod_mems_equals(lhs, rhs); return pod_mems_equals(lhs, rhs);
} }
......
...@@ -65,10 +65,10 @@ public: ...@@ -65,10 +65,10 @@ public:
size_t count_proxies(const key_type& node); size_t count_proxies(const key_type& node);
/// Returns all proxies for `node`. /// Returns all proxies for `node`.
std::vector<actor_proxy_ptr> get_all(); std::vector<actor_proxy_ptr> get_all() const;
/// Returns all proxies for `node`. /// Returns all proxies for `node`.
std::vector<actor_proxy_ptr> get_all(const key_type& node); std::vector<actor_proxy_ptr> get_all(const key_type& node) const;
/// Returns the proxy instance identified by `node` and `aid` /// Returns the proxy instance identified by `node` and `aid`
/// or `nullptr` if the actor either unknown or expired. /// or `nullptr` if the actor either unknown or expired.
......
...@@ -108,10 +108,10 @@ private: ...@@ -108,10 +108,10 @@ private:
bool filter(upgrade_lock<detail::shared_spinlock>&, const actor_addr& sender, bool filter(upgrade_lock<detail::shared_spinlock>&, const actor_addr& sender,
message_id mid, const message& content, execution_unit* host); message_id mid, const message& content, execution_unit* host);
// call without mtx_ held // call without workers_mtx_ held
void quit(); void quit();
detail::shared_spinlock mtx_; detail::shared_spinlock workers_mtx_;
std::vector<actor> workers_; std::vector<actor> workers_;
policy policy_; policy policy_;
uint32_t planned_reason_; uint32_t planned_reason_;
......
...@@ -82,7 +82,7 @@ public: ...@@ -82,7 +82,7 @@ public:
void request_deletion(bool decremented_ref_count) noexcept override; void request_deletion(bool decremented_ref_count) noexcept override;
inline anchor_ptr get_anchor() { inline anchor_ptr get_anchor() const {
return anchor_; return anchor_;
} }
......
...@@ -90,7 +90,7 @@ public: ...@@ -90,7 +90,7 @@ public:
public: public:
pointer value; pointer value;
std::atomic<node*> next; std::atomic<node*> next;
node(pointer val) : value(val), next(nullptr) { explicit node(pointer val) : value(val), next(nullptr) {
// nop // nop
} }
private: private:
...@@ -230,7 +230,7 @@ private: ...@@ -230,7 +230,7 @@ private:
class lock_guard { class lock_guard {
public: public:
lock_guard(std::atomic_flag& lock) : lock_(lock) { explicit lock_guard(std::atomic_flag& lock) : lock_(lock) {
while (lock.test_and_set(std::memory_order_acquire)) { while (lock.test_and_set(std::memory_order_acquire)) {
std::this_thread::yield(); std::this_thread::yield();
} }
......
...@@ -130,7 +130,7 @@ typename ieee_754_trait<T>::float_type unpack754(T i) { ...@@ -130,7 +130,7 @@ typename ieee_754_trait<T>::float_type unpack754(T i) {
++shift; ++shift;
} }
// sign it // sign it
result *= (i >> (trait::bits - 1)) & 1 ? -1 : 1; result *= ((i >> (trait::bits - 1)) & 1) ? -1 : 1;
return result; return result;
} }
......
...@@ -41,19 +41,16 @@ public: ...@@ -41,19 +41,16 @@ public:
using trait = typename detail::get_callable_trait<F>::type; using trait = typename detail::get_callable_trait<F>::type;
using arg_types = typename trait::arg_types; using arg_types = typename trait::arg_types;
using result_type = typename trait::result_type; using result_type = typename trait::result_type;
constexpr bool returns_behavior = using first_arg = typename detail::tl_head<arg_types>::type;
std::is_convertible<result_type, behavior>::value; bool_token<std::is_convertible<result_type, behavior>::value> token1;
constexpr bool uses_first_arg = std::is_pointer< bool_token<std::is_pointer<first_arg>::value> token2;
typename detail::tl_head<arg_types>::type>::value;
std::integral_constant<bool, returns_behavior> token1;
std::integral_constant<bool, uses_first_arg> token2;
return make(token1, token2, std::move(f), std::forward<Ts>(xs)...); return make(token1, token2, std::move(f), std::forward<Ts>(xs)...);
} }
private: private:
// behavior (pointer) // behavior (pointer)
template <class Fun> template <class Fun>
fun make(std::true_type, std::true_type, Fun fun) { static fun make(std::true_type, std::true_type, Fun fun) {
return [fun](local_actor* ptr) -> behavior { return [fun](local_actor* ptr) -> behavior {
auto res = fun(static_cast<Base*>(ptr)); auto res = fun(static_cast<Base*>(ptr));
return std::move(res.unbox()); return std::move(res.unbox());
...@@ -62,7 +59,7 @@ private: ...@@ -62,7 +59,7 @@ private:
// void (pointer) // void (pointer)
template <class Fun> template <class Fun>
fun make(std::false_type, std::true_type, Fun fun) { static fun make(std::false_type, std::true_type, Fun fun) {
return [fun](local_actor* ptr) -> behavior { return [fun](local_actor* ptr) -> behavior {
fun(static_cast<Base*>(ptr)); fun(static_cast<Base*>(ptr));
return behavior{}; return behavior{};
...@@ -71,7 +68,7 @@ private: ...@@ -71,7 +68,7 @@ private:
// behavior () // behavior ()
template <class Fun> template <class Fun>
fun make(std::true_type, std::false_type, Fun fun) { static fun make(std::true_type, std::false_type, Fun fun) {
return [fun](local_actor*) -> behavior { return [fun](local_actor*) -> behavior {
auto res = fun(); auto res = fun();
return std::move(res.unbox()); return std::move(res.unbox());
...@@ -80,7 +77,7 @@ private: ...@@ -80,7 +77,7 @@ private:
// void () // void ()
template <class Fun> template <class Fun>
fun make(std::false_type, std::false_type, Fun fun) { static fun make(std::false_type, std::false_type, Fun fun) {
return [fun](local_actor*) -> behavior { return [fun](local_actor*) -> behavior {
fun(); fun();
return behavior{}; return behavior{};
...@@ -88,14 +85,14 @@ private: ...@@ -88,14 +85,14 @@ private:
} }
template <class Token, typename T0, class... Ts> template <class Token, typename T0, class... Ts>
fun make(Token t1, std::true_type t2, F fun, T0&& x, Ts&&... xs) { static fun make(Token t1, std::true_type t2, F fun, T0&& x, Ts&&... xs) {
return make(t1, t2, return make(t1, t2,
std::bind(fun, std::placeholders::_1, detail::spawn_fwd<T0>(x), std::bind(fun, std::placeholders::_1, detail::spawn_fwd<T0>(x),
detail::spawn_fwd<Ts>(xs)...)); detail::spawn_fwd<Ts>(xs)...));
} }
template <class Token, typename T0, class... Ts> template <class Token, typename T0, class... Ts>
fun make(Token t1, std::false_type t2, F fun, T0&& x, Ts&&... xs) { static fun make(Token t1, std::false_type t2, F fun, T0&& x, Ts&&... xs) {
return make(t1, t2, std::bind(fun, detail::spawn_fwd<T0>(x), return make(t1, t2, std::bind(fun, detail::spawn_fwd<T0>(x),
detail::spawn_fwd<Ts>(xs)...)); detail::spawn_fwd<Ts>(xs)...));
} }
......
...@@ -32,11 +32,8 @@ ...@@ -32,11 +32,8 @@
namespace caf { namespace caf {
namespace detail { namespace detail {
/* // A vector with a fixed maximum size (uses an array internally).
* A vector with a fixed maximum size (uses an array internally). // @warning This implementation is highly optimized for arithmetic types and
* @warning This implementation is highly optimized for arithmetic types and
* does <b>not</b> call constructors or destructors.
*/
template <class T, size_t MaxSize> template <class T, size_t MaxSize>
class limited_vector { class limited_vector {
public: public:
...@@ -56,7 +53,7 @@ public: ...@@ -56,7 +53,7 @@ public:
// nop // nop
} }
limited_vector(size_t initial_size) : size_(initial_size) { explicit limited_vector(size_t initial_size) : size_(initial_size) {
T tmp; T tmp;
std::fill_n(begin(), initial_size, tmp); std::fill_n(begin(), initial_size, tmp);
} }
...@@ -76,7 +73,7 @@ public: ...@@ -76,7 +73,7 @@ public:
size_ = s; size_ = s;
} }
limited_vector(std::initializer_list<T> init) : size_(init.size()) { explicit limited_vector(std::initializer_list<T> init) : size_(init.size()) {
CAF_ASSERT(init.size() <= MaxSize); CAF_ASSERT(init.size() <= MaxSize);
std::copy(init.begin(), init.end(), begin()); std::copy(init.begin(), init.end(), begin());
} }
......
...@@ -33,6 +33,12 @@ ...@@ -33,6 +33,12 @@
namespace caf { namespace caf {
namespace detail { namespace detail {
template <bool X>
using bool_token = std::integral_constant<bool, X>;
template <int X>
using int_token = std::integral_constant<int, X>;
/// Joins all bool constants using operator &&. /// Joins all bool constants using operator &&.
template <bool... BoolConstants> template <bool... BoolConstants>
struct conjunction; struct conjunction;
......
...@@ -49,7 +49,6 @@ template <class T0, typename T1 = unit_t, typename T2 = unit_t, ...@@ -49,7 +49,6 @@ template <class T0, typename T1 = unit_t, typename T2 = unit_t,
typename T15 = unit_t, typename T16 = unit_t, typename T17 = unit_t, typename T15 = unit_t, typename T16 = unit_t, typename T17 = unit_t,
typename T18 = unit_t, typename T19 = unit_t, typename T20 = unit_t> typename T18 = unit_t, typename T19 = unit_t, typename T20 = unit_t>
struct variant_data { struct variant_data {
union { union {
T0 v0; T1 v1; T2 v2; T0 v0; T1 v1; T2 v2;
T3 v3; T4 v4; T5 v5; T3 v3; T4 v4; T5 v5;
...@@ -60,9 +59,13 @@ struct variant_data { ...@@ -60,9 +59,13 @@ struct variant_data {
T18 v18; T19 v19; T20 v20; T18 v18; T19 v19; T20 v20;
}; };
variant_data() { } variant_data() {
// nop
}
~variant_data() { } ~variant_data() {
// nop
}
CAF_VARIANT_DATA_GETTER(0) CAF_VARIANT_DATA_GETTER(0)
CAF_VARIANT_DATA_GETTER(1) CAF_VARIANT_DATA_GETTER(1)
...@@ -85,20 +88,15 @@ struct variant_data { ...@@ -85,20 +88,15 @@ struct variant_data {
CAF_VARIANT_DATA_GETTER(18) CAF_VARIANT_DATA_GETTER(18)
CAF_VARIANT_DATA_GETTER(19) CAF_VARIANT_DATA_GETTER(19)
CAF_VARIANT_DATA_GETTER(20) CAF_VARIANT_DATA_GETTER(20)
private:
template <class M, typename U>
inline void cr(M& member, U&& arg) {
new (&member) M (std::forward<U>(arg));
}
}; };
struct variant_data_destructor { struct variant_data_destructor {
using result_type = void; using result_type = void;
template <class T> template <class T>
inline void operator()(T& storage) const { storage.~T(); } void operator()(T& storage) const {
storage.~T();
}
}; };
} // namespace detail } // namespace detail
......
...@@ -29,9 +29,7 @@ namespace caf { ...@@ -29,9 +29,7 @@ namespace caf {
/// Base class for exceptions. /// Base class for exceptions.
class caf_exception : public std::exception { class caf_exception : public std::exception {
public: public:
~caf_exception() noexcept; ~caf_exception() noexcept;
caf_exception() = delete; caf_exception() = delete;
...@@ -42,28 +40,18 @@ public: ...@@ -42,28 +40,18 @@ public:
const char* what() const noexcept; const char* what() const noexcept;
protected: protected:
/// Creates an exception with the error string `what_str`. /// Creates an exception with the error string `what_str`.
caf_exception(std::string&& what_str); explicit caf_exception(std::string what_str);
/// Creates an exception with the error string `what_str`.
caf_exception(const std::string& what_str);
private: private:
std::string what_; std::string what_;
}; };
/// Thrown if an actor finished execution. /// Thrown if an actor finished execution.
class actor_exited : public caf_exception { class actor_exited : public caf_exception {
public: public:
~actor_exited() noexcept; ~actor_exited() noexcept;
explicit actor_exited(uint32_t exit_reason);
actor_exited(uint32_t exit_reason);
actor_exited(const actor_exited&) = default; actor_exited(const actor_exited&) = default;
actor_exited& operator=(const actor_exited&) = default; actor_exited& operator=(const actor_exited&) = default;
...@@ -71,42 +59,29 @@ public: ...@@ -71,42 +59,29 @@ public:
inline uint32_t reason() const noexcept; inline uint32_t reason() const noexcept;
private: private:
uint32_t reason_; uint32_t reason_;
}; };
/// Thrown to indicate that either an actor publishing failed or /// Thrown to indicate that either an actor publishing failed or
/// the middleman was unable to connect to a remote host. /// the middleman was unable to connect to a remote host.
class network_error : public caf_exception { class network_error : public caf_exception {
using super = caf_exception;
public: public:
~network_error() noexcept; ~network_error() noexcept;
network_error(std::string&& what_str); explicit network_error(std::string&& what_str);
network_error(const std::string& what_str); explicit network_error(const std::string& what_str);
network_error(const network_error&) = default; network_error(const network_error&) = default;
network_error& operator=(const network_error&) = default; network_error& operator=(const network_error&) = default;
}; };
/// Thrown to indicate that an actor publishing failed because /// Thrown to indicate that an actor publishing failed because
/// the requested port could not be used. /// the requested port could not be used.
class bind_failure : public network_error { class bind_failure : public network_error {
using super = network_error;
public: public:
~bind_failure() noexcept; ~bind_failure() noexcept;
explicit bind_failure(std::string&& what_str);
bind_failure(std::string&& what_str); explicit bind_failure(const std::string& what_str);
bind_failure(const std::string& what_str);
bind_failure(const bind_failure&) = default; bind_failure(const bind_failure&) = default;
bind_failure& operator=(const bind_failure&) = default; bind_failure& operator=(const bind_failure&) = default;
}; };
inline uint32_t actor_exited::reason() const noexcept { inline uint32_t actor_exited::reason() const noexcept {
......
...@@ -366,7 +366,7 @@ public: ...@@ -366,7 +366,7 @@ public:
} }
/// Checks wheter this actor has a user-defined sync failure handler. /// Checks wheter this actor has a user-defined sync failure handler.
inline bool has_sync_failure_handler() { inline bool has_sync_failure_handler() const {
return static_cast<bool>(sync_failure_handler_); return static_cast<bool>(sync_failure_handler_);
} }
...@@ -466,13 +466,11 @@ public: ...@@ -466,13 +466,11 @@ public:
// returns 0 if last_dequeued() is an asynchronous or sync request message, // returns 0 if last_dequeued() is an asynchronous or sync request message,
// a response id generated from the request id otherwise // a response id generated from the request id otherwise
inline message_id get_response_id() { inline message_id get_response_id() const {
auto mid = current_element_->mid; auto mid = current_element_->mid;
return (mid.is_request()) ? mid.response_id() : message_id(); return (mid.is_request()) ? mid.response_id() : message_id();
} }
void reply_message(message&& what);
void forward_message(const actor& dest, message_priority mp); void forward_message(const actor& dest, message_priority mp);
inline uint32_t planned_exit_reason() const { inline uint32_t planned_exit_reason() const {
...@@ -491,7 +489,7 @@ public: ...@@ -491,7 +489,7 @@ public:
return mailbox_; return mailbox_;
} }
inline bool has_behavior() { inline bool has_behavior() const {
return ! bhvr_stack_.empty() || ! pending_responses_.empty(); return ! bhvr_stack_.empty() || ! pending_responses_.empty();
} }
...@@ -599,7 +597,7 @@ private: ...@@ -599,7 +597,7 @@ private:
typename std::enable_if< typename std::enable_if<
! std::is_same<typename std::decay<T>::type, message>::value ! std::is_same<typename std::decay<T>::type, message>::value
>::type >::type
send_impl(message_id mid, abstract_channel* dest, T&& x, Ts&&... xs) { send_impl(message_id mid, abstract_channel* dest, T&& x, Ts&&... xs) const {
if (! dest) { if (! dest) {
return; return;
} }
...@@ -610,7 +608,7 @@ private: ...@@ -610,7 +608,7 @@ private:
host()); host());
} }
void send_impl(message_id mp, abstract_channel* dest, message what); void send_impl(message_id mp, abstract_channel* dest, message what) const;
void delayed_send_impl(message_id mid, const channel& whom, void delayed_send_impl(message_id mid, const channel& whom,
const duration& rtime, message data); const duration& rtime, message data);
......
...@@ -70,7 +70,7 @@ public: ...@@ -70,7 +70,7 @@ public:
using lockable = UpgradeLockable; using lockable = UpgradeLockable;
template <class LockType> template <class LockType>
upgrade_to_unique_lock(LockType& other) { explicit upgrade_to_unique_lock(LockType& other) {
lockable_ = other.release(); lockable_ = other.release();
if (lockable_) lockable_->unlock_upgrade_and_lock(); if (lockable_) lockable_->unlock_upgrade_and_lock();
} }
......
...@@ -289,19 +289,6 @@ public: ...@@ -289,19 +289,6 @@ public:
return vals_->tuple_type_names(); return vals_->tuple_type_names();
} }
struct move_from_tuple_helper {
template <class... Ts>
inline message operator()(Ts&... xs) {
return make_message(std::move(xs)...);
}
};
template <class... Ts>
inline message move_from_tuple(std::tuple<Ts...>&& tup) {
move_from_tuple_helper f;
return detail::apply_args(f, detail::get_indices(tup), tup);
}
bool match_element(size_t p, uint16_t tnr, const std::type_info* rtti) const; bool match_element(size_t p, uint16_t tnr, const std::type_info* rtti) const;
template <class T, class... Ts> template <class T, class... Ts>
...@@ -314,8 +301,8 @@ public: ...@@ -314,8 +301,8 @@ public:
private: private:
template <size_t P> template <size_t P>
bool match_elements_impl(std::integral_constant<size_t, P>, static bool match_elements_impl(std::integral_constant<size_t, P>,
detail::type_list<>) const { detail::type_list<>) {
return true; // end of recursion return true; // end of recursion
} }
...@@ -406,29 +393,29 @@ inline message make_message(message other) { ...@@ -406,29 +393,29 @@ inline message make_message(message other) {
template <class T> template <class T>
message::cli_arg::cli_arg(std::string nstr, std::string tstr, T& arg) message::cli_arg::cli_arg(std::string nstr, std::string tstr, T& arg)
: name(std::move(nstr)), : name(std::move(nstr)),
text(std::move(tstr)) { text(std::move(tstr)),
fun = [&arg](const std::string& str) -> bool { fun([&arg](const std::string& str) -> bool {
auto res = from_string<T>(str); auto res = from_string<T>(str);
if (! res) { if (! res)
return false; return false;
}
arg = *res; arg = *res;
return true; return true;
}; }) {
// nop
} }
template <class T> template <class T>
message::cli_arg::cli_arg(std::string nstr, std::string tstr, std::vector<T>& arg) message::cli_arg::cli_arg(std::string nstr, std::string tstr, std::vector<T>& arg)
: name(std::move(nstr)), : name(std::move(nstr)),
text(std::move(tstr)) { text(std::move(tstr)),
fun = [&arg](const std::string& str) -> bool { fun([&arg](const std::string& str) -> bool {
auto res = from_string<T>(str); auto res = from_string<T>(str);
if (! res) { if (! res)
return false; return false;
}
arg.push_back(*res); arg.push_back(*res);
return true; return true;
}; }) {
// nop
} }
} // namespace caf } // namespace caf
......
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright (C) 2011 - 2015 *
* 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 LICENSE_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_MIXIN_TYPED_FUNCTOR_BASED_HPP
#define CAF_MIXIN_TYPED_FUNCTOR_BASED_HPP
namespace caf {
namespace mixin {
template <class Base, class Subtype>
class typed_functor_based : public Base {
public:
using combined_type = typed_functor_based;
using pointer = Base*;
using behavior_type = typename Base::behavior_type;
using make_behavior_fun = std::function<behavior_type(pointer)>;
using void_fun = std::function<void(pointer)>;
typed_functor_based() {
// nop
}
template <class F, class... Ts>
typed_functor_based(F f, Ts&&... xs) {
init(std::move(f), std::forward<Ts>(xs)...);
}
template <class F, class... Ts>
void init(F f, Ts&&... xs) {
using trait = typename detail::get_callable_trait<F>::type;
using arg_types = typename trait::arg_types;
using result_type = typename trait::result_type;
constexpr bool returns_behavior =
std::is_convertible<result_type, behavior_type>::value;
constexpr bool uses_first_arg = std::is_same<
typename detail::tl_head<arg_types>::type, pointer>::value;
std::integral_constant<bool, returns_behavior> token1;
std::integral_constant<bool, uses_first_arg> token2;
set(token1, token2, std::move(f), std::forward<Ts>(xs)...);
}
protected:
make_behavior_fun m_make_behavior;
private:
template <class F>
void set(std::true_type, std::true_type, F&& fun) {
// behavior_type (pointer)
m_make_behavior = std::forward<F>(fun);
}
template <class F>
void set(std::false_type, std::true_type, F fun) {
// void (pointer)
m_make_behavior = [fun](pointer ptr) {
fun(ptr);
return behavior_type{};
};
}
template <class F>
void set(std::true_type, std::false_type, F fun) {
// behavior_type (void)
m_make_behavior = [fun](pointer) { return fun(); };
}
template <class F>
void set(std::false_type, std::false_type, F fun) {
// void (void)
m_make_behavior = [fun](pointer) {
fun();
return behavior_type{};
};
}
template <class Token, typename F, typename T0, class... Ts>
void set(Token t1, std::true_type t2, F fun, T0&& x, Ts&&... xs) {
set(t1, t2, std::bind(fun, std::placeholders::_1, std::forward<T0>(x),
std::forward<Ts>(xs)...));
}
template <class Token, typename F, typename T0, class... Ts>
void set(Token t1, std::false_type t2, F fun, T0&& x, Ts&&... xs) {
set(t1, t2, std::bind(fun, std::forward<T0>(x), std::forward<Ts>(xs)...));
}
};
} // namespace mixin
} // namespace caf
#endif // CAF_MIXIN_TYPED_FUNCTOR_BASED_HPP
...@@ -79,7 +79,7 @@ public: ...@@ -79,7 +79,7 @@ public:
// Convenience function to access the data field. // Convenience function to access the data field.
template <class WorkerOrCoordinator> template <class WorkerOrCoordinator>
auto d(WorkerOrCoordinator* self) -> decltype(self->data()) { static auto d(WorkerOrCoordinator* self) -> decltype(self->data()) {
return self->data(); return self->data();
} }
......
...@@ -248,11 +248,8 @@ private: ...@@ -248,11 +248,8 @@ private:
template <class T, class... Us> template <class T, class... Us>
T& get(variant<Us...>& value) { T& get(variant<Us...>& value) {
using namespace detail; using namespace detail;
constexpr int type_id = tl_find_if< int_token<tl_find_if<type_list<Us...>,
type_list<Us...>, tbind<is_same_ish, T>::template type>::value> token;
tbind<is_same_ish, T>::template type
>::value;
std::integral_constant<int, type_id> token;
// silence compiler error about "binding to unrelated types" such as // silence compiler error about "binding to unrelated types" such as
// 'signed char' to 'char' (which is obvious bullshit) // 'signed char' to 'char' (which is obvious bullshit)
return reinterpret_cast<T&>(value.get(token)); return reinterpret_cast<T&>(value.get(token));
...@@ -269,14 +266,10 @@ const T& get(const variant<Us...>& value) { ...@@ -269,14 +266,10 @@ const T& get(const variant<Us...>& value) {
template <class T, class... Us> template <class T, class... Us>
T* get(variant<Us...>* value) { T* get(variant<Us...>* value) {
using namespace detail; using namespace detail;
constexpr int type_id = tl_find_if< int_token<tl_find_if<type_list<Us...>,
type_list<Us...>, tbind<is_same_ish, T>::template type>::value> token;
tbind<is_same_ish, T>::template type if (value->is(token))
>::value;
std::integral_constant<int, type_id> token;
if (value->is(token)) {
return &get<T>(*value); return &get<T>(*value);
}
return nullptr; return nullptr;
} }
......
...@@ -55,7 +55,7 @@ void abstract_group::module::stop() { ...@@ -55,7 +55,7 @@ void abstract_group::module::stop() {
CAF_LOG_TRACE(""); CAF_LOG_TRACE("");
} }
const std::string& abstract_group::module::name() { const std::string& abstract_group::module::name() const {
return name_; return name_;
} }
......
...@@ -87,7 +87,7 @@ size_t actor_namespace::count_proxies(const key_type& node) { ...@@ -87,7 +87,7 @@ size_t actor_namespace::count_proxies(const key_type& node) {
return (i != proxies_.end()) ? i->second.size() : 0; return (i != proxies_.end()) ? i->second.size() : 0;
} }
std::vector<actor_proxy_ptr> actor_namespace::get_all() { std::vector<actor_proxy_ptr> actor_namespace::get_all() const {
std::vector<actor_proxy_ptr> result; std::vector<actor_proxy_ptr> result;
for (auto& outer : proxies_) { for (auto& outer : proxies_) {
for (auto& inner : outer.second) { for (auto& inner : outer.second) {
...@@ -100,15 +100,18 @@ std::vector<actor_proxy_ptr> actor_namespace::get_all() { ...@@ -100,15 +100,18 @@ std::vector<actor_proxy_ptr> actor_namespace::get_all() {
return result; return result;
} }
std::vector<actor_proxy_ptr> actor_namespace::get_all(const key_type& node) { std::vector<actor_proxy_ptr>
actor_namespace::get_all(const key_type& node) const {
std::vector<actor_proxy_ptr> result; std::vector<actor_proxy_ptr> result;
auto& submap = proxies_[node]; auto i = proxies_.find(node);
if (i == proxies_.end())
return result;
auto& submap = i->second;
for (auto& kvp : submap) { for (auto& kvp : submap) {
auto ptr = kvp.second->get(); auto ptr = kvp.second->get();
if (ptr) { if (ptr)
result.push_back(std::move(ptr)); result.push_back(std::move(ptr));
} }
}
return result; return result;
} }
......
...@@ -29,8 +29,10 @@ ...@@ -29,8 +29,10 @@
namespace caf { namespace caf {
actor_ostream::actor_ostream(actor self) : self_(std::move(self)) { actor_ostream::actor_ostream(actor self)
printer_ = detail::singletons::get_scheduling_coordinator()->printer(); : self_(std::move(self)),
printer_(detail::singletons::get_scheduling_coordinator()->printer()) {
// nop
} }
actor_ostream& actor_ostream::write(std::string arg) { actor_ostream& actor_ostream::write(std::string arg) {
......
...@@ -113,7 +113,7 @@ actor actor_pool::make(size_t num_workers, factory fac, policy pol) { ...@@ -113,7 +113,7 @@ actor actor_pool::make(size_t num_workers, factory fac, policy pol) {
void actor_pool::enqueue(const actor_addr& sender, message_id mid, void actor_pool::enqueue(const actor_addr& sender, message_id mid,
message content, execution_unit* eu) { message content, execution_unit* eu) {
upgrade_lock<detail::shared_spinlock> guard{mtx_}; upgrade_lock<detail::shared_spinlock> guard{workers_mtx_};
if (filter(guard, sender, mid, content, eu)) { if (filter(guard, sender, mid, content, eu)) {
return; return;
} }
...@@ -122,7 +122,7 @@ void actor_pool::enqueue(const actor_addr& sender, message_id mid, ...@@ -122,7 +122,7 @@ void actor_pool::enqueue(const actor_addr& sender, message_id mid,
} }
void actor_pool::enqueue(mailbox_element_ptr what, execution_unit* eu) { void actor_pool::enqueue(mailbox_element_ptr what, execution_unit* eu) {
upgrade_lock<detail::shared_spinlock> guard{mtx_}; upgrade_lock<detail::shared_spinlock> guard{workers_mtx_};
if (filter(guard, what->sender, what->mid, what->msg, eu)) { if (filter(guard, what->sender, what->mid, what->msg, eu)) {
return; return;
} }
...@@ -219,7 +219,7 @@ bool actor_pool::filter(upgrade_lock<detail::shared_spinlock>& guard, ...@@ -219,7 +219,7 @@ bool actor_pool::filter(upgrade_lock<detail::shared_spinlock>& guard,
void actor_pool::quit() { void actor_pool::quit() {
// we can safely run our cleanup code here without holding // we can safely run our cleanup code here without holding
// mtx_ because abstract_actor has its own lock // workers_mtx_ because abstract_actor has its own lock
cleanup(planned_reason_); cleanup(planned_reason_);
is_registered(false); is_registered(false);
} }
......
...@@ -47,12 +47,7 @@ caf_exception::~caf_exception() noexcept { ...@@ -47,12 +47,7 @@ caf_exception::~caf_exception() noexcept {
// nop // nop
} }
caf_exception::caf_exception(const std::string& what_str) : what_(what_str) { caf_exception::caf_exception(std::string x) : what_(std::move(x)) {
// nop
}
caf_exception::caf_exception(std::string&& what_str)
: what_(std::move(what_str)) {
// nop // nop
} }
...@@ -64,15 +59,15 @@ actor_exited::~actor_exited() noexcept { ...@@ -64,15 +59,15 @@ actor_exited::~actor_exited() noexcept {
// nop // nop
} }
actor_exited::actor_exited(uint32_t rsn) : caf_exception(ae_what(rsn)) { actor_exited::actor_exited(uint32_t x) : caf_exception(ae_what(x)) {
reason_ = rsn; reason_ = x;
} }
network_error::network_error(const std::string& str) : super(str) { network_error::network_error(const std::string& x) : caf_exception(x) {
// nop // nop
} }
network_error::network_error(std::string&& str) : super(std::move(str)) { network_error::network_error(std::string&& x) : caf_exception(std::move(x)) {
// nop // nop
} }
...@@ -80,11 +75,11 @@ network_error::~network_error() noexcept { ...@@ -80,11 +75,11 @@ network_error::~network_error() noexcept {
// nop // nop
} }
bind_failure::bind_failure(const std::string& str) : super(str) { bind_failure::bind_failure(const std::string& x) : network_error(x) {
// nop // nop
} }
bind_failure::bind_failure(std::string&& str) : super(std::move(str)) { bind_failure::bind_failure(std::string&& x) : network_error(std::move(x)) {
// nop // nop
} }
......
...@@ -108,21 +108,6 @@ std::vector<group> local_actor::joined_groups() const { ...@@ -108,21 +108,6 @@ std::vector<group> local_actor::joined_groups() const {
return result; return result;
} }
void local_actor::reply_message(message&& what) {
auto& whom = current_element_->sender;
if (! whom) {
return;
}
auto& mid = current_element_->mid;
if (mid.valid() == false || mid.is_response()) {
send(actor_cast<channel>(whom), std::move(what));
} else if (! mid.is_answered()) {
auto ptr = actor_cast<actor>(whom);
ptr->enqueue(address(), mid.response_id(), std::move(what), host());
mid.mark_as_answered();
}
}
void local_actor::forward_message(const actor& dest, message_priority prio) { void local_actor::forward_message(const actor& dest, message_priority prio) {
if (! dest) { if (! dest) {
return; return;
...@@ -807,7 +792,7 @@ void local_actor::await_data() { ...@@ -807,7 +792,7 @@ void local_actor::await_data() {
} }
void local_actor::send_impl(message_id mid, abstract_channel* dest, void local_actor::send_impl(message_id mid, abstract_channel* dest,
message what) { message what) const {
if (! dest) { if (! dest) {
return; return;
} }
......
...@@ -311,20 +311,23 @@ message::cli_arg::cli_arg(std::string nstr, std::string tstr) ...@@ -311,20 +311,23 @@ message::cli_arg::cli_arg(std::string nstr, std::string tstr)
message::cli_arg::cli_arg(std::string nstr, std::string tstr, std::string& arg) message::cli_arg::cli_arg(std::string nstr, std::string tstr, std::string& arg)
: name(std::move(nstr)), : name(std::move(nstr)),
text(std::move(tstr)) { text(std::move(tstr)),
fun = [&arg](const std::string& str) -> bool { fun([&arg](const std::string& str) -> bool {
arg = str; arg = str;
return true; return true;
}; }) {
// nop
} }
message::cli_arg::cli_arg(std::string nstr, std::string tstr, message::cli_arg::cli_arg(std::string nstr, std::string tstr,
std::vector<std::string>& arg) std::vector<std::string>& arg)
: name(std::move(nstr)), text(std::move(tstr)) { : name(std::move(nstr)),
fun = [&arg](const std::string& str) -> bool { text(std::move(tstr)),
fun([&arg](const std::string& str) -> bool {
arg.push_back(str); arg.push_back(str);
return true; return true;
}; }) {
// nop
} }
message message::concat_impl(std::initializer_list<data_ptr> xs) { message message::concat_impl(std::initializer_list<data_ptr> xs) {
......
...@@ -34,7 +34,7 @@ ref_counted::ref_counted(const ref_counted&) : rc_(1) { ...@@ -34,7 +34,7 @@ ref_counted::ref_counted(const ref_counted&) : rc_(1) {
} }
ref_counted& ref_counted::operator=(const ref_counted&) { ref_counted& ref_counted::operator=(const ref_counted&) {
// nop; don't copy reference count // nop; intentionally don't copy reference count
return *this; return *this;
} }
......
...@@ -38,8 +38,6 @@ ...@@ -38,8 +38,6 @@
#include "caf/detail/actor_registry.hpp" #include "caf/detail/actor_registry.hpp"
#include "caf/detail/sync_request_bouncer.hpp" #include "caf/detail/sync_request_bouncer.hpp"
#include "caf/mixin/typed_functor_based.hpp"
#include "caf/io/middleman.hpp" #include "caf/io/middleman.hpp"
#include "caf/io/abstract_broker.hpp" #include "caf/io/abstract_broker.hpp"
......
...@@ -40,9 +40,9 @@ public: ...@@ -40,9 +40,9 @@ public:
handle(const handle& other) = default; handle(const handle& other) = default;
Subtype& operator=(const handle& other) { handle& operator=(const handle& other) {
id_ = other.id(); id_ = other.id();
return *static_cast<Subtype*>(this); return *this;
} }
/// Returns the unique identifier of this handle. /// Returns the unique identifier of this handle.
......
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