1 #include <boost/filesystem/path.hpp>
2 #include <boost/algorithm/string/split.hpp>
6 namespace monazilla { namespace GikoMona { namespace core {
8 struct model::model_pimpl {
11 * bbs-name(TEXT)|board-name(TEXT)|thread-id(TEXT)|thread-name(TEXT)|is_fixed(INTEGAR)
17 * date(TEXT)|bbs-name(TEXT)|board-name(TEXT)|thread-id(TEXT)|thread-name(TEXT)
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";
32 model::model() noexcept {
34 pimpl = std::make_shared<model_pimpl>();
36 auto config_path = pimpl->app_config;
39 bool model::load_file(const boost::filesystem::path& file_path) {
40 if(!boost::filesystem::exists(file_path)) {
44 auto ext = file_path.extension();
45 auto file_name = file_path.filename();
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());
55 } else if(ext == "xml") {
56 // xml -> class `config'
63 bool model::save_to_file(const boost::filesystem::path& path) {
64 if(!boost::filesystem::exists(path)) { return false; }
66 auto ext = path.extension();
69 // caprice::sqlitexx::connection は open の時点でファイルの作成を完了している。
70 // さらに、connection に対する動作は全て db に書き込まれているので、単に true を返すに留める。
78 void model::execute_accumulated_query() {
79 inserted_value_triv_copyable_type q;
81 if(insertion_query_queue.empty()) { return; }
83 insertion_query_queue.pop(q);
87 std::tie(*q, into, value);
89 std::vector<mona_string> path_derimed = analyze_query(into);
91 if(path_derimed[0] != "application") {
93 } else if (path_derimed[0] == "session") {
95 if(path_derimed[1] == "history") {
97 } else if(path_derimed[1] == "tab-window") {
100 } else if(path_derimed[0] == "extension") {
107 boost::any model::select(const mona_string& from, bool tag) const noexcept {
108 std::vector<mona_string> path_derimed = analyze_query(from);
110 if(path_derimed[0] != "application") {
112 } else if (path_derimed[0] == "session") {
114 if(path_derimed[1] == "history") {
116 } else if(path_derimed[1] == "tab-window") {
119 } else if(path_derimed[0] == "extension") {
126 std::vector<mona_string> model::analyze_query(const mona_string& src) const {
127 std::vector<mona_string> result;
128 boost::algorithm::split(result,
131 if(c == '/') return true;
135 return std::move(result); // RVO を期待した方が良いか…?