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"
38 using remove_cvref_t =
typename std::remove_reference<typename std::remove_cv<T>::type>::type;
40 template<
typename T,
typename =
void>
43 bool operator()(
const T&)
const {
return true; }
49 bool operator()(
const T& node)
const {
return !node.expired(); }
53 template<
typename GraphTraits>
66 template<
typename GraphTraits>
95 template<
typename ArcType>
99 if (
const auto*
self =
dynamic_cast<const typename ArcType::FromType*
>(
this))
104 const auto& arcs = resource->arcs();
105 auto* arcsOfType = arcs.
at<ArcType>();
108 return arcsOfType->outgoing(
self);
110 std::ostringstream errorMessage;
111 errorMessage <<
"No arcs of the requested type (" << smtk::common::typeName<ArcType>()
112 <<
", " <<
typeid(ArcType).hash_code() <<
") are allowed.";
113 throw std::logic_error(errorMessage.str());
115 throw std::logic_error(
"Component has no parent resource.");
119 std::ostringstream msg;
120 msg <<
"This component is not the proper type (" << this->
typeName()
121 <<
") for the arc's endpoint (" << smtk::common::typeName<typename ArcType::FromType>()
123 throw std::logic_error(
130 template<
typename ArcType>
134 if (
auto*
self =
dynamic_cast<typename ArcType::FromType*
>(
this))
139 auto& arcs = resource->arcs();
140 auto* arcsOfType = arcs.
at<ArcType>();
143 return arcsOfType->outgoing(
self);
145 std::ostringstream errorMessage;
146 errorMessage <<
"No arcs of the requested type (" << smtk::common::typeName<ArcType>()
147 <<
", " <<
typeid(ArcType).hash_code() <<
") are allowed.";
148 throw std::logic_error(errorMessage.str());
150 throw std::logic_error(
"Component has no parent resource.");
154 std::ostringstream msg;
155 msg <<
"This component is not the proper type (" << this->
typeName()
156 <<
") for the arc's endpoint (" << smtk::common::typeName<typename ArcType::FromType>()
158 throw std::logic_error(
161 ArcEndpointInterface<ArcType, NonConstArc, OutgoingArc> dummy;
177 template<
typename ArcType>
181 if (
const auto*
self =
dynamic_cast<const typename ArcType::ToType*
>(
this))
186 const auto& arcs = resource->arcs();
187 auto* arcsOfType = arcs.
at<ArcType>();
190 return arcsOfType->incoming(
self);
192 std::ostringstream errorMessage;
193 errorMessage <<
"No arcs of the requested type (" << smtk::common::typeName<ArcType>()
194 <<
", " <<
typeid(ArcType).hash_code() <<
") are allowed.";
195 throw std::logic_error(errorMessage.str());
197 throw std::logic_error(
"Component has no parent resource.");
201 std::ostringstream msg;
202 msg <<
"This component is not the proper type (" << this->
typeName()
203 <<
") for the arc's endpoint (" << smtk::common::typeName<typename ArcType::ToType>()
205 throw std::logic_error(
212 template<
typename ArcType>
216 if (
auto*
self =
dynamic_cast<typename ArcType::ToType*
>(
this))
221 auto& arcs = resource->arcs();
222 auto* arcsOfType = arcs.
at<ArcType>();
225 return arcsOfType->incoming(
self);
227 std::ostringstream errorMessage;
228 errorMessage <<
"No arcs of the requested type (" << smtk::common::typeName<ArcType>()
229 <<
" id " <<
typeid(ArcType).hash_code() <<
", " <<
typeid(ArcType).hash_code()
231 throw std::logic_error(errorMessage.str());
233 throw std::logic_error(
"Component has no parent resource.");
237 std::ostringstream msg;
238 msg <<
"This component is not the proper type (" << this->
typeName()
239 <<
") for the arc's endpoint (" << smtk::common::typeName<typename ArcType::ToType>()
241 throw std::logic_error(
244 ArcEndpointInterface<ArcType, NonConstArc, IncomingArc> dummy;
257 bool disconnect(
bool onlyExplicit =
false);
269 Component(
const std::shared_ptr<smtk::graph::ResourceBase>&);
271 Component(
const std::shared_ptr<smtk::graph::ResourceBase>&,
const smtk::common::UUID&);
276 virtual void createDependentArcs() {}
278 smtk::WeakReferenceWrapper<smtk::graph::ResourceBase> m_resource;