OSDN Git Service

名前とdatabaseがばらけていたのをまとめた、が今ひとつすっきりしない
authorcaprice <caprice@users.sourceforge.jp>
Sat, 9 Aug 2014 16:39:16 +0000 (01:39 +0900)
committercaprice <caprice@users.sourceforge.jp>
Sat, 9 Aug 2014 16:39:16 +0000 (01:39 +0900)
そもそもmodelをもう少し練り直す必要があるのではないか…

src/model.cpp

index e745589..508e287 100644 (file)
@@ -6,27 +6,29 @@
 namespace monazilla { namespace GikoMona { namespace core {
 
 struct model::model_pimpl {
+    
+    struct resource_pair {
+        database database;
+        mona_string file_name;
+    };
+    
+    // gikomona/config
+    resource_pair config;
+    
+    // ict/board
+    resource_pair board;
+    
     // session/tab-window
     /* 構造
      * bbs-name(TEXT)|board-name(TEXT)|thread-id(TEXT)|thread-name(TEXT)|is_fixed(INTEGAR)
      */
-    database tab_db;
+    resource_pair tab;
     
     // session/history
     /* 構造
      * date(TEXT)|bbs-name(TEXT)|board-name(TEXT)|thread-id(TEXT)|thread-name(TEXT)
      */
-    database history_db;
-    
-    // application
-    config app_config;
-    
-    struct {
-        const mona_string tab_db = "session.tab-window.db";
-        const mona_string history_db = "session.history.db";
-        const mona_string linkref_db = "session.linkrefs.db";
-        const mona_string app_config = "application-config.xml";
-    } file_name;
+    resource_pair history;
 };
 
 model::model() noexcept {
@@ -44,17 +46,11 @@ bool model::load_file(const boost::filesystem::path& file_path) {
     auto ext = file_path.extension();
     auto file_name = file_path.filename();
     
-    /* 依存型が欲しいなぁって */
-    if(ext == "db") {
-        // sqlite -> class `database'
-        if(file_name == pimpl->file_name.tab_db) {
-            pimpl->tab_db.get_connection().open(file_path.c_str());
-        } else if(file_name == pimpl->file_name.history_db) {
-            pimpl->history_db.get_connection().open(file_path.c_str());
-        }
-    } else if(ext == "xml") {
-        // xml -> class `config'
-        pimpl->app_config;
+    /* TODO: BOOST_FUSION_ADAPT_STRUCTの利用を検討 */
+    if(file_name == pimpl->file_name.tab_db) {
+        pimpl->tab.database.get_connection().open(file_path.c_str());
+    } else if(file_name == pimpl->file_name.history_db) {
+        pimpl->history.database.get_connection().open(file_path.c_str());
     }
     
     return true;
@@ -63,15 +59,6 @@ bool model::load_file(const boost::filesystem::path& file_path) {
 bool model::save_to_file(const boost::filesystem::path& path) {
     if(!boost::filesystem::exists(path)) { return false; }
     
-    auto ext = path.extension();
-    
-    if(ext == "db") {
-        // caprice::sqlitexx::connection は open の時点でファイルの作成を完了している。
-        // さらに、connection に対する動作は全て db に書き込まれているので、単に true を返すに留める。
-        return true;
-    }
-    
-    pimpl->app_config;
     return true;
 }
 
@@ -128,8 +115,7 @@ std::vector<mona_string> model::analyze_query(const mona_string& src) const {
     boost::algorithm::split(result,
                             src,
                             [](char c) -> bool {
-                                if(c == '/') return true;
-                                return false;
+                                return (c == '/');
                             });
     
     return std::move(result); // RVO を期待した方が良いか…?