libos: Add more constructor variants for Action/Function
This commit is contained in:
parent
1f0286c9c7
commit
17a31e5ea9
@ -44,6 +44,15 @@ namespace os
|
||||
other.m_action = {};
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Construct a new Action object, copying it from another one.
|
||||
*
|
||||
* @param other The old Action object to copy from.
|
||||
*/
|
||||
Action(Action& other) : m_action(other.m_action)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Construct a new Action object, copying it from another one.
|
||||
*
|
||||
@ -143,7 +152,7 @@ namespace os
|
||||
*
|
||||
* @param other The old Function object to move from. This object will become invalid.
|
||||
*/
|
||||
Function(Function&& other) : m_action(other.m_action)
|
||||
Function(Function<Args...>&& other) : m_action(other.m_action)
|
||||
{
|
||||
other.m_action = {};
|
||||
}
|
||||
@ -153,7 +162,16 @@ namespace os
|
||||
*
|
||||
* @param other The old Function object to copy from.
|
||||
*/
|
||||
Function(const Function& other) : m_action(other.m_action)
|
||||
Function(Function<Args...>& other) : m_action(other.m_action)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Construct a new Function object, copying it from another one.
|
||||
*
|
||||
* @param other The old Function object to copy from.
|
||||
*/
|
||||
Function(const Function<Args...>& other) : m_action(other.m_action)
|
||||
{
|
||||
}
|
||||
|
||||
@ -194,24 +212,43 @@ namespace os
|
||||
return m_action->call(args...);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Call the underlying object.
|
||||
*/
|
||||
void operator()(Args... args) const
|
||||
{
|
||||
expect(m_action, "os::Function called with no underlying callable object");
|
||||
return m_action->call(args...);
|
||||
}
|
||||
|
||||
private:
|
||||
class FunctionBase : public Shareable
|
||||
{
|
||||
public:
|
||||
virtual void call(Args... args) = 0;
|
||||
virtual void call(Args... args) const = 0;
|
||||
virtual ~FunctionBase() = default;
|
||||
};
|
||||
|
||||
template <typename T> class FunctionImpl final : public FunctionBase
|
||||
{
|
||||
public:
|
||||
FunctionImpl(FunctionImpl<T>&& function) : m_function(move(function.m_function))
|
||||
{
|
||||
}
|
||||
|
||||
FunctionImpl(T&& function) : m_function(move(function))
|
||||
{
|
||||
}
|
||||
|
||||
void call(Args... args) override
|
||||
{
|
||||
return m_function(args...);
|
||||
m_function(args...);
|
||||
}
|
||||
|
||||
void call(Args... args) const override
|
||||
{
|
||||
m_function(args...);
|
||||
}
|
||||
|
||||
private:
|
||||
|
Loading…
Reference in New Issue
Block a user