-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathVisualNodeFactory.cpp
More file actions
72 lines (61 loc) · 2.07 KB
/
VisualNodeFactory.cpp
File metadata and controls
72 lines (61 loc) · 2.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "VisualNodeFactory.h"
using namespace VisNodeSys;
#ifdef VISUAL_NODE_SYSTEM_SHARED
extern "C" __declspec(dllexport) void* GetNodeFactory()
{
return NodeFactory::GetInstancePointer();
}
#endif
NodeFactory::NodeFactory() {}
NodeFactory::~NodeFactory() {}
bool NodeFactory::RegisterNodeType(const std::string& Type,
std::function<Node* ()> Constructor,
std::function<Node* (const Node&)> CopyConstructor)
{
if (Type.empty() || Constructor == nullptr || CopyConstructor == nullptr)
return false;
auto ConstructorIterator = Constructors.find(Type);
if (ConstructorIterator != Constructors.end())
return false;
Constructors[Type] = Constructor;
CopyConstructors[Type] = CopyConstructor;
return true;
}
Node* NodeFactory::CreateNode(const std::string& Type) const
{
auto ConstructorIterator = Constructors.find(Type);
if (ConstructorIterator == Constructors.end())
return nullptr;
return ConstructorIterator->second();
}
Node* NodeFactory::CopyNode(const std::string& Type, const Node& Node) const
{
auto CopyConstructorIterator = CopyConstructors.find(Type);
if (CopyConstructorIterator == CopyConstructors.end())
return nullptr;
return CopyConstructorIterator->second(Node);
}
std::pair<size_t, size_t> NodeFactory::GetSocketCount(std::string NodeClassName)
{
auto NodeClassNameToSocketCountIterator = NodeClassNameToSocketCount.find(NodeClassName);
if (NodeClassNameToSocketCountIterator != NodeClassNameToSocketCount.end())
{
return NodeClassNameToSocketCountIterator->second;
}
else
{
Node* TemporaryNode = CreateNode(NodeClassName);
if (TemporaryNode != nullptr)
{
size_t InputCount = TemporaryNode->GetInputSocketCount();
size_t OutputCount = TemporaryNode->GetOutputSocketCount();
NodeClassNameToSocketCount[NodeClassName] = std::pair<size_t, size_t>(InputCount, OutputCount);
delete TemporaryNode;
return std::pair<size_t, size_t>(InputCount, OutputCount);
}
else
{
return std::pair<size_t, size_t>(0, 0);
}
}
}