mirror of
https://github.com/BlackMATov/ecs.hpp.git
synced 2025-12-16 22:19:21 +07:00
operator accessories for component wrappers
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user