Commit 5e18bc9c authored by Dominik Charousset's avatar Dominik Charousset

Add macros for backwards compatibility with 0.17.5

parent 16a23dde
......@@ -136,7 +136,7 @@ public:
template <class T, class... Ts>
actor_system_config& add_actor_type(std::string name) {
using handle = typename infer_handle_from_class<T>::type;
static_assert(detail::is_complete<type_id<handle>>);
static_assert(has_type_id_v<handle>);
return add_actor_factory(std::move(name), make_actor_factory<T, Ts...>());
}
......@@ -146,7 +146,7 @@ public:
template <class F>
actor_system_config& add_actor_type(std::string name, F f) {
using handle = typename infer_handle_from_fun<F>::type;
static_assert(detail::is_complete<type_id<handle>>);
static_assert(has_type_id_v<handle>);
return add_actor_factory(std::move(name), make_actor_factory(std::move(f)));
}
......
......@@ -45,7 +45,7 @@ public:
// -- sanity checks ----------------------------------------------------------
static_assert(detail::is_complete<type_id<std::vector<output_type>>>);
static_assert(has_type_id_v<std::vector<output_type>>);
// -- constructors, destructors, and assignment operators --------------------
......
......@@ -125,6 +125,6 @@ template <class T>
using strip_and_convert_t = typename strip_and_convert<T>::type;
template <class T>
constexpr bool sendable = is_complete<type_id<strip_and_convert_t<T>>>;
constexpr bool sendable = has_type_id_v<strip_and_convert_t<T>>;
} // namespace caf::detail
......@@ -25,6 +25,7 @@
#include "caf/sec.hpp"
#include "caf/stream_manager.hpp"
#include "caf/stream_sink.hpp"
#include "caf/typed_message_view.hpp"
#include "caf/policy/arg.hpp"
......
......@@ -18,6 +18,9 @@
#pragma once
#include "caf/config.hpp"
#include "caf/detail/pp.hpp"
namespace caf {
/// Customization point for enabling conversion from an enum type to an
......@@ -33,10 +36,24 @@ constexpr bool is_error_code_enum_v = is_error_code_enum<T>::value;
} // namespace caf
#define CAF_ERROR_CODE_ENUM(type_name) \
#define CAF_ERROR_CODE_ENUM_1(type_name) \
namespace caf { \
template <> \
struct is_error_code_enum<type_name> { \
static constexpr bool value = true; \
}; \
}
// Exists only for backwards compatibility with 0.17.5.
#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
......@@ -114,6 +114,12 @@ public:
return !data_;
}
// -- reference counting -----------------------------------------------------
void force_unshare() {
data_.unshare();
}
// -- serialization ----------------------------------------------------------
error save(serializer& sink) const;
......@@ -183,7 +189,7 @@ template <class... Ts>
message make_message(Ts&&... xs) {
using namespace detail;
static_assert((!std::is_pointer<strip_and_convert_t<Ts>>::value && ...));
static_assert((is_complete<type_id<strip_and_convert_t<Ts>>> && ...));
static_assert((has_type_id_v<strip_and_convert_t<Ts>> && ...));
static constexpr size_t data_size
= sizeof(message_data) + (padded_size_v<strip_and_convert_t<Ts>> + ...);
auto types = make_type_id_list<strip_and_convert_t<Ts>...>();
......
......@@ -31,4 +31,11 @@ using timespan = std::chrono::duration<int64_t, std::nano>;
static constexpr timespan infinite
= timespan{std::numeric_limits<int64_t>::max()};
/// Checks whether `x` represents an infinite timespan. Timespan are considered
/// infinite if the underlying integer reached its maximum value.
template <class Rep, class Period>
constexpr bool is_infinite(std::chrono::duration<Rep, Period> x) {
return x.count() == std::numeric_limits<int64_t>::max();
}
} // namespace caf
......@@ -84,9 +84,15 @@ constexpr const char* type_name_v = type_name<T>::value;
/// The first type ID not reserved by CAF and its modules.
constexpr type_id_t first_custom_type_id = 200;
/// Checks whether `type_id` is specialized for `T`.
/// Evaluates to `true` if @ref type_id is specialized for `T`.
template <class T>
constexpr bool has_type_id = detail::is_complete<type_id<T>>;
struct has_type_id {
static constexpr bool value = detail::is_complete<type_id<T>>;
};
/// Checks whether @ref type_id is specialized for `T`.
template <class T>
constexpr bool has_type_id_v = has_type_id<T>::value;
} // namespace caf
......@@ -189,6 +195,15 @@ 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) \
CAF_ADD_ATOM_3(project_name, atom_namespace, atom_name) \
namespace atom_namespace { \
inline std::string to_string(atom_name) { \
return atom_text; \
} \
}
#ifdef CAF_MSVC
# define CAF_ADD_ATOM(...) \
CAF_PP_CAT(CAF_PP_OVERLOAD(CAF_ADD_ATOM_, __VA_ARGS__)(__VA_ARGS__), \
......
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