OSDN Git Service

プロセス間通信に必要なmessageの基本的なコンセプトを規定するクラスを追加
authorcaprice <caprice@users.sourceforge.jp>
Sun, 20 Apr 2014 14:15:53 +0000 (23:15 +0900)
committercaprice <caprice@users.sourceforge.jp>
Sun, 20 Apr 2014 14:15:53 +0000 (23:15 +0900)
include/message.hpp [new file with mode: 0644]

diff --git a/include/message.hpp b/include/message.hpp
new file mode 100644 (file)
index 0000000..2c1d188
--- /dev/null
@@ -0,0 +1,55 @@
+
+#ifndef GIKOMONA_CORE_MESSAGE_HPP
+#define GIKOMONA_CORE_MESSAGE_HPP
+
+#include <sstream>
+
+#include "string.hpp"
+
+namespace monazilla { namespace GikoMona { namespace core {
+    
+class message_concept {
+public:
+    message_concept(const mona_string& str);
+    ~message_concept() = default;
+    
+    static mona_string to_string() const {}
+};
+
+template <typename T>
+class is_satisfied_with_message_concept {
+    const static bool value = false;
+};
+    
+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:                                         \
+        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());
+}
+
+} } }
+
+#endif // GIKOMONA_CORE_MESSAGE_HPP