18 #ifndef IGNITION_PHYSICS_DETAIL_ENTITY_HH_ 19 #define IGNITION_PHYSICS_DETAIL_ENTITY_HH_ 39 template <
typename Policy,
typename Features>
40 struct DeterminePlugin;
43 template <
typename Policy,
typename... Features>
44 struct DeterminePlugin<Policy,
std::tuple<Features...>>
47 typename Features::template Implementation<Policy>...>;
54 template <
typename T,
typename Tuple>
55 struct TupleContainsBase;
60 template <
typename T,
typename... Types>
61 struct TupleContainsBase<T,
std::tuple<Types...>>
64 std::tuple<typename std::conditional<
65 std::is_base_of<T, Types>::value, Empty, Types>::type...>,
70 template <
typename ToFeatureTuple,
typename FromFeatureList>
71 struct HasAllFeaturesImpl;
73 template <
typename FromFeatureList,
74 typename ToFeature1,
typename... RemainingFeatures>
75 struct HasAllFeaturesImpl<
76 std::tuple<ToFeature1, RemainingFeatures...>, FromFeatureList>
78 static constexpr
bool innerValue =
79 FromFeatureList::template HasFeature<ToFeature1>();
81 static constexpr
bool value = innerValue
82 && HasAllFeaturesImpl<
std::tuple<RemainingFeatures...>,
83 FromFeatureList>::value;
87 "YOU CANNOT IMPLICITLY UPCAST TO THIS ENTITY TYPE, BECAUSE IT " 88 "CONTAINS A FEATURE THAT IS NOT INCLUDED IN THE ENTITY THAT YOU " 93 template <
typename FromFeatureList>
94 struct HasAllFeaturesImpl<std::tuple<>, FromFeatureList>
96 static constexpr
bool value =
true;
102 template <
typename To,
typename From>
103 struct HasAllFeatures
105 using ToFeatures =
typename To::Features;
106 using FromFeatures =
typename From::Features;
108 static constexpr
bool value =
110 typename ToFeatures::Features,
111 FromFeatures>::value;
115 template <
typename To,
typename From,
bool downcastable>
116 struct CheckForDowncastableMessage
118 static constexpr
bool value =
119 TupleContainsBase<
typename To::Identifier,
120 typename From::UpcastIdentifiers>::value;
123 value,
"YOU CANNOT UPCAST TO AN INCOMPATIBLE ENTITY TYPE.");
130 template <
typename To,
typename From>
131 struct CheckForDowncastableMessage<To, From, true>
133 static constexpr
bool value =
134 TupleContainsBase<
typename To::Identifier,
135 typename From::UpcastIdentifiers>::value;
139 "YOU CANNOT UPCAST TO AN ENTITY A MORE DERIVED TYPE. TO DOWNCAST " 140 "TO A MORE DERIVED TYPE (e.g. Joint to RevoluteJoint), USE THE " 141 "CASTING FEATURE OF THE BASE ENTITY, e.g. " 142 "Joint::CastToRevoluteJoint()");
146 template <
typename To,
typename From>
147 struct UpcastCompatible
151 "YOU CAN ONLY CAST BETWEEN ENTITIES THAT HAVE THE SAME POLICY (" 152 "e.g. FeaturePolicy3d, FeaturePolicy2d, FeaturePolicy3f). THE " 153 "REQUESTED CONVERSION IS NOT ADMISSIBLE.");
155 static_assert(HasAllFeatures<To, From>::value);
157 static_assert(CheckForDowncastableMessage<To, From,
159 typename From::Identifier,
160 typename To::UpcastIdentifiers>::value>::value);
164 "CANNOT CAST FROM A CONST-QUALIFIED ENTITY TO AN ENTITY WITHOUT A " 170 template <
typename EntityT>
177 template <
typename EntityT>
183 this->entity.emplace(_other.entity->pimpl, _other.entity->identity);
189 template <
typename EntityT>
191 : entity(
std::nullopt)
197 template <
typename EntityT>
199 : entity(
std::nullopt)
205 template <
typename EntityT>
208 this->entity.reset();
213 template <
typename EntityT>
216 this->entity.reset();
221 template <
typename EntityT>
223 template <
typename Pimpl>
233 this->entity.emplace(_pimpl, _identity);
238 template <
typename EntityT>
239 template <
typename OtherEntityT>
246 template <
typename EntityT>
247 template <
typename OtherEntityT>
252 detail::UpcastCompatible<EntityT, OtherEntityT>();
257 this->entity.reset();
265 if (!_other.entity->identity)
267 this->entity.reset();
276 this->entity.emplace(this->entity->pimpl, _other.entity->identity);
278 *this->entity->pimpl = *_other.entity->pimpl;
283 std::make_shared<typename EntityT::Pimpl>(
284 *_other.entity->pimpl);
286 this->entity.emplace(
std::move(newPimpl), _other.entity->identity);
293 template <
typename EntityT>
296 return &(this->entity.value());
300 template <
typename EntityT>
303 return this->entity.value();
307 template <
typename EntityT>
310 return this->entity.has_value();
314 template <
typename EntityT>
317 return this->entity.has_value();
321 template <
typename EntityT>
331 template <
typename Policy,
typename Features>
334 return this->identity;
338 template <
typename Policy,
typename Features>
341 return this->identity.id;
345 template <
typename Policy,
typename Features>
349 return this->identity.ref;
353 template <
typename Policy,
typename Features>
364 template <
typename Policy,
typename Features>
368 : pimpl(
std::move(_pimpl)),
375 template <
typename Policy,
typename Features>
376 template <
typename FeatureT>
377 typename FeatureT::template Implementation<Policy>*
380 return (*this->pimpl)->template QueryInterface<
381 typename FeatureT::template Implementation<Policy>>();
385 template <
typename Policy,
typename Features>
386 template <
typename FeatureT>
387 const typename FeatureT::template Implementation<Policy>*
390 return (*this->pimpl)->template QueryInterface<
391 typename FeatureT::template Implementation<Policy>>();
395 #define DETAIL_IGN_PHYSICS_ENTITY_PTR_IMPLEMENT_OPERATOR(op) \ 396 template <typename EntityT> \ 397 template <typename OtherEntityT> \ 398 bool EntityPtr<EntityT>::operator op (\ 399 const EntityPtr<OtherEntityT> &_other) const \ 402 if (!(*this) || !_other) \ 404 return (this->entity->EntityID() op _other.entity->EntityID()); \ 416 template <typename EntityT>
419 return !_ptr.Valid();
423 template <
typename EntityT>
426 return !_ptr.
Valid();
431 template <
typename EntityT>
434 return !(_ptr ==
nullptr);
438 template <
typename EntityT>
441 return !(_ptr ==
nullptr);
445 template <
typename EntityT>
448 return !_ptr.
Valid();
452 template <
typename EntityT>
455 return !_ptr.
Valid();
459 template <
typename EntityT>
462 return !(_ptr ==
nullptr);
466 template <
typename EntityT>
469 return !(_ptr ==
nullptr);
481 template <
typename EntityT>
bool operator!=(const EntityPtr< EntityT > &_ptr, std::nullopt_t)
Definition: detail/Entity.hh:467
This is the base class of all "proxy objects". The "proxy objects" are essentially interfaces into th...
Definition: Identity.hh:32
This class contains fields that identify an Entity. We use this separate class in order to have tight...
Definition: Identity.hh:73
EntityPtr & operator=(EntityPtr &&)=default
bool Valid() const
Check whether this is pointing at a valid Entity.
Definition: detail/Entity.hh:308
std::size_t Hash() const
Produces a hash for the Entity that this EntityPtr is referring to. This function allows EntityPtr in...
Definition: detail/Entity.hh:322
TemplatePluginPtr< SpecializedPlugin< SpecInterfaces... > > SpecializedPluginPtr
const std::size_t INVALID_ENTITY_ID
This constant-value should be used to indicate that an Entity ID is invalid (i.e. does not refer to a...
Definition: Entity.hh:37
#define DETAIL_IGN_PHYSICS_ENTITY_PTR_IMPLEMENT_OPERATOR(op)
Definition: detail/Entity.hh:395
Contains a static constexpr field named value which will be true if the type From has a const-quality...
Definition: TemplateHelpers.hh:58
bool operator==(const EntityPtr< EntityT > &_ptr, std::nullopt_t)
Definition: detail/Entity.hh:453
size_t operator()(const EntityPtr< EntityT > &ptr) const
Definition: detail/Entity.hh:484