Enzo
Loading...
Searching...
No Matches
Network.h
1#pragma once
2#include "Engine/Core/Types.h"
3#include "Engine/Network/NetworkPath.h"
4#include "Engine/Network/Node.h"
5#include "Engine/Network/Scope.h"
6#include "Engine/NetworkGraph/NetworkGraph.h"
7#include <memory>
8#include <ranges>
9#include <string>
10#include <unordered_map>
11#include <utility>
12#include <vector>
13
14namespace enzo::nt {
30{
31 public:
32 using NodeStore = std::unordered_map<NodeId, std::unique_ptr<Node>>;
33
34 Network() { clear(); }
35
36 Network(const Network&) = delete;
37 Network& operator=(const Network&) = delete;
38
43 auto nodes()
44 {
45 return std::views::transform(nodes_, [](NodeStore::value_type& entry) {
46 return std::pair<const NodeId, Node&>(entry.first, *entry.second);
47 });
48 }
49
52 Node& getNode(NodeId nodeId);
53
55 bool isValidNode(NodeId nodeId) const;
56
59 Node* getNodeAtPath(const Path& path);
60
63 std::vector<NodeId> getChildNodeIds(const Path& scope);
64
67 Node& createNode(NodeId nodeId, const NodeType& nodeType, const Path& path);
68
71 void deleteNode(NodeId nodeId);
72
74 NodeId reserveNodeId() { return ++maxNodeId_; }
75
87 Node* findNode(const NetworkPath& path, NodeId fromNode = nullNode);
88
94 std::weak_ptr<prm::NodeParameter>
95 findParameter(const NetworkPath& path, NodeId fromNode = nullNode);
100 Scope* getScope(const Path& path);
101
103 NetworkGraph& graph() { return graph_; }
104
106 void clear();
107
108 private:
109 // A scope exists only because a node holds it, so it opens and closes with that node
110 void createScope(const Path& path, const std::string& scopeType);
111 void deleteScope(const Path& path);
112
113 // Every node, flat, with nesting carried in their paths
114 NodeStore nodes_;
115 NetworkGraph graph_;
116 // Every scope that exists, keyed by the path it sits at, always holding the root
117 std::unordered_map<std::string, Scope> scopes_;
118 // The highest node id handed out so far
119 NodeId maxNodeId_ = 0;
120};
121} // namespace enzo::nt
Basic attribute, parameter, and node types for Enzo.
uint64_t NodeId
The unique ID assigned to each node in the network.
Definition Types.h:306
A path that references a network entity, either a node or a parameter on a node.
Definition NetworkPath.h:20
A default path class for creation and manipulation of tree-based paths.
Definition Path.h:14
The single owner of the network's wiring and dependencies.
Definition NetworkGraph.h:24
Every node in a scene, their wiring, and the scopes they live in.
Definition Network.h:30
void deleteNode(NodeId nodeId)
Drops a node, the scope it held, and its wiring.
Definition Network.cpp:55
Node * getNodeAtPath(const Path &path)
Returns the node at an exact path, or null when no node is there.
Definition Network.cpp:26
Node & createNode(NodeId nodeId, const NodeType &nodeType, const Path &path)
Builds a node, stores it, and opens the child scope its type declares.
Definition Network.cpp:43
std::vector< NodeId > getChildNodeIds(const Path &scope)
Returns the ids of the nodes living directly inside a scope, in no particular order.
Definition Network.cpp:35
void clear()
Empties the network back to a bare root scope.
Definition Network.cpp:77
bool isValidNode(NodeId nodeId) const
Returns whether a node with the given id is present.
Definition Network.cpp:20
NetworkGraph & graph()
Returns the wiring and dependencies between the nodes.
Definition Network.h:103
NodeId reserveNodeId()
Returns an id no node has used yet.
Definition Network.h:74
Node & getNode(NodeId nodeId)
Returns the node with the given id.
Definition Network.cpp:7
std::weak_ptr< prm::NodeParameter > findParameter(const NetworkPath &path, NodeId fromNode=nullNode)
Resolves a parameter reference to its parameter.
Definition Network.cpp:102
Node * findNode(const NetworkPath &path, NodeId fromNode=nullNode)
Resolves a node reference to its node.
Definition Network.cpp:88
Scope * getScope(const Path &path)
Returns the scope at a path, or null when no scope sits there.
Definition Network.cpp:64
auto nodes()
Returns an iterable range over every node, yielding {NodeId, Node&} pairs.
Definition Network.h:43
The unique runtime representation of a node.
Definition Node.h:18
One place nodes live, either the root or the inside of a node that holds one.
Definition Scope.h:26
Everything every node of one kind shares.
Definition NodeType.h:39