Skip to content

Commit

Permalink
Removed Create*EngineHelper. This is just syntax sugar. We would like…
Browse files Browse the repository at this point in the history
… to minimize the types of instantiation methods.

PiperOrigin-RevId: 709281313
  • Loading branch information
taku910 authored and hiroyuki-komatsu committed Dec 24, 2024
1 parent 3cb22a7 commit 528099a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 27 deletions.
4 changes: 3 additions & 1 deletion src/converter/converter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,9 @@ class ConverterTest : public testing::TestWithTempUserProfile {
}

std::unique_ptr<Engine> CreateEngineWithMobilePredictor() {
return Engine::CreateMobileEngineHelper<testing::MockDataManager>().value();
return Engine::CreateMobileEngine(
std::make_unique<testing::MockDataManager>())
.value();
}

bool FindCandidateByValue(absl::string_view value,
Expand Down
16 changes: 6 additions & 10 deletions src/engine/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,27 +62,23 @@ namespace mozc {
absl::StatusOr<std::unique_ptr<Engine>> Engine::CreateDesktopEngine(
std::unique_ptr<const DataManager> data_manager) {
constexpr bool kIsMobile = false;

auto modules = std::make_unique<engine::Modules>();
absl::Status modules_status = modules->Init(std::move(data_manager));
if (!modules_status.ok()) {
return modules_status;
}

return CreateEngine(std::move(modules), kIsMobile);
return CreateEngine(std::move(data_manager), kIsMobile);
}

absl::StatusOr<std::unique_ptr<Engine>> Engine::CreateMobileEngine(
std::unique_ptr<const DataManager> data_manager) {
constexpr bool kIsMobile = true;
return CreateEngine(std::move(data_manager), kIsMobile);
}

absl::StatusOr<std::unique_ptr<Engine>> Engine::CreateEngine(
std::unique_ptr<const DataManager> data_manager, bool is_mobile) {
auto modules = std::make_unique<engine::Modules>();
absl::Status modules_status = modules->Init(std::move(data_manager));
if (!modules_status.ok()) {
return modules_status;
}

return CreateEngine(std::move(modules), kIsMobile);
return CreateEngine(std::move(modules), is_mobile);
}

absl::StatusOr<std::unique_ptr<Engine>> Engine::CreateEngine(
Expand Down
16 changes: 3 additions & 13 deletions src/engine/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,14 @@ class Engine : public EngineInterface {
static absl::StatusOr<std::unique_ptr<Engine>> CreateDesktopEngine(
std::unique_ptr<const DataManager> data_manager);

// Helper function for the above factory, where data manager is instantiated
// by a default constructor. Intended to be used for OssDataManager etc.
template <typename DataManagerType>
static absl::StatusOr<std::unique_ptr<Engine>> CreateDesktopEngineHelper() {
return CreateDesktopEngine(std::make_unique<const DataManagerType>());
}

// Creates an instance with mobile configuration from a data manager. The
// ownership of data manager is passed to the engine instance.
static absl::StatusOr<std::unique_ptr<Engine>> CreateMobileEngine(
std::unique_ptr<const DataManager> data_manager);

// Helper function for the above factory, where data manager is instantiated
// by a default constructor. Intended to be used for OssDataManager etc.
template <typename DataManagerType>
static absl::StatusOr<std::unique_ptr<Engine>> CreateMobileEngineHelper() {
return CreateMobileEngine(std::make_unique<const DataManagerType>());
}
// Creates an instance from a data manager and is_mobile flag.
static absl::StatusOr<std::unique_ptr<Engine>> CreateEngine(
std::unique_ptr<const DataManager> data_manager, bool is_mobile);

// Creates an instance with the given modules and is_mobile flag.
static absl::StatusOr<std::unique_ptr<Engine>> CreateEngine(
Expand Down
3 changes: 2 additions & 1 deletion src/engine/mock_data_engine_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
namespace mozc {

absl::StatusOr<std::unique_ptr<Engine>> MockDataEngineFactory::Create() {
return Engine::CreateDesktopEngineHelper<mozc::testing::MockDataManager>();
return Engine::CreateDesktopEngine(
std::make_unique<mozc::testing::MockDataManager>());
}

} // namespace mozc
4 changes: 2 additions & 2 deletions src/engine/oss_engine_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ class OssEngineFactory {
public:
static absl::StatusOr<std::unique_ptr<Engine>> Create() {
#ifdef __ANDROID__
return Engine::CreateMobileEngineHelper<oss::OssDataManager>();
return Engine::CreateMobileEngine(std::make_unique<oss::OssDataManager>());
#else // __ANDROID__
return Engine::CreateDesktopEngineHelper<oss::OssDataManager>();
return Engine::CreateDesktopEngine(std::make_unique<oss::OssDataManager>());
#endif // __ANDROID__
}
};
Expand Down

0 comments on commit 528099a

Please sign in to comment.