Commit 8996b00c authored by Dominik Charousset's avatar Dominik Charousset

Improve backwards compatibility with 0.17

parent 2266cbe9
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-2020 Dominik Charousset *
* *
* 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. *
******************************************************************************/
#pragma once
#include "caf/error.hpp"
#include "caf/error_code.hpp"
#include "caf/sec.hpp"
#include "caf/type_id.hpp"
namespace caf::detail {
template <class T>
void assign_inspector_try_result(error& x, T&& y) {
x = std::forward<T>(y);
}
inline void assign_inspector_try_result(error_code<sec>& x, const error& y) {
if (y.category() == type_id_v<sec>)
x = static_cast<sec>(y.code());
else
x = sec::runtime_error;
}
inline void assign_inspector_try_result(error_code<sec>& x, error_code<sec> y) {
x = y;
}
} // namespace caf::detail
......@@ -22,11 +22,11 @@
#include "caf/logger.hpp"
#include "caf/make_counted.hpp"
#include "caf/message_id.hpp"
#include "caf/policy/arg.hpp"
#include "caf/sec.hpp"
#include "caf/stream_manager.hpp"
#include "caf/stream_sink.hpp"
#include "caf/policy/arg.hpp"
#include "caf/typed_message_view.hpp"
namespace caf::detail {
......
......@@ -18,6 +18,8 @@
#pragma once
#include "caf/detail/pp.hpp"
namespace caf {
/// Customization point for enabling conversion from an enum type to an
......@@ -33,10 +35,26 @@ constexpr bool is_error_code_enum_v = is_error_code_enum<T>::value;
} // namespace caf
#define CAF_ERROR_CODE_ENUM(type_name) \
// TODO: the overload with two arguments exists only for backwards compatibility
// with CAF 0.17. Remove with CAF 0.19.
#define CAF_ERROR_CODE_ENUM_1(type_name) \
namespace caf { \
template <> \
struct is_error_code_enum<type_name> { \
static constexpr bool value = true; \
}; \
}
#define CAF_ERROR_CODE_ENUM_2(type_name, unused) \
CAF_ERROR_CODE_ENUM_1(type_name)
#ifdef CAF_MSVC
# define CAF_ERROR_CODE_ENUM(...) \
CAF_PP_CAT(CAF_PP_OVERLOAD(CAF_ERROR_CODE_ENUM_, \
__VA_ARGS__)(__VA_ARGS__), \
CAF_PP_EMPTY())
#else
# define CAF_ERROR_CODE_ENUM(...) \
CAF_PP_OVERLOAD(CAF_ERROR_CODE_ENUM_, __VA_ARGS__)(__VA_ARGS__)
#endif
......@@ -167,6 +167,12 @@ public:
data_.reset(new_ptr, add_ref);
}
/// Forces the message to copy its content if more than one reference to the
/// content exists.
void force_unshare() {
data_.unshare();
}
private:
data_ptr data_;
};
......
......@@ -21,6 +21,7 @@
#include <type_traits>
#include "caf/allowed_unsafe_message_type.hpp"
#include "caf/detail/assign_inspector_try_result.hpp"
#include "caf/detail/inspect.hpp"
#include "caf/detail/squashed_int.hpp"
#include "caf/detail/type_traits.hpp"
......@@ -34,7 +35,7 @@
statement; \
} else { \
if (auto err = statement) { \
result = err; \
detail::assign_inspector_try_result(result, std::move(err)); \
return false; \
} \
}
......
......@@ -31,4 +31,9 @@ using timespan = std::chrono::duration<int64_t, std::nano>;
static constexpr timespan infinite
= timespan{std::numeric_limits<int64_t>::max()};
/// Checks whether `value` represents an infinite amount of time.
constexpr bool is_infinite(timespan value) {
return value == infinite;
}
} // namespace caf
......@@ -86,7 +86,13 @@ constexpr type_id_t first_custom_type_id = 200;
/// Checks whether `type_id` is specialized for `T`.
template <class T>
constexpr bool has_type_id = detail::is_complete<type_id<T>>;
constexpr bool has_type_id_v = detail::is_complete<type_id<T>>;
// TODO: remove with CAF 0.19 (this exists for compatibility with CAF 0.17).
template <class T>
struct has_type_id {
static constexpr bool value = detail::is_complete<type_id<T>>;
};
} // namespace caf
......@@ -189,6 +195,27 @@ constexpr bool has_type_id = detail::is_complete<type_id<T>>;
} \
CAF_ADD_TYPE_ID(project_name, (atom_namespace::atom_name))
/// Creates a new tag type (atom) and assigns the next free type ID to it.
#define CAF_ADD_ATOM_4(project_name, atom_namespace, atom_name, atom_text) \
namespace atom_namespace { \
struct atom_name {}; \
static constexpr atom_name atom_name##_v = atom_name{}; \
[[maybe_unused]] constexpr bool operator==(atom_name, atom_name) { \
return true; \
} \
[[maybe_unused]] constexpr bool operator!=(atom_name, atom_name) { \
return false; \
} \
inline std::string to_string(atom_name) { \
return atom_text; \
} \
template <class Inspector> \
auto inspect(Inspector& f, atom_name&) { \
return f(caf::meta::type_name(#atom_namespace "::" #atom_name)); \
} \
} \
CAF_ADD_TYPE_ID(project_name, (atom_namespace::atom_name))
#ifdef CAF_MSVC
# define CAF_ADD_ATOM(...) \
CAF_PP_CAT(CAF_PP_OVERLOAD(CAF_ADD_ATOM_, __VA_ARGS__)(__VA_ARGS__), \
......
......@@ -24,6 +24,7 @@
#include <utility>
#include "caf/allowed_unsafe_message_type.hpp"
#include "caf/detail/assign_inspector_try_result.hpp"
#include "caf/detail/inspect.hpp"
#include "caf/detail/squashed_int.hpp"
#include "caf/detail/type_traits.hpp"
......@@ -36,7 +37,7 @@
statement; \
} else { \
if (auto err = statement) { \
result = err; \
detail::assign_inspector_try_result(result, std::move(err)); \
return false; \
} \
}
......
......@@ -72,6 +72,9 @@ public:
/// default network backend.
static actor_system::module* make(actor_system&, detail::type_list<>);
/// Adds message types of the OpenSSL module to the global meta object table.
static void init_global_meta_objects();
private:
/// Private since instantiation is only allowed via `make`.
manager(actor_system& sys);
......
......@@ -174,6 +174,10 @@ actor_system::module* manager::make(actor_system& sys, detail::type_list<>) {
return new manager(sys);
}
void manager::init_global_meta_objects() {
// nop
}
manager::manager(actor_system& sys) : system_(sys) {
// nop
}
......
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