Update tool manager to handle the std::any parameters

This commit is contained in:
Ian McInerney 2022-09-28 23:13:32 +01:00
parent 8b833211b5
commit 9ebe6e7614
2 changed files with 13 additions and 19 deletions

View File

@ -285,7 +285,7 @@ bool TOOL_MANAGER::InvokeTool( const std::string& aToolName )
}
bool TOOL_MANAGER::RunAction( const std::string& aActionName, bool aNow, void* aParam )
bool TOOL_MANAGER::RunAction( const std::string& aActionName, bool aNow, std::any aParam )
{
TOOL_ACTION* action = m_actionMgr->FindAction( aActionName );
@ -319,7 +319,7 @@ VECTOR2D TOOL_MANAGER::GetCursorPosition() const
}
bool TOOL_MANAGER::RunAction( const TOOL_ACTION& aAction, bool aNow, void* aParam )
bool TOOL_MANAGER::RunAction( const TOOL_ACTION& aAction, bool aNow, std::any aParam )
{
if( m_shuttingDown )
return true;
@ -331,7 +331,7 @@ bool TOOL_MANAGER::RunAction( const TOOL_ACTION& aAction, bool aNow, void* aPara
event.SetMousePosition( GetCursorPosition() );
// Allow to override the action parameter
if( aParam )
if( aParam.has_value() )
event.SetParameter( aParam );
if( aNow )

View File

@ -138,17 +138,14 @@ public:
* depends on the action.
* @return False if the action was not found.
*/
template<typename T>
bool RunAction( const std::string& aActionName, bool aNow = false, T aParam = NULL )
{
return RunAction( aActionName, aNow, reinterpret_cast<void*>( aParam ) );
}
bool RunAction( const std::string& aActionName, bool aNow, void* aParam );
bool RunAction( const std::string& aActionName, bool aNow, std::any aParam );
bool RunAction( const std::string& aActionName, bool aNow = false )
{
return RunAction( aActionName, aNow, (void*) NULL );
// Default initialize the parameter argument to an empty std::any
std::any a;
return RunAction( aActionName, aNow, a );
}
/**
@ -164,17 +161,14 @@ public:
* depends on the action.
* @return True if the action was handled immediately
*/
template <typename T>
bool RunAction( const TOOL_ACTION& aAction, bool aNow = false, T aParam = NULL )
{
return RunAction( aAction, aNow, reinterpret_cast<void*>( aParam ) );
}
bool RunAction( const TOOL_ACTION& aAction, bool aNow, void* aParam );
bool RunAction( const TOOL_ACTION& aAction, bool aNow, std::any aParam );
bool RunAction( const TOOL_ACTION& aAction, bool aNow = false )
{
return RunAction( aAction, aNow, (void*) NULL );
// Default initialize the parameter argument to an empty std::any
std::any a;
return RunAction( aAction, aNow, a );
}
/**