Commit 4a6eefe0 authored by Dominik Charousset's avatar Dominik Charousset

makred cppa types as builtin

parent e540b210
...@@ -32,9 +32,10 @@ ...@@ -32,9 +32,10 @@
#define ADDRESSED_MESSAGE_HPP #define ADDRESSED_MESSAGE_HPP
#include "cppa/actor.hpp" #include "cppa/actor.hpp"
#include "cppa/cow_tuple.hpp"
#include "cppa/channel.hpp" #include "cppa/channel.hpp"
#include "cppa/any_tuple.hpp" #include "cppa/any_tuple.hpp"
#include "cppa/cow_tuple.hpp"
#include "cppa/any_tuple.hpp"
#include "cppa/ref_counted.hpp" #include "cppa/ref_counted.hpp"
#include "cppa/intrusive_ptr.hpp" #include "cppa/intrusive_ptr.hpp"
......
...@@ -49,10 +49,14 @@ struct ta_util<cppa_tinf, false, T> { ...@@ -49,10 +49,14 @@ struct ta_util<cppa_tinf, false, T> {
static inline const uniform_type_info* get() { return nullptr; } static inline const uniform_type_info* get() { return nullptr; }
}; };
// only built-in types are guaranteed to be available at static initialization
// time, other types are announced at runtime
// implements types_array // implements types_array
template<bool BuiltinOnlyTypes, typename... T> template<bool BuiltinOnlyTypes, typename... T>
struct types_array_impl { struct types_array_impl {
static constexpr bool builtin_only = true; static constexpr bool builtin_only = true;
inline bool is_pure() const { return true; }
// all types are builtin, perform lookup on constuction // all types are builtin, perform lookup on constuction
const uniform_type_info* data[sizeof...(T)]; const uniform_type_info* data[sizeof...(T)];
types_array_impl() : data{ta_util<cppa_tinf, true, T>::get()...} { } types_array_impl() : data{ta_util<cppa_tinf, true, T>::get()...} { }
...@@ -67,6 +71,7 @@ struct types_array_impl { ...@@ -67,6 +71,7 @@ struct types_array_impl {
template<typename... T> template<typename... T>
struct types_array_impl<false, T...> { struct types_array_impl<false, T...> {
static constexpr bool builtin_only = false; static constexpr bool builtin_only = false;
inline bool is_pure() const { return false; }
// contains std::type_info for all non-builtin types // contains std::type_info for all non-builtin types
const std::type_info* tinfo_data[sizeof...(T)]; const std::type_info* tinfo_data[sizeof...(T)];
// contains uniform_type_infos for builtin types and lazy initializes // contains uniform_type_infos for builtin types and lazy initializes
......
#ifndef IS_BUILTIN_HPP #ifndef IS_BUILTIN_HPP
#define IS_BUILTIN_HPP #define IS_BUILTIN_HPP
#include <string>
#include <type_traits> #include <type_traits>
#include "cppa/atom.hpp"
#include "cppa/actor.hpp"
#include "cppa/group.hpp"
#include "cppa/channel.hpp"
#include "cppa/anything.hpp" #include "cppa/anything.hpp"
#include "cppa/intrusive_ptr.hpp"
#include "cppa/process_information.hpp"
namespace cppa { class any_tuple; }
namespace cppa { namespace detail { class addressed_message; } }
namespace cppa { namespace util { namespace cppa { namespace util {
...@@ -12,9 +23,37 @@ struct is_builtin { ...@@ -12,9 +23,37 @@ struct is_builtin {
}; };
template<> template<>
struct is_builtin<anything> { struct is_builtin<anything> : std::true_type { };
static constexpr bool value = true;
}; template<>
struct is_builtin<std::string> : std::true_type { };
template<>
struct is_builtin<std::u16string> : std::true_type { };
template<>
struct is_builtin<std::u32string> : std::true_type { };
template<>
struct is_builtin<atom_value> : std::true_type { };
template<>
struct is_builtin<any_tuple> : std::true_type { };
template<>
struct is_builtin<detail::addressed_message> : std::true_type { };
template<>
struct is_builtin<actor_ptr> : std::true_type { };
template<>
struct is_builtin<group_ptr> : std::true_type { };
template<>
struct is_builtin<channel_ptr> : std::true_type { };
template<>
struct is_builtin<intrusive_ptr<process_information> > : std::true_type { };
} } // namespace cppa::util } } // namespace cppa::util
......
...@@ -29,8 +29,10 @@ void ping(size_t num_pings) { ...@@ -29,8 +29,10 @@ void ping(size_t num_pings) {
} }
}, },
others() >> []() { others() >> []() {
cout << __FILE__ << " line " << __LINE__ << ": " cout << "unexpected message; "
<< __FILE__ << " line " << __LINE__ << ": "
<< to_string(self->last_dequeued()) << endl; << to_string(self->last_dequeued()) << endl;
self->quit(exit_reason::user_defined);
} }
) )
.until(gref(s_pongs) == num_pings); .until(gref(s_pongs) == num_pings);
...@@ -53,8 +55,10 @@ actor_ptr spawn_event_based_ping(size_t num_pings) { ...@@ -53,8 +55,10 @@ actor_ptr spawn_event_based_ping(size_t num_pings) {
} }
}, },
others() >> []() { others() >> []() {
cout << __FILE__ << " line " << __LINE__ << ": " cout << "unexpected message; "
<< __FILE__ << " line " << __LINE__ << ": "
<< to_string(self->last_dequeued()) << endl; << to_string(self->last_dequeued()) << endl;
self->quit(exit_reason::user_defined);
} }
); );
} }
...@@ -71,20 +75,10 @@ void pong(actor_ptr ping_actor) { ...@@ -71,20 +75,10 @@ void pong(actor_ptr ping_actor) {
reply(atom("pong"), value + 1); reply(atom("pong"), value + 1);
}, },
others() >> []() { others() >> []() {
cout << __FILE__ << " line " << __LINE__ << ": " cout << "unexpected message; "
<< __FILE__ << " line " << __LINE__ << ": "
<< to_string(self->last_dequeued()) << endl; << to_string(self->last_dequeued()) << endl;
cout << "trap_exit? => " << std::boolalpha << self->trap_exit() << endl; self->quit(exit_reason::user_defined);
auto& arr = detail::static_types_array<atom_value, std::uint32_t>::arr;
auto msg = self->last_dequeued();
if (msg.size() == 2) {
cout << "msg.type_at(0) == arr[0] => " << (msg.type_at(0) == arr[0]) << endl;
cout << "msg.type_at(1) == arr[1] => " << (msg.type_at(1) == arr[1]) << endl;
cout << "msg.type_at(1)->name() => " << (msg.type_at(1)->name()) << endl;
cout << "arr[1]->name() => " << (arr[1]->name()) << endl;
cout << std::hex << "arr[1] => " << arr[1] << endl;
cout << "msg.type_at(1) => " << msg.type_at(1) << endl;
}
self->quit(exit_reason::normal);
} }
); );
} }
...@@ -100,8 +94,10 @@ actor_ptr spawn_event_based_pong(actor_ptr ping_actor) { ...@@ -100,8 +94,10 @@ actor_ptr spawn_event_based_pong(actor_ptr ping_actor) {
reply(atom("pong"), value + 1); reply(atom("pong"), value + 1);
}, },
others() >> []() { others() >> []() {
cout << __FILE__ << " line " << __LINE__ << ": " cout << "unexpected message; "
<< __FILE__ << " line " << __LINE__ << ": "
<< to_string(self->last_dequeued()) << endl; << to_string(self->last_dequeued()) << endl;
self->quit(exit_reason::user_defined);
} }
); );
} }
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "cppa/deserializer.hpp" #include "cppa/deserializer.hpp"
#include "cppa/uniform_type_info.hpp" #include "cppa/uniform_type_info.hpp"
#include "cppa/detail/types_array.hpp" #include "cppa/detail/types_array.hpp"
#include "cppa/detail/addressed_message.hpp"
#include "cppa/util/callable_trait.hpp" #include "cppa/util/callable_trait.hpp"
...@@ -76,7 +77,7 @@ size_t test__uniform_type() { ...@@ -76,7 +77,7 @@ size_t test__uniform_type() {
// default announced cppa types // default announced cppa types
"@atom", // cppa::atom_value "@atom", // cppa::atom_value
"@<>", // cppa::any_tuple "@<>", // cppa::any_tuple
"@msg", // cppa::message "@msg", // cppa::detail::addressed_message
"@actor", // cppa::actor_ptr "@actor", // cppa::actor_ptr
"@group", // cppa::group_ptr "@group", // cppa::group_ptr
"@channel", // cppa::channel_ptr "@channel", // cppa::channel_ptr
...@@ -110,7 +111,49 @@ size_t test__uniform_type() { ...@@ -110,7 +111,49 @@ size_t test__uniform_type() {
} }
} }
// check if static types are identical to runtime types
auto& sarr = detail::static_types_array<
std::int8_t, std::int16_t, std::int32_t, std::int64_t,
std::uint8_t, std::uint16_t, std::uint32_t, std::uint64_t,
std::string, std::u16string, std::u32string,
float, double,
atom_value, any_tuple, detail::addressed_message,
actor_ptr, group_ptr,
channel_ptr, intrusive_ptr<process_information>
>::arr;
std::vector<const uniform_type_info*> rarr{
uniform_typeid<std::int8_t>(),
uniform_typeid<std::int16_t>(),
uniform_typeid<std::int32_t>(),
uniform_typeid<std::int64_t>(),
uniform_typeid<std::uint8_t>(),
uniform_typeid<std::uint16_t>(),
uniform_typeid<std::uint32_t>(),
uniform_typeid<std::uint64_t>(),
uniform_typeid<std::string>(),
uniform_typeid<std::u16string>(),
uniform_typeid<std::u32string>(),
uniform_typeid<float>(),
uniform_typeid<double>(),
uniform_typeid<atom_value>(),
uniform_typeid<any_tuple>(),
uniform_typeid<detail::addressed_message>(),
uniform_typeid<actor_ptr>(),
uniform_typeid<group_ptr>(),
uniform_typeid<channel_ptr>(),
uniform_typeid<intrusive_ptr<process_information> >()
};
CPPA_CHECK_EQUAL(true, sarr.is_pure());
for (size_t i = 0; i < sarr.size; ++i) {
CPPA_CHECK_EQUAL(sarr[i]->name(), rarr[i]->name());
CPPA_CHECK(sarr[i] == rarr[i]);
}
auto& arr0 = detail::static_types_array<atom_value, std::uint32_t>::arr; auto& arr0 = detail::static_types_array<atom_value, std::uint32_t>::arr;
CPPA_CHECK(arr0.is_pure());
CPPA_CHECK(arr0[0] == uniform_typeid<atom_value>()); CPPA_CHECK(arr0[0] == uniform_typeid<atom_value>());
CPPA_CHECK(arr0[0] == uniform_type_info::from("@atom")); CPPA_CHECK(arr0[0] == uniform_type_info::from("@atom"));
CPPA_CHECK(arr0[1] == uniform_typeid<std::uint32_t>()); CPPA_CHECK(arr0[1] == uniform_typeid<std::uint32_t>());
......
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