Commit b98cfd6e authored by Dominik Charousset's avatar Dominik Charousset

Fix several warnings on GCC and Clang

parent 5744dc5d
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| 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_DETAIL_ENUM_TO_STRING_HPP
#define CAF_DETAIL_ENUM_TO_STRING_HPP
#include <type_traits>
namespace caf {
namespace detail {
/// Converts x to its underlying type and fetches the name from the
/// lookup table. Assumes consecutive enum values.
template <class E, size_t N>
const char* enum_to_string(E x, const char* (&lookup_table)[N]) {
auto index = static_cast<typename std::underlying_type<E>::type>(x);
return index < N ? lookup_table[index] : "<unknown>";
}
} // namespace detail
} // namespace caf
#endif // CAF_DETAIL_ENUM_TO_STRING_HPP
......@@ -32,14 +32,14 @@ namespace caf {
/// SI time units to specify timeouts.
/// @relates duration
enum class time_unit : uint32_t {
invalid = 0,
seconds = 1,
milliseconds = 1000,
microseconds = 1000000
invalid,
seconds,
milliseconds,
microseconds
};
/// Relates time_unit
std::string to_string(const time_unit& x);
std::string to_string(time_unit x);
/// Converts the ratio Num/Denom to a `time_unit` if the ratio describes
/// seconds, milliseconds, microseconds, or minutes. Minutes are mapped
......
......@@ -104,9 +104,9 @@ class mailbox_element_vals
public detail::tuple_vals_impl<type_erased_tuple, Ts...> {
public:
template <class... Us>
mailbox_element_vals(strong_actor_ptr&& sender, message_id id,
forwarding_stack&& stages, Us&&... xs)
: mailbox_element(std::move(sender), id, std::move(stages)),
mailbox_element_vals(strong_actor_ptr&& x0, message_id x1,
forwarding_stack&& x2, Us&&... xs)
: mailbox_element(std::move(x0), x1, std::move(x2)),
detail::tuple_vals_impl<type_erased_tuple, Ts...>(std::forward<Us>(xs)...) {
// nop
}
......@@ -131,9 +131,9 @@ template <class... Ts>
class mailbox_element_view : public mailbox_element,
public detail::type_erased_tuple_view<Ts...> {
public:
mailbox_element_view(strong_actor_ptr&& sender, message_id id,
forwarding_stack&& stages, Ts&... xs)
: mailbox_element(std::move(sender), id, std::move(stages)),
mailbox_element_view(strong_actor_ptr&& x0, message_id x1,
forwarding_stack&& x2, Ts&... xs)
: mailbox_element(std::move(x0), x1, std::move(x2)),
detail::type_erased_tuple_view<Ts...>(xs...) {
// nop
}
......
......@@ -40,6 +40,7 @@
#include "caf/actor_control_block.hpp"
#include "caf/detail/disposer.hpp"
#include "caf/detail/enum_to_string.hpp"
#include "caf/detail/shared_spinlock.hpp"
namespace caf {
......@@ -100,17 +101,19 @@ void abstract_actor::is_registered(bool value) {
set_flag(value, is_registered_flag);
}
namespace {
const char* linking_operation_strings[] = {
"establish_link",
"establish_backlink",
"remove_link",
"remove_backlink"
};
} // namespace <anonymous>
std::string to_string(abstract_actor::linking_operation op) {
switch (op) {
case abstract_actor::establish_link_op:
return "establish_link";
case abstract_actor::establish_backlink_op:
return "establish_backlink";
case abstract_actor::remove_link_op:
return "remove_link";
default:
return "remove_backlink";
}
return detail::enum_to_string(op, linking_operation_strings);
}
} // namespace caf
......@@ -21,36 +21,37 @@
#include "caf/duration.hpp"
#include "caf/detail/enum_to_string.hpp"
namespace caf {
std::string to_string(const time_unit& x) {
switch (x) {
case time_unit::seconds:
return "seconds";
case time_unit::milliseconds:
return "milliseconds";
case time_unit::microseconds:
return "microseconds";
default:
return "invalid";
}
namespace {
const char* time_unit_strings[] = {
"invalid",
"seconds",
"milliseconds",
"microseconds"
};
const char* time_unit_short_strings[] = {
"?",
"s",
"ms",
"us"
};
} // namespace <anonymous>
std::string to_string(time_unit x) {
return detail::enum_to_string(x, time_unit_strings);
}
std::string to_string(const duration& x) {
if (x.unit == time_unit::invalid)
return "infinite";
auto result = std::to_string(x.count);
switch (x.unit) {
case time_unit::seconds:
result += "s";
break;
case time_unit::milliseconds:
result += "ms";
break;
case time_unit::microseconds:
result += "us";
break;
default:
return "infinite";
}
result += detail::enum_to_string(x.unit, time_unit_short_strings);
return result;
}
......
......@@ -21,6 +21,8 @@
#include "caf/message.hpp"
#include "caf/detail/enum_to_string.hpp"
namespace caf {
namespace {
......@@ -40,10 +42,7 @@ const char* exit_reason_strings[] = {
std::string to_string(exit_reason x) {
auto index = static_cast<size_t>(x);
if (index > static_cast<size_t>(exit_reason::unreachable))
return "<unknown>";
return exit_reason_strings[index];
return detail::enum_to_string(x, exit_reason_strings);
}
error make_error(exit_reason x) {
......
......@@ -294,7 +294,7 @@ void logger::run() {
}
void logger::start() {
#if CAF_LOG_LEVEL >= CAF_LOG_LEVEL_INFO
#if defined(CAF_LOG_LEVEL) && CAF_LOG_LEVEL >= CAF_LOG_LEVEL_INFO
const char* log_level_table[] = {"ERROR", "WARN", "INFO", "DEBUG", "TRACE"};
thread_ = std::thread{[this] { this->run(); }};
std::string msg = "ENTRY log level = ";
......@@ -304,7 +304,7 @@ void logger::start() {
}
void logger::stop() {
#if CAF_LOG_LEVEL >= CAF_LOG_LEVEL_INFO
#if defined(CAF_LOG_LEVEL) && CAF_LOG_LEVEL >= CAF_LOG_LEVEL_INFO
log(CAF_LOG_LEVEL_INFO, "caf", "caf::logger", "run", __FILE__, __LINE__, "EXIT");
// an empty string means: shut down
queue_.synchronized_enqueue(queue_mtx_, queue_cv_, new event{""});
......
......@@ -19,6 +19,8 @@
#include "caf/sec.hpp"
#include "caf/detail/enum_to_string.hpp"
namespace caf {
namespace {
......@@ -59,10 +61,7 @@ const char* sec_strings[] = {
} // namespace <anonymous>
std::string to_string(sec x) {
auto index = static_cast<size_t>(x);
if (index > static_cast<size_t>(sec::bad_function_call))
return "<unknown>";
return sec_strings[index];
return detail::enum_to_string(x, sec_strings);
}
error make_error(sec x) {
......
......@@ -65,6 +65,7 @@
#include "caf/detail/int_list.hpp"
#include "caf/detail/safe_equal.hpp"
#include "caf/detail/type_traits.hpp"
#include "caf/detail/enum_to_string.hpp"
#include "caf/detail/get_mac_addresses.hpp"
using namespace std;
......@@ -94,13 +95,10 @@ enum class test_enum : uint32_t {
c
};
const char* test_enum_strings[] = { "a", "b", "c" };
std::string to_string(test_enum x) {
switch (x) {
case test_enum::a: return "a";
case test_enum::b: return "b";
case test_enum::c: return "c";
}
return "???";
return detail::enum_to_string(x, test_enum_strings);
}
struct test_array {
......
......@@ -123,10 +123,10 @@ connection_handle asio_multiplexer::add_tcp_scribe(abstract_broker* self,
CAF_LOG_TRACE("");
class impl : public scribe {
public:
impl(abstract_broker* ptr, asio_multiplexer& ref, Socket&& s)
impl(abstract_broker* ptr, asio_multiplexer& am, Socket&& s)
: scribe(ptr, network::conn_hdl_from_socket(s)),
launched_(false),
stream_(ref) {
stream_(am) {
stream_.init(std::move(s));
}
void configure_read(receive_policy::config config) override {
......@@ -249,9 +249,9 @@ asio_multiplexer::add_tcp_doorman(abstract_broker* self,
bool new_connection() override {
CAF_LOG_TRACE("");
auto& am = acceptor_.backend();
auto hdl = am.add_tcp_scribe(parent(),
std::move(acceptor_.accepted_socket()));
return doorman::new_connection(&am, hdl);
auto x = am.add_tcp_scribe(parent(),
std::move(acceptor_.accepted_socket()));
return doorman::new_connection(&am, x);
}
void stop_reading() override {
CAF_LOG_TRACE("");
......
......@@ -19,27 +19,27 @@
#include "caf/io/basp/message_type.hpp"
#include "caf/detail/enum_to_string.hpp"
namespace caf {
namespace io {
namespace basp {
namespace {
const char* message_type_strings[] = {
"server_handshake",
"client_handshake",
"dispatch_message",
"announce_proxy_instance",
"kill_proxy_instance",
"heartbeat"
};
} // namespace <anonymous>
std::string to_string(message_type x) {
switch (x) {
case message_type::server_handshake:
return "server_handshake";
case message_type::client_handshake:
return "client_handshake";
case message_type::dispatch_message:
return "dispatch_message";
case message_type::announce_proxy:
return "announce_proxy_instance";
case message_type::kill_proxy:
return "kill_proxy_instance";
case message_type::heartbeat:
return "heartbeat";
default:
return "???";
}
return detail::enum_to_string(x, message_type_strings);
}
} // namespace basp
......
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