diff options
author | Alec Thomas <alec@swapoff.org> | 2014-03-02 12:58:57 +1100 |
---|---|---|
committer | Alec Thomas <alec@swapoff.org> | 2014-03-02 12:58:57 +1100 |
commit | 644d0560c925fa9068b6d03b199c63387ceb9352 (patch) | |
tree | 8dffc3e51ee17767a5d285c7d7cd182c3e4d62d9 | |
parent | dff92af29e45c86bbb5d22f2a0b0e6f4e62bc494 (diff) |
Fix visibility issue with gcc.
-rw-r--r-- | entityx/Entity.h | 36 |
1 files 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 <typename T> 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<T> &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 <typename R> friend inline std::ostream &operator << (std::ostream &out, const ComponentPtr<R> &ptr); @@ -227,6 +233,7 @@ private: }; + /** * Emitted when an entity is added to the system. */ @@ -341,12 +348,6 @@ public: }; -template <typename T> -inline std::ostream &operator << (std::ostream &out, const ComponentPtr<T> &ptr) { - return out << *(ptr.manager_->template get_component_ptr<T>(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<uint32_t> free_list_; }; + template <typename C> BaseComponent::Family Component<C>::family() { static Family family = family_counter_++; @@ -758,6 +760,7 @@ BaseComponent::Family Component<C>::family() { return family; } + template <typename C, typename ... Args> ComponentPtr<C> Entity::assign(Args && ... args) { assert(valid()); @@ -786,6 +789,7 @@ inline bool Entity::valid() const { return !manager_.expired() && manager_.lock()->valid(id_); } + template <typename T> inline T *ComponentPtr<T>::operator -> () { return manager_->get_component_ptr<T>(id_); @@ -797,9 +801,23 @@ inline const T *ComponentPtr<T>::operator -> () const { } template <typename T> -inline ComponentPtr<T>::operator bool () const { +inline bool ComponentPtr<T>::valid() const { return manager_ && manager_->valid(id_); } +template <typename T> +inline T *ComponentPtr<T>::get_component_ptr() { + return manager_->get_component_ptr<T>(id_); +} + +template <typename T> +inline const T *ComponentPtr<T>::get_component_ptr() const { + return manager_->get_component_ptr<T>(id_); +} + +template <typename T> +inline std::ostream &operator << (std::ostream &out, const ComponentPtr<T> &ptr) { + return out << *(ptr.get_component_ptr()); +} } // namespace entityx |