chigraph  master
Systems programming language written for beginners in LLVM
NodeInstance.hpp
Go to the documentation of this file.
1 
4 #ifndef CHI_NODE_INSTANCE_HPP
5 #define CHI_NODE_INSTANCE_HPP
6 
7 #pragma once
8 
9 #include "chi/Fwd.hpp"
10 
11 #include <vector>
12 
13 #include <boost/uuid/uuid.hpp>
14 #include <boost/uuid/uuid_generators.hpp>
15 #include <boost/uuid/uuid_io.hpp>
16 
17 namespace chi {
19 struct NodeInstance {
27  NodeInstance(GraphFunction* func, std::unique_ptr<NodeType> nodeType, float posX, float posY,
28  boost::uuids::uuid nodeID = boost::uuids::random_generator()());
29 
31  ~NodeInstance();
32 
34  NodeInstance(NodeInstance&&) = default;
35 
37  explicit NodeInstance(const NodeInstance& other,
38  boost::uuids::uuid id = boost::uuids::random_generator()());
39 
42  void setType(std::unique_ptr<NodeType> newType);
43 
46  NodeType& type() { return *mType; }
49  const NodeType& type() const { return *mType; }
52  float x() const { return mX; }
55  float y() const { return mY; }
58  void setX(float newX) { mX = newX; }
61  void setY(float newY) { mY = newY; }
64  boost::uuids::uuid id() const { return mId; }
65 
68  std::string stringId() const { return boost::uuids::to_string(id()); }
69 
70  // connections
71 
72  // TODO: better documentation here and OOify
74  std::vector<std::vector<std::pair<NodeInstance*, size_t>>> inputExecConnections;
75 
77  std::vector<std::pair<NodeInstance*, size_t>> inputDataConnections;
78 
80  std::vector<std::pair<NodeInstance*, size_t>> outputExecConnections;
81 
83  std::vector<std::vector<std::pair<NodeInstance*, size_t>>> outputDataConnections;
84 
87  Context& context() const { return *mContext; }
88 
91  GraphFunction& function() const { return *mFunction; }
92 
95  GraphModule& module() const { return *mGraphModule; }
96 
97 private:
98  std::unique_ptr<NodeType> mType;
99 
100  float mX = 0.f;
101  float mY = 0.0;
102 
103  boost::uuids::uuid mId;
104 
105  Context* mContext;
106  GraphFunction* mFunction = nullptr;
107  GraphModule* mGraphModule = nullptr;
108 };
109 
113 
121 Result connectData(NodeInstance& lhs, size_t lhsConnID, NodeInstance& rhs, size_t rhsConnID);
122 
130 Result connectExec(NodeInstance& lhs, size_t lhsConnID, NodeInstance& rhs, size_t rhsConnID);
131 
138 Result disconnectData(NodeInstance& lhs, size_t lhsConnID, NodeInstance& rhs);
139 
144 Result disconnectExec(NodeInstance& lhs, size_t lhsConnID);
145 
147 
148 } // namespace chi
149 
150 #endif // CHI_NODE_INSTANCE_HPP
std::vector< std::vector< std::pair< NodeInstance *, size_t > > > inputExecConnections
The connections that lead to this node, exec.
this is an AST-like representation of a function in a graph It is used for IDE-like behavior...
Forward declares all the chigraph data types.
void setType(std::unique_ptr< NodeType > newType)
Set the type of the node instance.
std::string stringId() const
Get the ID as a string.
std::vector< std::vector< std::pair< NodeInstance *, size_t > > > outputDataConnections
The connections that lead out of this node, data.
NodeType & type()
Get the type of the instance.
An instance of a node.
std::vector< std::pair< NodeInstance *, size_t > > inputDataConnections
The connections that go into this node, data.
GraphModule & module() const
Get the containing GraphModule.
NodeInstance(GraphFunction *func, std::unique_ptr< NodeType > nodeType, float posX, float posY, boost::uuids::uuid nodeID=boost::uuids::random_generator()())
Construct a nodeinstace with a type location and an ID, usually called from GraphFunction::insertNode...
A generic node type.
Definition: NodeType.hpp:19
The class that handles the loading, creation, storing, and compilation of modules It also stores a LL...
Definition: Context.hpp:55
void setY(float newY)
Set the Y location of the instance.
~NodeInstance()
Destructor.
Result disconnectData(NodeInstance &lhs, size_t lhsConnID, NodeInstance &rhs)
Disconnect a data connection.
Result connectData(NodeInstance &lhs, size_t lhsConnID, NodeInstance &rhs, size_t rhsConnID)
Connects two nodes&#39; data connections.
Result connectExec(NodeInstance &lhs, size_t lhsConnID, NodeInstance &rhs, size_t rhsConnID)
Connects two nodes&#39; exec connections.
std::vector< std::pair< NodeInstance *, size_t > > outputExecConnections
The connections that go out of this node, exec.
Module that holds graph functions.
Definition: GraphModule.hpp:16
Result disconnectExec(NodeInstance &lhs, size_t lhsConnID)
Disconnect a exec connection.
float x() const
Get the X location of the instance.
The namespace where chigraph lives.
Context & context() const
Get the containing Context object.
const NodeType & type() const
Get the type of the instance, const version.
boost::uuids::uuid id() const
Get the ID of the instance, unique to the graph.
The result object, used for identifiying errors with good diagnostics.
Definition: Result.hpp:72
void setX(float newX)
Set the X location of the instance.
float y() const
Get the Y location of the instance.