+39
-18
@@ -37,18 +37,27 @@ struct INode {
|
||||
// InputNames — optional kpn::in<"a","b"> tag type (at most one)
|
||||
// OutputNames — optional kpn::out<"x","y"> tag type (at most one)
|
||||
|
||||
template<auto Func, typename InputTag = in<>, typename OutputTag = out<>>
|
||||
template<auto Func,
|
||||
typename InputTag = in<>,
|
||||
typename OutputTag = out<>,
|
||||
fixed_string Label = "",
|
||||
std::size_t UniqueTag = 0>
|
||||
class Node;
|
||||
|
||||
// Specialisation that unpacks the in<>/out<> tag packs
|
||||
template<auto Func, fixed_string... InNames, fixed_string... OutNames>
|
||||
class Node<Func, in<InNames...>, out<OutNames...>> : public INode {
|
||||
template<auto Func, fixed_string... InNames, fixed_string... OutNames,
|
||||
fixed_string Label, std::size_t UniqueTag>
|
||||
class Node<Func, in<InNames...>, out<OutNames...>, Label, UniqueTag> : public INode {
|
||||
public:
|
||||
using F = decltype(Func);
|
||||
using args_tuple = args_t<F>;
|
||||
using return_raw = return_t<F>;
|
||||
using return_tuple = normalised_return_t<return_raw>;
|
||||
|
||||
// Identity accessors — used by StaticNetwork for diagnostics and type-level uniqueness
|
||||
static constexpr std::string_view label() { return Label.view(); }
|
||||
static constexpr std::size_t unique_tag = UniqueTag;
|
||||
|
||||
static constexpr std::size_t input_count = arity_v<F>;
|
||||
static constexpr std::size_t output_count = std::tuple_size_v<return_tuple>;
|
||||
|
||||
@@ -289,17 +298,25 @@ private:
|
||||
// MyFunctor obj(...);
|
||||
// auto node = make_node(obj, in<"x">{}, out<"y">{}, capacity);
|
||||
|
||||
template<typename Obj, typename InputTag = in<>, typename OutputTag = out<>>
|
||||
template<typename Obj,
|
||||
typename InputTag = in<>,
|
||||
typename OutputTag = out<>,
|
||||
fixed_string Label = "",
|
||||
std::size_t UniqueTag = 0>
|
||||
class ObjectNode;
|
||||
|
||||
template<typename Obj, fixed_string... InNames, fixed_string... OutNames>
|
||||
class ObjectNode<Obj, in<InNames...>, out<OutNames...>> : public INode {
|
||||
template<typename Obj, fixed_string... InNames, fixed_string... OutNames,
|
||||
fixed_string Label, std::size_t UniqueTag>
|
||||
class ObjectNode<Obj, in<InNames...>, out<OutNames...>, Label, UniqueTag> : public INode {
|
||||
public:
|
||||
using F = decltype(&Obj::operator());
|
||||
using args_tuple = args_t<F>;
|
||||
using return_raw = return_t<F>;
|
||||
using return_tuple = normalised_return_t<return_raw>;
|
||||
|
||||
static constexpr std::string_view label() { return Label.view(); }
|
||||
static constexpr std::size_t unique_tag = UniqueTag;
|
||||
|
||||
static constexpr std::size_t input_count = arity_v<F>;
|
||||
static constexpr std::size_t output_count = std::tuple_size_v<return_tuple>;
|
||||
|
||||
@@ -534,32 +551,36 @@ auto make_node(Obj& obj, in<InNames...>, out<OutNames...>, std::size_t fifo_capa
|
||||
//
|
||||
// Usage:
|
||||
// make_node<func>(capacity)
|
||||
// make_node<func, "label">(capacity)
|
||||
// make_node<func, "label", 1>(capacity) // UniqueTag=1
|
||||
// make_node<func>(in<"a","b">{}, capacity)
|
||||
// make_node<func>(out<"x">{}, capacity)
|
||||
// make_node<func>(in<"a","b">{}, out<"x">{}, capacity)
|
||||
// make_node<func, "label">(in<"a","b">{}, out<"x">{}, capacity)
|
||||
|
||||
// No names
|
||||
template<auto Func>
|
||||
// No port names
|
||||
template<auto Func, fixed_string Label = "", std::size_t UniqueTag = 0>
|
||||
auto make_node(std::size_t fifo_capacity = 5) {
|
||||
return Node<Func, in<>, out<>>(fifo_capacity);
|
||||
return Node<Func, in<>, out<>, Label, UniqueTag>(fifo_capacity);
|
||||
}
|
||||
|
||||
// in<> only
|
||||
template<auto Func, fixed_string... InNames>
|
||||
template<auto Func, fixed_string Label = "", std::size_t UniqueTag = 0,
|
||||
fixed_string... InNames>
|
||||
auto make_node(in<InNames...>, std::size_t fifo_capacity = 5) {
|
||||
return Node<Func, in<InNames...>, out<>>(fifo_capacity);
|
||||
return Node<Func, in<InNames...>, out<>, Label, UniqueTag>(fifo_capacity);
|
||||
}
|
||||
|
||||
// out<> only (no input names)
|
||||
template<auto Func, fixed_string... OutNames>
|
||||
// out<> only
|
||||
template<auto Func, fixed_string Label = "", std::size_t UniqueTag = 0,
|
||||
fixed_string... OutNames>
|
||||
auto make_node(out<OutNames...>, std::size_t fifo_capacity = 5) {
|
||||
return Node<Func, in<>, out<OutNames...>>(fifo_capacity);
|
||||
return Node<Func, in<>, out<OutNames...>, Label, UniqueTag>(fifo_capacity);
|
||||
}
|
||||
|
||||
// in<> and out<>
|
||||
template<auto Func, fixed_string... InNames, fixed_string... OutNames>
|
||||
template<auto Func, fixed_string Label = "", std::size_t UniqueTag = 0,
|
||||
fixed_string... InNames, fixed_string... OutNames>
|
||||
auto make_node(in<InNames...>, out<OutNames...>, std::size_t fifo_capacity = 5) {
|
||||
return Node<Func, in<InNames...>, out<OutNames...>>(fifo_capacity);
|
||||
return Node<Func, in<InNames...>, out<OutNames...>, Label, UniqueTag>(fifo_capacity);
|
||||
}
|
||||
|
||||
} // namespace kpn
|
||||
|
||||
Reference in New Issue
Block a user