File tree 4 files changed +21
-26
lines changed
4 files changed +21
-26
lines changed Original file line number Diff line number Diff line change @@ -345,10 +345,14 @@ bool LevelDb::CommitTransaction() {
345
345
}
346
346
347
347
template <>
348
- const string UserDbFormat<LevelDb>::extension(" .userdb" );
348
+ string UserDbComponent<LevelDb>::extension() const {
349
+ return " .userdb" ;
350
+ }
349
351
350
352
template <>
351
- const string UserDbFormat<LevelDb>::snapshot_extension(" .userdb.txt" );
353
+ string UserDbComponent<LevelDb>::snapshot_extension() const {
354
+ return " .userdb.txt" ;
355
+ }
352
356
353
357
template <>
354
358
UserDbWrapper<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) {
53
53
return true ;
54
54
}
55
55
56
+ static const string plain_userdb_extension (" .userdb.txt" );
57
+
56
58
template <>
57
- const string UserDbFormat<TextDb>::extension(" .userdb.txt" );
59
+ string UserDbComponent<TextDb>::extension() const {
60
+ return plain_userdb_extension;
61
+ }
58
62
59
63
template <>
60
- const string UserDbFormat<TextDb>::snapshot_extension(" .userdb.txt" );
64
+ string UserDbComponent<TextDb>::snapshot_extension() const {
65
+ return plain_userdb_extension;
66
+ }
61
67
62
68
// key ::= code <space> <Tab> phrase
63
69
@@ -110,8 +116,7 @@ bool UserDbHelper::UpdateUserInfo() {
110
116
}
111
117
112
118
bool 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);
115
120
}
116
121
117
122
bool UserDbHelper::UniformBackup (const string& snapshot_file) {
Original file line number Diff line number Diff line change @@ -99,27 +99,16 @@ class UserDbWrapper : public BaseDb {
99
99
}
100
100
};
101
101
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
-
109
102
// / Implements a component that serves as a factory for a user db class.
110
103
template <class BaseDb >
111
104
class UserDbComponent : public UserDb ::Component {
112
105
public:
113
- virtual Db* Create (const string& name) {
106
+ Db* Create (const string& name) override {
114
107
return new UserDbWrapper<BaseDb>(name + extension ());
115
108
}
116
109
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 ;
123
112
};
124
113
125
114
class UserDbMerger : public Sink {
Original file line number Diff line number Diff line change @@ -67,8 +67,7 @@ bool UserDictManager::Backup(const string& dict_name) {
67
67
return false ;
68
68
}
69
69
}
70
- string snapshot_file =
71
- dict_name + UserDbFormat<TextDb>::snapshot_extension;
70
+ string snapshot_file = dict_name + user_db_component_->snapshot_extension ();
72
71
return db->Backup ((dir / snapshot_file).string ());
73
72
}
74
73
@@ -178,8 +177,7 @@ bool UserDictManager::UpgradeUserDict(const string& dict_name) {
178
177
return false ;
179
178
}
180
179
}
181
- string snapshot_file =
182
- dict_name + UserDbFormat<TextDb>::snapshot_extension;
180
+ string snapshot_file = dict_name + user_db_component_->snapshot_extension ();
183
181
fs::path snapshot_path = trash / snapshot_file;
184
182
return legacy_db->Backup (snapshot_path.string ()) &&
185
183
legacy_db->Close () &&
@@ -199,8 +197,7 @@ bool UserDictManager::Synchronize(const string& dict_name) {
199
197
}
200
198
}
201
199
// *.userdb.txt
202
- string snapshot_file =
203
- dict_name + UserDbFormat<TextDb>::snapshot_extension;
200
+ string snapshot_file = dict_name + user_db_component_->snapshot_extension ();
204
201
for (fs::directory_iterator it (sync_dir), end; it != end; ++it) {
205
202
if (!fs::is_directory (it->path ()))
206
203
continue ;
You can’t perform that action at this time.
0 commit comments