7 namespace ComponentModel
15 template<
typename ComponentType>
18 static_assert(std::is_base_of<Component, ComponentType>::value,
"<ComponentType> not derived from Component");
20 typedef ComponentType value_type;
32 : owner(std::move(owner))
44 : owner(std::move(source.owner))
60 ComponentPtr<ComponentType> & operator=(ComponentPtr<ComponentType> && rhs)
noexcept
62 owner = std::move(rhs.owner);
66 ComponentType * get()
const
68 return owner->getComponent<ComponentType>();
71 ComponentType * operator ->()
const
79 operator bool()
const {
return owner !=
nullptr && operator->() !=
nullptr; }
91 std::shared_ptr<Entity>
getEntity()
const {
return owner; }
94 std::shared_ptr<Entity> owner;
A shared_pointer type pointer to a component in an entity.
constexpr ComponentPtr(std::nullptr_t)
Construct empty instance.
std::shared_ptr< Entity > getEntity() const
Get the owning entity.
ComponentPtr(std::shared_ptr< Entity > &&owner) noexcept
Initializes a component pointer for component in the given entity.
void reset()
Reset to empty.
ComponentPtr(const std::shared_ptr< Entity > &owner)
Initializes a component pointer for component in the given entity.
constexpr bool operator==(const ComponentPtr< ComponentType > &other) const
Comparison operator. If the entity of both objects are equal the objects are considered equal.
ComponentPtr(const ComponentPtr< ComponentType > &source)
Initializes a component pointer as a copy constructor.
ComponentPtr(ComponentPtr< ComponentType > &&source) noexcept
Initializes a component pointer using RValue constructor.
Contains all Cogs related functionality.