Hedgehog  3.1.0
A library to generate hybrid pipeline workflow systems
Loading...
Searching...
No Matches
graph_receiver.h
Go to the documentation of this file.
1// NIST-developed software is provided by NIST as a public service. You may use, copy and distribute copies of the
2// software in any medium, provided that you keep intact this entire notice. You may improve, modify and create
3// derivative works of the software or any portion of the software, and you may copy and distribute such modifications
4// or works. Modified works should carry a notice stating that you changed the software and should note the date and
5// nature of any such change. Please explicitly acknowledge the National Institute of Standards and Technology as the
6// source of the software. NIST-developed software is expressly provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND,
7// EXPRESS, IMPLIED, IN FACT OR ARISING BY OPERATION OF LAW, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
8// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT AND DATA ACCURACY. NIST NEITHER REPRESENTS NOR
9// WARRANTS THAT THE OPERATION OF THE SOFTWARE WILL BE UNINTERRUPTED OR ERROR-FREE, OR THAT ANY DEFECTS WILL BE
10// CORRECTED. NIST DOES NOT WARRANT OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF THE SOFTWARE OR THE RESULTS
11// THEREOF, INCLUDING BUT NOT LIMITED TO THE CORRECTNESS, ACCURACY, RELIABILITY, OR USEFULNESS OF THE SOFTWARE. You
12// are solely responsible for determining the appropriateness of using and distributing the software and you assume
13// all risks associated with its use, including but not limited to the risks and costs of program errors, compliance
14// with applicable laws, damage to or loss of data, programs or equipment, and the unavailability or interruption of
15// operation. This software is not intended to be used in any situation where a failure could cause risk of injury or
16// damage to property. The software developed by NIST employees is not subject to copyright protection within the
17// United States.
18
19#ifndef HEDGEHOG_GRAPH_RECEIVER_H
20#define HEDGEHOG_GRAPH_RECEIVER_H
21
22#include <memory>
23#include <mutex>
24#include "../../implementor/implementor_receiver.h"
25#include "../../../abstractions/base/input_output/receiver_abstraction.h"
26
28namespace hh {
30namespace core {
32namespace implementor {
33
36template<class Input>
37class GraphReceiver : public ImplementorReceiver<Input> {
38 public:
39
41 explicit GraphReceiver() = default;
42
44 virtual ~GraphReceiver() = default;
45
48 void initialize([[maybe_unused]]abstraction::ReceiverAbstraction<Input> *receiverAbstraction) override {}
49
54 [[nodiscard]] size_t numberElementsReceived() const override {
55 throw std::runtime_error("It is not possible to get the number of input data from the graph receiver as it is only "
56 "used to transfer data to input nodes.");
57 }
58
63 [[nodiscard]] size_t maxNumberElementsReceived() const override {
64 throw std::runtime_error("It is not possible to get the number of input data from the graph receiver as it is only "
65 "used to transfer data to input nodes.");
66 }
67
72 [[nodiscard]] bool empty() const override {
73 throw std::runtime_error("It is not possible to test if there is input data from the graph receiver as it is only "
74 "used to transfer data to input nodes.");
75 }
76
81 std::shared_ptr<Input> getInputData() override {
82 throw std::runtime_error("It is not possible to get input data from the graph receiver as it is only used to "
83 "transfer data to input nodes.");
84 }
85
89 std::set<abstraction::SenderAbstraction<Input> *> const &connectedSenders() const override {
90 throw std::runtime_error("A graph is not connected to any senders");
91 }
92
95 void receive(std::shared_ptr<Input> data) override {
96 std::for_each(
97 this->abstractReceivers_->begin(), this->abstractReceivers_->end(),
98 [&data](abstraction::ReceiverAbstraction<Input> *receiver) { receiver->receive(data); }
99 );
100 }
101
105 std::for_each(
106 this->abstractReceivers_->begin(), this->abstractReceivers_->end(),
107 [&sender](abstraction::ReceiverAbstraction<Input> *receiver) { receiver->addSender(sender); }
108 );
109 }
110
114 std::for_each(
115 this->abstractReceivers_->begin(), this->abstractReceivers_->end(),
116 [&sender](abstraction::ReceiverAbstraction<Input> *receiver) { receiver->removeSender(sender); }
117 );
118 }
119};
120}
121}
122}
123#endif //HEDGEHOG_GRAPH_RECEIVER_H
Hedgehog main namespace.
Core's abstraction to receive a piece of data.
Core abstraction to send data.
Default concrete implementation of the receiver abstraction for the graph core.
size_t numberElementsReceived() const override
Do nothing, throw an error, a graph does not receive data, its input nodes do.
void initialize(abstraction::ReceiverAbstraction< Input > *receiverAbstraction) override
Redefine the implementor to do nothing, the graph do nothing by itself.
void addSender(abstraction::SenderAbstraction< Input > *const sender) override
Add a sender to add to the graph input nodes.
std::shared_ptr< Input > getInputData() override
Do nothing, throw an error, a graph does not receive data, its input nodes do.
bool empty() const override
Do nothing, throw an error, a graph does not receive data, its input nodes do.
void removeSender(abstraction::SenderAbstraction< Input > *const sender) override
Remove a sender to add to the graph input nodes.
virtual ~GraphReceiver()=default
Default destructor.
std::set< abstraction::SenderAbstraction< Input > * > const & connectedSenders() const override
Do nothing, throw an error, a graph is not really connected to other nodes.
void receive(std::shared_ptr< Input > data) override
Receive a data and transmit to its input nodes.
GraphReceiver()=default
Default constructor.
size_t maxNumberElementsReceived() const override
Do nothing, throw an error, a graph does not receive data, its input nodes do.
Implementor for the ReceiverAbstraction.
std::unique_ptr< std::set< abstraction::ReceiverAbstraction< Input > * > > abstractReceivers_
Set of linked ReceiverAbstraction.