Commit cedc10b3 authored by Dominik Charousset's avatar Dominik Charousset

Make CAF types streamable

parent aec90867
...@@ -164,21 +164,15 @@ public: ...@@ -164,21 +164,15 @@ public:
|| (std::is_default_constructible<T>::value || (std::is_default_constructible<T>::value
&& std::is_copy_constructible<T>::value), && std::is_copy_constructible<T>::value),
"T must provide default and copy constructors"); "T must provide default and copy constructors");
using stream_type = stream<T>;
std::string stream_name = "stream<"; std::string stream_name = "stream<";
stream_name += name; stream_name += name;
stream_name += ">"; stream_name += ">";
static_assert(detail::is_serializable<T>::value, "T must be serializable"); add_message_type_impl<stream<T>>(std::move(stream_name));
type_names_by_rtti.emplace(std::type_index(typeid(T)), name); std::string vec_name = "std::vector<";
value_factories_by_name.emplace(std::move(name), &make_type_erased_value<T>); vec_name += name;
value_factories_by_rtti.emplace(std::type_index(typeid(T)), vec_name += ">";
&make_type_erased_value<T>); add_message_type_impl<std::vector<T>>(std::move(vec_name));
type_names_by_rtti.emplace(std::type_index(typeid(stream_type)), add_message_type_impl<T>(std::move(name));
stream_name);
value_factories_by_name.emplace(std::move(stream_name),
&make_type_erased_value<stream_type>);
value_factories_by_rtti.emplace(std::type_index(typeid(stream_type)),
&make_type_erased_value<stream_type>);
return *this; return *this;
} }
...@@ -320,6 +314,14 @@ protected: ...@@ -320,6 +314,14 @@ protected:
option_vector custom_options_; option_vector custom_options_;
private: private:
template <class T>
void add_message_type_impl(std::string name) {
type_names_by_rtti.emplace(std::type_index(typeid(T)), name);
value_factories_by_name.emplace(std::move(name), &make_type_erased_value<T>);
value_factories_by_rtti.emplace(std::type_index(typeid(T)),
&make_type_erased_value<T>);
}
static std::string render_sec(uint8_t, atom_value, const message&); static std::string render_sec(uint8_t, atom_value, const message&);
static std::string render_exit_reason(uint8_t, atom_value, const message&); static std::string render_exit_reason(uint8_t, atom_value, const message&);
......
...@@ -100,6 +100,15 @@ actor_system_config::actor_system_config() ...@@ -100,6 +100,15 @@ actor_system_config::actor_system_config()
: cli_helptext_printed(false), : cli_helptext_printed(false),
slave_mode(false), slave_mode(false),
slave_mode_fun(nullptr) { slave_mode_fun(nullptr) {
// add `vector<T>` and `stream<T>` for each statically known type
add_message_type_impl<stream<actor>>("stream<@actor>");
add_message_type_impl<stream<actor_addr>>("stream<@addr>");
add_message_type_impl<stream<atom_value>>("stream<@atom>");
add_message_type_impl<stream<message>>("stream<@message>");
add_message_type_impl<std::vector<actor>>("std::vector<@actor>");
add_message_type_impl<std::vector<actor_addr>>("std::vector<@addr>");
add_message_type_impl<std::vector<atom_value>>("std::vector<@atom>");
add_message_type_impl<std::vector<message>>("std::vector<@message>");
// (1) hard-coded defaults // (1) hard-coded defaults
scheduler_policy = atom("stealing"); scheduler_policy = atom("stealing");
scheduler_max_threads = std::max(std::thread::hardware_concurrency(), scheduler_max_threads = std::max(std::thread::hardware_concurrency(),
......
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