From 644d0560c925fa9068b6d03b199c63387ceb9352 Mon Sep 17 00:00:00 2001 From: Alec Thomas Date: Sun, 2 Mar 2014 12:58:57 +1100 Subject: Fix visibility issue with gcc. --- entityx/Entity.h | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/entityx/Entity.h b/entityx/Entity.h index 84a8cfb..141f2e6 100644 --- a/entityx/Entity.h +++ b/entityx/Entity.h @@ -199,16 +199,19 @@ struct Component : public BaseComponent { }; +/** + * Managed pointer for components. + */ template class ComponentPtr { public: ComponentPtr() : id_(0), manager_(nullptr) {} T *operator -> (); - const T *operator -> () const; - operator bool () const; + operator bool () const { return valid(); } + bool valid() const; bool operator == (const ComponentPtr &other) const { return other.id_ == id_ && other.manager_ == manager_; @@ -219,6 +222,9 @@ private: ComponentPtr(Entity::Id id, EntityManager *manager) : id_(id), manager_(manager) {} + T *get_component_ptr(); + const T *get_component_ptr() const; + template friend inline std::ostream &operator << (std::ostream &out, const ComponentPtr &ptr); @@ -227,6 +233,7 @@ private: }; + /** * Emitted when an entity is added to the system. */ @@ -341,12 +348,6 @@ public: }; -template -inline std::ostream &operator << (std::ostream &out, const ComponentPtr &ptr) { - return out << *(ptr.manager_->template get_component_ptr(ptr.id_)); -} - - /** * Manages Entity::Id creation and component assignment. */ @@ -751,6 +752,7 @@ class EntityManager : entityx::help::NonCopyable, public enable_shared_from_this std::list free_list_; }; + template BaseComponent::Family Component::family() { static Family family = family_counter_++; @@ -758,6 +760,7 @@ BaseComponent::Family Component::family() { return family; } + template ComponentPtr Entity::assign(Args && ... args) { assert(valid()); @@ -786,6 +789,7 @@ inline bool Entity::valid() const { return !manager_.expired() && manager_.lock()->valid(id_); } + template inline T *ComponentPtr::operator -> () { return manager_->get_component_ptr(id_); @@ -797,9 +801,23 @@ inline const T *ComponentPtr::operator -> () const { } template -inline ComponentPtr::operator bool () const { +inline bool ComponentPtr::valid() const { return manager_ && manager_->valid(id_); } +template +inline T *ComponentPtr::get_component_ptr() { + return manager_->get_component_ptr(id_); +} + +template +inline const T *ComponentPtr::get_component_ptr() const { + return manager_->get_component_ptr(id_); +} + +template +inline std::ostream &operator << (std::ostream &out, const ComponentPtr &ptr) { + return out << *(ptr.get_component_ptr()); +} } // namespace entityx -- cgit v1.2.3