Hedgehog  3.1.0
A library to generate hybrid pipeline workflow systems
Loading...
Searching...
No Matches
node.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_CX_NODE_H_
20#define HEDGEHOG_CX_NODE_H_
21
22#ifdef HH_ENABLE_HH_CX
23
24#include <string>
25
26#include "../tools/concepts.h"
27#include "../tools/meta_functions.h"
28
29#include "../behavior/abstract_node.h"
30
32namespace hh_cx {
33
41template<tool::HedgehogConnectableNode HedgehogDynamicNodeType, class ...InputTypesRO> requires (hh::tool::ContainsInTupleConcept<
42 InputTypesRO,
43 typename HedgehogDynamicNodeType::inputs_t> &&...)
44class Node : public hh_cx::behavior::AbstractNode {
45 private:
46 std::vector<std::string>
47 inputTypesAsName_{},
48 outputTypesAsName_{},
49 roTypesAsName_{},
50 constInputTypesAsName_{};
51
52 public:
53 using ro_type_t = std::tuple<InputTypesRO...>;
54 using dynamic_node_t = HedgehogDynamicNodeType;
55 using inputs_t = typename HedgehogDynamicNodeType::inputs_t;
56 using outputs_t = typename HedgehogDynamicNodeType::outputs_t;
57
60 constexpr explicit Node(std::string const &name) : AbstractNode(name) {
61 using OutputIndices = std::make_index_sequence<std::tuple_size_v<outputs_t>>;
62 using ROIndices = std::make_index_sequence<std::tuple_size_v<ro_type_t>>;
63 using InputIndices = std::make_index_sequence<std::tuple_size_v<ro_type_t>>;
64 registerInputType(InputIndices{});
65 registerROInputType(ROIndices{});
66 registerOutputType(OutputIndices{});
67 };
68
70 constexpr ~Node() override = default;
71
74 [[nodiscard]] constexpr bool isCanTerminateOverloaded() const final {
75 if constexpr (std::is_base_of_v<hh::behavior::CanTerminate, HedgehogDynamicNodeType>) {
76 using task_t =
77 hh_cx::tool::AbstractTask_t<
78 std::tuple_size_v<inputs_t>,
79 hh_cx::tool::CatTuples_t<inputs_t, outputs_t>
80 >;
81
82 using stateManager_t =
83 hh_cx::tool::StateManager_t<
84 std::tuple_size_v<inputs_t>,
85 hh_cx::tool::CatTuples_t<inputs_t, outputs_t>
86 >;
87
88 if constexpr (std::is_base_of_v<task_t, HedgehogDynamicNodeType>) {
89 return !std::is_same_v<decltype(&task_t::canTerminate), decltype(&dynamic_node_t::canTerminate)>;
90 } else if constexpr (std::is_base_of_v<stateManager_t, HedgehogDynamicNodeType>) {
91 return !std::is_same_v<decltype(&stateManager_t::canTerminate), decltype(&dynamic_node_t::canTerminate)>;
92 } else {
93 throw std::runtime_error("The overload detection can not detect the tested type");
94 }
95 }
96 return false;
97 }
98
102 [[nodiscard]] constexpr bool isTypeAnROType(std::string const &typeName) const final {
103 return std::any_of(
104 roTypesAsName_.cbegin(), roTypesAsName_.cend(),
105 [&typeName](auto const &type) { return type == typeName; });
106 }
107
111 [[nodiscard]] constexpr bool isTypeAConstType(std::string const &typeName) const final {
112 return std::any_of(
113 constInputTypesAsName_.cbegin(), constInputTypesAsName_.cend(),
114 [&typeName](auto const &type) { return type == typeName; });
115 }
116
117 private:
120 template<size_t ...Indices>
121 constexpr void registerInputType(std::index_sequence<Indices...>) {
122 (inputTypesAsName_.push_back(hh::tool::typeToStr<std::tuple_element_t<Indices, inputs_t>>()), ...);
123 (testAndRegisterConstInputType<std::tuple_element_t<Indices, inputs_t>>(), ...);
124 }
125
128 template<class T>
129 constexpr void testAndRegisterConstInputType() {
130 if (std::is_const_v<T>) { constInputTypesAsName_.push_back(hh::tool::typeToStr<T>()); }
131 }
132
135 template<size_t ...Indices>
136 constexpr void registerOutputType(std::index_sequence<Indices...>) {
137 (outputTypesAsName_.push_back(hh::tool::typeToStr<std::tuple_element_t<Indices, outputs_t>>()), ...);
138 }
139
142 template<size_t ...Indices>
143 constexpr void registerROInputType(std::index_sequence<Indices...>) {
144 (roTypesAsName_.push_back(hh::tool::typeToStr<std::tuple_element_t<Indices, ro_type_t>>()), ...);
145 }
146};
147
148}
149#endif //HH_ENABLE_HH_CX
150#endif //HEDGEHOG_CX_NODE_H_
constexpr auto typeToStr()
Create a string containing the type name.
Concept verifying that a type is in a tuple.
Definition: concepts.h:92