11 #ifndef smtk_graph_RuntimeArcEndpoint_h
12 #define smtk_graph_RuntimeArcEndpoint_h
15 #include "smtk/graph/ArcTraits.h"
36 template<
typename Const>
37 class SMTK_ALWAYS_EXPORT RuntimeArcEndpoint
40 using Constness = Const;
41 using DegreeLimitsFunctor = std::function<std::size_t(
bool)>;
42 using ContainsFunctor = std::function<bool(
const Component*)>;
43 using NodeValenceFunctor = std::function<std::size_t()>;
44 using InsertArcFunctor =
45 std::function<bool(
const Component*,
const Component*,
const Component*)>;
46 using EraseArcFunctor = std::function<bool(
const Component*)>;
57 : m_degreeLimitsFunctor([](bool isMax) {
return isMax ? 0 : ~0; })
58 , m_nodeValenceFunctor([]() {
return 0; })
59 , m_containsFunctor([](
const Component*) {
return false; })
60 , m_insertArcFunctor([](
const Component*,
const Component*,
const Component*) {
return false; })
61 , m_eraseArcFunctor([](
const Component*) {
return false; })
66 RuntimeArcEndpoint(
const RuntimeArcEndpoint<Const>&) =
default;
67 RuntimeArcEndpoint& operator=(
const RuntimeArcEndpoint<Const>&) =
default;
71 const Component*
self,
73 DegreeLimitsFunctor degreeLimitsFunctor,
74 NodeValenceFunctor nodeValenceFunctor,
75 ContainsFunctor containsFunctor,
76 InsertArcFunctor insertArcFunctor,
77 EraseArcFunctor eraseArcFunctor,
78 FullVisitFunctor fullVisitFunctor)
79 : m_arcTypeName(arcType)
80 , m_endpoint(const_cast<Component*>(self))
81 , m_outgoing(isOutgoing)
82 , m_degreeLimitsFunctor(degreeLimitsFunctor)
83 , m_nodeValenceFunctor(nodeValenceFunctor)
84 , m_containsFunctor(containsFunctor)
85 , m_insertArcFunctor(insertArcFunctor)
86 , m_eraseArcFunctor(eraseArcFunctor)
87 , m_fullVisitFunctor(fullVisitFunctor)
94 bool valid()
const {
return m_arcTypeName.valid(); }
97 std::size_t maxDegree()
const {
return m_degreeLimitsFunctor(
true); }
98 std::size_t minDegree()
const {
return m_degreeLimitsFunctor(
false); }
100 template<
typename Functor>
104 return m_fullVisitFunctor(vv);
107 bool contains(
const Component* node)
const {
return m_containsFunctor(node); }
108 bool contains(
const std::shared_ptr<Component>& node)
const {
return this->contains(node.get()); }
110 std::size_t degree()
const {
return m_nodeValenceFunctor(); }
111 std::size_t size()
const {
return this->degree(); }
112 bool empty()
const {
return this->size() == 0; }
118 this->visit([&result](
const Component* node) {
132 static_assert(!Const::value,
"Attempt to modify a const endpoint.");
134 if (!m_insertArcFunctor)
139 return m_insertArcFunctor(other, beforeOther, beforeThis);
142 const std::shared_ptr<Component>& other,
143 const std::shared_ptr<Component>& beforeOther =
nullptr,
144 const std::shared_ptr<Component>& beforeThis =
nullptr)
146 return this->insert(other.get(), beforeOther.get(), beforeThis.get());
148 bool connect(
const Component* other)
151 if (!m_insertArcFunctor)
156 return m_insertArcFunctor(other,
nullptr,
nullptr);
158 bool connect(
const std::shared_ptr<Component>& other) {
return this->connect(other.get()); }
160 bool disconnect(
const Component* other)
162 static_assert(!Const::value,
"Attempt to modify a const endpoint.");
164 if (!m_eraseArcFunctor)
169 return m_eraseArcFunctor(other);
171 bool disconnect(
const std::shared_ptr<Component>& other) {
return this->disconnect(other.get()); }
173 bool erase(
const Component* other)
175 static_assert(!Const::value,
"Attempt to modify a const endpoint.");
177 if (!m_eraseArcFunctor)
182 return m_eraseArcFunctor(other);
184 bool erase(
const std::shared_ptr<Component>& other) {
return this->erase(other.get()); }
188 Component* m_endpoint{
nullptr };
189 bool m_outgoing{
true };
191 DegreeLimitsFunctor m_degreeLimitsFunctor;
192 NodeValenceFunctor m_nodeValenceFunctor;
193 ContainsFunctor m_containsFunctor;
194 InsertArcFunctor m_insertArcFunctor;
195 EraseArcFunctor m_eraseArcFunctor;
196 FullVisitFunctor m_fullVisitFunctor;
202 #endif // smtk_graph_RuntimeArcEndpoint_h