23 virtual auto Id()
const noexcept ->
size_t = 0;
24 virtual auto Name()
const noexcept -> std::string_view = 0;
25 virtual auto HasDrawUI()
const noexcept ->
bool = 0;
30template<PooledComponent T>
35 : m_instance{instance}, m_handler{handler} {}
39 auto Id()
const noexcept ->
size_t override;
40 auto Name()
const noexcept -> std::string_view
override;
41 auto HasDrawUI()
const noexcept ->
bool override;
55 template<PooledComponent T>
66 return std::ranges::equal(buffer, other.buffer);
69 auto HasValue()
const noexcept ->
bool
71 return std::ranges::any_of(buffer, [](
auto b) {
return b != std::byte{}; });
81 return reinterpret_cast<const AnyImplBase*
>(buffer);
84 auto AsStorage()
noexcept ->
void*
95 alignas(align) std::byte buffer[size];
97 void Clear()
noexcept;
100template<PooledComponent T>
106template<PooledComponent T>
107auto AnyImplConcrete<T>::MoveTo(AnyImplStorage& dest)
noexcept -> AnyImplBase*
109 return new (dest.AsStorage()) AnyImplConcrete<T>{std::move(*
this)};
112template<PooledComponent T>
113auto AnyImplConcrete<T>::Id() const noexcept ->
size_t
115 return m_handler->id;
118template<PooledComponent T>
119auto AnyImplConcrete<T>::Name() const noexcept -> std::string_view
121 return m_handler->name;
124template<PooledComponent T>
125auto AnyImplConcrete<T>::HasDrawUI() const noexcept ->
bool
127 return m_handler->drawUI !=
nullptr;
130template<PooledComponent T>
131void AnyImplConcrete<T>::DrawUI(ui::editor::EditorContext& ctx)
133 m_handler->drawUI(*m_instance, ctx, m_handler->userData);
136template<PooledComponent T>
137AnyImplStorage::AnyImplStorage(T* instance, ComponentHandler<T>* handler)
139 NC_ASSERT(instance && handler,
"AnyComponent params must not be null, use AnyComponent() instead.")
140 using Impl = detail::AnyImplConcrete<T>;
143 static_assert(sizeof(Impl) == size &&
144 alignof(Impl) == align &&
145 std::has_virtual_destructor_v<Impl> &&
146 std::is_nothrow_destructible_v<Impl> &&
147 std::is_nothrow_copy_constructible_v<Impl> &&
148 std::is_nothrow_move_constructible_v<Impl> &&
149 std::is_nothrow_copy_assignable_v<Impl> &&
150 std::is_nothrow_move_assignable_v<Impl>);
152 new (buffer) Impl{instance, handler};
155inline AnyImplStorage::~AnyImplStorage() noexcept
159 AsImpl()->~AnyImplBase();
163inline AnyImplStorage::AnyImplStorage(
const AnyImplStorage& other) noexcept
166 if (other.HasValue())
168 other.AsImpl()->Clone(*
this);
172inline AnyImplStorage::AnyImplStorage(AnyImplStorage&& other) noexcept
175 if (other.HasValue())
177 other.AsImpl()->MoveTo(*
this);
181inline auto AnyImplStorage::operator=(
const AnyImplStorage& other)
noexcept -> AnyImplStorage&
184 if (other.HasValue())
186 other.AsImpl()->Clone(*
this);
192inline auto AnyImplStorage::operator=(AnyImplStorage&& other)
noexcept -> AnyImplStorage&
195 if (other.HasValue())
197 other.AsImpl()->MoveTo(*
this);
203inline void AnyImplStorage::Clear() noexcept
207 AsImpl()->~AnyImplBase();
208 std::memset(buffer, 0, size);
Definition: AnyComponentUtility.h:32
Definition: AnyComponentUtility.h:50
Optional data and callbacks for generic component operations.
Definition: Component.h:101
Definition: AnyComponentUtility.h:19
State for the editor.
Definition: EditorContext.h:39