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 {
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;
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;
}
boost::algorithm::split(result,
src,
[](char c) -> bool {
- if(c == '/') return true;
- return false;
+ return (c == '/');
});
return std::move(result); // RVO を期待した方が良いか…?