5367ebddbd
- aggiornamento prototipi.
54 lines
1.8 KiB
C++
54 lines
1.8 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2014-2014
|
|
//----------------------------------------------------------------------------
|
|
// File : EgtExecMgr.h Data : 21.03.14 Versione : 1.5c3
|
|
// Contenuto : Classe ExecManager.
|
|
// Per facilitare l'implementazione di ICmdExecutor.
|
|
//
|
|
//
|
|
// Modifiche : 21.03.14 DS Creazione modulo.
|
|
//
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
#pragma once
|
|
|
|
#include <string>
|
|
#include <unordered_map>
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
enum { ER_ERR = 0, ER_OK = 1, ER_MISSING = 2 } ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
template <class T>
|
|
class ExecManager
|
|
{
|
|
public :
|
|
typedef bool ( T::*Exec) ( const std::string& sCmd2, const STRVECTOR& vsParams) ;
|
|
|
|
public :
|
|
bool Init( int nBuckets)
|
|
{ m_pExecMap.clear() ;
|
|
m_pExecMap.rehash( nBuckets) ;
|
|
return true ; }
|
|
|
|
bool Insert( const std::string& sName, Exec eFunc)
|
|
{ return m_pExecMap.insert( std::pair< std::string, Exec>( sName, eFunc)).second ; }
|
|
|
|
int Execute( T& Executor, const std::string& sCmd1, const std::string& sCmd2, const STRVECTOR& vsParams)
|
|
{ const auto Iter = m_pExecMap.find( sCmd1) ;
|
|
if ( Iter != m_pExecMap.end() && (Iter->second) != nullptr) {
|
|
if ( ( Executor.*(Iter->second))( sCmd2, vsParams))
|
|
return ER_OK ;
|
|
else
|
|
return ER_ERR ;
|
|
}
|
|
else
|
|
return ER_MISSING ; }
|
|
|
|
private :
|
|
typedef std::unordered_map< std::string, Exec> KeyExecMap ;
|
|
KeyExecMap m_pExecMap ;
|
|
} ;
|