OSDN Git Service

大量変更… (こういう風に書くのは好ましくない〜)
[gikomona/GikoMona.git] / core / include / model.hpp
index 647d54c..432c6d2 100644 (file)
@@ -3,8 +3,8 @@
 
 #include <unistd.h>
 #include <memory>
-#include <tuple>
 
+#include <boost/fusion/include/vector.hpp>
 #include <boost/any.hpp>
 #include <boost/lockfree/queue.hpp>
 #include <boost/filesystem/path.hpp>
 
 namespace monazilla { namespace GikoMona { namespace core {
 
-class model {
+class model : public query {
 public:
     typedef model self_type;
-    typedef std::tuple<mona_string, boost::any> inserted_query_type;
-    typedef inserted_query_type *inserted_query_triv_copyable_type;
+    typedef query base_type;
+    typedef boost::fusion::vector<mona_string, boost::any> inserted_value_type;
+    typedef inserted_value_type *inserted_value_triv_copyable_type;
     
     model() noexcept;
     ~model();
@@ -29,25 +30,47 @@ public:
     model *get_instance() {
         return instance;
     }
+
+    /**
+     *  @breif query_concept を満たすクラスはこの関数と同じ型、名前を持つ関数を持っていなければならない。
+     *  @retval true insert 操作が成功した
+     *          false insert 操作に失敗した
+     *  @param[in] into どのテーブルのどの要素に対し insertion query を実行するかを記述する。
+     *                  記述の仕方は次の通り:(テーブル名)/[(サブテーブル名)/]*(要素名)
+     *  @param[in] value テーブルに対して代入する値を記述する。
+     *  @note さらに、最大限 multi-threading な環境を考慮しなければならない。
+     */
+    template <typename T, typename U, typename ...ValueType>
+    bool insert(const mona_string& into,
+                const boost::fusion::vector<T, U, ValueType...>& value) {}
     
-    template <typename ...ValueType>
+    template <typename T>
     bool insert(const mona_string& into,
-                const std::tuple<ValueType...>& values) {
-        /*
-        auto any_value = boost::any(values);
-        auto obj = std::make_tuple(into, any_value);
-        return inserted_query_queue.push();
-        */
-    }
+                const boost::fusion::vector<T>& value) {}
     
     template <typename T>
+    virtual
+    bool insert(const mona_string& into,
+                const boost::any& value,
+                base_type::enable_if_T_is_U<T, boost::any>*& = enabler) {}
+    
+    /**
+     *  @brief query_concept を満たすクラスはこの関数と同じ型、名前を持つ関数を持っていなければならない。
+     *  @return 引数で指定したテーブルの要素から、テンプレートで指定した方に変換された値が返される。
+     */
+    template <typename T>
     T select(const mona_string& column,
              const mona_string& from) const noexcept {}
     
+    template <typename T>
+    boost::any select(const mona_string& column,
+                      const mona_string& from,
+                      base_type::enable_if_T_is_U<T, boost::any>*& = enabler) const noexcept {}
+    
     template <typename ...ValueType>
-    std::tuple<ValueType...>
+    boost::fusion::vector<ValueType...>
     select_all(const mona_string& from) const noexcept {}
-    
+
     void exec_inserted_query();
     bool load_file(const boost::filesystem::path& file_path,
                    const mona_string& loaded_table_name);
@@ -55,11 +78,15 @@ public:
                       const mona_string& saved_table_name);
 
 private:
+    void get_object_expressing_into_path_in_query(const mona_string& src,
+                                                  const boost::any& value);
+    void analyze_into_path_in_query(const mona_string& into_path_in_query);
+    
     static self_type *instance;
     struct model_pimpl;
     
     std::shared_ptr<model_pimpl> pimpl;
-    boost::lockfree::queue<inserted_query_triv_copyable_type> inserted_query_queue;
+    boost::lockfree::queue<inserted_value_triv_copyable_type> query_queue;
 };
 
 template <>