11 #ifndef smtk_graph_Functions_h
12 #define smtk_graph_Functions_h
14 #include "smtk/graph/ArcImplementation.h"
15 #include "smtk/graph/Component.h"
16 #include "smtk/graph/Resource.h"
29 template<
typename NodeType,
typename ArcType,
typename Outgoing>
33 template<
typename NodeType,
typename ArcType>
37 typename ArcType::FromType* node,
38 std::function<
void(
const typename ArcType::ToType*)> visitor)
42 node->template outgoing<ArcType>().visit(visitor);
47 template<
typename NodeType,
typename ArcType>
51 typename ArcType::ToType* node,
52 std::function<
void(
const typename ArcType::FromType*)> visitor)
56 node->template incoming<ArcType>().visit(visitor);
80 typename Outgoing =
typename std::conditional<
81 std::is_same<typename ArcType::FromType, SourceNode>::value,
84 typename TargetNode =
typename std::
85 conditional<Outgoing::value, typename ArcType::ToType, typename ArcType::FromType>::type>
89 std::function<
bool(TargetNode*, TargetNode*)> comparator)
92 std::set<TargetNode*> targetsA;
94 targetsA.insert(
const_cast<TargetNode*
>(nodeC));
96 std::set<std::pair<TargetNode*, TargetNode*>> matches;
98 nodeB, [&targetsA, &matches, &comparator](
const TargetNode* constNodeD) {
99 auto* nodeD =
const_cast<TargetNode*
>(constNodeD);
100 for (
auto* candidate : targetsA)
102 if (comparator(candidate, nodeD))
104 matches.insert(std::make_pair(candidate, nodeD));
105 targetsA.erase(candidate);
109 matches.insert(std::make_pair(
nullptr, nodeD));
112 for (
auto* unmatched : targetsA)
114 matches.insert(std::make_pair(unmatched,
nullptr));
123 typename Outgoing = std::conditional<
124 std::is_same<typename ArcType::FromType, SourceNode>::value,
127 typename TargetNode =
128 std::conditional<Outgoing::value, typename ArcType::ToType, typename ArcType::FromType>>
130 const std::shared_ptr<SourceNode>& nodeA,
131 const std::shared_ptr<SourceNode>& nodeB,
132 std::function<
bool(TargetNode*, TargetNode*)> comparator)
140 #endif // smtk_graph_Functions_h