File tree Expand file tree Collapse file tree 4 files changed +21
-26
lines changed Expand file tree Collapse file tree 4 files changed +21
-26
lines changed Original file line number Diff line number Diff line change @@ -345,10 +345,14 @@ bool LevelDb::CommitTransaction() {
345345}
346346
347347template <>
348- const string UserDbFormat<LevelDb>::extension(" .userdb" );
348+ string UserDbComponent<LevelDb>::extension() const {
349+ return " .userdb" ;
350+ }
349351
350352template <>
351- const string UserDbFormat<LevelDb>::snapshot_extension(" .userdb.txt" );
353+ string UserDbComponent<LevelDb>::snapshot_extension() const {
354+ return " .userdb.txt" ;
355+ }
352356
353357template <>
354358UserDbWrapper<LevelDb>::UserDbWrapper(const string& db_name)
Original file line number Diff line number Diff line change @@ -53,11 +53,17 @@ bool UserDbValue::Unpack(const string& value) {
5353 return true ;
5454}
5555
56+ static const string plain_userdb_extension (" .userdb.txt" );
57+
5658template <>
57- const string UserDbFormat<TextDb>::extension(" .userdb.txt" );
59+ string UserDbComponent<TextDb>::extension() const {
60+ return plain_userdb_extension;
61+ }
5862
5963template <>
60- const string UserDbFormat<TextDb>::snapshot_extension(" .userdb.txt" );
64+ string UserDbComponent<TextDb>::snapshot_extension() const {
65+ return plain_userdb_extension;
66+ }
6167
6268// key ::= code <space> <Tab> phrase
6369
@@ -110,8 +116,7 @@ bool UserDbHelper::UpdateUserInfo() {
110116}
111117
112118bool UserDbHelper::IsUniformFormat (const string& file_name) {
113- return boost::ends_with (file_name,
114- UserDbFormat<TextDb>::snapshot_extension);
119+ return boost::ends_with (file_name, plain_userdb_extension);
115120}
116121
117122bool UserDbHelper::UniformBackup (const string& snapshot_file) {
Original file line number Diff line number Diff line change @@ -99,27 +99,16 @@ class UserDbWrapper : public BaseDb {
9999 }
100100};
101101
102- // / Provides information of the db file format by its base class.
103- template <class BaseDb >
104- struct UserDbFormat {
105- static const string extension;
106- static const string snapshot_extension;
107- };
108-
109102// / Implements a component that serves as a factory for a user db class.
110103template <class BaseDb >
111104class UserDbComponent : public UserDb ::Component {
112105 public:
113- virtual Db* Create (const string& name) {
106+ Db* Create (const string& name) override {
114107 return new UserDbWrapper<BaseDb>(name + extension ());
115108 }
116109
117- virtual string extension () const {
118- return UserDbFormat<BaseDb>::extension;
119- }
120- virtual string snapshot_extension () const {
121- return UserDbFormat<BaseDb>::snapshot_extension;
122- }
110+ string extension () const override ;
111+ string snapshot_extension () const override ;
123112};
124113
125114class UserDbMerger : public Sink {
Original file line number Diff line number Diff line change @@ -67,8 +67,7 @@ bool UserDictManager::Backup(const string& dict_name) {
6767 return false ;
6868 }
6969 }
70- string snapshot_file =
71- dict_name + UserDbFormat<TextDb>::snapshot_extension;
70+ string snapshot_file = dict_name + user_db_component_->snapshot_extension ();
7271 return db->Backup ((dir / snapshot_file).string ());
7372}
7473
@@ -178,8 +177,7 @@ bool UserDictManager::UpgradeUserDict(const string& dict_name) {
178177 return false ;
179178 }
180179 }
181- string snapshot_file =
182- dict_name + UserDbFormat<TextDb>::snapshot_extension;
180+ string snapshot_file = dict_name + user_db_component_->snapshot_extension ();
183181 fs::path snapshot_path = trash / snapshot_file;
184182 return legacy_db->Backup (snapshot_path.string ()) &&
185183 legacy_db->Close () &&
@@ -199,8 +197,7 @@ bool UserDictManager::Synchronize(const string& dict_name) {
199197 }
200198 }
201199 // *.userdb.txt
202- string snapshot_file =
203- dict_name + UserDbFormat<TextDb>::snapshot_extension;
200+ string snapshot_file = dict_name + user_db_component_->snapshot_extension ();
204201 for (fs::directory_iterator it (sync_dir), end; it != end; ++it) {
205202 if (!fs::is_directory (it->path ()))
206203 continue ;
You can’t perform that action at this time.
0 commit comments