-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathentityfactory.inl
More file actions
40 lines (39 loc) · 1.65 KB
/
entityfactory.inl
File metadata and controls
40 lines (39 loc) · 1.65 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
37
38
39
40
template<typename Function>
void EntityFactory::addDataType(const std::string& dataTypeName, Function parser)
{
FEA_ASSERT(mRegistrators.find(dataTypeName) == mRegistrators.end(),"Trying to add data type '" + dataTypeName + "' but it already exists!");
using Type = typename std::result_of<Function(const Parameters&)>::type;
//Make attribute registrator
mRegistrators[dataTypeName] = [this, parser](const std::string& attributeName)->Parser
{
mManager.registerAttribute<Type>(attributeName);
//Make parser
return [this, parser, attributeName](const std::string& params)->Setter
{
auto value = parser(splitByDelimeter(params, ','));
//make setter.
return [attributeName, value](EntityPtr& entity)
{
entity->setAttribute<Type>(attributeName, value);
};
};
};
}
template<typename Type>
void EntityFactory::addDataType(const std::string& dataTypeName)
{
FEA_ASSERT(mRegistrators.find(dataTypeName) == mRegistrators.end(),"Trying to add data type '" + dataTypeName + "' but it already exists!");
//Make attribute registrator
mRegistrators[dataTypeName] = [this](const std::string& attributeName)->Parser
{
mManager.registerAttribute<Type>(attributeName);
//Make parser
return [attributeName](const std::string& params)->Setter
{
FEA_ASSERT(1 == 0, "Trying to register a template where a default value has been added to the attribute '" + attributeName + "' which doesn't have a parser function!");
return [](EntityPtr& entity)
{
};
};
};
}