From 32be71d8a782641d1a2a604ea4d3a86a97b8ca0d Mon Sep 17 00:00:00 2001 From: nekosu Date: Mon, 6 Nov 2023 15:19:31 +0800 Subject: [PATCH] refactor: don't use optional --- source/MaaFramework/API/MaaController.cpp | 8 ++++---- source/include/Utils/LibraryHolder.h | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/source/MaaFramework/API/MaaController.cpp b/source/MaaFramework/API/MaaController.cpp index ec401296a..21086bb97 100644 --- a/source/MaaFramework/API/MaaController.cpp +++ b/source/MaaFramework/API/MaaController.cpp @@ -37,13 +37,13 @@ MaaControllerHandle MaaAdbControllerCreateV2(MaaStringView adb_path, MaaStringVi using create_controller_unit_t = void(std::shared_ptr*, MaaStringView, MaaStringView, MaaAdbControllerType, MaaStringView, MaaStringView); auto create_func = MAA_CTRL_NS::AdbController::get_function("create_controller_unit"); - if (!create_func.has_value()) { + if (!create_func) { LogError << "Failed to get function create_controller_unit"; return nullptr; } std::shared_ptr unit_mgr; - create_func.value()(&unit_mgr, adb_path, address, type, config, agent_path); + create_func(&unit_mgr, adb_path, address, type, config, agent_path); if (!unit_mgr) { LogError << "Failed to create controller unit"; @@ -106,12 +106,12 @@ MaaControllerHandle MaaDbgControllerCreate(MaaStringView read_path, MaaStringVie using create_controller_unit_t = std::shared_ptr( MaaStringView, MaaStringView, MaaDbgControllerType, MaaStringView); auto create_func = MAA_CTRL_NS::DebuggingController::get_function("create_controller"); - if (!create_func.has_value()) { + if (!create_func) { LogError << "Failed to get function create_controller"; return nullptr; } - auto unit_mgr = create_func.value()(read_path, write_path, type, config); + auto unit_mgr = create_func(read_path, write_path, type, config); if (!unit_mgr) { LogError << "Failed to create controller unit"; return nullptr; diff --git a/source/include/Utils/LibraryHolder.h b/source/include/Utils/LibraryHolder.h index f9bb8d6ac..a49695b5a 100644 --- a/source/include/Utils/LibraryHolder.h +++ b/source/include/Utils/LibraryHolder.h @@ -22,7 +22,7 @@ class LibraryHolder : public NonCopyable static bool load_library(const std::filesystem::path& libname); template - static std::optional> get_function(const std::string& func_name); + static boost::function get_function(const std::string& func_name); private: static void unload_library(); @@ -112,18 +112,18 @@ inline void LibraryHolder::unload_library() template template -inline std::optional> LibraryHolder::get_function(const std::string& func_name) +inline boost::function LibraryHolder::get_function(const std::string& func_name) { LogFunc << VAR(func_name); if (!module_.is_loaded()) { LogError << "LibraryHolder not loaded"; - return std::nullopt; + return {}; } if (!module_.has(func_name)) { LogError << "Failed to find exported function" << VAR(func_name); - return std::nullopt; + return {}; } return module_.get(func_name);