21#ifndef HEDGEHOG_GRAPH_OUTPUTS_MANAGEMENT_ABSTRACTION_H
22#define HEDGEHOG_GRAPH_OUTPUTS_MANAGEMENT_ABSTRACTION_H
25#include "../../parts/graph_sink.h"
27#include "../base/input_output/slot_abstraction.h"
28#include "../base/input_output/sender_abstraction.h"
29#include "../base/input_output/notifier_abstraction.h"
30#include "../base/input_output/receiver_abstraction.h"
32#include "../../../tools/concepts.h"
33#include "../../implementors/concrete_implementor/graph/graph_notifier.h"
34#include "../../implementors/concrete_implementor/graph/graph_sender.h"
40namespace abstraction {
44template<
class ...Outputs>
57 SenderAbstraction<Outputs>(std::make_shared<implementor::GraphSender<Outputs>>())...,
76 template<
class OutputDataType>
80 assert(outputAsNotifier !=
nullptr && outputAsSender !=
nullptr);
82 if (
sink_ !=
nullptr) {
86 for (
auto receiver : sinkAsReceiver->receivers()) {
87 for (
auto sender : outputAsSender->senders()) {
88 sender->addReceiver(receiver);
89 receiver->addSender(sender);
93 for (
auto slot : sinkAsSlot->slots()) {
94 for (
auto notifier : outputAsNotifier->notifiers()) {
96 notifier->addSlot(slot);
106 for (
auto slot : sinkAsSlot->slots()) {
107 for (
auto outputNotifier :
sink_->connectedNotifiers()) {
108 for (
auto notifier : outputNotifier->notifiers()) {
110 notifier->removeSlot(slot);
114 (disconnectSinkFromSender<Outputs>(), ...);
123 this->
sink_->print(printer);
132 (duplicateSinkEdge<Outputs>(rhs, mapping), ...);
145 template<
class Output>
148 for (
auto receiver : sourceAsReceiver->receivers()) {
149 for (
auto outputSender : receiver->connectedSenders()) {
150 for (
auto sender : outputSender->senders()) {
152 sender->removeReceiver(receiver);
163 template<
class Output>
169 if (!correspondenceMap.contains(senderAsNode)) {
170 auto duplicate = senderAsClonable->clone(correspondenceMap);
172 correspondenceMap.insert({senderAsNode, duplicate});
175 auto outputNode = correspondenceMap.at(senderAsNode).get();
180 assert(outputAsNotifier !=
nullptr && outputAsSender !=
nullptr);
182 for (
auto & outputNotifier : outputAsNotifier->notifiers()) {
183 this->
notifiers().insert(outputNotifier);
186 for (
auto & outputSender : outputAsSender->senders()) {
191 throw std::runtime_error(
"An input node core is not a NodeAbstraction.");
Printer abstraction to get a snapshot of the metrics of the Hedgehog graph.
Core abstraction for clonable nodes, nodes duplicated by execution pipeline.
Core abstraction to notify slots.
void duplicateEdgeNotifier(std::map< abstraction::NodeAbstraction *, std::shared_ptr< NodeAbstraction > > &mapping)
Duplicate edges of the current notifier to slots to clone in map.
std::set< NotifierAbstraction * > const & notifiers() const
Const accessor to notifiers.
Core's abstraction to receive a piece of data.
Core abstraction to send data.
std::set< SenderAbstraction< Output > * > const & senders() const
Const accessor to senders.
void duplicateEdgeSender(std::map< abstraction::NodeAbstraction *, std::shared_ptr< NodeAbstraction > > &mapping)
Duplicate edges of the current sender to receiver to clone in map.
Core's abstraction to receive a signal.
void addNotifier(NotifierAbstraction *const notifier)
Add a NotifierAbstraction to this slot.
Base graph node abstraction.
Base core node abstraction.
Output management abstraction for the grpah.
void disconnectSinkFromSender()
Disconnect the sink from the graph's output senders.
void duplicateSinkEdge(GraphOutputsManagementAbstraction< Outputs... > const &rhs, std::map< abstraction::NodeAbstraction *, std::shared_ptr< NodeAbstraction > > &correspondenceMap)
Duplicate sink edge.
void duplicateSinkEdges(GraphOutputsManagementAbstraction< Outputs... > const &rhs, std::map< abstraction::NodeAbstraction *, std::shared_ptr< NodeAbstraction > > &mapping)
Duplicate sink edges.
std::tuple< Outputs... > outputs_t
Accessor to the output types.
void duplicateOutputEdges(std::map< abstraction::NodeAbstraction *, std::shared_ptr< NodeAbstraction > > &mapping)
Duplicate output edges.
~GraphOutputsManagementAbstraction() override=default
Default destructor.
void addOutputNodeToGraph(NodeAbstraction *const outputNode)
Add an output node in the graph.
GraphOutputsManagementAbstraction()
Default constructor.
std::unique_ptr< GraphSink< Outputs... > > const & sink() const
Accessor to the graph's sink.
void disconnectSink()
Disconnect the sink.
void printSink(Printer *printer)
Visit the sink.
auto getBlockingResult()
Get a blocking result for the outer graph from the sink.
std::unique_ptr< GraphSink< Outputs... > > sink_
Graph's sink.
Sink of the graph, only used in an outer graph.