20 #ifndef HEDGEHOG_GRAPH_H 21 #define HEDGEHOG_GRAPH_H 26 #include "scheduler/abstract_scheduler.h" 27 #include "printer/dot_printer.h" 28 #include "../core/node/core_graph.h" 29 #include "../tools/helper.h" 30 #include "../tools/traits.h" 31 #include "../tools/logger.h" 32 #include "../behavior/io/multi_receivers.h" 33 #include "../behavior/io/sender.h" 84 template<
class GraphOutput,
class ...GraphInputs>
89 static_assert(traits::isUnique<GraphInputs...>,
"A Graph can't accept multiple inputs with the same type.");
90 static_assert(
sizeof... (GraphInputs) >= 1,
"A node need to have one output type and at least one output type.");
124 explicit Graph(std::string_view
const &
name, std::unique_ptr<AbstractScheduler> scheduler) {
126 std::ostringstream oss;
127 oss <<
"Internal error, the graph's scheduler is null, please instantiate an AbstractScheduler.";
128 HLOG_SELF(0, oss.str())
129 throw (std::runtime_error(oss.str()));
133 this, core::NodeType::Graph,
name, std::move(scheduler));
137 virtual ~Graph() =
default;
145 std::string_view
const &
name() {
return this->
core()->name(); }
159 class UserDefinedMultiReceiver,
160 class InputsMR =
typename UserDefinedMultiReceiver::inputs_t,
162 class isMultiReceiver =
typename std::enable_if_t<
163 std::is_base_of_v<typename helper::HelperMultiReceiversType<InputsMR>::type, UserDefinedMultiReceiver>
165 class isInputCompatible =
typename std::enable_if_t<traits::is_included_v<InputsMR, InputsG>>>
166 void input(std::shared_ptr<UserDefinedMultiReceiver>
input) {
167 assert(input !=
nullptr);
168 this->insideNodes_.insert(input);
170 if (test ==
nullptr) { std::cout <<
"big problem " << input << std::endl; }
179 class UserDefinedSender,
180 class IsSender =
typename std::enable_if_t<
187 assert(output !=
nullptr);
188 this->insideNodes_.insert(output);
189 this->
graphCore_->output(std::static_pointer_cast<behavior::Sender<GraphOutput>>(output));
202 class UserDefinedSender,
class UserDefinedMultiReceiver,
203 class Output =
typename UserDefinedSender::output_t,
204 class Inputs =
typename UserDefinedMultiReceiver::inputs_t,
205 class IsSender =
typename std::enable_if_t<std::is_base_of_v<behavior::Sender<Output>, UserDefinedSender>>,
206 class IsMultiReceivers =
typename std::enable_if_t<
212 void addEdge(std::shared_ptr<UserDefinedSender> from, std::shared_ptr<UserDefinedMultiReceiver> to) {
213 static_assert(traits::Contains_v<Output, Inputs>,
214 "The given io cannot be linked to this io: No common types.");
215 this->insideNodes_.insert(from);
216 this->insideNodes_.insert(to);
218 std::static_pointer_cast<
typename helper::HelperMultiReceiversType<Inputs>::type>(to));
231 class =
typename std::enable_if_t<
traits::Contains<Input, GraphInputs...>::value>
233 void pushData(std::shared_ptr<Input> data) { this->
graphCore_->broadcastAndNotifyToAllInputs(data); }
264 DotPrinter printer(std::filesystem::absolute(dotFilePath), colorScheme, structureOptions, debugOption,
core);
265 core->visit(&printer);
270 #endif //HEDGEHOG_GRAPH_H void waitForTermination()
Wait for the graph to terminate (data to be processed, all threads to join)
void pushData(std::shared_ptr< Input > data)
Push data into the graph.
std::shared_ptr< core::CoreGraph< GraphOutput, GraphInputs... > > graphCore_
Graph core as shared_ptr.
std::shared_ptr< GraphOutput > getBlockingResult()
Get a data out of the graph.
void addEdge(std::shared_ptr< UserDefinedSender > from, std::shared_ptr< UserDefinedMultiReceiver > to)
Add a directed edge from a compatible "from" node to "to" node.
Printer to produce a dot representation of the current state of the graph.
Graph(std::string_view const &name)
Graph constructor with a custom name.
StructureOptions
Enum structural options.
std::set< std::shared_ptr< Node > > insideNodes_
Graph's inside nodes, register user node in case it's not saved elsewhere.
void finishPushingData()
Signal the graph that no more data will be pushed into the graph.
Sender Behavior definition, node has an output type.
Check if a template T is in Template pack Ts.
Graph()
Default graph constructor, the default name is "Graph".
virtual ~Graph()=default
Default Graph destructor.
DebugOptions
Enum to enable debug printing.
Node Behavior definition.
void createDotFile(std::filesystem::path const &dotFilePath, ColorScheme colorScheme=ColorScheme::NONE, StructureOptions structureOptions=StructureOptions::NONE, DebugOptions debugOption=DebugOptions::NONE)
Create a dot file representing a snapshot of the state of the graph at the moment of the call...
Main Hedgehog object that does computation.
void output(std::shared_ptr< UserDefinedSender > output)
Set a node as output for the graph.
std::string_view const & name()
Graph name accessor.
MultiReceivers Behavior definition, node has a list of input types.
Core associated to the Graph.
void executeGraph()
Launch the graph once it has been structured.
std::shared_ptr< core::CoreNode > core() final
Graph core accessor.
Graph(std::string_view const &name, std::unique_ptr< AbstractScheduler > scheduler)
Graph constructor with a custom name and a custom scheduler.
Base definition of HelperMultiReceiversType.
ColorScheme
Enum color options.
void deviceId(int deviceId)
Device Id for the graph, all inside nodes will be bound to this device Id.
std::tuple< Inputs... > inputs_t
Tuple with the list of input types.
void input(std::shared_ptr< UserDefinedMultiReceiver > input)
Set a node as input for the graph.