OSDN Git Service

[core] :
authorcaprice <caprice@users.sourceforge.jp>
Tue, 23 Jul 2013 13:04:39 +0000 (22:04 +0900)
committercaprice <caprice@users.sourceforge.jp>
Tue, 23 Jul 2013 13:04:39 +0000 (22:04 +0900)
queryの大きな変更に伴って書き換え。

core/include/model.hpp

index ffcbcaf..28a6ee0 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <unistd.h>
 
+#include <boost/any.hpp>
 #include <boost/lockfree/queue.hpp>
 #include <boost/filesystem/path.hpp>
 
 #include "config.hpp"
 
 namespace monazilla { namespace GikoMona { namespace core {
-    
+
 class model {
 public:
     typedef model self_type;
+    typedef std::tuple<mona_string, boost::any> inserted_query_type;
+    typedef inserted_query_type *inserted_query_triv_copyable_type;
     
     model() noexcept {
         instance = this;
@@ -28,39 +31,33 @@ public:
         return instance;
     }
     
-    bool push_query_in_queue(const query& src) {
-        return query_queue.push(src);
+    template <typename ...ValueType>
+    bool insert(const mona_string& into,
+                const std::tuple<ValueType...>& values) {
+        return inserted_query_queue.push(new inserted_query_type(into, boost::any(values)));
     }
     
-    template <typename ResultType>
-    ResultType pop_query() {
-        exec_all_query();
-    }
+    template <typename T>
+    T select() {}
     
-    bool load_file(const boost::filesystem::path& file_path);
+    void exec_inserted_query();
+    bool load_file(const boost::filesystem::path& file_path,
+                   const mona_string& loaded_table_name);
     bool save_to_file(const boost::filesystem::path& file_path,
                       const mona_string& saved_table_name);
 
 private:
     static self_type *instance;
-    database db;
+    database history_db;
     config app_config;
-    boost::lockfree::queue<query> query_queue;
-
-    void exec_all_query() {
-        query val("");
-        while(!query_queue.empty()) {
-            if(!query_queue.pop(val)) { continue; }
-            // valの処理
-        }
-    }
+    boost::lockfree::queue<inserted_query_triv_copyable_type> inserted_query_queue;
 };
 
-void post_query_to_model(const query& src) {
-    model *obj = model::get_instance();
-    while(!obj->push_query_in_queue(src)) {
-        ::sleep(10);
-    }
+template <>
+struct is_satisfied_with_query_concept<model> : public boost::mpl::true_ {};
+
+void exec_insert_query() {
+    model::get_instance()->exec_insert_query();
 }
 
 } } }