diff --git a/src/rime/dict/level_db.cc b/src/rime/dict/level_db.cc index 31e41b7df..21c106611 100644 --- a/src/rime/dict/level_db.cc +++ b/src/rime/dict/level_db.cc @@ -345,10 +345,14 @@ bool LevelDb::CommitTransaction() { } template <> -const string UserDbFormat::extension(".userdb"); +string UserDbComponent::extension() const { + return ".userdb"; +} template <> -const string UserDbFormat::snapshot_extension(".userdb.txt"); +string UserDbComponent::snapshot_extension() const { + return ".userdb.txt"; +} template <> UserDbWrapper::UserDbWrapper(const string& db_name) diff --git a/src/rime/dict/user_db.cc b/src/rime/dict/user_db.cc index 32a8a8691..d97b30457 100644 --- a/src/rime/dict/user_db.cc +++ b/src/rime/dict/user_db.cc @@ -53,11 +53,17 @@ bool UserDbValue::Unpack(const string& value) { return true; } +static const string plain_userdb_extension(".userdb.txt"); + template <> -const string UserDbFormat::extension(".userdb.txt"); +string UserDbComponent::extension() const { + return plain_userdb_extension; +} template <> -const string UserDbFormat::snapshot_extension(".userdb.txt"); +string UserDbComponent::snapshot_extension() const { + return plain_userdb_extension; +} // key ::= code phrase @@ -110,8 +116,7 @@ bool UserDbHelper::UpdateUserInfo() { } bool UserDbHelper::IsUniformFormat(const string& file_name) { - return boost::ends_with(file_name, - UserDbFormat::snapshot_extension); + return boost::ends_with(file_name, plain_userdb_extension); } bool UserDbHelper::UniformBackup(const string& snapshot_file) { diff --git a/src/rime/dict/user_db.h b/src/rime/dict/user_db.h index 168f6af96..a3e1047fd 100644 --- a/src/rime/dict/user_db.h +++ b/src/rime/dict/user_db.h @@ -99,27 +99,16 @@ class UserDbWrapper : public BaseDb { } }; -/// Provides information of the db file format by its base class. -template -struct UserDbFormat { - static const string extension; - static const string snapshot_extension; -}; - /// Implements a component that serves as a factory for a user db class. template class UserDbComponent : public UserDb::Component { public: - virtual Db* Create(const string& name) { + Db* Create(const string& name) override { return new UserDbWrapper(name + extension()); } - virtual string extension() const { - return UserDbFormat::extension; - } - virtual string snapshot_extension() const { - return UserDbFormat::snapshot_extension; - } + string extension() const override; + string snapshot_extension() const override; }; class UserDbMerger : public Sink { diff --git a/src/rime/lever/user_dict_manager.cc b/src/rime/lever/user_dict_manager.cc index 515521f24..2a23f049d 100644 --- a/src/rime/lever/user_dict_manager.cc +++ b/src/rime/lever/user_dict_manager.cc @@ -67,8 +67,7 @@ bool UserDictManager::Backup(const string& dict_name) { return false; } } - string snapshot_file = - dict_name + UserDbFormat::snapshot_extension; + string snapshot_file = dict_name + user_db_component_->snapshot_extension(); return db->Backup((dir / snapshot_file).string()); } @@ -178,8 +177,7 @@ bool UserDictManager::UpgradeUserDict(const string& dict_name) { return false; } } - string snapshot_file = - dict_name + UserDbFormat::snapshot_extension; + string snapshot_file = dict_name + user_db_component_->snapshot_extension(); fs::path snapshot_path = trash / snapshot_file; return legacy_db->Backup(snapshot_path.string()) && legacy_db->Close() && @@ -199,8 +197,7 @@ bool UserDictManager::Synchronize(const string& dict_name) { } } // *.userdb.txt - string snapshot_file = - dict_name + UserDbFormat::snapshot_extension; + string snapshot_file = dict_name + user_db_component_->snapshot_extension(); for (fs::directory_iterator it(sync_dir), end; it != end; ++it) { if (!fs::is_directory(it->path())) continue;