/usr/include/caf/message_handler.hpp is in libcaf-dev 0.13.2-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | /******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| 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_MESSAGE_HANDLER_HPP
#define CAF_MESSAGE_HANDLER_HPP
#include <list>
#include <vector>
#include <memory>
#include <utility>
#include <type_traits>
#include "caf/fwd.hpp"
#include "caf/none.hpp"
#include "caf/intrusive_ptr.hpp"
#include "caf/on.hpp"
#include "caf/message.hpp"
#include "caf/duration.hpp"
#include "caf/behavior.hpp"
#include "caf/ref_counted.hpp"
#include "caf/may_have_timeout.hpp"
#include "caf/timeout_definition.hpp"
#include "caf/detail/behavior_impl.hpp"
namespace caf {
/**
* A partial function implementation used to process a `message`.
*/
class message_handler {
public:
friend class behavior;
message_handler() = default;
message_handler(message_handler&&) = default;
message_handler(const message_handler&) = default;
message_handler& operator=(message_handler&&) = default;
message_handler& operator=(const message_handler&) = default;
/**
* A pointer to the underlying implementation.
*/
using impl_ptr = intrusive_ptr<detail::behavior_impl>;
/**
* Returns a pointer to the implementation.
*/
inline const impl_ptr& as_behavior_impl() const {
return m_impl;
}
/**
* Creates a message handler from @p ptr.
*/
message_handler(impl_ptr ptr);
/**
* Checks whether the message handler is not empty.
*/
inline operator bool() const {
return static_cast<bool>(m_impl);
}
/**
* Create a message handler a list of match expressions,
* functors, or other message handlers.
*/
template <class T, class... Ts>
message_handler(const T& v, Ts&&... xs) {
assign(v, std::forward<Ts>(xs)...);
}
/**
* Assigns new message handlers.
*/
template <class... Ts>
void assign(Ts... xs) {
static_assert(sizeof...(Ts) > 0, "assign without arguments called");
m_impl = detail::make_behavior(xs...);
}
/**
* Equal to `*this = other`.
*/
void assign(message_handler other);
/**
* Runs this handler and returns its (optional) result.
*/
inline optional<message> operator()(message& arg) {
return (m_impl) ? m_impl->invoke(arg) : none;
}
/**
* Returns a new handler that concatenates this handler
* with a new handler from `xs...`.
*/
template <class... Ts>
typename std::conditional<
detail::disjunction<may_have_timeout<
typename std::decay<Ts>::type>::value...
>::value,
behavior,
message_handler
>::type
or_else(Ts&&... xs) const {
// using a behavior is safe here, because we "cast"
// it back to a message_handler when appropriate
behavior tmp{std::forward<Ts>(xs)...};
if (! tmp) {
return *this;
}
if (m_impl) {
return m_impl->or_else(tmp.as_behavior_impl());
}
return tmp.as_behavior_impl();
}
private:
impl_ptr m_impl;
};
} // namespace caf
#endif // CAF_MESSAGE_HANDLER_HPP
|