mirror of
https://github.com/ksherlock/mpw.git
synced 2024-09-27 10:55:49 +00:00
__with_handle tool_return<void> was losing it's error.
This commit is contained in:
parent
68c2f65f15
commit
a4fb750886
@ -50,6 +50,7 @@ namespace MacOS {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
typedef T value_type;
|
||||||
|
|
||||||
tool_return(T value) : _value(value)
|
tool_return(T value) : _value(value)
|
||||||
{}
|
{}
|
||||||
@ -116,8 +117,9 @@ namespace MacOS {
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
tool_return()
|
typedef void value_type;
|
||||||
{}
|
|
||||||
|
tool_return() = default;
|
||||||
|
|
||||||
tool_return(macos_error error) : tool_return_base(error)
|
tool_return(macos_error error) : tool_return_base(error)
|
||||||
{}
|
{}
|
||||||
|
@ -110,38 +110,56 @@ namespace MM
|
|||||||
template<class T>
|
template<class T>
|
||||||
struct tool_return_base { typedef T type; };
|
struct tool_return_base { typedef T type; };
|
||||||
|
|
||||||
|
// not quite right.... gets turned to tool_return<void>();
|
||||||
|
/*
|
||||||
|
template<>
|
||||||
|
struct tool_return_base<macos_error> { typedef void type ; };
|
||||||
|
*/
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
struct tool_return_base<tool_return<T>> { typedef T type; };
|
struct tool_return_base<tool_return<T>> { typedef T type; };
|
||||||
|
|
||||||
|
|
||||||
template<class T, class F>
|
|
||||||
tool_return<T> with_handle_helper(F &&f, HandleInfo &info, typename std::enable_if<!std::is_void<T>::value>::type* = 0) {
|
template<class T>
|
||||||
tool_return<T> rv = f(info);
|
struct tool_return_type { typedef tool_return<T> type; };
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct tool_return_type<MacOS::macos_error> { typedef tool_return<void> type; };
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
struct tool_return_type<tool_return<T>> { typedef tool_return<T> type; };
|
||||||
|
|
||||||
|
|
||||||
|
template<class T, class FRT, class F>
|
||||||
|
T with_handle_helper(F &&f, HandleInfo &info, typename std::enable_if<!std::is_void<FRT>::value>::type* = 0) {
|
||||||
|
T rv = f(info);
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T, class F>
|
template<class T, class FRT, class F>
|
||||||
tool_return<void> with_handle_helper(F &&f, HandleInfo &info, typename std::enable_if<std::is_void<T>::value>::type* = 0) {
|
T with_handle_helper(F &&f, HandleInfo &info, typename std::enable_if<std::is_void<FRT>::value>::type* = 0) {
|
||||||
f(info);
|
f(info);
|
||||||
return tool_return<void>();
|
return tool_return<void>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<class F, typename T = typename tool_return_base<typename std::result_of<F(HandleInfo &)>::type>::type>
|
template<class F,
|
||||||
tool_return<T>
|
typename FRT = typename std::result_of<F(HandleInfo &)>::type, // function return type
|
||||||
__with_handle(uint32_t handle, F &&f)
|
typename TRT = typename tool_return_type<FRT>::type> // tool return type.
|
||||||
|
TRT __with_handle(uint32_t handle, F &&f)
|
||||||
{
|
{
|
||||||
const auto iter = HandleMap.find(handle);
|
const auto iter = HandleMap.find(handle);
|
||||||
|
|
||||||
if (iter == HandleMap.end()) {
|
if (iter == HandleMap.end()) {
|
||||||
tool_return<T> rv = SetMemError(MacOS::memWZErr);
|
TRT rv = SetMemError(MacOS::memWZErr);
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto &info = iter->second;
|
auto &info = iter->second;
|
||||||
//tool_return<T> rv = f(info);
|
TRT rv = with_handle_helper<TRT, FRT>(std::forward<F>(f), info);
|
||||||
tool_return<T> rv = with_handle_helper<T>(std::forward<F>(f), info);
|
|
||||||
SetMemError(rv.error());
|
SetMemError(rv.error());
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user