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;
|
||||
RegisterInputHandler::RegisterInputHandler( const istring &sName, CreateInputHandlerFn pfn )
|
||||
static DriverList g_pRegistrees;
|
||||
RegisterInputHandler::RegisterInputHandler( const istring &sName, CreateRageDriverFn pfn )
|
||||
{
|
||||
if( g_pRegistrees == NULL )
|
||||
g_pRegistrees = new map<istring, CreateInputHandlerFn>;
|
||||
|
||||
ASSERT( g_pRegistrees->find(sName) == g_pRegistrees->end() );
|
||||
(*g_pRegistrees)[sName] = pfn;
|
||||
g_pRegistrees.Add( sName, pfn );
|
||||
}
|
||||
|
||||
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 )
|
||||
{
|
||||
map<istring, CreateInputHandlerFn>::const_iterator iter = RegisterInputHandler::g_pRegistrees->find( istring(*s) );
|
||||
|
||||
if( iter == RegisterInputHandler::g_pRegistrees->end() )
|
||||
RageDriver *pDriver = g_pRegistrees.Create( *s );
|
||||
if( pDriver == NULL )
|
||||
{
|
||||
LOG->Trace( "Unknown Input Handler name: %s", s->c_str() );
|
||||
continue;
|
||||
}
|
||||
InputHandler *ret = (iter->second)();
|
||||
|
||||
InputHandler *ret = dynamic_cast<InputHandler *>( pDriver );
|
||||
DEBUG_ASSERT( ret );
|
||||
Add.push_back( ret );
|
||||
}
|
||||
|
||||
@@ -21,8 +21,9 @@
|
||||
* We don't need this now; I'll write it if it becomes needed.)
|
||||
*/
|
||||
#include "RageInputDevice.h" // for InputDevice
|
||||
#include "arch/RageDriver.h"
|
||||
|
||||
class InputHandler
|
||||
class InputHandler: public RageDriver
|
||||
{
|
||||
public:
|
||||
InputHandler() { m_iInputsSinceUpdate = 0; }
|
||||
@@ -68,14 +69,12 @@ private:
|
||||
int m_iInputsSinceUpdate;
|
||||
};
|
||||
|
||||
typedef InputHandler *(*CreateInputHandlerFn)();
|
||||
struct RegisterInputHandler
|
||||
{
|
||||
static map<istring, CreateInputHandlerFn> *g_pRegistrees;
|
||||
RegisterInputHandler( const istring &sName, CreateInputHandlerFn pfn );
|
||||
RegisterInputHandler( const istring &sName, CreateRageDriverFn pfn );
|
||||
};
|
||||
#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 )
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user