47 lines
849 B
C++
47 lines
849 B
C++
/*
|
|
* ModuleFactory.cpp
|
|
*
|
|
* Created on: 2011-8-30
|
|
* Author: dev
|
|
*/
|
|
#include "ModuleFactory.h"
|
|
// #include "Log.h"
|
|
#include <cassert>
|
|
|
|
namespace pai {
|
|
namespace module {
|
|
|
|
CModuleFactory* CModuleFactory::Instance()
|
|
{
|
|
static CModuleFactory f;
|
|
return &f;
|
|
}
|
|
|
|
CModule* CModuleFactory::CreateModule(const std::string& typeID)
|
|
{
|
|
std::map<std::string,pCreateObjectFunction>::iterator it=m_mapCreateFunctions.find(typeID);
|
|
if(it!=m_mapCreateFunctions.end())
|
|
{
|
|
return (*(it->second))();
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
bool CModuleFactory::Register(const std::string& typeID,pCreateObjectFunction pFunc)
|
|
{
|
|
// assert(m_mapCreateFunctions.end()==m_mapCreateFunctions.find(typeID));
|
|
|
|
if(m_mapCreateFunctions.end()==m_mapCreateFunctions.find(typeID)){
|
|
|
|
m_mapCreateFunctions.insert(make_pair(typeID,pFunc));
|
|
|
|
return true;
|
|
}else
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
}
|
|
}
|