11 #ifndef smtk_graph_Component_h
12 #define smtk_graph_Component_h
14 #include "smtk/common/WeakReferenceWrapper.h"
15 #include "smtk/resource/Component.h"
19 #include "smtk/graph/ArcMap.h"
20 #include "smtk/graph/ResourceBase.h"
21 #include "smtk/graph/detail/TypeTraits.h"
42 using remove_cvref_t =
typename std::remove_reference<typename std::remove_cv<T>::type>::type;
44 template<
typename T,
typename =
void>
47 bool operator()(
const T&)
const {
return true; }
53 bool operator()(
const T& node)
const {
return !node.expired(); }
57 template<
typename GraphTraits>
70 template<
typename GraphTraits>
99 template<
typename ArcType>
103 if (
const auto*
self =
dynamic_cast<const typename ArcType::FromType*
>(
this))
108 const auto& arcs = resource->arcs();
109 auto* arcsOfType = arcs.
at<ArcType>();
112 return arcsOfType->outgoing(
self);
114 std::ostringstream errorMessage;
115 errorMessage <<
"No arcs of the requested type (" << smtk::common::typeName<ArcType>()
116 <<
", " <<
typeid(ArcType).hash_code() <<
") are allowed.";
117 throw std::logic_error(errorMessage.str());
119 throw std::logic_error(
"Component has no parent resource.");
123 std::ostringstream msg;
124 msg <<
"This component is not the proper type (" << this->
typeName()
125 <<
") for the arc's endpoint (" << smtk::common::typeName<typename ArcType::FromType>()
127 throw std::logic_error(
134 template<
typename ArcType>
138 if (
auto*
self =
dynamic_cast<typename ArcType::FromType*
>(
this))
143 auto& arcs = resource->arcs();
144 auto* arcsOfType = arcs.
at<ArcType>();
147 return arcsOfType->outgoing(
self);
149 std::ostringstream errorMessage;
150 errorMessage <<
"No arcs of the requested type (" << smtk::common::typeName<ArcType>()
151 <<
", " <<
typeid(ArcType).hash_code() <<
") are allowed.";
152 throw std::logic_error(errorMessage.str());
154 throw std::logic_error(
"Component has no parent resource.");
158 std::ostringstream msg;
159 msg <<
"This component is not the proper type (" << this->
typeName()
160 <<
") for the arc's endpoint (" << smtk::common::typeName<typename ArcType::FromType>()
162 throw std::logic_error(
165 ArcEndpointInterface<ArcType, NonConstArc, OutgoingArc> dummy;
181 template<
typename ArcType>
185 if (
const auto*
self =
dynamic_cast<const typename ArcType::ToType*
>(
this))
190 const auto& arcs = resource->arcs();
191 auto* arcsOfType = arcs.
at<ArcType>();
194 return arcsOfType->incoming(
self);
196 std::ostringstream errorMessage;
197 errorMessage <<
"No arcs of the requested type (" << smtk::common::typeName<ArcType>()
198 <<
", " <<
typeid(ArcType).hash_code() <<
") are allowed.";
199 throw std::logic_error(errorMessage.str());
201 throw std::logic_error(
"Component has no parent resource.");
205 std::ostringstream msg;
206 msg <<
"This component is not the proper type (" << this->
typeName()
207 <<
") for the arc's endpoint (" << smtk::common::typeName<typename ArcType::ToType>()
209 throw std::logic_error(
216 template<
typename ArcType>
220 if (
auto*
self =
dynamic_cast<typename ArcType::ToType*
>(
this))
225 auto& arcs = resource->arcs();
226 auto* arcsOfType = arcs.
at<ArcType>();
229 return arcsOfType->incoming(
self);
231 std::ostringstream errorMessage;
232 errorMessage <<
"No arcs of the requested type (" << smtk::common::typeName<ArcType>()
233 <<
" id " <<
typeid(ArcType).hash_code() <<
", " <<
typeid(ArcType).hash_code()
235 throw std::logic_error(errorMessage.str());
237 throw std::logic_error(
"Component has no parent resource.");
241 std::ostringstream msg;
242 msg <<
"This component is not the proper type (" << this->
typeName()
243 <<
") for the arc's endpoint (" << smtk::common::typeName<typename ArcType::ToType>()
245 throw std::logic_error(
248 ArcEndpointInterface<ArcType, NonConstArc, IncomingArc> dummy;
261 bool disconnect(
bool onlyExplicit =
false);
285 Component(
const std::shared_ptr<smtk::graph::ResourceBase>&);
287 Component(
const std::shared_ptr<smtk::graph::ResourceBase>&,
const smtk::common::UUID&);
292 virtual void createDependentArcs() {}
294 smtk::WeakReferenceWrapper<smtk::graph::ResourceBase> m_resource;