-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathObjectFactory.cpp
More file actions
36 lines (32 loc) · 1.07 KB
/
ObjectFactory.cpp
File metadata and controls
36 lines (32 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#ifndef OBJECTFACTORY_H
#include "ObjectFactory.h"
#endif
#include <cassert>
#include <stdio.h>
//----------------------------------------------------------------------------------------------
UserObject* ObjectFactory::Create(const string& p_typeName)
{
_ASSERTE(!p_typeName.empty());
ObjectFactoryMap::iterator where;
if(m_cNameToFullNameTable.find(p_typeName) != m_cNameToFullNameTable.end())
{
where = m_factories.find(m_cNameToFullNameTable[p_typeName]);
}
else
{
where = m_factories.find(p_typeName);
}
if (where == m_factories.end())
{
char buffer[256];
sprintf_s(buffer, sizeof(buffer), "Failed to retrieve object '%s'", p_typeName.c_str());
throw std::exception(buffer);
}
return where->second();
}
//----------------------------------------------------------------------------------------------
const string& ObjectFactory::FromCName(const string& p_cName)
{
_ASSERTE(m_cNameToFullNameTable.find(p_cName) != m_cNameToFullNameTable.end());
return m_cNameToFullNameTable[p_cName];
}