Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(user_db): unwanted implicit instantiation of UserDbFormat template #189

Merged
merged 1 commit into from
Mar 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/rime/dict/level_db.cc
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,14 @@ bool LevelDb::CommitTransaction() {
}

template <>
const string UserDbFormat<LevelDb>::extension(".userdb");
string UserDbComponent<LevelDb>::extension() const {
return ".userdb";
}

template <>
const string UserDbFormat<LevelDb>::snapshot_extension(".userdb.txt");
string UserDbComponent<LevelDb>::snapshot_extension() const {
return ".userdb.txt";
}

template <>
UserDbWrapper<LevelDb>::UserDbWrapper(const string& db_name)
Expand Down
13 changes: 9 additions & 4 deletions src/rime/dict/user_db.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,17 @@ bool UserDbValue::Unpack(const string& value) {
return true;
}

static const string plain_userdb_extension(".userdb.txt");

template <>
const string UserDbFormat<TextDb>::extension(".userdb.txt");
string UserDbComponent<TextDb>::extension() const {
return plain_userdb_extension;
}

template <>
const string UserDbFormat<TextDb>::snapshot_extension(".userdb.txt");
string UserDbComponent<TextDb>::snapshot_extension() const {
return plain_userdb_extension;
}

// key ::= code <space> <Tab> phrase

Expand Down Expand Up @@ -110,8 +116,7 @@ bool UserDbHelper::UpdateUserInfo() {
}

bool UserDbHelper::IsUniformFormat(const string& file_name) {
return boost::ends_with(file_name,
UserDbFormat<TextDb>::snapshot_extension);
return boost::ends_with(file_name, plain_userdb_extension);
}

bool UserDbHelper::UniformBackup(const string& snapshot_file) {
Expand Down
17 changes: 3 additions & 14 deletions src/rime/dict/user_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,27 +99,16 @@ class UserDbWrapper : public BaseDb {
}
};

/// Provides information of the db file format by its base class.
template <class BaseDb>
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 BaseDb>
class UserDbComponent : public UserDb::Component {
public:
virtual Db* Create(const string& name) {
Db* Create(const string& name) override {
return new UserDbWrapper<BaseDb>(name + extension());
}

virtual string extension() const {
return UserDbFormat<BaseDb>::extension;
}
virtual string snapshot_extension() const {
return UserDbFormat<BaseDb>::snapshot_extension;
}
string extension() const override;
string snapshot_extension() const override;
};

class UserDbMerger : public Sink {
Expand Down
9 changes: 3 additions & 6 deletions src/rime/lever/user_dict_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ bool UserDictManager::Backup(const string& dict_name) {
return false;
}
}
string snapshot_file =
dict_name + UserDbFormat<TextDb>::snapshot_extension;
string snapshot_file = dict_name + user_db_component_->snapshot_extension();
return db->Backup((dir / snapshot_file).string());
}

Expand Down Expand Up @@ -178,8 +177,7 @@ bool UserDictManager::UpgradeUserDict(const string& dict_name) {
return false;
}
}
string snapshot_file =
dict_name + UserDbFormat<TextDb>::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() &&
Expand All @@ -199,8 +197,7 @@ bool UserDictManager::Synchronize(const string& dict_name) {
}
}
// *.userdb.txt
string snapshot_file =
dict_name + UserDbFormat<TextDb>::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;
Expand Down