2 #ifndef GIKOMONA_CORE_COMMUNICATION_MESSAGE_HPP
3 #define GIKOMONA_CORE_COMMUNICATION_MESSAGE_HPP
7 #include <boost/type_erasure/any.hpp>
8 #include <boost/type_erasure/constructible.hpp>
9 #include <boost/type_erasure/member.hpp>
10 #include <boost/mpl/vector.hpp>
14 namespace monazilla { namespace GikoMona { namespace core { namespace communication {
16 BOOST_TYPE_ERASURE_MEMBER(has_to_raw, to_raw, 0)
17 BOOST_TYPE_ERASURE_MEMBER(has_msg_type, get_type, 0)
19 typedef mona_string raw_message;
21 enum class message_type {
29 has_to_raw<raw_message()>,
30 has_msg_type<message_type()>
31 > message_requirements
34 typedef boost::type_erasure::any<message_requirements> message;
36 #define DEFINE_MESSAGE(type_, name, message) \
40 name (const mona_string& str) : detail(str) {} \
42 raw_message to_raw() const { \
43 std::ostringstream str_builder; \
44 str_builder << #type_ << ":" \
47 return static_cast<raw_message>( \
48 convert_from(str_builder.str()) \
51 message_type get_type() { return type; } \
53 const mona_string detail; \
54 const message_type type = message_type::type_; \
59 #endif // GIKOMONA_CORE_COMMUNICATION_MESSAGE_HPP