Commit a7a8dc50 authored by Dominik Charousset's avatar Dominik Charousset

Merge branch 'topic/forward-compatibility'

parents a7752756 f9f35653
...@@ -390,6 +390,46 @@ while [ $# -ne 0 ]; do ...@@ -390,6 +390,46 @@ while [ $# -ne 0 ]; do
append_cache_entry CAF_ENABLE_ADDRESS_SANITIZER BOOL yes append_cache_entry CAF_ENABLE_ADDRESS_SANITIZER BOOL yes
append_cache_entry CAF_ENABLE_TYPE_ID_CHECKS BOOL yes append_cache_entry CAF_ENABLE_TYPE_ID_CHECKS BOOL yes
;; ;;
# "overloads" for forward compatibility with new 0.18 disable-* syntax
--disable-memory-management)
append_cache_entry CAF_NO_MEM_MANAGEMENT BOOL yes
;;
--disable-compiler-check)
append_cache_entry CAF_NO_COMPILER_CHECK BOOL yes
;;
--disable-auto-libc++)
append_cache_entry CAF_NO_AUTO_LIBCPP BOOL yes
;;
--disable-exceptions)
append_cache_entry CAF_NO_EXCEPTIONS BOOL yes
;;
--disable-examples)
append_cache_entry CAF_NO_EXAMPLES BOOL yes
;;
--disable-curl-examples)
append_cache_entry CAF_NO_CURL_EXAMPLES BOOL yes
;;
--disable-testing)
append_cache_entry CAF_NO_UNIT_TESTS BOOL yes
;;
--disable-opencl)
append_cache_entry CAF_NO_OPENCL BOOL yes
;;
--disable-openssl)
append_cache_entry CAF_NO_OPENSSL BOOL yes
;;
--disable-tools)
append_cache_entry CAF_NO_TOOLS BOOL yes
;;
--disable-io)
append_cache_entry CAF_NO_IO BOOL yes
;;
--disable-python)
append_cache_entry CAF_NO_PYTHON BOOL yes
;;
--disable-summary)
append_cache_entry CAF_NO_SUMMARY BOOL yes
;;
*) *)
echo "Invalid option '$1'. Try $0 --help to see available options." echo "Invalid option '$1'. Try $0 --help to see available options."
exit 1 exit 1
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include <tuple> #include <tuple>
#include "caf/broadcast_downstream_manager.hpp" #include "caf/broadcast_downstream_manager.hpp"
#include "caf/check_typed_input.hpp"
#include "caf/default_downstream_manager.hpp" #include "caf/default_downstream_manager.hpp"
#include "caf/detail/stream_source_driver_impl.hpp" #include "caf/detail/stream_source_driver_impl.hpp"
#include "caf/detail/stream_source_impl.hpp" #include "caf/detail/stream_source_impl.hpp"
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <stdexcept> #include <stdexcept>
#include "caf/error.hpp" #include "caf/error.hpp"
#include "caf/timespan.hpp"
namespace caf { namespace caf {
...@@ -75,15 +76,6 @@ constexpr time_unit get_time_unit_from_period() { ...@@ -75,15 +76,6 @@ constexpr time_unit get_time_unit_from_period() {
return ratio_to_time_unit_helper<Period::num, Period::den>::value; return ratio_to_time_unit_helper<Period::num, Period::den>::value;
} }
/// Represents an infinite amount of timeout for specifying "invalid" timeouts.
struct infinite_t {
constexpr infinite_t() {
// nop
}
};
static constexpr infinite_t infinite = infinite_t{};
/// Time duration consisting of a `time_unit` and a 64 bit unsigned integer. /// Time duration consisting of a `time_unit` and a 64 bit unsigned integer.
class duration { class duration {
public: public:
...@@ -145,6 +137,12 @@ inline bool operator!=(const duration& lhs, const duration& rhs) { ...@@ -145,6 +137,12 @@ inline bool operator!=(const duration& lhs, const duration& rhs) {
return !(lhs == rhs); return !(lhs == rhs);
} }
/// @relates duration
template <class T>
inline bool is_infinite(duration x) {
return !x.valid();
}
/// @relates duration /// @relates duration
template <class Clock, class Duration> template <class Clock, class Duration>
std::chrono::time_point<Clock, Duration>& std::chrono::time_point<Clock, Duration>&
......
...@@ -23,7 +23,9 @@ ...@@ -23,7 +23,9 @@
#include <utility> #include <utility>
#include "caf/atom.hpp" #include "caf/atom.hpp"
#include "caf/config.hpp"
#include "caf/detail/comparable.hpp" #include "caf/detail/comparable.hpp"
#include "caf/detail/pp.hpp"
#include "caf/fwd.hpp" #include "caf/fwd.hpp"
#include "caf/meta/omittable_if_empty.hpp" #include "caf/meta/omittable_if_empty.hpp"
#include "caf/meta/type_name.hpp" #include "caf/meta/type_name.hpp"
...@@ -71,6 +73,11 @@ template <class T, class U = void> ...@@ -71,6 +73,11 @@ template <class T, class U = void>
using enable_if_has_error_factory_t = using enable_if_has_error_factory_t =
typename std::enable_if<detail::error_factory<T>::specialized, U>::type; typename std::enable_if<detail::error_factory<T>::specialized, U>::type;
/// @private
template <class T, class U = void>
using enable_if_can_construct_error_t = typename std::enable_if<
detail::error_factory<T>::specialized || has_make_error<T>::value, U>::type;
/// A serializable type for storing error codes with category and optional, /// A serializable type for storing error codes with category and optional,
/// human-readable context information. Unlike error handling classes from /// human-readable context information. Unlike error handling classes from
/// the C++ standard library, this type is serializable. It consists of an /// the C++ standard library, this type is serializable. It consists of an
...@@ -105,9 +112,9 @@ class error : detail::comparable<error> { ...@@ -105,9 +112,9 @@ class error : detail::comparable<error> {
public: public:
// -- member types ----------------------------------------------------------- // -- member types -----------------------------------------------------------
using inspect_fun = std::function< using inspect_fun
error(meta::type_name_t, uint8_t&, atom_value&, meta::omittable_if_empty_t, = std::function<error(meta::type_name_t, uint8_t&, atom_value&,
message&)>; meta::omittable_if_empty_t, message&)>;
// -- constructors, destructors, and assignment operators -------------------- // -- constructors, destructors, and assignment operators --------------------
...@@ -276,15 +283,21 @@ bool operator!=(E x, const error& y) { ...@@ -276,15 +283,21 @@ bool operator!=(E x, const error& y) {
return !(x == y); return !(x == y);
} }
/// @relates error
template <class Code, class... Ts>
enable_if_has_error_factory_t<Code, error> make_error(Code code, Ts&&... xs) {
return error{code, std::forward<Ts>(xs)...};
}
} // namespace caf } // namespace caf
#define CAF_ERROR_CODE_ENUM(enum_name) \ #define CAF_ERROR_CODE_ENUM_2(enum_type, category_name) \
namespace caf { \ namespace caf { \
namespace detail { \ namespace detail { \
template <> \ template <> \
struct error_factory<enum_name> { \ struct error_factory<enum_type> { \
static constexpr bool specialized = true; \ static constexpr bool specialized = true; \
static constexpr atom_value category = atom(#enum_name); \ static constexpr atom_value category = atom(category_name); \
template <class... Ts> \ template <class... Ts> \
static message context(Ts&&... xs) { \ static message context(Ts&&... xs) { \
return make_message(std::forward<Ts>(xs)...); \ return make_message(std::forward<Ts>(xs)...); \
...@@ -292,3 +305,16 @@ bool operator!=(E x, const error& y) { ...@@ -292,3 +305,16 @@ bool operator!=(E x, const error& y) {
}; \ }; \
} \ } \
} }
#define CAF_ERROR_CODE_ENUM_1(type_name) \
CAF_ERROR_CODE_ENUM_2(type_name, #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
...@@ -91,9 +91,9 @@ public: ...@@ -91,9 +91,9 @@ public:
construct(other); construct(other);
} }
template <class Code, class E = enable_if_has_make_error_t<Code>> template <class Code, class = enable_if_can_construct_error_t<Code>>
expected(Code code) : engaged_(false) { expected(Code code) : engaged_(false) {
new (std::addressof(error_)) caf::error(make_error(code)); new (std::addressof(error_)) caf::error(code);
} }
expected(expected&& other) noexcept(nothrow_move) { expected(expected&& other) noexcept(nothrow_move) {
...@@ -139,7 +139,6 @@ public: ...@@ -139,7 +139,6 @@ public:
return *this; return *this;
} }
expected& operator=(T&& x) noexcept(nothrow_move) { expected& operator=(T&& x) noexcept(nothrow_move) {
if (engaged_) { if (engaged_) {
value_ = std::move(x); value_ = std::move(x);
...@@ -169,8 +168,8 @@ public: ...@@ -169,8 +168,8 @@ public:
} }
template <class Code> template <class Code>
enable_if_has_make_error_t<Code, expected&> operator=(Code code) { enable_if_can_construct_error_t<Code, expected&> operator=(Code code) {
return *this = make_error(code); return *this = caf::error{code};
} }
// -- modifiers -------------------------------------------------------------- // -- modifiers --------------------------------------------------------------
...@@ -390,8 +389,8 @@ public: ...@@ -390,8 +389,8 @@ public:
// nop // nop
} }
template <class Code, class E = enable_if_has_make_error_t<Code>> template <class Code, class = enable_if_can_construct_error_t<Code>>
expected(Code code) : error_(make_error(code)) { expected(Code code) : error_(code) {
// nop // nop
} }
...@@ -402,6 +401,11 @@ public: ...@@ -402,6 +401,11 @@ public:
return *this; return *this;
} }
template <class Code>
enable_if_can_construct_error_t<Code, expected&> operator=(Code code) {
error_ = caf::error{code};
}
explicit operator bool() const { explicit operator bool() const {
return !error_; return !error_;
} }
...@@ -458,4 +462,3 @@ auto operator<<(ostream& oss, const caf::expected<T>& x) ...@@ -458,4 +462,3 @@ auto operator<<(ostream& oss, const caf::expected<T>& x)
} }
} // namespace std } // namespace std
// This header only exists to make transition to CAF 0.18 easier by not having
// to use #ifdef blocks for includes.
...@@ -61,14 +61,6 @@ struct is_serializable_or_whitelisted { ...@@ -61,14 +61,6 @@ struct is_serializable_or_whitelisted {
|| allowed_unsafe_message_type<T>::value; || allowed_unsafe_message_type<T>::value;
}; };
/// @private
template <class T>
struct has_type_id {
static constexpr bool value = detail::is_complete<type_id<T>>::value
|| is_atom_constant<T>::value
|| allowed_unsafe_message_type<T>::value;
};
/// Returns a new `message` containing the values `(x, xs...)`. /// Returns a new `message` containing the values `(x, xs...)`.
/// @relates message /// @relates message
template <class T, class... Ts> template <class T, class... Ts>
......
...@@ -26,5 +26,25 @@ namespace caf { ...@@ -26,5 +26,25 @@ namespace caf {
/// A portable timespan type with nanosecond resolution. /// A portable timespan type with nanosecond resolution.
using timespan = std::chrono::duration<int64_t, std::nano>; using timespan = std::chrono::duration<int64_t, std::nano>;
} // namespace caf /// Represents an infinite amount of timeout for specifying "invalid" timeouts.
struct infinite_t {
constexpr infinite_t() {
// nop
}
};
/// Constant for passing "no timeout" to functions such as `request`.
static constexpr infinite_t infinite = infinite_t{};
// -- forward compatibility with CAF 0.18 --------------------------------------
constexpr bool is_infinite(infinite_t) {
return true;
}
template <class Rep, class Period>
constexpr bool is_infinite(std::chrono::duration<Rep, Period>) {
return false;
}
} // namespace caf
...@@ -23,7 +23,9 @@ ...@@ -23,7 +23,9 @@
#include <string> #include <string>
#include <utility> #include <utility>
#include "caf/allowed_unsafe_message_type.hpp"
#include "caf/atom.hpp" #include "caf/atom.hpp"
#include "caf/detail/is_complete.hpp"
#include "caf/detail/pp.hpp" #include "caf/detail/pp.hpp"
#include "caf/detail/squashed_int.hpp" #include "caf/detail/squashed_int.hpp"
#include "caf/fwd.hpp" #include "caf/fwd.hpp"
...@@ -63,6 +65,17 @@ struct type_name_by_id; ...@@ -63,6 +65,17 @@ struct type_name_by_id;
/// The first type ID not reserved by CAF and its modules. /// The first type ID not reserved by CAF and its modules.
constexpr type_id_t first_custom_type_id = 200; constexpr type_id_t first_custom_type_id = 200;
/// Evaluates to `true` if any of these statements holds true:
/// - `type_id<T>` is specialized
/// - `T` is an atom constant
/// - `allowed_unsafe_message_type<T>` is specialized
template <class T>
struct has_type_id {
static constexpr bool value = detail::is_complete<type_id<T>>::value
|| is_atom_constant<T>::value
|| allowed_unsafe_message_type<T>::value;
};
} // namespace caf } // namespace caf
/// Starts a code block for registering custom types to CAF. Stores the first ID /// Starts a code block for registering custom types to CAF. Stores the first ID
......
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