| 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
chi::NodeInstance::inputExecConnections
std::vector< std::vector< std::pair< NodeInstance *, size_t > > > inputExecConnections
The connections that lead to this node, exec.
Definition: NodeInstance.hpp:74
chi::GraphFunction
this is an AST-like representation of a function in a graph It is used for IDE-like behavior...
Definition: GraphFunction.hpp:23
Fwd.hpp
Forward declares all the chigraph data types.
chi::NodeInstance::setType
void setType(std::unique_ptr< NodeType > newType)
Set the type of the node instance.
Definition: NodeInstance.cpp:56
chi::NodeInstance::stringId
std::string stringId() const
Get the ID as a string.
Definition: NodeInstance.hpp:68
chi::NodeInstance::outputDataConnections
std::vector< std::vector< std::pair< NodeInstance *, size_t > > > outputDataConnections
The connections that lead out of this node, data.
Definition: NodeInstance.hpp:83
chi::NodeInstance::type
NodeType & type()
Get the type of the instance.
Definition: NodeInstance.hpp:46
chi::NodeInstance
An instance of a node.
Definition: NodeInstance.hpp:19
chi::NodeInstance::inputDataConnections
std::vector< std::pair< NodeInstance *, size_t > > inputDataConnections
The connections that go into this node, data.
Definition: NodeInstance.hpp:77
chi::NodeInstance::module
GraphModule & module() const
Get the containing GraphModule.
Definition: NodeInstance.hpp:95
chi::NodeInstance::NodeInstance
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...
Definition: NodeInstance.cpp:14
chi::NodeType
A generic node type.
Definition: NodeType.hpp:19
chi::Context
The class that handles the loading, creation, storing, and compilation of modules It also stores a LL...
Definition: Context.hpp:55
chi::NodeInstance::setY
void setY(float newY)
Set the Y location of the instance.
Definition: NodeInstance.hpp:61
chi::NodeInstance::~NodeInstance
~NodeInstance()
Destructor.
chi::disconnectData
Result disconnectData(NodeInstance &lhs, size_t lhsConnID, NodeInstance &rhs)
Disconnect a data connection.
Definition: NodeInstance.cpp:229
chi::connectData
Result connectData(NodeInstance &lhs, size_t lhsConnID, NodeInstance &rhs, size_t rhsConnID)
Connects two nodes&#39; data connections.
Definition: NodeInstance.cpp:128
chi::connectExec
Result connectExec(NodeInstance &lhs, size_t lhsConnID, NodeInstance &rhs, size_t rhsConnID)
Connects two nodes&#39; exec connections.
Definition: NodeInstance.cpp:186
chi::NodeInstance::outputExecConnections
std::vector< std::pair< NodeInstance *, size_t > > outputExecConnections
The connections that go out of this node, exec.
Definition: NodeInstance.hpp:80
chi::GraphModule
Module that holds graph functions.
Definition: GraphModule.hpp:16
chi::disconnectExec
Result disconnectExec(NodeInstance &lhs, size_t lhsConnID)
Disconnect a exec connection.
Definition: NodeInstance.cpp:294
chi::NodeInstance::x
float x() const
Get the X location of the instance.
Definition: NodeInstance.hpp:52
chi
The namespace where chigraph lives.
Definition: BitcodeParser.hpp:12
chi::NodeInstance::context
Context & context() const
Get the containing Context object.
Definition: NodeInstance.hpp:87
chi::NodeInstance::type
const NodeType & type() const
Get the type of the instance, const version.
Definition: NodeInstance.hpp:49
chi::NodeInstance::id
boost::uuids::uuid id() const
Get the ID of the instance, unique to the graph.
Definition: NodeInstance.hpp:64
chi::Result
The result object, used for identifiying errors with good diagnostics.
Definition: Result.hpp:72
chi::NodeInstance::setX
void setX(float newX)
Set the X location of the instance.
Definition: NodeInstance.hpp:58
chi::NodeInstance::y
float y() const
Get the Y location of the instance.
Definition: NodeInstance.hpp:55