GikoMonaのソフトウェアの基幹部分を集めて1つのライブラリに集約したものです。gikomona/pnutsのコンパイルにはこのライブラリが必須です。
Revision | 78a6170fed2827a4a0d3d118d59969a29b3dd426 (tree) |
---|---|
Time | 2014-08-10 01:39:16 |
Author | caprice <caprice@user...> |
Commiter | caprice |
名前とdatabaseがばらけていたのをまとめた、が今ひとつすっきりしない
そもそもmodelをもう少し練り直す必要があるのではないか…
@@ -6,27 +6,29 @@ | ||
6 | 6 | namespace monazilla { namespace GikoMona { namespace core { |
7 | 7 | |
8 | 8 | struct model::model_pimpl { |
9 | + | |
10 | + struct resource_pair { | |
11 | + database database; | |
12 | + mona_string file_name; | |
13 | + }; | |
14 | + | |
15 | + // gikomona/config | |
16 | + resource_pair config; | |
17 | + | |
18 | + // ict/board | |
19 | + resource_pair board; | |
20 | + | |
9 | 21 | // session/tab-window |
10 | 22 | /* 構造 |
11 | 23 | * bbs-name(TEXT)|board-name(TEXT)|thread-id(TEXT)|thread-name(TEXT)|is_fixed(INTEGAR) |
12 | 24 | */ |
13 | - database tab_db; | |
25 | + resource_pair tab; | |
14 | 26 | |
15 | 27 | // session/history |
16 | 28 | /* 構造 |
17 | 29 | * date(TEXT)|bbs-name(TEXT)|board-name(TEXT)|thread-id(TEXT)|thread-name(TEXT) |
18 | 30 | */ |
19 | - database history_db; | |
20 | - | |
21 | - // application | |
22 | - config app_config; | |
23 | - | |
24 | - struct { | |
25 | - const mona_string tab_db = "session.tab-window.db"; | |
26 | - const mona_string history_db = "session.history.db"; | |
27 | - const mona_string linkref_db = "session.linkrefs.db"; | |
28 | - const mona_string app_config = "application-config.xml"; | |
29 | - } file_name; | |
31 | + resource_pair history; | |
30 | 32 | }; |
31 | 33 | |
32 | 34 | model::model() noexcept { |
@@ -44,17 +46,11 @@ bool model::load_file(const boost::filesystem::path& file_path) { | ||
44 | 46 | auto ext = file_path.extension(); |
45 | 47 | auto file_name = file_path.filename(); |
46 | 48 | |
47 | - /* 依存型が欲しいなぁって */ | |
48 | - if(ext == "db") { | |
49 | - // sqlite -> class `database' | |
50 | - if(file_name == pimpl->file_name.tab_db) { | |
51 | - pimpl->tab_db.get_connection().open(file_path.c_str()); | |
52 | - } else if(file_name == pimpl->file_name.history_db) { | |
53 | - pimpl->history_db.get_connection().open(file_path.c_str()); | |
54 | - } | |
55 | - } else if(ext == "xml") { | |
56 | - // xml -> class `config' | |
57 | - pimpl->app_config; | |
49 | + /* TODO: BOOST_FUSION_ADAPT_STRUCTの利用を検討 */ | |
50 | + if(file_name == pimpl->file_name.tab_db) { | |
51 | + pimpl->tab.database.get_connection().open(file_path.c_str()); | |
52 | + } else if(file_name == pimpl->file_name.history_db) { | |
53 | + pimpl->history.database.get_connection().open(file_path.c_str()); | |
58 | 54 | } |
59 | 55 | |
60 | 56 | return true; |
@@ -63,15 +59,6 @@ bool model::load_file(const boost::filesystem::path& file_path) { | ||
63 | 59 | bool model::save_to_file(const boost::filesystem::path& path) { |
64 | 60 | if(!boost::filesystem::exists(path)) { return false; } |
65 | 61 | |
66 | - auto ext = path.extension(); | |
67 | - | |
68 | - if(ext == "db") { | |
69 | - // caprice::sqlitexx::connection は open の時点でファイルの作成を完了している。 | |
70 | - // さらに、connection に対する動作は全て db に書き込まれているので、単に true を返すに留める。 | |
71 | - return true; | |
72 | - } | |
73 | - | |
74 | - pimpl->app_config; | |
75 | 62 | return true; |
76 | 63 | } |
77 | 64 |
@@ -128,8 +115,7 @@ std::vector<mona_string> model::analyze_query(const mona_string& src) const { | ||
128 | 115 | boost::algorithm::split(result, |
129 | 116 | src, |
130 | 117 | [](char c) -> bool { |
131 | - if(c == '/') return true; | |
132 | - return false; | |
118 | + return (c == '/'); | |
133 | 119 | }); |
134 | 120 | |
135 | 121 | return std::move(result); // RVO を期待した方が良いか…? |