Skip to content

Commit 3cbc9cb

Browse files
lotemPrcuvu
authored andcommitted
fix(user_db): unwanted implicit instantiation of UserDbFormat template
Fixes #188: UserDbFormat<BaseDb>::extension not working
1 parent 9e1114e commit 3cbc9cb

File tree

4 files changed

+21
-26
lines changed

4 files changed

+21
-26
lines changed

src/rime/dict/level_db.cc

+6-2
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,14 @@ bool LevelDb::CommitTransaction() {
345345
}
346346

347347
template <>
348-
const string UserDbFormat<LevelDb>::extension(".userdb");
348+
string UserDbComponent<LevelDb>::extension() const {
349+
return ".userdb";
350+
}
349351

350352
template <>
351-
const string UserDbFormat<LevelDb>::snapshot_extension(".userdb.txt");
353+
string UserDbComponent<LevelDb>::snapshot_extension() const {
354+
return ".userdb.txt";
355+
}
352356

353357
template <>
354358
UserDbWrapper<LevelDb>::UserDbWrapper(const string& db_name)

src/rime/dict/user_db.cc

+9-4
Original file line numberDiff line numberDiff 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+
5658
template <>
57-
const string UserDbFormat<TextDb>::extension(".userdb.txt");
59+
string UserDbComponent<TextDb>::extension() const {
60+
return plain_userdb_extension;
61+
}
5862

5963
template <>
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

112118
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);
115120
}
116121

117122
bool UserDbHelper::UniformBackup(const string& snapshot_file) {

src/rime/dict/user_db.h

+3-14
Original file line numberDiff line numberDiff 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.
110103
template <class BaseDb>
111104
class 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

125114
class UserDbMerger : public Sink {

src/rime/lever/user_dict_manager.cc

+3-6
Original file line numberDiff line numberDiff 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;

0 commit comments

Comments
 (0)