Hedgehog  0.0.0
A library to generate hybrid pipeline workflow systems
core_switch.h
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 
20 #ifndef HEDGEHOG_CORE_SWITCH_H
21 #define HEDGEHOG_CORE_SWITCH_H
22 
23 #include <ostream>
24 #include "../../io/queue/sender/core_queue_sender.h"
25 
27 namespace hh::core {
28 
31 template<class ...GraphInputs>
32 class CoreSwitch : public CoreQueueSender<GraphInputs> ... {
33  public:
36  : CoreNode("switch", NodeType::Switch, 1),
37  CoreNotifier("switch", NodeType::Switch, 1),
38  CoreQueueNotifier("switch", NodeType::Switch, 1),
39  CoreQueueSender<GraphInputs>("switch", NodeType::Switch, 1)... {}
40 
43  std::shared_ptr<CoreNode> clone() override { return std::make_shared<CoreSwitch<GraphInputs...>>(); }
44 
49  behavior::Node *node() override {
50  std::ostringstream oss;
51  oss << "Internal error, a switch has no nodes: " << __FUNCTION__;
52  HLOG_SELF(0, oss.str())
53  throw (std::runtime_error(oss.str()));
54  }
55 
57  void visit([[maybe_unused]]AbstractPrinter *) override {}
58 
61  void addSlot(CoreSlot *slot) override { (CoreQueueSender<GraphInputs>::addSlot(slot), ...); }
62 
65  void removeSlot(CoreSlot *slot) override { (CoreQueueSender<GraphInputs>::removeSlot(slot), ...); }
66 
69 
72  std::string extraPrintingInformation() override {
73  std::ostringstream oss;
74  oss << "Switch Info: " << std::endl;
75  (printSenderInfo<GraphInputs>(oss), ...);
76  return oss.str();
77  }
78 
79  protected:
83  void duplicateEdge(CoreNode *duplicateNode,
84  std::map<CoreNode *, std::shared_ptr<CoreNode>> &correspondenceMap) override {
85  (CoreQueueSender<GraphInputs>::duplicateEdge(duplicateNode, correspondenceMap), ...);
86  }
87 
88  private:
92  template<class GraphInput>
93  void printSenderInfo(std::ostringstream &oss) {
94  oss << typeid(GraphInput).name() << std::endl;
95  for (auto slot : *(static_cast<CoreQueueSender<GraphInput> *>(this)->slots())) {
96  oss << "\t" << slot->id() << " / " << slot->name() << std::endl;
97  }
98  }
99 
103  std::set<CoreSlot *> getSlots() override {
104  std::ostringstream oss;
105  oss << "Runtime error, A switch does not have any slots: " << __FUNCTION__;
106  HLOG_SELF(0, oss.str())
107  throw (std::runtime_error(oss.str()));
108  }
109 };
110 
111 }
112 #endif //HEDGEHOG_CORE_SWITCH_H
void printSenderInfo(std::ostringstream &oss)
Stream all sender information into oss.
Definition: core_switch.h:93
Core Notifier interface, emit notification to CoreSlot.
Definition: core_notifier.h:34
void removeSlot(CoreSlot *slot) override
Remove a slot from every input types.
Definition: core_switch.h:65
void visit([[maybe_unused]]AbstractPrinter *) override
Visit a switch, do nothing.
Definition: core_switch.h:57
Sender for nodes possessing a queue of data.
void duplicateEdge(CoreNode *duplicateNode, std::map< CoreNode *, std::shared_ptr< CoreNode >> &correspondenceMap) override
Duplicate all the edges from this to it&#39;s copy duplicateNode.
CoreSwitch()
Default core switch.
Definition: core_switch.h:35
void notifyAllTerminated() override
Notify all slots that the node is terminated.
std::shared_ptr< CoreNode > clone() override
Clone a default core switch.
Definition: core_switch.h:43
Printer interface.
std::shared_ptr< std::set< CoreSlot * > > const & slots() const
Connected slots accessor.
Core switch, determine where to divert data to the graphs.
Definition: core_switch.h:32
Node Behavior definition.
Definition: node.h:39
Slot interface, receive notification from CoreNotifier.
Definition: core_slot.h:34
void addSlot(CoreSlot *slot) override
Add a slot to the set of connected slots.
void notifyAllTerminated() override
Notify terminated for all input types.
Definition: core_switch.h:68
std::set< CoreSlot * > getSlots() override
Slots accessors, throw an error, a switch does not have any slots.
Definition: core_switch.h:103
NodeType
Hedgehog node&#39;s type.
Definition: core_node.h:40
void removeSlot(CoreSlot *slot) override
Remove a slot from the set of connected slots.
behavior::Node * node() override
Send a user node, not possible for a switch, should only be managed by an execution pipeline...
Definition: core_switch.h:49
Main Hedgehog core abstraction.
Definition: core_node.h:48
Notifier of CoreQueueSlot.
void duplicateEdge(CoreNode *duplicateNode, std::map< CoreNode *, std::shared_ptr< CoreNode >> &correspondenceMap) override
Duplicate all the edges from this to its copy duplicateNode.
Definition: core_switch.h:83
Hedgehog core namespace.
Definition: core_execute.h:25
std::string_view const & name() const
Node name accessor.
Definition: core_node.h:128
void addSlot(CoreSlot *slot) override
Add a slot for every input types.
Definition: core_switch.h:61
std::string extraPrintingInformation() override
Print extra information for the switch.
Definition: core_switch.h:72