-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathVisualNodeFactory.h
More file actions
38 lines (31 loc) · 1.61 KB
/
VisualNodeFactory.h
File metadata and controls
38 lines (31 loc) · 1.61 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
#pragma once
#include "VisualNode.h"
namespace VisNodeSys
{
class VISUAL_NODE_SYSTEM_API NodeFactory
{
SINGLETON_PRIVATE_PART(NodeFactory)
friend class Node;
std::unordered_map<std::string, std::function<Node* ()>> Constructors;
std::unordered_map<std::string, std::function<Node* (const Node&)>> CopyConstructors;
std::unordered_map<std::string, std::pair<size_t, size_t>> NodeClassNameToSocketCount;
// Retrieves the expected number of input and output sockets for a given node type,
// as defined by its current C++ class implementation.
// It is used to validate loaded node data (e.g., from a JSON file)
// If a node class's socket structure(number of inputs / outputs) has changed since a file was saved,
// loading that file could lead to inconsistencies or crashes.
// TO-DO: Implement a more robust NodeClass integrity check. With socket type validation and more.
std::pair<size_t, size_t> GetSocketCount(std::string NodeClassName);
public:
SINGLETON_PUBLIC_PART(NodeFactory)
bool RegisterNodeType(const std::string& Type, std::function<Node* ()> Constructor, std::function<Node* (const Node&)> CopyConstructor);
Node* CreateNode(const std::string& Type) const;
Node* CopyNode(const std::string& Type, const Node& Node) const;
};
#ifdef VISUAL_NODE_SYSTEM_SHARED
extern "C" __declspec(dllexport) void* GetNodeFactory();
#define NODE_FACTORY (*static_cast<VisNodeSys::NodeFactory*>(VisNodeSys::GetNodeFactory()))
#else
#define NODE_FACTORY VisNodeSys::NodeFactory::GetInstance()
#endif
}