-#ifndef GIKOMONA_CORE_MESSAGE_HPP
-#define GIKOMONA_CORE_MESSAGE_HPP
+#ifndef GIKOMONA_CORE_COMMUNICATION_MESSAGE_HPP
+#define GIKOMONA_CORE_COMMUNICATION_MESSAGE_HPP
#include <sstream>
+#include <boost/type_erasure/any.hpp>
+#include <boost/type_erasure/constructible.hpp>
+#include <boost/type_erasure/member.hpp>
+#include <boost/mpl/vector.hpp>
+
#include "string.hpp"
-#include "communication.hpp"
namespace monazilla { namespace GikoMona { namespace core { namespace communication {
-class message_concept {
-public:
- message_concept(const mona_string& str);
- ~message_concept() = default;
+BOOST_TYPE_ERASURE_MEMBER(has_to_raw, to_raw, 0)
+BOOST_TYPE_ERASURE_MEMBER(has_msg_type, get_type, 0)
+
+typedef mona_string raw_message;
- static mona_string to_string() const {}
+enum class message_type {
+ FAILURE,
+ REQUEST,
+ SUCCEED
};
-template <typename T>
-class is_satisfied_with_message_concept {
- const static bool value = false;
-};
+typedef
+ boost::mpl::vector<
+ has_to_raw<raw_message()>,
+ has_msg_type<message_type()>
+ > message_requirements
+ ;
-template <typename T>
-constexpr bool is_satisfied_with_message_concept_v() {
- return is_satisfied_message_concept<T>::value;
-}
-
-#define DEFINE_MESSAGE(type, name, message) \
- class name { \
- public: \
- explicit \
- name (const mona_string& str) : msg(str) {} \
- ~name() = default; \
- mona_string to_string() const { \
- std::ostringstream str_builder; \
- str_builder << #type << ":" \
- << message << "(" \
- << msg << ")."; \
- return convert_from(str_builder.str()); \
- } \
- private: \
- const mona_string msg; \
- };
-
-template <typename T>
-bool is_same_mail(mona_string src, T&& obj) {
- static_assert(is_satisfied_with_message_concept_v<T>(),
- "`T' does not satisfy the `message_concept'");
-
- return (src == obj.to_string());
-}
+typedef boost::type_erasure::any<message_requirements> message;
+
+#define DEFINE_MESSAGE(type_, name, message) \
+ class name { \
+ public: \
+ explicit \
+ name (const mona_string& str) : detail(str) {} \
+ ~name() = default; \
+ raw_message to_raw() const { \
+ std::ostringstream str_builder; \
+ str_builder << #type_ << ":" \
+ << message << "(" \
+ << detail << ")."; \
+ return static_cast<raw_message>( \
+ convert_from(str_builder.str()) \
+ ); \
+ } \
+ message_type get_type() { return type; } \
+ private: \
+ const mona_string detail; \
+ const message_type type = message_type::type_; \
+};
} } } }
-#endif // GIKOMONA_CORE_MESSAGE_HPP
+#endif // GIKOMONA_CORE_COMMUNICATION_MESSAGE_HPP