SMTK
@SMTK_VERSION@
Simulation Modeling Tool Kit
|
11 #ifndef smtk_graph_ArcImplementation_h
12 #define smtk_graph_ArcImplementation_h
16 #include "smtk/graph/detail/TypeTraits.h"
17 #include "smtk/resource/Component.h"
18 #include "smtk/string/Token.h"
26 template<
bool Constness>
34 template<
bool OutgoingDirection>
35 struct ArcDirection : std::integral_constant<bool, OutgoingDirection>
42 template<
typename TraitsType>
44 template<
typename TraitsType,
typename Const,
typename Outgoing>
53 template<
typename ArcTraits>
57 using Traits = ArcTraits;
64 using ToType =
typename ArcTraits::ToType;
87 Directed::value || !std::is_same<FromType, ToType>::value ||
90 Undirected arcs with identical From/To types must
91 have identical in- and out-degree constraints.)");
106 std::string
typeName()
const {
return smtk::common::typeName<ArcTraits>(); }
142 bool result =
m_data.contains(from, to);
160 typename ResourcePtr,
175 std::function<void(
const std::shared_ptr<smtk::resource::Component>&)> compVisitor =
177 if (
const auto* node =
dynamic_cast<const typename Traits::FromType*
>(component.get()))
182 rsrc->visit(compVisitor);
190 typename ResourcePtr,
214 typename ResourcePtr,
229 std::function<void(
const std::shared_ptr<smtk::resource::Component>&)> compVisitor =
231 if (
const auto* node =
dynamic_cast<const typename Traits::ToType*
>(component.get()))
236 rsrc->visit(compVisitor);
244 typename ResourcePtr,
264 template<
typename U = Mutable>
266 typename std::enable_if<!U::value, bool>::type
connect(
269 const FromType* beforeFrom =
nullptr,
270 const ToType* beforeTo =
nullptr)
279 template<
typename U = Mutable>
280 typename std::enable_if<U::value, bool>::type
connect(
283 const FromType* beforeFrom =
nullptr,
284 const ToType* beforeTo =
nullptr)
286 bool result =
m_data.connect(from, to, beforeFrom, beforeTo);
294 template<
typename U = Mutable>
303 template<
typename U = Mutable>
306 bool result =
m_data.disconnect(from, to);
312 template<
typename Functor>
315 return m_data.outVisitor(from, visitor);
326 typename std::enable_if<!U::value && !V::value, std::size_t>::type
outDegree(
332 std::size_t result = 0;
346 typename std::enable_if<!U::value && V::value, std::size_t>::type
outDegree(
352 std::size_t result = 0;
362 reinterpret_cast<const ToType*
>(from), [&result](
const FromType*) { ++result; });
372 std::size_t result =
m_data.outDegree(from);
385 typename std::enable_if<!U::value && !V::value, std::size_t>::type
inDegree(
391 std::size_t result = 0;
405 typename std::enable_if<!U::value && V::value, std::size_t>::type
inDegree(
const ToType* to)
const
410 std::size_t result = 0;
427 typename std::enable_if<U::value, std::size_t>::type
inDegree(
const ToType* to)
const
429 std::size_t result =
m_data.inDegree(to);
441 return m_data.inVisitor(to, visitor);
451 template<
typename Functor>
454 return this->inVisitorDetail<Functor, true>(to, visitor);
499 template<
typename TraitsType,
typename Const,
typename Outgoing>
503 using Traits = TraitsType;
504 using FromType =
typename TraitsType::FromType;
505 using ToType =
typename TraitsType::ToType;
506 using Directed =
typename TraitsType::Directed;
510 using ThisType =
typename std::
511 conditional<Outgoing::value, typename ImplType::FromType, typename ImplType::ToType>::type;
512 using OtherType =
typename std::
513 conditional<Outgoing::value, typename ImplType::ToType, typename ImplType::FromType>::type;
514 using Constness = Const;
519 This arc type is not indexed for reverse lookups.
527 , m_endpoint(nullptr)
535 constexpr std::size_t maxDegree()
const
537 return Outgoing::value ? maxOutDegree<Traits>(
unconstrained())
540 constexpr std::size_t minDegree()
const
542 return Outgoing::value ? minOutDegree<Traits>(
unconstrained())
547 template<
bool Outgoingness,
typename Functor>
552 return self->m_arcs->outVisitor(self->m_endpoint, visitor);
556 template<
typename Functor>
561 return self->m_arcs->inVisitor(self->m_endpoint, visitor);
565 template<
bool Outgoingness,
int Dummy = 0>
568 bool operator()(
const SelfEndpoint*
self,
const ToType* endpoint)
const
570 return self->m_arcs->contains(self->m_endpoint, endpoint);
577 bool operator()(
const SelfEndpoint*
self,
const FromType* endpoint)
const
579 return self->m_arcs->contains(endpoint, self->m_endpoint);
585 template<
bool Outgoingness,
int Dummy = 0>
590 return self->m_arcs->outDegree(self->m_endpoint);
600 return self->m_arcs->inDegree(self->m_endpoint);
606 template<
typename Functor>
622 std::size_t
degree()
const
625 std::size_t dd = Degree<Outgoing::value>()(
this);
647 const OtherType* result =
nullptr;
648 this->
visit([&result](
const OtherType*
node) {
662 template<
bool Mutability,
bool Outgoingness,
int Dummy = 0>
667 const OtherType* other,
668 const OtherType* beforeOther =
nullptr,
669 const ThisType* beforeThis =
nullptr)
const
671 return self->m_arcs->connect(self->m_endpoint, other, beforeThis, beforeOther);
680 const OtherType* other,
681 const OtherType* beforeOther =
nullptr,
682 const ThisType* beforeThis =
nullptr)
const
684 return self->m_arcs->connect(other, self->m_endpoint, beforeOther, beforeThis);
689 template<
bool Outgoingness,
int Dummy>
694 const OtherType* other,
695 const OtherType* beforeOther =
nullptr,
696 const ThisType* beforeThis =
nullptr)
const
706 template<
bool Mutability,
bool Outgoingness,
int Dummy = 0>
709 bool operator()(
SelfEndpoint*
self,
const OtherType* other)
const
711 bool didDisconnect =
self->m_arcs->disconnect(self->m_endpoint, other);
712 return didDisconnect;
719 bool operator()(
SelfEndpoint*
self,
const OtherType* other)
const
721 bool didDisconnect =
self->m_arcs->disconnect(other, self->m_endpoint);
722 return didDisconnect;
726 template<
bool Outgoingness,
int Dummy>
729 bool operator()(
SelfEndpoint*
self,
const OtherType* other)
const
741 static_assert(!Constness::value,
"A const-referenced node may not be edited.");
746 bool connect(
const std::shared_ptr<OtherType>& other) {
return this->
connect(other.get()); }
750 const OtherType* other,
751 const OtherType* beforeOther =
nullptr,
752 const ThisType* beforeThis =
nullptr)
754 static_assert(!Constness::value,
"A const-referenced node may not be edited.");
761 static_assert(!Constness::value,
"A const-referenced node may not be edited.");
766 static_assert(!Constness::value,
"A const-referenced node may not be edited.");
772 bool erase(
const std::shared_ptr<OtherType>& other) {
return this->
erase(other.get()); }
787 typename std::conditional<Const::value, const ThisType*, ThisType*>::type endpoint)
789 , m_endpoint(endpoint)
794 typename std::conditional<Const::value, const ThisType*, ThisType*>::type m_endpoint;
800 #endif // smtk_graph_ArcImplementation_h
The main namespace for the Simulation Modeling Tool Kit (SMTK).
Definition: doc.h:33
ArcEndpointInterface< ArcTraits, ConstArc, OutgoingArc > outgoing(const FromType *from) const
Return a "container" of outgoing arcs of the given from node.
Definition: ArcImplementation.h:458
const OtherType * front() const
STL-container synonym for node():
Definition: ArcImplementation.h:656
bool erase(const OtherType *other)
Connect the other node to this node.
Definition: ArcImplementation.h:764
@ Halt
Stop visiting items immediately.
bool connect(const OtherType *other)
Connect the other node to this node.
Definition: ArcImplementation.h:739
detail::SelectArcContainer< ArcTraits, ArcTraits > m_data
Store arc endpoint data.
Definition: ArcImplementation.h:487
True when the order in which arcs are stored is significant.
Definition: ArcProperties.h:207
std::enable_if<!U::value &&!V::value, std::size_t >::type inDegree(const ToType *to) const
Compute the in-degree of the node.
Definition: ArcImplementation.h:385
std::enable_if< U::value, smtk::common::Visited >::type visitAllOutgoingNodes(ResourcePtr rsrc, Functor ff) const
Visit all nodes which have outgoing arcs of this type.
Definition: ArcImplementation.h:192
smtk::common::Visited inVisitor(const ToType *to, Functor visitor) const
Visit nodes attached via incoming arcs.
Definition: ArcImplementation.h:452
@ All
The visitor was invoked on every item exhaustively.
typename TraitsType ::ToType ToType
The type of node that these arcs point to.
Definition: ArcImplementation.h:64
bool isMutable() const
Return whether arcs of this type may be edited.
Definition: ArcImplementation.h:100
@ Empty
The were no values to visit.
static constexpr std::size_t MinInDegree
The minimum in-degree of a ToType node. This is not enforced.
Definition: ArcImplementation.h:81
Definition: ArcImplementation.h:566
std::enable_if< U::value, std::size_t >::type outDegree(const FromType *from) const
Compute the out-degree of the node.
Definition: ArcImplementation.h:370
For endpoint interfaces, provide tag classes used to select incoming or outgoing APIs.
Definition: ArcImplementation.h:35
bool insert(const OtherType *other, const OtherType *beforeOther=nullptr, const ThisType *beforeThis=nullptr)
Insert a new arc connecting this endpoint to the other.
Definition: ArcImplementation.h:749
std::size_t degree() const
Return the number of arcs of this type that terminate at this endpoint.
Definition: ArcImplementation.h:623
std::enable_if<!U::value, bool >::type disconnect(const FromType *from, const ToType *to)
Remove an arc from from to to.
Definition: ArcImplementation.h:296
bool erase(const std::shared_ptr< OtherType > &other)
A convenience version of erase() that accepts shared pointers.
Definition: ArcImplementation.h:772
bool disconnect(const OtherType *other)
Disconnect the other node from this one (i.e., erase an arc).
Definition: ArcImplementation.h:759
bool contains(const OtherType *node) const
Return true if this endpoint is connected to node.
Definition: ArcImplementation.h:613
bool empty() const
Return whether this endpoint has zero arcs.
Definition: ArcImplementation.h:632
typename TraitsType ::Directed Directed
If "truthy," this arc is considered directed rather than undirected.
Definition: ArcImplementation.h:60
Check whether the arc traits object (1) is implicit and has methods to insert and remove arcs; or (2)...
Definition: ArcProperties.h:254
Definition: ArcImplementation.h:707
typename TraitsType ::FromType FromType
The type of node that these arcs originate from.
Definition: ArcImplementation.h:62
Edit methods (only enabled for non-const interfaces).
Definition: ArcImplementation.h:663
An object that a node instance can present to access/edit its outgoing/incoming arcs.
Definition: ArcImplementation.h:45
static constexpr std::size_t MaxInDegree
The maximum in-degree of a ToType node. This is enforced.
Definition: ArcImplementation.h:85
Checks that can be performed on arc trait-types.
Definition: ArcProperties.h:43
std::enable_if<!U::value &&V::value, std::size_t >::type inDegree(const ToType *to) const
Compute the in-degree of the node.
Definition: ArcImplementation.h:405
ArcEndpointInterface()
This is a dummy constructor that is not used by valid code.
Definition: ArcImplementation.h:525
@ Continue
Continue to visit items.
std::enable_if< U::value, bool >::type contains(const FromType *from, const ToType *to) const
Test whether an arc from from to to exists.
Definition: ArcImplementation.h:139
bool disconnect(const std::shared_ptr< OtherType > &other)
A convenience version of disconnect() that accepts shared pointers.
Definition: ArcImplementation.h:770
For endpoint interfaces, provide tag classes used to select const or non-const APIs.
Definition: ArcImplementation.h:27
Definition: ArcImplementation.h:586
std::enable_if<!U::value &&V::value, std::size_t >::type outDegree(const FromType *from) const
Compute the out-degree of the node.
Definition: ArcImplementation.h:346
std::enable_if<!U::value, smtk::common::Visited >::type visitAllIncomingNodes(ResourcePtr rsrc, Functor ff) const
Visit all nodes which have incoming arcs of this type.
Definition: ArcImplementation.h:216
smtk::common::Visited outVisitor(const FromType *from, Functor visitor) const
Visit nodes attached via outgoing arcs.
Definition: ArcImplementation.h:313
const OtherType * node() const
Return the first destination endpoint.
Definition: ArcImplementation.h:645
std::size_t size() const
Return the number of arcs of this type that terminate at this endpoint.
Definition: ArcImplementation.h:628
bool isOrdered() const
Return whether arcs of this type are ordered (true) or unordered (false).
Definition: ArcImplementation.h:94
bool isDirected() const
Return whether arcs of this type are directed (true) or undirected (false).
Definition: ArcImplementation.h:97
bool isExplicit() const
Return whether arcs of this type are explicit.
Definition: ArcImplementation.h:103
std::string typeName() const
Return the type of arc this class implements.
Definition: ArcImplementation.h:106
std::enable_if< U::value, smtk::common::Visited >::type visitAllIncomingNodes(ResourcePtr rsrc, Functor ff) const
Visit all nodes which have incoming arcs of this type.
Definition: ArcImplementation.h:246
smtk::common::Visited visit(Functor visitor) const
Visit nodes attached to the endpoint by arcs of this type.
Definition: ArcImplementation.h:607
std::enable_if< U::value, std::size_t >::type inDegree(const ToType *to) const
Compute the in-degree of the node.
Definition: ArcImplementation.h:427
constexpr std::enable_if< std::is_integral< decltype(T::MaxInDegree)>::value, std::size_t >::type maxInDegree(std::size_t)
Return the maximum in-degree of an arc type (or unconstrained() if unspecified).
Definition: ArcProperties.h:340
A wrapper around arc type-traits classes that provides API.
Definition: ArcImplementation.h:43
Visited
Return value for functions/methods that accept visitors.
Definition: Visit.h:35
std::enable_if<!U::value, smtk::common::Visited >::type visitAllOutgoingNodes(ResourcePtr rsrc, Functor ff) const
Visit all nodes which have outgoing arcs of this type.
Definition: ArcImplementation.h:162
constexpr std::size_t unconstrained()
Return a constant used to indicate the maximimum degree of an arc endpoint is unconstrained.
Definition: ArcProperties.h:30
static constexpr std::size_t MaxOutDegree
The maximum out-degree of a FromType node. This is enforced.
Definition: ArcImplementation.h:83
typename ArcProperties< TraitsType >::isOrdered Ordered
If "truthy," this arc will report incoming/outgoing nodes in a (user-specified) order.
Definition: ArcImplementation.h:66
False when an arc class provides implementations of required methods; true otherwise.
Definition: ArcProperties.h:243
std::enable_if<!U::value &&!V::value, std::size_t >::type outDegree(const FromType *from) const
Compute the out-degree of the node.
Definition: ArcImplementation.h:326
constexpr std::enable_if< std::is_integral< decltype(T::MinInDegree)>::value, std::size_t >::type minInDegree(std::size_t)
Return the minimum in-degree of an arc type (or 0 if unspecified).
Definition: ArcProperties.h:374
static constexpr std::size_t MinOutDegree
The minimum out-degree of a FromType node. This is not enforced.
Definition: ArcImplementation.h:79
ArcEndpointInterface< ArcTraits, ConstArc, IncomingArc > incoming(const ToType *to) const
Return a "container" of incoming arcs of the given to node.
Definition: ArcImplementation.h:468
Definition: ArcImplementation.h:548
typename ArcProperties< TraitsType >::isExplicit Explicit
If "truthy," arc endpoint connections are explicitly stored by SMTK.
Definition: ArcImplementation.h:76
bool connect(const std::shared_ptr< OtherType > &other)
A convenience version of connect() that accepts shared pointers.
Definition: ArcImplementation.h:746
std::enable_if< U::value, bool >::type disconnect(const FromType *from, const ToType *to)
Remove an arc from from to to.
Definition: ArcImplementation.h:304
std::enable_if<!U::value, bool >::type contains(const FromType *from, const ToType *to) const
Test whether an arc from from to to exists.
Definition: ArcImplementation.h:115
std::enable_if<!U::value, bool >::type connect(const FromType *from, const ToType *to, const FromType *beforeFrom=nullptr, const ToType *beforeTo=nullptr)
Insert an arc from from to to, optionally ordered by beforeFrom and beforeTo.
Definition: ArcImplementation.h:266
typename ArcProperties< TraitsType >::isMutable Mutable
If "truthy," methods that edit arcs may sometimes return true.
Definition: ArcImplementation.h:74
std::enable_if< U::value, bool >::type connect(const FromType *from, const ToType *to, const FromType *beforeFrom=nullptr, const ToType *beforeTo=nullptr)
Insert an arc from from to to, optionally ordered by beforeFrom and beforeTo.
Definition: ArcImplementation.h:280
smtk::shared_ptr< smtk::resource::Component > ComponentPtr
Definition: PublicPointerDefs.h:297
Provide no default arc storage.
Definition: TypeTraits.h:37
A template for accepting visitors with different return types.
Definition: Visit.h:56