Skip to content

Commit

Permalink
refactor: don't use optional
Browse files Browse the repository at this point in the history
  • Loading branch information
neko-para committed Nov 6, 2023
1 parent 05f3be2 commit 32be71d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions source/MaaFramework/API/MaaController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ MaaControllerHandle MaaAdbControllerCreateV2(MaaStringView adb_path, MaaStringVi
using create_controller_unit_t = void(std::shared_ptr<MAA_ADB_CTRL_UNIT_NS::ControlUnitAPI>*, MaaStringView,
MaaStringView, MaaAdbControllerType, MaaStringView, MaaStringView);
auto create_func = MAA_CTRL_NS::AdbController::get_function<create_controller_unit_t>("create_controller_unit");
if (!create_func.has_value()) {
if (!create_func) {
LogError << "Failed to get function create_controller_unit";
return nullptr;
}

std::shared_ptr<MAA_ADB_CTRL_UNIT_NS::ControlUnitAPI> 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";
Expand Down Expand Up @@ -106,12 +106,12 @@ MaaControllerHandle MaaDbgControllerCreate(MaaStringView read_path, MaaStringVie
using create_controller_unit_t = std::shared_ptr<MAA_DBG_CTRL_UNIT_NS::ControllerAPI>(
MaaStringView, MaaStringView, MaaDbgControllerType, MaaStringView);
auto create_func = MAA_CTRL_NS::DebuggingController::get_function<create_controller_unit_t>("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;
Expand Down
8 changes: 4 additions & 4 deletions source/include/Utils/LibraryHolder.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class LibraryHolder : public NonCopyable
static bool load_library(const std::filesystem::path& libname);

template <typename FuncT>
static std::optional<boost::function<FuncT>> get_function(const std::string& func_name);
static boost::function<FuncT> get_function(const std::string& func_name);

private:
static void unload_library();
Expand Down Expand Up @@ -112,18 +112,18 @@ inline void LibraryHolder<T>::unload_library()

template <typename T>
template <typename FuncT>
inline std::optional<boost::function<FuncT>> LibraryHolder<T>::get_function(const std::string& func_name)
inline boost::function<FuncT> LibraryHolder<T>::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<FuncT>(func_name);
Expand Down

0 comments on commit 32be71d

Please sign in to comment.