Cerata
A library to generate structural hardware designs
edge.h
1 // Copyright 2018-2019 Delft University of Technology
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma once
16 
17 #include <algorithm>
18 #include <iostream>
19 #include <utility>
20 #include <memory>
21 #include <string>
22 #include <vector>
23 
24 #include "cerata/utils.h"
25 #include "cerata/node.h"
26 #include "cerata/array.h"
27 #include "cerata/pool.h"
28 
29 namespace cerata {
30 
31 // Forward decl.
32 class Component;
33 
35 class Edge : public Named {
36  public:
38  static std::shared_ptr<Edge> Make(const std::string &name, Node *dst, Node *src);
39 
41  [[nodiscard]] std::optional<Node *> GetOtherNode(const Node &node) const;
42 
44  [[nodiscard]] Node *dst() const { return dst_; }
46  [[nodiscard]] Node *src() const { return src_; }
47 
48  protected:
55  Edge(std::string name, Node *dst, Node *src);
56 
61 };
62 
69 std::shared_ptr<Edge> Connect(Node *dst, Node *src);
70 
77 std::shared_ptr<Edge> Connect(Node *dst, const std::shared_ptr<Node> &src);
78 
85 std::shared_ptr<Edge> Connect(const std::shared_ptr<Node> &dst, Node *src);
86 
93 std::shared_ptr<Edge> Connect(const std::shared_ptr<Node> &dst, const std::shared_ptr<Node> &src);
94 
101 std::shared_ptr<Edge> Connect(Node *dst, std::string str);
102 
103 // Connect operators:
104 
106 std::shared_ptr<Edge> operator<<=(Node *dst, const std::shared_ptr<Node> &src);
108 std::shared_ptr<Edge> operator<<=(const std::shared_ptr<Node> &dst, const std::shared_ptr<Node> &src);
110 std::shared_ptr<Edge> operator<<=(const std::shared_ptr<Node> &dst, Node *src);
111 
113 std::vector<Edge *> GetAllEdges(const Graph &graph);
114 
123 Signal *AttachSignalToNode(Component *comp, NormalNode *node, NodeMap *rebinding, std::string name = "");
124 
133 
134 } // namespace cerata
cerata::Component
A Component graph.
Definition: graph.h:158
cerata::GetAllEdges
std::vector< Edge * > GetAllEdges(const Graph &graph)
Obtain all edges in a graph.
Definition: edge.cc:180
cerata::operator<<=
std::shared_ptr< Edge > operator<<=(Node *dst, const std::shared_ptr< Node > &src)
Create an edge, connecting the src node to the dst node.
Definition: edge.cc:168
cerata::SignalArray
An array of signal nodes.
Definition: array.h:100
cerata::Edge::dst
Node * dst() const
Return the destination node.
Definition: edge.h:44
cerata::Edge::src
Node * src() const
Return the source node.
Definition: edge.h:46
cerata::Graph
A graph representing a hardware structure.
Definition: graph.h:37
cerata::NodeArray
An array of nodes.
Definition: array.h:31
cerata::Signal
A Signal Node.
Definition: signal.h:30
cerata
Contains every Cerata class, function, etc...
Definition: api.h:41
cerata::AttachSignalToNode
Signal * AttachSignalToNode(Component *comp, NormalNode *node, NodeMap *rebinding, std::string name)
Attach a Signal to a Node, redirecting all edges through the new Signal.
Definition: edge.cc:254
cerata::Node
A node.
Definition: node.h:42
cerata::NodeMap
std::unordered_map< const Node *, Node * > NodeMap
A mapping from one object to another object, used in e.g. type generic rebinding.
Definition: node.h:135
cerata::Edge::Make
static std::shared_ptr< Edge > Make(const std::string &name, Node *dst, Node *src)
Shorthand to get a smart pointer to an edge.
Definition: edge.cc:36
cerata::Named::name
std::string name() const
Return the name of the object.
Definition: utils.h:45
cerata::Edge
A directed edge between two nodes.
Definition: edge.h:35
cerata::NormalNode
A single-input, multiple-outputs node.
Definition: node.h:167
cerata::Edge::src_
Node * src_
Source node.
Definition: edge.h:60
cerata::Named
Convenience structure for anything that is named. Names are case-sensitive.
Definition: utils.h:40
cerata::Edge::dst_
Node * dst_
Destination node.
Definition: edge.h:58
cerata::AttachSignalArrayToNodeArray
SignalArray * AttachSignalArrayToNodeArray(Component *comp, NodeArray *array, NodeMap *rebinding)
Attach a SignalArray to a Node, redirecting all edges through the new SignalArray.
Definition: edge.cc:327
cerata::Edge::Edge
Edge(std::string name, Node *dst, Node *src)
Construct a new edge.
Definition: edge.cc:29
cerata::Edge::GetOtherNode
std::optional< Node * > GetOtherNode(const Node &node) const
Get the node opposite to the other edge node.
Definition: edge.cc:231
cerata::Connect
std::shared_ptr< Edge > Connect(Node *dst, Node *src)
Connect two nodes, returns the corresponding edge.
Definition: edge.cc:68