merge duplicate boilerplate code
This commit is contained in:
@@ -162,14 +162,10 @@ RString InputHandler::GetLocalizedInputString( const DeviceInput &di )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
map<istring, CreateInputHandlerFn> *RegisterInputHandler::g_pRegistrees;
|
static DriverList g_pRegistrees;
|
||||||
RegisterInputHandler::RegisterInputHandler( const istring &sName, CreateInputHandlerFn pfn )
|
RegisterInputHandler::RegisterInputHandler( const istring &sName, CreateRageDriverFn pfn )
|
||||||
{
|
{
|
||||||
if( g_pRegistrees == NULL )
|
g_pRegistrees.Add( sName, pfn );
|
||||||
g_pRegistrees = new map<istring, CreateInputHandlerFn>;
|
|
||||||
|
|
||||||
ASSERT( g_pRegistrees->find(sName) == g_pRegistrees->end() );
|
|
||||||
(*g_pRegistrees)[sName] = pfn;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static LocalizedString INPUT_HANDLERS_EMPTY( "Arch", "Input Handlers cannot be empty." );
|
static LocalizedString INPUT_HANDLERS_EMPTY( "Arch", "Input Handlers cannot be empty." );
|
||||||
@@ -184,14 +180,14 @@ void MakeInputHandlers( const RString &drivers_, vector<InputHandler *> &Add )
|
|||||||
|
|
||||||
FOREACH_CONST( RString, DriversToTry, s )
|
FOREACH_CONST( RString, DriversToTry, s )
|
||||||
{
|
{
|
||||||
map<istring, CreateInputHandlerFn>::const_iterator iter = RegisterInputHandler::g_pRegistrees->find( istring(*s) );
|
RageDriver *pDriver = g_pRegistrees.Create( *s );
|
||||||
|
if( pDriver == NULL )
|
||||||
if( iter == RegisterInputHandler::g_pRegistrees->end() )
|
|
||||||
{
|
{
|
||||||
LOG->Trace( "Unknown Input Handler name: %s", s->c_str() );
|
LOG->Trace( "Unknown Input Handler name: %s", s->c_str() );
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
InputHandler *ret = (iter->second)();
|
|
||||||
|
InputHandler *ret = dynamic_cast<InputHandler *>( pDriver );
|
||||||
DEBUG_ASSERT( ret );
|
DEBUG_ASSERT( ret );
|
||||||
Add.push_back( ret );
|
Add.push_back( ret );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,8 +21,9 @@
|
|||||||
* We don't need this now; I'll write it if it becomes needed.)
|
* We don't need this now; I'll write it if it becomes needed.)
|
||||||
*/
|
*/
|
||||||
#include "RageInputDevice.h" // for InputDevice
|
#include "RageInputDevice.h" // for InputDevice
|
||||||
|
#include "arch/RageDriver.h"
|
||||||
|
|
||||||
class InputHandler
|
class InputHandler: public RageDriver
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
InputHandler() { m_iInputsSinceUpdate = 0; }
|
InputHandler() { m_iInputsSinceUpdate = 0; }
|
||||||
@@ -68,14 +69,12 @@ private:
|
|||||||
int m_iInputsSinceUpdate;
|
int m_iInputsSinceUpdate;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef InputHandler *(*CreateInputHandlerFn)();
|
|
||||||
struct RegisterInputHandler
|
struct RegisterInputHandler
|
||||||
{
|
{
|
||||||
static map<istring, CreateInputHandlerFn> *g_pRegistrees;
|
RegisterInputHandler( const istring &sName, CreateRageDriverFn pfn );
|
||||||
RegisterInputHandler( const istring &sName, CreateInputHandlerFn pfn );
|
|
||||||
};
|
};
|
||||||
#define REGISTER_INPUT_HANDLER_CLASS2( name, x ) \
|
#define REGISTER_INPUT_HANDLER_CLASS2( name, x ) \
|
||||||
static RegisterInputHandler register_##name( #name, CreateClass<InputHandler_##x, InputHandler> )
|
static RegisterInputHandler register_##name( #name, CreateClass<InputHandler_##x, RageDriver> )
|
||||||
#define REGISTER_INPUT_HANDLER_CLASS( name ) REGISTER_INPUT_HANDLER_CLASS2( name, name )
|
#define REGISTER_INPUT_HANDLER_CLASS( name ) REGISTER_INPUT_HANDLER_CLASS2( name, name )
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user