Skip to content

Commit

Permalink
clear primaries recursively on entry to connectsecondary
Browse files Browse the repository at this point in the history
  • Loading branch information
TillHeinzel committed Sep 10, 2019
1 parent f77a0ae commit 2effd9a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
26 changes: 26 additions & 0 deletions include/pipes/detail/core/clearPrimary.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#include "pipes/detail/core/Node.hpp"

namespace tillh
{
namespace pipes
{
template<class T>
decltype(auto) clearPrimary(T&& t)
{
return FWD(t);
}

inline auto clearPrimary(PrimaryOpenConnectionPlaceHolder)
{
return OpenConnectionPlaceHolder();
}

template<class Op, class Connections>
auto clearPrimary(Node<Op, Connections>&& node)
{
return apply_last(std::move(node), [](auto&& connection) {return clearPrimary(FWD(connection)); });
}
}
}
23 changes: 3 additions & 20 deletions include/pipes/detail/core/connect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "pipes/detail/core/openCount.hpp"
#include "pipes/detail/core/getIndices.hpp"
#include "pipes/detail/core/clearPrimary.hpp"

namespace tillh
{
Expand All @@ -26,24 +27,6 @@ namespace tillh

using primary_constant = mode_constant<ConnectMode::Primary>;
using secondary_constant = mode_constant<ConnectMode::Secondary>;

template<class T>
decltype(auto) clearPrimary(T&& t)
{
return FWD(t);
}

inline auto clearPrimary(PrimaryOpenConnectionPlaceHolder)
{
return OpenConnectionPlaceHolder();
}

template<class Op, class Connections>
auto clearPrimary(Node<Op, Connections>&& node)
{
return apply_last(std::move(node), [](auto&& connection) {return clearPrimary(FWD(connection)); });
}

template<class Connection, std::size_t... Indices, class NewConnects>
auto connectIndices(Connection&& connection, std::index_sequence<Indices...>, NewConnects newConnects)
{
Expand All @@ -53,7 +36,7 @@ namespace tillh
}
else
{
return clearPrimary(connectImpl(secondary_constant(), FWD(connection), std::get<Indices>(newConnects)...));
return connectSecondaryImpl(FWD(connection), std::get<Indices>(newConnects)...);
}
}

Expand Down Expand Up @@ -186,7 +169,7 @@ namespace tillh
template<class Lhs, class... Rhs>
auto connectSecondary(Lhs&& lhs, Rhs&& ... rhs)
{
return connectImpl(secondary_constant(), ensureValidInputF(FWD(lhs))(), ensureValidOutputF(FWD(rhs))()...);
return connectImpl(secondary_constant(), ensureValidInputF(FWD(lhs))(), clearPrimary(ensureValidOutputF(FWD(rhs))())...);
}
}
}

0 comments on commit 2effd9a

Please sign in to comment.