Atoms Crowd  7.0.0
NetworkManager.h
1 #pragma once
2 // ===========================================================================
3 // Copyright (c) 2015 Toolchefs Ltd. All rights reserved.
4 //
5 // Use of this software is subject to the terms of the Toolchefs license
6 // agreement provided at the time of installation or download, or which
7 // otherwise accompanies this software in either electronic or hard copy form.
8 // ===========================================================================
9 
10 #include <AtomsGraph/Globals.h>
11 #include <AtomsGraph/Node.h>
12 #include <AtomsGraph/Port.h>
13 #include <AtomsGraph/PortTemplate.h>
14 
15 #include <unordered_map>
16 #include <map>
17 #include <string>
18 
19 namespace AtomsGraph
20 {
21 
23  /*
24  This class defines a dependency graph
25  */
26  class ATOMSGRAPH_EXPORT NetworkManager
27  {
28  public:
29 
32 
35 
38 
41 
43 
48  Node* createNode(const std::string& typeName, const std::string& name);
49 
51 
55  bool renameNode(const std::string& name, const std::string& newName);
56 
58 
62  void addNode(Node* node, const std::string& name);
63 
65 
68  void deleteNode(const std::string& name);
69 
71  /*
72  \param sourceNode Source node name
73  \param sourceAttribute Source node port
74  \param destinationNode Destination node name
75  \param destinationAttribute Destination node port name
76  */
77  bool connectAttr(const std::string& sourceNode, const std::string& sourceAttribute,
78  const std::string& destinationNode, const std::string& destinationAttribute);
79 
81  /*
82  \param sourceNode Source node name
83  \param sourceAttribute Source node port
84  \param destinationNode Destination node name
85  \param destinationAttribute Destination node port name
86  */
87  bool disconnectAttr(const std::string& sourceNode, const std::string& sourceAttribute,
88  const std::string& destinationNode, const std::string& destinationAttribute);
89 
91 
94  Node* getNode(const std::string& name);
95 
97 
100  template<class T>
101  T* getNode(const std::string& name);
102 
104 
107  Node * getNodeByType(const unsigned int id);
108 
110  std::vector<Node*> getAllNodes();
111 
113  std::vector<std::string> getNodeNames();
114 
116 
121  const std::string& nodeName,
122  const AtomsGraph::ComputeData* computeData,
123  bool multithread=false,
124  bool useNetworkCache=false
125  );
126 
129 
131  void cleanNetwork();
132 
134 
139  void cacheNodeNetwork(const std::string& nodeName);
140 
142  /*
143  \param nodeName Node name
144  */
145  void clearNodeNetworkCache(const std::string& nodeName);
146 
149 
151  void reset();
152 
155 
158 
159  protected:
160 
162  std::string getUniqueName(const std::string& name);
163 
164  private:
165 
167  std::map<std::string, Node*> m_nodes;
168 
170  std::map<std::string, std::vector<Node*>> m_networkCache;
171 
173 
177  std::map<std::string, std::pair<bool, Node*>> m_nodesCached;
178  };
179 }
180 
181 #include "NetworkManager.impl.h"
Definition: Node.h:21
Network manager class.
Definition: NetworkManager.h:27
void cleanNetwork()
Deletes all the nodes.
std::string getUniqueName(const std::string &name)
Generates an unique node name.
NetworkManager & operator=(const NetworkManager &other)
Assign operator.
std::vector< std::string > getNodeNames()
Gets all node names of the graph.
void setAllNodeDirty()
Set all nodes as dirty.
void reset()
Reset the network without deleting the node cached.
Node * createNode(const std::string &typeName, const std::string &name)
Creates a node inside this graph.
void clearNodeCache()
Clear the node cache removing all the nodes that are not in use.
bool disconnectAttr(const std::string &sourceNode, const std::string &sourceAttribute, const std::string &destinationNode, const std::string &destinationAttribute)
Disconnects two nodes.
bool connectAttr(const std::string &sourceNode, const std::string &sourceAttribute, const std::string &destinationNode, const std::string &destinationAttribute)
Connects two nodes.
void clearNodeNetworkCaches()
Clear all caches.
void deleteNode(const std::string &name)
Deletes a node.
bool renameNode(const std::string &name, const std::string &newName)
Renames a node inside this graph.
NetworkManager(const NetworkManager &other)
Copy constructor.
void clearNodeNetworkCache(const std::string &nodeName)
Clear a cache.
Node * getNode(const std::string &name)
Gets the node with the given name.
NetworkManager()
Constructor.
NetworkManager clone() const
Clones the graph.
void computeNode(const std::string &nodeName, const AtomsGraph::ComputeData *computeData, bool multithread=false, bool useNetworkCache=false)
Evaluates a node and the incoming graph.
std::vector< Node * > getAllNodes()
Gets all nodes of the graph.
void cacheNodeNetwork(const std::string &nodeName)
Cache nodes order.
void addNode(Node *node, const std::string &name)
Adds a node to the graph.
Node * getNodeByType(const unsigned int id)
Gets the node with the given name.
Definition: Node.h:31
AtomsGraph namespace.
Definition: PosePort.h:15