operator accessories for component wrappers

This commit is contained in:
2019-05-14 12:42:38 +07:00
parent c08d4995f6
commit d7456c4228
3 changed files with 107 additions and 0 deletions

View File

@@ -991,6 +991,14 @@ namespace ecs_hpp
T* find() noexcept;
const T* find() const noexcept;
T& operator*();
const T& operator*() const;
T* operator->() noexcept;
const T* operator->() const noexcept;
explicit operator bool() const noexcept;
private:
entity owner_;
};
@@ -1047,6 +1055,10 @@ namespace ecs_hpp
const T& get() const;
const T* find() const noexcept;
const T& operator*() const;
const T* operator->() const noexcept;
explicit operator bool() const noexcept;
private:
const_entity owner_;
};
@@ -1689,6 +1701,31 @@ namespace ecs_hpp
return detail::as_const(owner_).template find_component<T>();
}
template < typename T >
T& component<T>::operator*() {
return get();
}
template < typename T >
const T& component<T>::operator*() const {
return get();
}
template < typename T >
T* component<T>::operator->() noexcept {
return find();
}
template < typename T >
const T* component<T>::operator->() const noexcept {
return find();
}
template < typename T >
component<T>::operator bool() const noexcept {
return exists();
}
template < typename T >
bool operator<(const component<T>& l, const component<T>& r) noexcept {
return l.owner() < r.owner();
@@ -1751,6 +1788,21 @@ namespace ecs_hpp
return detail::as_const(owner_).template find_component<T>();
}
template < typename T >
const T& const_component<T>::operator*() const {
return get();
}
template < typename T >
const T* const_component<T>::operator->() const noexcept {
return find();
}
template < typename T >
const_component<T>::operator bool() const noexcept {
return exists();
}
template < typename T >
bool operator<(const const_component<T>& l, const const_component<T>& r) noexcept {
return l.owner() < r.owner();