1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 15:27:35 +00:00

AK: Move Handle from LibCore and name it MaybeOwned

The new name should make it abundantly clear what it does.
This commit is contained in:
Tim Schumacher 2023-01-22 04:24:18 +01:00 committed by Andrew Kaster
parent 5fa590de71
commit 5f2ea31816
16 changed files with 115 additions and 92 deletions

View file

@ -27,48 +27,6 @@
namespace Core::Stream {
template<DerivedFrom<Core::Stream::Stream> T>
class Handle {
public:
template<DerivedFrom<T> U>
Handle(NonnullOwnPtr<U> handle)
: m_handle(adopt_own<T>(*handle.leak_ptr()))
{
}
// This is made `explicit` to not accidentally create a non-owning Handle,
// which may not always be intended.
explicit Handle(T& handle)
: m_handle(&handle)
{
}
T* ptr()
{
if (m_handle.template has<T*>())
return m_handle.template get<T*>();
else
return m_handle.template get<NonnullOwnPtr<T>>();
}
T const* ptr() const
{
if (m_handle.template has<T*>())
return m_handle.template get<T*>();
else
return m_handle.template get<NonnullOwnPtr<T>>();
}
T* operator->() { return ptr(); }
T const* operator->() const { return ptr(); }
T& operator*() { return *ptr(); }
T const& operator*() const { return *ptr(); }
private:
Variant<NonnullOwnPtr<T>, T*> m_handle;
};
/// The base, abstract class for stream operations. This class defines the
/// operations one can perform on every stream in LibCore.
/// Operations without a sensible default that are unsupported by an implementation