Commit a96f232d authored by Dominik Charousset's avatar Dominik Charousset

New terminology, e.g., `any_tuple` => `message`

This patch renames several classes to give programmers without functional
background a better intuition about the purpose of a particular class. For
example, `partial_function` is not a concept familiar to all C++ developers and
has been renamed to `message_handler`. Although the former is a better and more
general name in theory, the latter is a better description for what the class
is actually used for in the library.
parent f83fdfb4
......@@ -119,16 +119,6 @@ if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
set(CMAKE_BUILD_TYPE RelWithDebInfo)
endif ("${CMAKE_BUILD_TYPE}" STREQUAL "")
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(LIBCPPA_PLATFORM_SRC src/middleman_event_handler_epoll.cpp)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(LIBCPPA_PLATFORM_SRC src/middleman_event_handler_poll.cpp)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Window")
set(LIBCPPA_PLATFORM_SRC src/middleman_event_handler_poll.cpp src/execinfo_windows.cpp)
else ()
message(FATAL_ERROR "This platform is not supported by libcppa")
endif()
# get header files; only needed by CMake generators,
# e.g., for creating proper Xcode projects
file(GLOB LIBCPPA_HDRS "cppa/*.hpp"
......@@ -139,94 +129,106 @@ file(GLOB LIBCPPA_HDRS "cppa/*.hpp"
"cppa/qtsupport/*.hpp"
"cppa/util/*.hpp")
# list cpp files including platform-dependent files
set(LIBCPPA_SRC
${LIBCPPA_PLATFORM_SRC}
src/abstract_actor.cpp
src/abstract_channel.cpp
src/abstract_group.cpp
src/abstract_tuple.cpp
src/acceptor.cpp
src/actor.cpp
src/actor_addr.cpp
src/actor_companion.cpp
src/actor_namespace.cpp
src/actor_ostream.cpp
src/actor_proxy.cpp
src/actor_proxy.cpp
src/actor_registry.cpp
src/algorithm.cpp
src/any_tuple.cpp
src/atom.cpp
src/attachable.cpp
src/behavior.cpp
src/behavior_stack.cpp
src/binary_deserializer.cpp
src/binary_serializer.cpp
src/blocking_actor.cpp
src/broker.cpp
src/buffer.cpp
src/channel.cpp
src/context_switching_resume.cpp
src/continuable.cpp
src/continue_helper.cpp
src/cs_thread.cpp
src/decorated_tuple.cpp
src/default_message_queue.cpp
src/demangle.cpp
src/deserializer.cpp
src/duration.cpp
src/event_based_actor.cpp
src/exception.cpp
src/execution_unit.cpp
src/exit_reason.cpp
src/fd_util.cpp
src/functor_based_actor.cpp
src/functor_based_blocking_actor.cpp
src/get_mac_addresses.cpp
src/get_root_uuid.cpp
src/group.cpp
src/group_manager.cpp
src/input_stream.cpp
src/local_actor.cpp
src/logging.cpp
src/mailbox_element.cpp
src/match.cpp
src/memory.cpp
src/memory_managed.cpp
src/message_header.cpp
src/middleman.cpp
src/middleman_event_handler.cpp
src/node_id.cpp
src/object_array.cpp
src/opt.cpp
src/output_stream.cpp
src/partial_function.cpp
src/peer.cpp
src/peer_acceptor.cpp
src/primitive_variant.cpp
src/ref_counted.cpp
src/remote_actor_proxy.cpp
src/response_promise.cpp
src/resumable.cpp
src/ripemd_160.cpp
src/scheduler.cpp
src/scoped_actor.cpp
src/serializer.cpp
src/shared_spinlock.cpp
src/singleton_manager.cpp
src/stream.cpp
src/string_serialization.cpp
src/sync_request_bouncer.cpp
src/tcp_acceptor.cpp
src/tcp_io_stream.cpp
src/to_uniform_name.cpp
src/type_lookup_table.cpp
src/unicast_network.cpp
src/uniform_type_info.cpp
src/uniform_type_info_map.cpp
src/weak_ptr_anchor.cpp
src/yield_interface.cpp)
# platform-dependent files
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(LIBCPPA_PLATFORM_SRCS src/middleman_event_handler_epoll.cpp)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(LIBCPPA_PLATFORM_SRCS src/middleman_event_handler_poll.cpp)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Window")
set(LIBCPPA_PLATFORM_SRCS src/middleman_event_handler_poll.cpp src/execinfo_windows.cpp)
else ()
message(FATAL_ERROR "This platform is not supported by libcppa")
endif()
# list cpp files excluding platform-dependent files
set (LIBCPPA_SRCS
${LIBCPPA_PLATFORM_SRCS}
src/abstract_actor.cpp
src/abstract_channel.cpp
src/abstract_group.cpp
src/acceptor.cpp
src/actor.cpp
src/actor_addr.cpp
src/actor_companion.cpp
src/actor_namespace.cpp
src/actor_ostream.cpp
src/actor_proxy.cpp
src/actor_registry.cpp
src/algorithm.cpp
src/atom.cpp
src/attachable.cpp
src/behavior.cpp
src/behavior_stack.cpp
src/binary_deserializer.cpp
src/binary_serializer.cpp
src/blocking_actor.cpp
src/broker.cpp
src/buffer.cpp
src/channel.cpp
src/context_switching_resume.cpp
src/continuable.cpp
src/continue_helper.cpp
src/cs_thread.cpp
src/decorated_tuple.cpp
src/default_message_queue.cpp
src/demangle.cpp
src/deserializer.cpp
src/duration.cpp
src/event_based_actor.cpp
src/exception.cpp
src/execution_unit.cpp
src/exit_reason.cpp
src/fd_util.cpp
src/functor_based_actor.cpp
src/functor_based_blocking_actor.cpp
src/get_mac_addresses.cpp
src/get_root_uuid.cpp
src/group.cpp
src/group_manager.cpp
src/input_stream.cpp
src/local_actor.cpp
src/logging.cpp
src/mailbox_element.cpp
src/match.cpp
src/memory.cpp
src/memory_managed.cpp
src/message.cpp
src/message_builder.cpp
src/message_handler.cpp
src/message_header.cpp
src/middleman.cpp
src/middleman_event_handler.cpp
src/node_id.cpp
src/opencl/global.cpp
src/opencl/opencl_metainfo.cpp
src/opencl/program.cpp
src/opt.cpp
src/output_stream.cpp
src/peer.cpp
src/peer_acceptor.cpp
src/primitive_variant.cpp
src/ref_counted.cpp
src/remote_actor_proxy.cpp
src/response_promise.cpp
src/resumable.cpp
src/ripemd_160.cpp
src/scheduler.cpp
src/scoped_actor.cpp
src/serializer.cpp
src/shared_spinlock.cpp
src/singleton_manager.cpp
src/stream.cpp
src/string_serialization.cpp
src/sync_request_bouncer.cpp
src/tcp_acceptor.cpp
src/tcp_io_stream.cpp
src/to_uniform_name.cpp
src/type_lookup_table.cpp
src/unicast_network.cpp
src/uniform_type_info.cpp
src/uniform_type_info_map.cpp
src/weak_ptr_anchor.cpp
src/yield_interface.cpp)
if (BOOST_ROOT)
# Prevent falling back to system paths when using a custom Boost prefix.
......@@ -279,7 +281,7 @@ endif (ENABLE_CONTEXT_SWITCHING)
# build shared library if not compiling static only
if (NOT "${CPPA_BUILD_STATIC_ONLY}" STREQUAL "yes")
add_library(libcppa SHARED ${LIBCPPA_SRC} ${LIBCPPA_HDRS})
add_library(libcppa SHARED ${LIBCPPA_SRCS} ${LIBCPPA_HDRS})
target_link_libraries(libcppa ${LD_FLAGS})
set(LIBRARY_VERSION ${LIBCPPA_VERSION_MAJOR}.${LIBCPPA_VERSION_MINOR}.${LIBCPPA_VERSION_PATCH})
set(LIBRARY_SOVERSION ${LIBCPPA_VERSION_MAJOR})
......@@ -295,7 +297,7 @@ endif ()
# build static library only if --build-static or --build-static-only was set
if ("${CPPA_BUILD_STATIC_ONLY}" STREQUAL "yes" OR "${CPPA_BUILD_STATIC}" STREQUAL "yes")
add_library(libcppaStatic STATIC ${LIBCPPA_HDRS} ${LIBCPPA_SRC})
add_library(libcppaStatic STATIC ${LIBCPPA_HDRS} ${LIBCPPA_SRCS})
set_target_properties(libcppaStatic PROPERTIES OUTPUT_NAME cppa_static)
install(TARGETS libcppaStatic ARCHIVE DESTINATION lib)
endif ()
......
......@@ -46,7 +46,7 @@ class abstract_channel : public ref_counted {
* is not a scheduled actor.
*/
virtual void enqueue(msg_hdr_cref header,
any_tuple content,
message content,
execution_unit* host) = 0;
protected:
......
......@@ -47,7 +47,7 @@ class broker;
} // namespace io
namespace opencl {
template <typename Signature>
template<typename Signature>
class actor_facade;
} // namespace opencl
......
......@@ -65,7 +65,7 @@ class actor_companion : public extend<local_actor, actor_companion>::
*/
void on_enqueue(enqueue_handler handler);
void enqueue(msg_hdr_cref hdr, any_tuple msg, execution_unit* eu) override;
void enqueue(msg_hdr_cref hdr, message msg, execution_unit* eu) override;
private:
......
......@@ -21,7 +21,7 @@
#define CPPA_ACTOR_OSTREAM_HPP
#include "cppa/actor.hpp"
#include "cppa/any_tuple.hpp"
#include "cppa/message.hpp"
#include "cppa/to_string.hpp"
namespace cppa {
......@@ -51,11 +51,11 @@ class actor_ostream {
return write(move(arg));
}
inline actor_ostream& operator<<(const any_tuple& arg) {
inline actor_ostream& operator<<(const message& arg) {
return write(cppa::to_string(arg));
}
// disambiguate between conversion to string and to any_tuple
// disambiguate between conversion to string and to message
inline actor_ostream& operator<<(const char* arg) {
return *this << std::string{arg};
}
......@@ -63,7 +63,7 @@ class actor_ostream {
template<typename T>
inline typename std::enable_if<
!std::is_convertible<T, std::string>::value
&& !std::is_convertible<T, any_tuple>::value,
&& !std::is_convertible<T, message>::value,
actor_ostream&
>::type
operator<<(T&& arg) {
......
......@@ -63,7 +63,7 @@ class actor_proxy : public extend<abstract_actor>::with<enable_weak_ptr> {
* middleman's thread.
* @note This function is guaranteed to be called non-concurrently.
*/
virtual void deliver(msg_hdr_cref hdr, any_tuple msg) = 0;
virtual void deliver(msg_hdr_cref hdr, message msg) = 0;
protected:
......
......@@ -241,8 +241,8 @@ class meta_cow_tuple : public uniform_type_info {
return create_impl<tuple_type>(other);
}
any_tuple as_any_tuple(void* instance) const override {
return (instance) ? any_tuple{*cast(instance)} : any_tuple{};
message as_message(void* instance) const override {
return (instance) ? make_message(*cast(instance)) : message{};
}
bool equal_to(const std::type_info& tinfo) const override {
......
......@@ -32,18 +32,18 @@
namespace cppa {
class partial_function;
class message_handler;
/**
* @brief Describes the behavior of an actor.
*/
class behavior {
friend class partial_function;
friend class message_handler;
public:
typedef std::function<optional<any_tuple> (any_tuple&)> continuation_fun;
typedef std::function<optional<message> (message&)> continuation_fun;
/** @cond PRIVATE */
......@@ -61,7 +61,7 @@ class behavior {
behavior& operator=(behavior&&) = default;
behavior& operator=(const behavior&) = default;
behavior(const partial_function& fun);
behavior(const message_handler& fun);
template<typename F>
behavior(const timeout_definition<F>& arg);
......@@ -91,7 +91,7 @@ class behavior {
* does not evaluate guards.
*/
template<typename T>
inline optional<any_tuple> operator()(T&& arg);
inline optional<message> operator()(T&& arg);
/**
* @brief Adds a continuation to this behavior that is executed
......@@ -151,7 +151,7 @@ inline const util::duration& behavior::timeout() const {
}
template<typename T>
inline optional<any_tuple> behavior::operator()(T&& arg) {
inline optional<message> behavior::operator()(T&& arg) {
return (m_impl) ? m_impl->invoke(std::forward<T>(arg)) : none;
}
......
......@@ -46,11 +46,11 @@ class behavior_stack_based_impl : public single_timeout<Base, Subtype> {
typedef behavior_stack_based_impl combined_type;
typedef response_handle<behavior_stack_based_impl,
any_tuple,
message,
nonblocking_response_handle_tag>
response_handle_type;
template <typename... Ts>
template<typename... Ts>
behavior_stack_based_impl(Ts&&... vs) : super(std::forward<Ts>(vs)...) { }
/**************************************************************************
......
......@@ -124,7 +124,7 @@ class blocking_actor
* @code
* int i = 0;
* receive_for(i, 10) (
* on(atom("get")) >> [&]() -> any_tuple { return {"result", i}; }
* on(atom("get")) >> [&]() -> message { return {"result", i}; }
* );
* @endcode
* @param begin First value in range.
......
......@@ -135,7 +135,7 @@ using ::backtrace_symbols_fd;
} \
abort()
# define CPPA_REQUIRE(stmt) \
if ((stmt) == false) { \
if (static_cast<bool>(stmt) == false) { \
CPPA_REQUIRE__(#stmt, __FILE__, __LINE__); \
}((void) 0)
#else
......
......@@ -25,7 +25,7 @@
#include "cppa/on.hpp"
#include "cppa/behavior.hpp"
#include "cppa/message_id.hpp"
#include "cppa/partial_function.hpp"
#include "cppa/message_handler.hpp"
namespace cppa {
......@@ -50,7 +50,7 @@ class continue_helper {
*/
template<typename F>
continue_helper& continue_with(F fun) {
return continue_with(behavior::continuation_fun{partial_function{
return continue_with(behavior::continuation_fun{message_handler{
on(any_vals, arg_match) >> fun
}});
}
......
......@@ -26,7 +26,7 @@
#include <type_traits>
#include "cppa/get.hpp"
#include "cppa/cow_ptr.hpp"
#include "cppa/message.hpp"
#include "cppa/ref_counted.hpp"
#include "cppa/util/type_traits.hpp"
......@@ -39,13 +39,6 @@
namespace cppa {
// forward declaration
class any_tuple;
class local_actor;
template<typename... ElementTypes>
class cow_tuple;
/**
* @ingroup CopyOnWrite
* @brief A fixed-length copy-on-write cow_tuple.
......@@ -58,22 +51,16 @@ class cow_tuple<Head, Tail...> {
"illegal types in cow_tuple definition: "
"pointers and references are prohibited");
friend class any_tuple;
typedef detail::tuple_vals<Head, Tail...> data_type;
cow_ptr<detail::abstract_tuple> m_vals;
struct priv_ctor { };
using data_type = detail::tuple_vals<
typename detail::strip_and_convert<Head>::type,
typename detail::strip_and_convert<Tail>::type...>;
cow_tuple(priv_ctor, cow_ptr<detail::abstract_tuple>&& ptr) : m_vals(std::move(ptr)) { }
using data_ptr = detail::message_data::ptr;
public:
typedef util::type_list<Head, Tail...> types;
typedef cow_ptr<detail::abstract_tuple> cow_ptr_type;
static constexpr size_t num_elements = sizeof...(Tail) + 1;
cow_tuple() : m_vals(new data_type) { }
......@@ -99,12 +86,6 @@ class cow_tuple<Head, Tail...> {
cow_tuple& operator=(cow_tuple&&) = default;
cow_tuple& operator=(const cow_tuple&) = default;
static cow_tuple offset_subtuple(cow_ptr_type ptr, size_t offset) {
CPPA_REQUIRE(offset > 0);
auto ti = detail::static_type_list<Head, Tail...>::by_offset(offset);
return {priv_ctor{}, detail::decorated_tuple::create(std::move(ptr), ti, offset)};
}
/**
* @brief Gets the size of this cow_tuple.
*/
......@@ -138,28 +119,21 @@ class cow_tuple<Head, Tail...> {
return cow_tuple<Tail...>::offset_subtuple(m_vals, 1);
}
/** @cond PRIVATE */
static cow_tuple from(cow_ptr_type ptr) {
return {priv_ctor{}, std::move(ptr)};
inline operator message() {
return message{m_vals};
}
static cow_tuple from(cow_ptr_type ptr, std::vector<size_t> mv) {
auto ti = detail::static_type_list<Head, Tail...>::list;
return {priv_ctor{}, detail::decorated_tuple::create(std::move(ptr), ti, std::move(mv))};
}
private:
static cow_tuple from(cow_ptr_type ptr, const util::limited_vector<size_t, num_elements>& mv) {
std::vector<size_t> v(mv.size());
std::copy(mv.begin(), mv.end(), v.begin());
return from(ptr, std::move(v));
data_type* ptr() {
return static_cast<data_type*>(m_vals.get());
}
inline const cow_ptr<detail::abstract_tuple>& vals() const {
return m_vals;
const data_type* ptr() const {
return static_cast<data_type*>(m_vals.get());
}
/** @endcond */
data_ptr m_vals;
};
......
......@@ -37,7 +37,7 @@
#include "cppa/sb_actor.hpp"
#include "cppa/scheduler.hpp"
#include "cppa/to_string.hpp"
#include "cppa/any_tuple.hpp"
#include "cppa/message.hpp"
#include "cppa/cow_tuple.hpp"
#include "cppa/singletons.hpp"
#include "cppa/typed_actor.hpp"
......@@ -322,7 +322,7 @@
* std::vector<int> vec {1, 2, 3, 4};
* auto i = vec.begin();
* receive_for(i, vec.end()) (
* on(atom("get")) >> [&]() -> any_tuple { return {atom("result"), *i}; }
* on(atom("get")) >> [&]() -> message { return {atom("result"), *i}; }
* );
* @endcode
*
......@@ -425,7 +425,7 @@ namespace cppa {
/**
* @brief Sends @p to a message under the identity of @p from.
*/
inline void send_tuple_as(const actor& from, const channel& to, any_tuple msg) {
inline void send_tuple_as(const actor& from, const channel& to, message msg) {
if (to) to->enqueue({from.address(), to}, std::move(msg), nullptr);
}
......@@ -434,13 +434,13 @@ inline void send_tuple_as(const actor& from, const channel& to, any_tuple msg) {
*/
template<typename... Ts>
void send_as(const actor& from, const channel& to, Ts&&... args) {
send_tuple_as(from, to, make_any_tuple(std::forward<Ts>(args)...));
send_tuple_as(from, to, make_message(std::forward<Ts>(args)...));
}
/**
* @brief Anonymously sends @p to a message.
*/
inline void anon_send_tuple(const channel& to, any_tuple msg) {
inline void anon_send_tuple(const channel& to, message msg) {
send_tuple_as(invalid_actor, to, std::move(msg));
}
......
......@@ -31,7 +31,7 @@ class channel;
class node_id;
class behavior;
class resumable;
class any_tuple;
class message;
class actor_addr;
class actor_proxy;
class scoped_actor;
......@@ -40,7 +40,7 @@ class abstract_actor;
class abstract_group;
class blocking_actor;
class message_header;
class partial_function;
class message_handler;
class uniform_type_info;
class event_based_actor;
class primitive_variant;
......
......@@ -16,45 +16,41 @@
* accompanying file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt *
\******************************************************************************/
#ifndef CALL_HPP
#define CALL_HPP
#include "cppa/detail/abstract_tuple.hpp"
#include "cppa/util/int_list.hpp"
namespace cppa {
namespace detail {
abstract_tuple::abstract_tuple(bool is_dynamic) : m_is_dynamic(is_dynamic) { }
bool abstract_tuple::equals(const abstract_tuple &other) const {
return this == &other
|| ( size() == other.size()
&& std::equal(begin(), end(), other.begin(), detail::full_eq));
}
abstract_tuple::abstract_tuple(const abstract_tuple& other)
: m_is_dynamic(other.m_is_dynamic) { }
const std::type_info* abstract_tuple::type_token() const {
return &typeid(void);
template <typename F, long... Is, class Tuple>
inline auto apply_args(F& f, util::int_list<Is...>, Tuple&& tup)
-> decltype(f(get<Is>(tup)...)) {
return f(get<Is>(tup)...);
}
const void* abstract_tuple::native_data() const {
return nullptr;
template <typename F, class Tuple, typename... Ts>
inline auto apply_args_prefixed(F& f, util::int_list<>, Tuple&, Ts&&... args)
-> decltype(f(std::forward<Ts>(args)...)) {
return f(std::forward<Ts>(args)...);
}
void* abstract_tuple::mutable_native_data() {
return nullptr;
template <typename F, long... Is, class Tuple, typename... Ts>
inline auto apply_args_prefixed(F& f, util::int_list<Is...>, Tuple& tup,
Ts&&... args)
-> decltype(f(std::forward<Ts>(args)..., get<Is>(tup)...)) {
return f(std::forward<Ts>(args)..., get<Is>(tup)...);
}
std::string get_tuple_type_names(const detail::abstract_tuple& tup) {
std::string result = "@<>";
for (size_t i = 0; i < tup.size(); ++i) {
auto uti = tup.type_at(i);
result += "+";
result += uti->name();
}
return result;
template <typename F, long... Is, class Tuple, typename... Ts>
inline auto apply_args_suffxied(F& f, util::int_list<Is...>, Tuple& tup,
Ts&&... args)
-> decltype(f(get<Is>(tup)..., std::forward<Ts>(args)...)) {
return f(get<Is>(tup)..., std::forward<Ts>(args)...);
}
} // namespace detail
} // namespace cppa
#endif // CALL_HPP
......@@ -16,18 +16,15 @@
* accompanying file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt *
\******************************************************************************/
#include "cppa/logging.hpp"
#include "cppa/io/protocol.hpp"
#include "cppa/io/middleman.hpp"
#ifndef CPPA_ARG_MATCH_T_HPP
#define CPPA_ARG_MATCH_T_HPP
namespace cppa {
namespace io {
namespace detail {
protocol::protocol(middleman* parent) : m_parent(parent) {
CPPA_REQUIRE(parent != nullptr);
}
struct arg_match_t {};
} // namespace io
} // namespace detail
} // namespace cppa
#endif // CPPA_ARG_MATCH_T_HPP
This diff is collapsed.
......@@ -16,30 +16,28 @@
* accompanying file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt *
\******************************************************************************/
#ifndef CPPA_DETAIL_DECORATED_TUPLE_HPP
#define CPPA_DETAIL_DECORATED_TUPLE_HPP
#ifndef CPPA_DECORATED_TUPLE_HPP
#define CPPA_DECORATED_TUPLE_HPP
#include <vector>
#include <algorithm>
#include "cppa/config.hpp"
#include "cppa/cow_ptr.hpp"
#include "cppa/ref_counted.hpp"
#include "cppa/uniform_type_info.hpp"
#include "cppa/util/type_list.hpp"
#include "cppa/detail/tuple_vals.hpp"
#include "cppa/detail/abstract_tuple.hpp"
#include "cppa/detail/message_data.hpp"
#include "cppa/detail/serialize_tuple.hpp"
namespace cppa {
namespace detail {
class decorated_tuple : public abstract_tuple {
class decorated_tuple : public message_data {
typedef abstract_tuple super;
typedef message_data super;
decorated_tuple& operator=(const decorated_tuple&) = delete;
......@@ -47,7 +45,7 @@ class decorated_tuple : public abstract_tuple {
typedef std::vector<size_t> vector_type;
typedef cow_ptr<abstract_tuple> pointer;
typedef message_data::ptr pointer;
typedef const std::type_info* rtti;
......@@ -87,8 +85,8 @@ class decorated_tuple : public abstract_tuple {
private:
pointer m_decorated;
rtti m_token;
pointer m_decorated;
rtti m_token;
vector_type m_mapping;
void init();
......@@ -110,4 +108,4 @@ class decorated_tuple : public abstract_tuple {
} // namespace detail
} // namespace cppa
#endif // CPPA_DETAIL_DECORATED_TUPLE_HPP
#endif // CPPA_DECORATED_TUPLE_HPP
/******************************************************************************\
* ___ __ *
* /\_ \ __/\ \ *
* \//\ \ /\_\ \ \____ ___ _____ _____ __ *
* \ \ \ \/\ \ \ '__`\ /'___\/\ '__`\/\ '__`\ /'__`\ *
* \_\ \_\ \ \ \ \L\ \/\ \__/\ \ \L\ \ \ \L\ \/\ \L\.\_ *
* /\____\\ \_\ \_,__/\ \____\\ \ ,__/\ \ ,__/\ \__/.\_\ *
* \/____/ \/_/\/___/ \/____/ \ \ \/ \ \ \/ \/__/\/_/ *
* \ \_\ \ \_\ *
* \/_/ \/_/ *
* *
* Copyright (C) 2011 - 2014 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* *
* Distributed under the Boost Software License, Version 1.0. See *
* accompanying file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt *
\******************************************************************************/
#ifndef CPPA_DETAIL_LIFTED_FUN_HPP
#define CPPA_DETAIL_LIFTED_FUN_HPP
#include "cppa/none.hpp"
#include "cppa/optional.hpp"
#include "cppa/skip_message.hpp"
#include "cppa/util/int_list.hpp"
#include "cppa/util/type_list.hpp"
#include "cppa/util/type_traits.hpp"
#include "cppa/util/left_or_right.hpp"
#include "cppa/detail/tuple_zip.hpp"
#include "cppa/detail/apply_args.hpp"
namespace cppa {
namespace detail {
class lifted_fun_zipper {
public:
template <typename F, typename T>
auto operator()(const F& fun, T& arg) -> decltype(fun(arg)) const {
return fun(arg);
}
// forward everything as reference if no guard/transformation is set
template <typename T>
auto operator()(const unit_t&, T& arg) const -> decltype(std::ref(arg)) {
return std::ref(arg);
}
};
template <typename T>
T& unopt(T& v) {
return v;
}
template <typename T>
T& unopt(optional<T>& v) {
return *v;
}
inline bool has_none() { return false; }
template <typename T, typename... Ts>
inline bool has_none(const T&, const Ts&... vs) {
return has_none(vs...);
}
template <typename T, typename... Ts>
inline bool has_none(const optional<T>& v, const Ts&... vs) {
return !v || has_none(vs...);
}
// allows F to have fewer arguments than the lifted_fun calling it
template <typename R, typename F>
class lifted_fun_invoker {
typedef typename util::get_callable_trait<F>::arg_types arg_types;
static constexpr size_t args = util::tl_size<arg_types>::value;
public:
lifted_fun_invoker(F& fun) : f(fun) {}
template <typename... Ts>
typename std::enable_if<sizeof...(Ts) == args, R>::type
operator()(Ts&... args) const {
if (has_none(args...)) return none;
return f(unopt(args)...);
}
template <typename T, typename... Ts>
typename std::enable_if<(sizeof...(Ts) + 1 > args), R>::type
operator()(T& arg, Ts&... args) const {
if (has_none(arg)) return none;
return (*this)(args...);
}
private:
F& f;
};
template <typename F>
class lifted_fun_invoker<bool, F> {
typedef typename util::get_callable_trait<F>::arg_types arg_types;
static constexpr size_t args = util::tl_size<arg_types>::value;
public:
lifted_fun_invoker(F& fun) : f(fun) {}
template <typename... Ts>
typename std::enable_if<sizeof...(Ts) == args, bool>::type
operator()(Ts&&... args) const {
if (has_none(args...)) return false;
f(unopt(args)...);
return true;
}
template <typename T, typename... Ts>
typename std::enable_if<(sizeof...(Ts) + 1 > args), bool>::type
operator()(T&& arg, Ts&&... args) const {
if (has_none(arg)) return false;
return (*this)(args...);
}
private:
F& f;
};
/**
* @brief A lifted functor consists of a set of projections, a plain-old
* functor and its signature. Note that the signature of the lifted
* functor might differ from the underlying functor, because
* of the projections.
*/
template <typename F, class ListOfProjections, typename... Args>
class lifted_fun {
public:
typedef typename util::get_callable_trait<F>::result_type result_type;
// Let F be "R (Ts...)" then lifted_fun<F...> returns optional<R>
// unless R is void in which case bool is returned
typedef typename std::conditional<std::is_same<result_type, void>::value,
bool, optional<result_type>>::type
optional_result_type;
typedef ListOfProjections projections_list;
typedef typename util::tl_apply<projections_list, std::tuple>::type projections;
typedef util::type_list<Args...> arg_types;
lifted_fun() = default;
lifted_fun(lifted_fun&&) = default;
lifted_fun(const lifted_fun&) = default;
lifted_fun& operator=(lifted_fun&&) = default;
lifted_fun& operator=(const lifted_fun&) = default;
lifted_fun(F f) : m_fun(std::move(f)) {}
lifted_fun(F f, projections ps)
: m_fun(std::move(f)), m_ps(std::move(ps)) {}
/**
* @brief Invokes @p fun with a lifted_fun of <tt>args...</tt>.
*/
optional_result_type operator()(Args... args) {
auto indices = util::get_indices(m_ps);
lifted_fun_zipper zip;
lifted_fun_invoker<optional_result_type, F> invoke{m_fun};
return apply_args(
invoke, indices,
tuple_zip(zip, indices, m_ps, std::forward_as_tuple(args...)));
}
private:
F m_fun;
projections m_ps;
};
template <typename F, class ListOfProjections, class List>
struct get_lifted_fun;
template <typename F, class ListOfProjections, typename... Ts>
struct get_lifted_fun<F, ListOfProjections, util::type_list<Ts...>> {
typedef lifted_fun<F, ListOfProjections, Ts...> type;
};
} // namespace detail
} // namespace cppa
#endif // CPPA_DETAIL_LIFTED_FUN_HPP
......@@ -22,10 +22,11 @@
#include <numeric>
#include "cppa/any_tuple.hpp"
#include "cppa/message.hpp"
#include "cppa/wildcard_position.hpp"
#include "cppa/util/type_list.hpp"
#include "cppa/util/limited_vector.hpp"
namespace cppa {
namespace detail {
......@@ -294,9 +295,9 @@ struct match_impl_from_type_list<Tuple, util::type_list<Ts...> > {
* @brief Returns true if this tuple matches the pattern <tt>{Ts...}</tt>.
*/
template<typename... Ts>
bool matches(const any_tuple& tup) {
bool matches(const message& tup) {
typedef util::type_list<Ts...> tl;
return match_impl<get_wildcard_position<tl>(), any_tuple, Ts...>
return match_impl<get_wildcard_position<tl>(), message, Ts...>
::_(tup);
}
......@@ -304,25 +305,25 @@ bool matches(const any_tuple& tup) {
* @brief Returns true if this tuple matches the pattern <tt>{Ts...}</tt>.
*/
template<typename... Ts>
bool matches(const any_tuple& tup,
bool matches(const message& tup,
util::limited_vector<
size_t,
util::tl_count_not<
util::type_list<Ts...>,
is_anything>::value>& mv) {
typedef util::type_list<Ts...> tl;
return match_impl<get_wildcard_position<tl>(), any_tuple, Ts...>
return match_impl<get_wildcard_position<tl>(), message, Ts...>
::_(tup, mv);
}
// support for type_list based matching
template<typename... Ts>
inline bool matches(const any_tuple& tup, const util::type_list<Ts...>&) {
inline bool matches(const message& tup, const util::type_list<Ts...>&) {
return matches<Ts...>(tup);
}
template<typename... Ts>
inline bool matches(const any_tuple& tup, const util::type_list<Ts...>&,
inline bool matches(const message& tup, const util::type_list<Ts...>&,
util::limited_vector<
size_t,
util::tl_count_not<
......@@ -332,10 +333,21 @@ inline bool matches(const any_tuple& tup, const util::type_list<Ts...>&,
}
template<typename... Ts>
inline bool matches_types(const any_tuple& tup, const util::type_list<Ts...>&) {
inline bool matches_types(const message& tup, const util::type_list<Ts...>&) {
return matches<Ts...>(tup);
}
template<class Tuple, class List>
struct select_matcher;
template<class Tuple, typename... Ts>
struct select_matcher<Tuple, util::type_list<Ts...> > {
typedef matcher<get_wildcard_position<util::type_list<Ts...>>(),
Tuple,
Ts...>
type;
};
} // namespace detail
} // namespace cppa
......
......@@ -16,31 +16,32 @@
* accompanying file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt *
\******************************************************************************/
#ifndef CPPA_DETAIL_ABSTRACT_TUPLE_HPP
#define CPPA_DETAIL_ABSTRACT_TUPLE_HPP
#ifndef CPPA_ABSTRACT_TUPLE_HPP
#define CPPA_ABSTRACT_TUPLE_HPP
#include <string>
#include <iterator>
#include <typeinfo>
#include "cppa/intrusive_ptr.hpp"
#include "cppa/config.hpp"
#include "cppa/ref_counted.hpp"
#include "cppa/uniform_type_info.hpp"
#include "cppa/util/type_list.hpp"
#include "cppa/detail/tuple_iterator.hpp"
#include "cppa/detail/message_iterator.hpp"
namespace cppa {
namespace detail {
class abstract_tuple : public ref_counted {
class message_data : public ref_counted {
public:
abstract_tuple(bool dynamically_typed);
abstract_tuple(const abstract_tuple& other);
message_data(bool dynamically_typed);
message_data(const message_data& other);
// mutators
virtual void* mutable_at(size_t pos) = 0;
......@@ -48,7 +49,7 @@ class abstract_tuple : public ref_counted {
// accessors
virtual size_t size() const = 0;
virtual abstract_tuple* copy() const = 0;
virtual message_data* copy() const = 0;
virtual const void* at(size_t pos) const = 0;
virtual const uniform_type_info* type_at(size_t pos) const = 0;
virtual const std::string* tuple_type_names() const = 0;
......@@ -68,42 +69,84 @@ class abstract_tuple : public ref_counted {
// (default returns &typeid(void))
virtual const std::type_info* type_token() const;
bool equals(const abstract_tuple& other) const;
bool equals(const message_data& other) const;
typedef message_iterator<message_data> const_iterator;
inline const_iterator begin() const {
return {this};
}
inline const_iterator cbegin() const {
return {this};
}
inline const_iterator end() const {
return {this, size()};
}
inline const_iterator cend() const {
return {this, size()};
}
class ptr {
public:
ptr() = default;
ptr(ptr&&) = default;
ptr(const ptr&) = default;
ptr& operator=(ptr&&) = default;
ptr& operator=(const ptr&) = default;
inline explicit ptr(message_data* p) : m_ptr(p) {}
inline void detach() { static_cast<void>(get_detached()); }
typedef tuple_iterator<abstract_tuple> const_iterator;
inline message_data* operator->() { return get_detached(); }
inline message_data& operator*() { return *get_detached(); }
inline const message_data* operator->() const { return m_ptr.get(); }
inline const message_data& operator*() const { return *m_ptr.get(); }
inline void swap(ptr& other) { m_ptr.swap(other.m_ptr); }
inline void reset(message_data* p = nullptr) { m_ptr.reset(p); }
inline const message_data* get() const { return m_ptr.get(); }
inline message_data* get() { return m_ptr.get(); }
inline const_iterator begin() const { return {this}; }
inline const_iterator cbegin() const { return {this}; }
inline explicit operator bool() const {
return static_cast<bool>(m_ptr);
}
inline const_iterator end() const { return {this, size()}; }
inline const_iterator cend() const { return {this, size()}; }
private:
message_data* get_detached();
intrusive_ptr<message_data> m_ptr;
};
private:
bool m_is_dynamic;
};
struct full_eq_type {
constexpr full_eq_type() { }
constexpr full_eq_type() {}
template<class Tuple>
inline bool operator()(const tuple_iterator<Tuple>& lhs,
const tuple_iterator<Tuple>& rhs) const {
return lhs.type() == rhs.type()
&& lhs.type()->equals(lhs.value(), rhs.value());
inline bool operator()(const message_iterator<Tuple>& lhs,
const message_iterator<Tuple>& rhs) const {
return lhs.type() == rhs.type() &&
lhs.type()->equals(lhs.value(), rhs.value());
}
};
struct types_only_eq_type {
constexpr types_only_eq_type() { }
constexpr types_only_eq_type() {}
template<class Tuple>
inline bool operator()(const tuple_iterator<Tuple>& lhs,
const uniform_type_info* rhs ) const {
inline bool operator()(const message_iterator<Tuple>& lhs,
const uniform_type_info* rhs) const {
return lhs.type() == rhs;
}
template<class Tuple>
inline bool operator()(const uniform_type_info* lhs,
const tuple_iterator<Tuple>& rhs) const {
const message_iterator<Tuple>& rhs) const {
return lhs == rhs.type();
}
};
......@@ -113,9 +156,9 @@ constexpr full_eq_type full_eq;
constexpr types_only_eq_type types_only_eq;
} // namespace <anonymous>
std::string get_tuple_type_names(const detail::abstract_tuple&);
std::string get_tuple_type_names(const detail::message_data&);
} // namespace detail
} // namespace cppa
#endif // CPPA_DETAIL_ABSTRACT_TUPLE_HPP
#endif // CPPA_ABSTRACT_TUPLE_HPP
......@@ -16,9 +16,8 @@
* accompanying file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt *
\******************************************************************************/
#ifndef CPPA_DETAIL_TUPLE_ITERATOR_HPP
#define CPPA_DETAIL_TUPLE_ITERATOR_HPP
#ifndef CPPA_TUPLE_ITERATOR_HPP
#define CPPA_TUPLE_ITERATOR_HPP
#include <cstddef>
......@@ -28,56 +27,55 @@ namespace cppa {
namespace detail {
template<class Tuple>
class tuple_iterator {
class message_iterator {
size_t m_pos;
const Tuple* m_tuple;
public:
inline tuple_iterator(const Tuple* tup, size_t pos = 0)
: m_pos(pos), m_tuple(tup) {
}
inline message_iterator(const Tuple* tup, size_t pos = 0)
: m_pos(pos), m_tuple(tup) {}
tuple_iterator(const tuple_iterator&) = default;
message_iterator(const message_iterator&) = default;
tuple_iterator& operator=(const tuple_iterator&) = default;
message_iterator& operator=(const message_iterator&) = default;
inline bool operator==(const tuple_iterator& other) const {
inline bool operator==(const message_iterator& other) const {
CPPA_REQUIRE(other.m_tuple == other.m_tuple);
return other.m_pos == m_pos;
}
inline bool operator!=(const tuple_iterator& other) const {
inline bool operator!=(const message_iterator& other) const {
return !(*this == other);
}
inline tuple_iterator& operator++() {
inline message_iterator& operator++() {
++m_pos;
return *this;
}
inline tuple_iterator& operator--() {
inline message_iterator& operator--() {
CPPA_REQUIRE(m_pos > 0);
--m_pos;
return *this;
}
inline tuple_iterator operator+(size_t offset) {
inline message_iterator operator+(size_t offset) {
return {m_tuple, m_pos + offset};
}
inline tuple_iterator& operator+=(size_t offset) {
inline message_iterator& operator+=(size_t offset) {
m_pos += offset;
return *this;
}
inline tuple_iterator operator-(size_t offset) {
inline message_iterator operator-(size_t offset) {
CPPA_REQUIRE(m_pos >= offset);
return {m_tuple, m_pos - offset};
}
inline tuple_iterator& operator-=(size_t offset) {
inline message_iterator& operator-=(size_t offset) {
CPPA_REQUIRE(m_pos >= offset);
m_pos -= offset;
return *this;
......@@ -85,19 +83,17 @@ class tuple_iterator {
inline size_t position() const { return m_pos; }
inline const void* value() const {
return m_tuple->at(m_pos);
}
inline const void* value() const { return m_tuple->at(m_pos); }
inline const uniform_type_info* type() const {
return m_tuple->type_at(m_pos);
}
inline tuple_iterator& operator*() { return *this; }
inline message_iterator& operator*() { return *this; }
};
} // namespace detail
} // namespace cppa
#endif // CPPA_DETAIL_TUPLE_ITERATOR_HPP
#endif // CPPA_TUPLE_ITERATOR_HPP
......@@ -143,17 +143,14 @@ struct is_rd_arg<rd_arg_functor<T> > : std::true_type { };
template<typename T>
struct is_rd_arg<add_arg_functor<T> > : std::true_type { };
typedef decltype(on<std::string>().when(cppa::placeholders::_x1.in(std::vector<std::string>())))
opt0_rvalue_builder;
typedef decltype(on<std::string>()) opt0_rvalue_builder;
template<bool HasShortOpt = true>
class opt1_rvalue_builder {
public:
typedef decltype(on<std::string, std::string>()
.when(cppa::placeholders::_x1.in(std::vector<std::string>())))
left_type;
typedef decltype(on<std::string, std::string>()) left_type;
typedef decltype(on(std::function<optional<std::string>(const std::string&)>()))
right_type;
......
/******************************************************************************\
* ___ __ *
* /\_ \ __/\ \ *
* \//\ \ /\_\ \ \____ ___ _____ _____ __ *
* \ \ \ \/\ \ \ '__`\ /'___\/\ '__`\/\ '__`\ /'__`\ *
* \_\ \_\ \ \ \ \L\ \/\ \__/\ \ \L\ \ \ \L\ \/\ \L\.\_ *
* /\____\\ \_\ \_,__/\ \____\\ \ ,__/\ \ ,__/\ \__/.\_\ *
* \/____/ \/_/\/___/ \/____/ \ \ \/ \ \ \/ \/__/\/_/ *
* \ \_\ \ \_\ *
* \/_/ \/_/ *
* *
* Copyright (C) 2011 - 2014 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* *
* Distributed under the Boost Software License, Version 1.0. See *
* accompanying file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt *
\******************************************************************************/
#ifndef CPPA_DETAIL_PROJECTION_HPP
#define CPPA_DETAIL_PROJECTION_HPP
#include "cppa/optional.hpp"
#include "cppa/guard_expr.hpp"
#include "cppa/util/call.hpp"
#include "cppa/util/int_list.hpp"
#include "cppa/util/type_list.hpp"
#include "cppa/util/type_traits.hpp"
#include "cppa/util/left_or_right.hpp"
#include "cppa/detail/tdata.hpp"
namespace cppa {
namespace detail {
template<typename Fun, typename Tuple, long... Is>
inline bool is_defined_at(Fun& f, Tuple& tup, util::int_list<Is...>) {
return f.defined_at(get_cv_aware<Is>(tup)...);
}
template<typename ProjectionFuns, typename... Ts>
struct collected_args_tuple {
typedef typename tdata_from_type_list<
typename util::tl_zip<
typename util::tl_map<
ProjectionFuns,
util::map_to_result_type,
util::rm_optional
>::type,
typename util::tl_map<
util::type_list<Ts...>,
mutable_gref_wrapped
>::type,
util::left_or_right
>::type
>::type
type;
};
template<typename Fun>
struct is_void_fun {
static constexpr bool value = std::is_same<typename Fun::result_type, void>::value;
};
/**
* @brief Projection implemented by a set of functors.
*/
template<class ProjectionFuns, typename... Ts>
class projection {
public:
typedef typename tdata_from_type_list<ProjectionFuns>::type fun_container;
typedef util::type_list<typename util::rm_const_and_ref<Ts>::type...> arg_types;
projection() = default;
projection(fun_container&& args) : m_funs(std::move(args)) { }
projection(const fun_container& args) : m_funs(args) { }
projection(const projection&) = default;
/**
* @brief Invokes @p fun with a projection of <tt>args...</tt>.
*/
template<class PartFun>
optional<typename PartFun::result_type> operator()(PartFun& fun, Ts... args) const {
typename collected_args_tuple<ProjectionFuns, Ts...>::type pargs;
auto indices = util::get_indices(pargs);
if (collect(pargs, m_funs, std::forward<Ts>(args)...)) {
if (is_defined_at(fun, pargs, indices)) {
return util::apply_args(fun, pargs, indices);
}
}
return none;
}
private:
template<typename Storage, typename T>
static inline bool store(Storage& storage, T&& value) {
storage = std::forward<T>(value);
return true;
}
template<class Storage>
static inline bool store(Storage& storage, optional<Storage>&& value) {
if (value) {
storage = std::move(*value);
return true;
}
return false;
}
template<typename T>
static inline auto fetch(const unit_t&, T&& arg)
-> decltype(std::forward<T>(arg)) {
return std::forward<T>(arg);
}
template<typename Fun, typename T>
static inline auto fetch(const Fun& fun, T&& arg)
-> decltype(fun(std::forward<T>(arg))) {
return fun(std::forward<T>(arg));
}
static inline bool collect(tdata<>&, const tdata<>&) {
return true;
}
template<class TData, class Trans, typename U, typename... Us>
static inline bool collect(TData& td, const Trans& tr,
U&& arg, Us&&... args) {
return store(td.head, fetch(tr.head, std::forward<U>(arg)))
&& collect(td.tail(), tr.tail(), std::forward<Us>(args)...);
}
fun_container m_funs;
};
template<>
class projection<util::empty_type_list> {
public:
projection() = default;
projection(const tdata<>&) { }
projection(const projection&) = default;
template<class PartFun>
optional<typename PartFun::result_type> operator()(PartFun& fun) const {
if (fun.defined_at()) {
return fun();
}
return none;
}
};
template<class ProjectionFuns, class List>
struct projection_from_type_list;
template<class ProjectionFuns, typename... Ts>
struct projection_from_type_list<ProjectionFuns, util::type_list<Ts...> > {
typedef projection<ProjectionFuns, Ts...> type;
};
} // namespace detail
} // namespace cppa
#endif // CPPA_DETAIL_PROJECTION_HPP
......@@ -26,7 +26,7 @@ class proper_actor_base : public Policies::resume_policy::template mixin<Base, D
public:
template <typename... Ts>
template<typename... Ts>
proper_actor_base(Ts&&... args) : super(std::forward<Ts>(args)...) {
CPPA_REQUIRE(this->m_hidden == true);
}
......@@ -40,7 +40,7 @@ class proper_actor_base : public Policies::resume_policy::template mixin<Base, D
typedef typename Policies::scheduling_policy::timeout_type timeout_type;
void enqueue(msg_hdr_cref hdr, any_tuple msg, execution_unit* eu) override {
void enqueue(msg_hdr_cref hdr, message msg, execution_unit* eu) override {
CPPA_PUSH_AID(dptr()->id());
CPPA_LOG_DEBUG(CPPA_TARG(hdr, to_string)
<< ", " << CPPA_TARG(msg, to_string));
......@@ -189,7 +189,7 @@ class proper_actor : public proper_actor_base<Base,
// that Base is derived from local_actor and uses the
// behavior_stack_based mixin
template <typename... Ts>
template<typename... Ts>
proper_actor(Ts&&... args) : super(std::forward<Ts>(args)...) { }
// required by event_based_resume::mixin::resume
......@@ -223,7 +223,7 @@ class proper_actor : public proper_actor_base<Base,
};
// for blocking actors, there's one more member function to implement
template <class Base, class Policies>
template<class Base, class Policies>
class proper_actor<Base, Policies, true> : public proper_actor_base<Base,
proper_actor<Base,
Policies,
......@@ -234,7 +234,7 @@ class proper_actor<Base, Policies, true> : public proper_actor_base<Base,
public:
template <typename... Ts>
template<typename... Ts>
proper_actor(Ts&&... args)
: super(std::forward<Ts>(args)...), m_next_timeout_id(0) { }
......@@ -304,7 +304,7 @@ class proper_actor<Base, Policies, true> : public proper_actor_base<Base,
std::uint32_t request_timeout(const util::duration& d) {
CPPA_REQUIRE(d.valid());
auto tid = ++m_next_timeout_id;
auto msg = make_any_tuple(timeout_msg{tid});
auto msg = make_message(timeout_msg{tid});
if (d.is_zero()) {
// immediately enqueue timeout message if duration == 0s
this->enqueue({this->address(), this},
......
This diff is collapsed.
......@@ -20,12 +20,11 @@
#ifndef CPPA_DETAIL_TUPLE_CAST_IMPL_HPP
#define CPPA_DETAIL_TUPLE_CAST_IMPL_HPP
#include "cppa/any_tuple.hpp"
#include "cppa/message.hpp"
#include "cppa/detail/matches.hpp"
#include "cppa/detail/tuple_vals.hpp"
#include "cppa/detail/types_array.hpp"
#include "cppa/detail/abstract_tuple.hpp"
namespace cppa {
namespace detail {
......@@ -46,7 +45,7 @@ struct tuple_cast_impl {
static_cast<size_t>(
util::tl_find<util::type_list<T...>, anything>::value);
typedef util::limited_vector<size_t, size> mapping_vector;
static inline optional<Result> safe(any_tuple& tup) {
static inline optional<Result> safe(message& tup) {
mapping_vector mv;
if (matches<T...>(tup, mv)) return {Result::from(std::move(tup.vals()),
mv)};
......@@ -56,7 +55,7 @@ struct tuple_cast_impl {
template<class Result, typename... T>
struct tuple_cast_impl<wildcard_position::nil, Result, T...> {
static inline optional<Result> safe(any_tuple& tup) {
static inline optional<Result> safe(message& tup) {
if (matches<T...>(tup)) return {Result::from(std::move(tup.vals()))};
return none;
}
......@@ -69,7 +68,7 @@ struct tuple_cast_impl<wildcard_position::trailing, Result, T...>
template<class Result, typename... T>
struct tuple_cast_impl<wildcard_position::leading, Result, T...> {
static inline optional<Result> safe(any_tuple& tup) {
static inline optional<Result> safe(message& tup) {
size_t o = tup.size() - (sizeof...(T) - 1);
if (matches<T...>(tup)) return {Result::offset_subtuple(tup.vals(), o)};
return none;
......
......@@ -23,14 +23,14 @@
#include <typeinfo>
#include "cppa/util/type_list.hpp"
#include "cppa/detail/tuple_iterator.hpp"
#include "cppa/detail/message_iterator.hpp"
namespace cppa {
namespace detail {
struct tuple_dummy {
typedef util::empty_type_list types;
typedef detail::tuple_iterator<tuple_dummy> const_iterator;
typedef detail::message_iterator<tuple_dummy> const_iterator;
inline size_t size() const {
return 0;
}
......
......@@ -16,68 +16,77 @@
* accompanying file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt *
\******************************************************************************/
#ifndef CPPA_TUPLE_VALS_HPP
#define CPPA_TUPLE_VALS_HPP
#ifndef CPPA_DETAIL_TUPLE_VALS_HPP
#define CPPA_DETAIL_TUPLE_VALS_HPP
#include <tuple>
#include <stdexcept>
#include "cppa/util/type_list.hpp"
#include "cppa/detail/tdata.hpp"
#include "cppa/detail/types_array.hpp"
#include "cppa/detail/abstract_tuple.hpp"
#include "cppa/detail/message_data.hpp"
#include "cppa/detail/serialize_tuple.hpp"
namespace cppa {
namespace detail {
template<size_t Pos, size_t Max, bool InRange = (Pos < Max)>
struct tup_ptr_access {
template<class T>
static inline typename std::conditional<std::is_const<T>::value,
const void*, void*>::type
get(size_t pos, T& tup) {
if (pos == Pos) return &std::get<Pos>(tup);
return tup_ptr_access<Pos + 1, Max>::get(pos, tup);
}
};
template<size_t Pos, size_t Max>
struct tup_ptr_access<Pos, Max, false> {
template<class T>
static inline typename std::conditional<std::is_const<T>::value,
const void*, void*>::type
get(size_t, T&) {
// end of recursion
return nullptr;
}
};
template<typename... Ts>
class tuple_vals : public abstract_tuple {
class tuple_vals : public message_data {
static_assert(sizeof...(Ts) > 0,
"tuple_vals is not allowed to be empty");
static_assert(sizeof...(Ts) > 0, "tuple_vals is not allowed to be empty");
typedef abstract_tuple super;
typedef message_data super;
public:
typedef tdata<Ts...> data_type;
typedef std::tuple<Ts...> data_type;
typedef types_array<Ts...> element_types;
tuple_vals(const tuple_vals&) = default;
template<typename... Us>
tuple_vals(Us&&... args) : super(false), m_data(std::forward<Us>(args)...) { }
tuple_vals(Us&&... args)
: super(false), m_data(std::forward<Us>(args)...) {}
const void* native_data() const {
return &m_data;
}
const void* native_data() const { return &m_data; }
void* mutable_native_data() {
return &m_data;
}
void* mutable_native_data() { return &m_data; }
inline data_type& data() {
return m_data;
}
inline data_type& data() { return m_data; }
inline const data_type& data() const {
return m_data;
}
inline const data_type& data() const { return m_data; }
size_t size() const {
return sizeof...(Ts);
}
size_t size() const { return sizeof...(Ts); }
tuple_vals* copy() const {
return new tuple_vals(*this);
}
tuple_vals* copy() const { return new tuple_vals(*this); }
const void* at(size_t pos) const {
CPPA_REQUIRE(pos < size());
return m_data.at(pos);
return tup_ptr_access<0, sizeof...(Ts)>::get(pos, m_data);
}
void* mutable_at(size_t pos) {
......@@ -90,13 +99,13 @@ class tuple_vals : public abstract_tuple {
return m_types[pos];
}
bool equals(const abstract_tuple& other) const {
bool equals(const message_data& other) const {
if (size() != other.size()) return false;
const tuple_vals* o = dynamic_cast<const tuple_vals*>(&other);
if (o) {
return m_data == (o->m_data);
}
return abstract_tuple::equals(other);
return message_data::equals(other);
}
const std::type_info* type_token() const {
......@@ -120,15 +129,7 @@ class tuple_vals : public abstract_tuple {
template<typename... Ts>
types_array<Ts...> tuple_vals<Ts...>::m_types;
template<typename TypeList>
struct tuple_vals_from_type_list;
template<typename... Ts>
struct tuple_vals_from_type_list< util::type_list<Ts...> > {
typedef tuple_vals<Ts...> type;
};
} // namespace detail
} // namespace cppa
#endif // CPPA_DETAIL_TUPLE_VALS_HPP
#endif // CPPA_TUPLE_VALS_HPP
/******************************************************************************\
* ___ __ *
* /\_ \ __/\ \ *
* \//\ \ /\_\ \ \____ ___ _____ _____ __ *
* \ \ \ \/\ \ \ '__`\ /'___\/\ '__`\/\ '__`\ /'__`\ *
* \_\ \_\ \ \ \ \L\ \/\ \__/\ \ \L\ \ \ \L\ \/\ \L\.\_ *
* /\____\\ \_\ \_,__/\ \____\\ \ ,__/\ \ ,__/\ \__/.\_\ *
* \/____/ \/_/\/___/ \/____/ \ \ \/ \ \ \/ \/__/\/_/ *
* \ \_\ \ \_\ *
* \/_/ \/_/ *
* *
* Copyright (C) 2011 - 2014 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* *
* Distributed under the Boost Software License, Version 1.0. See *
* accompanying file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt *
\******************************************************************************/
#ifndef CPPA_DETAIL_TUPLE_VIEW_HPP
#define CPPA_DETAIL_TUPLE_VIEW_HPP
#include "cppa/guard_expr.hpp"
#include "cppa/util/rebindable_reference.hpp"
#include "cppa/detail/tuple_vals.hpp"
#include "cppa/detail/abstract_tuple.hpp"
namespace cppa {
namespace detail {
struct tuple_view_copy_helper {
size_t pos;
abstract_tuple* target;
tuple_view_copy_helper(abstract_tuple* trgt) : pos(0), target(trgt) { }
template<typename T>
void operator()(const T* value) {
*(reinterpret_cast<T*>(target->mutable_at(pos++))) = *value;
}
};
template<typename... Ts>
class tuple_view : public abstract_tuple {
static_assert(sizeof...(Ts) > 0,
"tuple_vals is not allowed to be empty");
typedef abstract_tuple super;
public:
typedef tdata<util::rebindable_reference<Ts>...> data_type;
typedef types_array<Ts...> element_types;
tuple_view() = delete;
tuple_view(const tuple_view&) = delete;
/**
* @warning @p tuple_view does @b NOT takes ownership for given pointers
*/
tuple_view(Ts*... args) : super(false), m_data(args...) { }
inline data_type& data() {
return m_data;
}
inline const data_type& data() const {
return m_data;
}
size_t size() const {
return sizeof...(Ts);
}
abstract_tuple* copy() const {
return new tuple_vals<Ts...>{m_data};
}
const void* at(size_t pos) const {
CPPA_REQUIRE(pos < size());
return m_data.at(pos).get_ptr();
}
void* mutable_at(size_t pos) {
CPPA_REQUIRE(pos < size());
return m_data.mutable_at(pos).get_ptr();
}
const uniform_type_info* type_at(size_t pos) const {
CPPA_REQUIRE(pos < size());
return m_types[pos];
}
const std::type_info* type_token() const {
return detail::static_type_list<Ts...>::list;
}
private:
data_type m_data;
static types_array<Ts...> m_types;
tuple_view(const data_type& data) : m_data(data) { }
};
template<typename... Ts>
types_array<Ts...> tuple_view<Ts...>::m_types;
} // namespace detail
} // namespace cppa
#endif // CPPA_DETAIL_TUPLE_VIEW_HPP
......@@ -16,53 +16,23 @@
* accompanying file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt *
\******************************************************************************/
#ifndef CPPA_DETAIL_TUPLE_ZIP_HPP
#define CPPA_DETAIL_TUPLE_ZIP_HPP
#ifndef CPPA_DETAIL_OBJECT_ARRAY_HPP
#define CPPA_DETAIL_OBJECT_ARRAY_HPP
#include <tuple>
#include <vector>
#include "cppa/uniform_type_info.hpp"
#include "cppa/detail/abstract_tuple.hpp"
#include "cppa/util/int_list.hpp"
namespace cppa {
namespace detail {
class object_array : public abstract_tuple {
typedef abstract_tuple super;
public:
using abstract_tuple::const_iterator;
object_array();
object_array(object_array&&) = default;
object_array(const object_array&);
~object_array();
void push_back(uniform_value what);
void* mutable_at(size_t pos) override;
size_t size() const override;
object_array* copy() const override;
const void* at(size_t pos) const override;
const uniform_type_info* type_at(size_t pos) const override;
const std::string* tuple_type_names() const override;
private:
std::vector<uniform_value> m_elements;
};
template <typename F, long... Is, class Tup0, class Tup1>
auto tuple_zip(F& f, util::int_list<Is...>, Tup0&& tup0, Tup1&& tup1)
-> decltype(std::make_tuple(f(std::get<Is>(tup0), std::get<Is>(tup1))...)) {
return std::make_tuple(f(std::get<Is>(tup0), std::get<Is>(tup1))...);
}
} // namespace detail
} // namespace cppa
#endif // CPPA_DETAIL_OBJECT_ARRAY_HPP
#endif // CPPA_DETAIL_TUPLE_ZIP_HPP
......@@ -62,14 +62,6 @@ struct deduce_signature {
typedef typename deduce_signature_helper<result_type, arg_types>::type type;
};
template<typename T>
struct match_expr_has_no_guard {
static constexpr bool value = std::is_same<
typename T::second_type::guard_type,
detail::empty_value_guard
>::value;
};
template<typename Arguments>
struct input_is {
template<typename Signature>
......
......@@ -54,7 +54,6 @@ using mapped_type_list = util::type_list<
acceptor_closed_msg,
actor,
actor_addr,
any_tuple,
atom_value,
channel,
connection_closed_msg,
......@@ -65,6 +64,7 @@ using mapped_type_list = util::type_list<
node_id_ptr,
io::accept_handle,
io::connection_handle,
message,
message_header,
new_connection_msg,
new_data_msg,
......
/******************************************************************************\
* ___ __ *
* /\_ \ __/\ \ *
* \//\ \ /\_\ \ \____ ___ _____ _____ __ *
* \ \ \ \/\ \ \ '__`\ /'___\/\ '__`\/\ '__`\ /'__`\ *
* \_\ \_\ \ \ \ \L\ \/\ \__/\ \ \L\ \ \ \L\ \/\ \L\.\_ *
* /\____\\ \_\ \_,__/\ \____\\ \ ,__/\ \ ,__/\ \__/.\_\ *
* \/____/ \/_/\/___/ \/____/ \ \ \/ \ \ \/ \/__/\/_/ *
* \ \_\ \ \_\ *
* \/_/ \/_/ *
* *
* Copyright (C) 2011 - 2014 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* *
* Distributed under the Boost Software License, Version 1.0. See *
* accompanying file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt *
\******************************************************************************/
#ifndef CPPA_DETAIL_VALUE_GUARD_HPP
#define CPPA_DETAIL_VALUE_GUARD_HPP
#include <type_traits>
#include "cppa/unit.hpp"
#include "cppa/util/algorithm.hpp"
#include "cppa/util/type_list.hpp"
#include "cppa/util/type_traits.hpp"
#include "cppa/detail/tdata.hpp"
namespace cppa {
namespace detail {
// 'absorbs' callables and instances of `anything`
template<typename T>
const T& vg_fwd(const T& arg, typename std::enable_if<not util::is_callable<T>::value>::type* = 0) {
return arg;
}
inline unit_t vg_fwd(const anything&) {
return unit;
}
template<typename T>
unit_t vg_fwd(const T&, typename std::enable_if<util::is_callable<T>::value>::type* = 0) {
return unit;
}
template<typename T>
struct vg_cmp {
template<typename U>
inline static bool _(const T& lhs, const U& rhs) {
return util::safe_equal(lhs, rhs);
}
};
template<>
struct vg_cmp<unit_t> {
template<typename T>
inline static bool _(const unit_t&, const T&) {
return true;
}
};
template<typename FilteredPattern>
class value_guard {
public:
value_guard() = default;
value_guard(const value_guard&) = default;
template<typename... Ts>
value_guard(const Ts&... args) : m_args(vg_fwd(args)...) { }
template<typename... Ts>
inline bool operator()(const Ts&... args) const {
return _eval(m_args.head, m_args.tail(), args...);
}
private:
typename tdata_from_type_list<FilteredPattern>::type m_args;
template<typename T, typename U>
static inline bool cmp(const T& lhs, const U& rhs) {
return vg_cmp<T>::_(lhs, rhs);
}
template<typename T, typename U>
static inline bool cmp(const T& lhs, const std::reference_wrapper<U>& rhs) {
return vg_cmp<T>::_(lhs, rhs.get());
}
static inline bool _eval(const unit_t&, const tdata<>&) {
return true;
}
template<typename T, typename U, typename... Us>
static inline bool _eval(const T& head, const tdata<>&,
const U& arg, const Us&...) {
return cmp(head, arg);
}
template<typename T0, typename T1, typename... Ts,
typename U, typename... Us>
static inline bool _eval(const T0& head, const tdata<T1, Ts...>& tail,
const U& arg, const Us&... args) {
return cmp(head, arg) && _eval(tail.head, tail.tail(), args...);
}
};
typedef value_guard<util::empty_type_list> empty_value_guard;
} // namespace detail
} // namespace cppa
#endif // CPPA_DETAIL_VALUE_GUARD_HPP
......@@ -29,7 +29,7 @@
namespace cppa {
class channel;
class any_tuple;
class message;
class message_header;
struct invalid_group_t { constexpr invalid_group_t() { } };
......
This diff is collapsed.
......@@ -146,7 +146,7 @@ class broker : public extend<local_actor>::
return add_acceptor(tcp_acceptor::from_sockfd(tcp_sockfd));
}
void enqueue(msg_hdr_cref, any_tuple, execution_unit*) override;
void enqueue(msg_hdr_cref, message, execution_unit*) override;
template<typename F>
static broker_ptr from(F fun) {
......@@ -192,7 +192,7 @@ class broker : public extend<local_actor>::
static broker_ptr from_impl(std::function<behavior (broker*)> fun);
void invoke_message(msg_hdr_cref hdr, any_tuple msg);
void invoke_message(msg_hdr_cref hdr, message msg);
bool invoke_message_from_cache();
......
......@@ -22,7 +22,7 @@
#include <vector>
#include "cppa/any_tuple.hpp"
#include "cppa/message.hpp"
#include "cppa/ref_counted.hpp"
#include "cppa/message_header.hpp"
......@@ -33,7 +33,7 @@ class default_message_queue : public ref_counted {
public:
typedef std::pair<message_header, any_tuple> value_type;
typedef std::pair<message_header, message> value_type;
typedef value_type& reference;
......
......@@ -134,7 +134,7 @@ class middleman {
*/
virtual void deliver(const node_id& node,
msg_hdr_cref hdr,
any_tuple msg ) = 0;
message msg ) = 0;
/**
* @brief This callback is invoked by {@link peer} implementations
......
......@@ -26,7 +26,7 @@
#include "cppa/extend.hpp"
#include "cppa/node_id.hpp"
#include "cppa/actor_proxy.hpp"
#include "cppa/partial_function.hpp"
#include "cppa/message_handler.hpp"
#include "cppa/type_lookup_table.hpp"
#include "cppa/weak_intrusive_ptr.hpp"
......@@ -63,7 +63,7 @@ class peer : public extend<continuable>::with<buffered_writing> {
void io_failed(event_bitmask mask) override;
void enqueue(msg_hdr_cref hdr, const any_tuple& msg);
void enqueue(msg_hdr_cref hdr, const message& msg);
inline bool stop_on_last_proxy_exited() const {
return m_stop_on_last_proxy_exited;
......@@ -109,7 +109,7 @@ class peer : public extend<continuable>::with<buffered_writing> {
// point to the published actor of the remote node
bool m_stop_on_last_proxy_exited;
partial_function m_content_handler;
message_handler m_content_handler;
type_lookup_table m_incoming_types;
type_lookup_table m_outgoing_types;
......@@ -122,13 +122,13 @@ class peer : public extend<continuable>::with<buffered_writing> {
void unlink(const actor_addr& sender, const actor_addr& ptr);
void deliver(msg_hdr_cref hdr, any_tuple msg);
void deliver(msg_hdr_cref hdr, message msg);
inline void enqueue(const any_tuple& msg) {
inline void enqueue(const message& msg) {
enqueue({invalid_actor_addr, nullptr}, msg);
}
void enqueue_impl(msg_hdr_cref hdr, const any_tuple& msg);
void enqueue_impl(msg_hdr_cref hdr, const message& msg);
void add_type_if_needed(const std::string& tname);
......
......@@ -72,7 +72,7 @@ class remote_actor_proxy : public actor_proxy {
node_id_ptr pinfo,
middleman* parent);
void enqueue(msg_hdr_cref hdr, any_tuple msg, execution_unit*) override;
void enqueue(msg_hdr_cref hdr, message msg, execution_unit*) override;
void link_to(const actor_addr& other) override;
......@@ -86,7 +86,7 @@ class remote_actor_proxy : public actor_proxy {
void local_unlink_from(const actor_addr& other) override;
void deliver(msg_hdr_cref hdr, any_tuple msg) override;
void deliver(msg_hdr_cref hdr, message msg) override;
protected:
......@@ -94,7 +94,7 @@ class remote_actor_proxy : public actor_proxy {
private:
void forward_msg(msg_hdr_cref hdr, any_tuple msg);
void forward_msg(msg_hdr_cref hdr, message msg);
middleman* m_parent;
intrusive::single_reader_queue<sync_request_info, detail::disposer> m_pending_requests;
......
......@@ -28,7 +28,7 @@
#include "cppa/extend.hpp"
#include "cppa/channel.hpp"
#include "cppa/behavior.hpp"
#include "cppa/any_tuple.hpp"
#include "cppa/message.hpp"
#include "cppa/cow_tuple.hpp"
#include "cppa/spawn_fwd.hpp"
#include "cppa/message_id.hpp"
......@@ -43,7 +43,7 @@
#include "cppa/mailbox_element.hpp"
#include "cppa/response_promise.hpp"
#include "cppa/message_priority.hpp"
#include "cppa/partial_function.hpp"
#include "cppa/message_handler.hpp"
#include "cppa/util/duration.hpp"
......@@ -147,12 +147,12 @@ class local_actor : public extend<abstract_actor>::with<memory_cached> {
/**
* @brief Sends @p what to the receiver specified in @p dest.
*/
void send_tuple(message_priority prio, const channel& whom, any_tuple what);
void send_tuple(message_priority prio, const channel& whom, message what);
/**
* @brief Sends @p what to the receiver specified in @p dest.
*/
inline void send_tuple(const channel& whom, any_tuple what) {
inline void send_tuple(const channel& whom, message what) {
send_tuple(message_priority::normal, whom, std::move(what));
}
......@@ -166,7 +166,7 @@ class local_actor : public extend<abstract_actor>::with<memory_cached> {
template<typename... Ts>
inline void send(message_priority prio, const channel& whom, Ts&&... what) {
static_assert(sizeof...(Ts) > 0, "sizeof...(Ts) == 0");
send_tuple(prio, whom, make_any_tuple(std::forward<Ts>(what)...));
send_tuple(prio, whom, make_message(std::forward<Ts>(what)...));
}
/**
......@@ -179,7 +179,7 @@ class local_actor : public extend<abstract_actor>::with<memory_cached> {
inline void send(const channel& whom, Ts&&... what) {
static_assert(sizeof...(Ts) > 0, "sizeof...(Ts) == 0");
send_tuple(message_priority::normal, whom,
make_any_tuple(std::forward<Ts>(what)...));
make_message(std::forward<Ts>(what)...));
}
/**
......@@ -193,7 +193,7 @@ class local_actor : public extend<abstract_actor>::with<memory_cached> {
const typed_actor<Rs...>& whom,
cow_tuple<Ts...> what) {
check_typed_input(whom, what);
send_tuple(prio, whom.m_ptr, any_tuple{std::move(what)});
send_tuple(prio, whom.m_ptr, message{std::move(what)});
}
/**
......@@ -265,7 +265,7 @@ class local_actor : public extend<abstract_actor>::with<memory_cached> {
void delayed_send_tuple(message_priority prio,
const channel& whom,
const util::duration& rtime,
any_tuple data);
message data);
/**
* @brief Sends a message to @p whom that is delayed by @p rel_time.
......@@ -276,7 +276,7 @@ class local_actor : public extend<abstract_actor>::with<memory_cached> {
*/
inline void delayed_send_tuple(const channel& whom,
const util::duration& rtime,
any_tuple data) {
message data) {
delayed_send_tuple(message_priority::normal, whom,
rtime, std::move(data));
}
......@@ -293,7 +293,7 @@ class local_actor : public extend<abstract_actor>::with<memory_cached> {
void delayed_send(message_priority prio, const channel& whom,
const util::duration& rtime, Ts&&... args) {
delayed_send_tuple(prio, whom, rtime,
make_any_tuple(std::forward<Ts>(args)...));
make_message(std::forward<Ts>(args)...));
}
/**
......@@ -307,7 +307,7 @@ class local_actor : public extend<abstract_actor>::with<memory_cached> {
void delayed_send(const channel& whom, const util::duration& rtime,
Ts&&... args) {
delayed_send_tuple(message_priority::normal, whom, rtime,
make_any_tuple(std::forward<Ts>(args)...));
make_message(std::forward<Ts>(args)...));
}
/**************************************************************************
......@@ -371,7 +371,7 @@ class local_actor : public extend<abstract_actor>::with<memory_cached> {
* from the actor's mailbox.
* @warning Only set during callback invocation.
*/
inline any_tuple& last_dequeued();
inline message& last_dequeued();
/**
* @brief Returns the address of the last sender of the
......@@ -502,12 +502,12 @@ class local_actor : public extend<abstract_actor>::with<memory_cached> {
message_id timed_sync_send_tuple_impl(message_priority mp,
const actor& whom,
const util::duration& rel_time,
any_tuple&& what);
message&& what);
// returns the response ID
message_id sync_send_tuple_impl(message_priority mp,
const actor& whom,
any_tuple&& what);
message&& what);
// returns the response ID
template<typename... Rs, typename... Ts>
......@@ -517,14 +517,14 @@ class local_actor : public extend<abstract_actor>::with<memory_cached> {
check_typed_input(whom, what);
return sync_send_tuple_impl(mp,
actor{whom.m_ptr.get()},
any_tuple{std::move(what)});
message{std::move(what)});
}
// returns 0 if last_dequeued() is an asynchronous or sync request message,
// a response id generated from the request id otherwise
inline message_id get_response_id();
void reply_message(any_tuple&& what);
void reply_message(message&& what);
void forward_message(const actor& new_receiver, message_priority prio);
......@@ -616,7 +616,7 @@ inline void local_actor::trap_exit(bool new_value) {
m_trap_exit = new_value;
}
inline any_tuple& local_actor::last_dequeued() {
inline message& local_actor::last_dequeued() {
return m_current_node->msg;
}
......
......@@ -23,7 +23,7 @@
#include <cstdint>
#include "cppa/extend.hpp"
#include "cppa/any_tuple.hpp"
#include "cppa/message.hpp"
#include "cppa/actor_addr.hpp"
#include "cppa/message_id.hpp"
#include "cppa/ref_counted.hpp"
......@@ -45,7 +45,7 @@ class mailbox_element : public extend<memory_managed>::with<memory_cached> {
mailbox_element* next; // intrusive next pointer
bool marked; // denotes if this node is currently processed
actor_addr sender;
any_tuple msg; // 'content field'
message msg; // 'content field'
message_id mid;
~mailbox_element();
......@@ -64,7 +64,7 @@ class mailbox_element : public extend<memory_managed>::with<memory_cached> {
mailbox_element() = default;
mailbox_element(msg_hdr_cref hdr, any_tuple data);
mailbox_element(msg_hdr_cref hdr, message data);
};
......
......@@ -25,10 +25,11 @@
#include <iterator>
#include <type_traits>
#include "cppa/any_tuple.hpp"
#include "cppa/message.hpp"
#include "cppa/match_expr.hpp"
#include "cppa/skip_message.hpp"
#include "cppa/partial_function.hpp"
#include "cppa/message_handler.hpp"
#include "cppa/message_builder.hpp"
#include "cppa/util/tbind.hpp"
#include "cppa/util/type_list.hpp"
......@@ -45,11 +46,11 @@ class match_helper {
match_helper(match_helper&&) = default;
inline match_helper(any_tuple t) : tup(std::move(t)) { }
inline match_helper(message t) : tup(std::move(t)) { }
template<typename... Ts>
auto operator()(Ts&&... args)
-> decltype(match_expr_collect(std::forward<Ts>(args)...)(any_tuple{})) {
-> decltype(match_expr_collect(std::forward<Ts>(args)...)(message{})) {
static_assert(sizeof...(Ts) > 0, "at least one argument required");
auto tmp = match_expr_collect(std::forward<Ts>(args)...);
return tmp(tup);
......@@ -57,7 +58,7 @@ class match_helper {
private:
any_tuple tup;
message tup;
};
......@@ -301,7 +302,7 @@ namespace cppa {
* @param what Tuple that should be matched against a pattern.
* @returns A helper object providing <tt>operator(...)</tt>.
*/
inline detail::match_helper match(any_tuple what) {
inline detail::match_helper match(message what) {
return what;
}
......@@ -312,7 +313,7 @@ inline detail::match_helper match(any_tuple what) {
*/
template<typename T>
detail::match_helper match(T&& what) {
return any_tuple::view(std::forward<T>(what));
return message_builder{std::forward<T>(what)}.to_message();
}
/**
......
This diff is collapsed.
This diff is collapsed.
/******************************************************************************\
* ___ __ *
* /\_ \ __/\ \ *
* \//\ \ /\_\ \ \____ ___ _____ _____ __ *
* \ \ \ \/\ \ \ '__`\ /'___\/\ '__`\/\ '__`\ /'__`\ *
* \_\ \_\ \ \ \ \L\ \/\ \__/\ \ \L\ \ \ \L\ \/\ \L\.\_ *
* /\____\\ \_\ \_,__/\ \____\\ \ ,__/\ \ ,__/\ \__/.\_\ *
* \/____/ \/_/\/___/ \/____/ \ \ \/ \ \ \/ \/__/\/_/ *
* \ \_\ \ \_\ *
* \/_/ \/_/ *
* *
* Copyright (C) 2011 - 2014 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* *
* Distributed under the Boost Software License, Version 1.0. See *
* accompanying file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt *
\******************************************************************************/
#ifndef CPPA_MESSAGE_BUILDER_HPP
#define CPPA_MESSAGE_BUILDER_HPP
#include <vector>
#include "cppa/message.hpp"
#include "cppa/uniform_type_info.hpp"
#include "cppa/detail/message_data.hpp"
#include "cppa/detail/implicit_conversions.hpp"
namespace cppa {
class message_builder {
public:
message_builder() = default;
message_builder(const message_builder&) = delete;
message_builder& operator=(const message_builder&) = delete;
template<typename Iter>
message_builder(Iter first, Iter last) {
append(first, last);
}
template<typename T>
message_builder& append(T what) {
return append_impl<T>(std::move(what));
}
template<typename Iter>
message_builder& append(Iter first, Iter last) {
using vtype = typename util::rm_const_and_ref<decltype(*first)>::type;
using converted = typename detail::implicit_conversions<vtype>::type;
auto uti = uniform_typeid<converted>();
for (; first != last; ++first) {
auto uval = uti->create();
*reinterpret_cast<converted*>(uval->val) = *first;
append(std::move(uval));
}
return *this;
}
message_builder& append(uniform_value what);
message to_message();
optional<message> apply(message_handler handler);
private:
template<typename T>
message_builder&
append_impl(typename detail::implicit_conversions<T>::type what) {
typedef decltype(what) type;
auto uti = uniform_typeid<type>();
auto uval = uti->create();
*reinterpret_cast<type*>(uval->val) = std::move(what);
return append(std::move(uval));
}
std::vector<uniform_value> m_elements;
};
} // namespace cppa
#endif // CPPA_MESSAGE_BUILDER_HPP
......@@ -27,11 +27,11 @@
namespace cppa {
class any_tuple;
class message;
/**
* @brief Encapsulates information about sender, receiver and (synchronous)
* message ID of a message. The message itself is usually an any_tuple.
* message ID of a message. The message itself is usually an message.
*/
class message_header {
......@@ -54,7 +54,7 @@ class message_header {
channel dest,
message_id mid = message_id::invalid);
void deliver(any_tuple msg) const;
void deliver(message msg) const;
};
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -53,7 +53,7 @@ class no_scheduling {
template<class Actor>
void enqueue(Actor* self, msg_hdr_cref hdr,
any_tuple& msg, execution_unit*) {
message& msg, execution_unit*) {
auto ptr = self->new_mailbox_element(hdr, std::move(msg));
// returns false if mailbox has been closed
if (!self->mailbox().synchronized_enqueue(m_mtx, m_cv, ptr)) {
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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