Commit Graph

13 Commits

Author SHA1 Message Date
Andreas Kling
fdcff7d15e AK: Make it possible to use HashMap<K, NonnullOwnPtr>::get()
Add the concept of a PeekType to Traits<T>. This is the type we'll
return (wrapped in an Optional) from HashMap::get().

The PeekType for OwnPtr<T> and NonnullOwnPtr<T> is const T*,
which means that HashMap::get() will return an Optional<const T*> for
maps-of-those.
2019-08-14 11:47:38 +02:00
Andreas Kling
c5903ec4bb AK: Remove two redundant RefPtr constructors.
We already have constructors for "const T*" and "const T&" so we don't
need to have non-const variants.
2019-08-03 14:16:05 +02:00
Andreas Kling
fe25426ee4 AK: Simplify RefPtr and NonnullRefPtr's leak_ref() functions
Use AK::exchange() to switch out the internal storage. Also mark these
functions with [[nodiscard]] to provoke an compile-time error if they
are called without using the return value.
2019-08-02 12:05:09 +02:00
Andreas Kling
15866714da AK: Add anti-null assertions in RefPtr.
This gives us better error messages when dereferencing null RefPtrs.
2019-08-02 12:00:43 +02:00
Andreas Kling
cbc1272810 AK: Fix ref leaks in RefPtr assignment operators.
Many of the RefPtr assignment operators would cause ref leaks when we
call them to assign a pointer that's already the one kept.
2019-08-02 11:56:55 +02:00
Andreas Kling
fa6f601170 AK: RefPtr::operator=(RefPtr<U>&&) needs to cast the incoming pointer.
Otherwise it's not possible to assign a RefPtr<Derived>&& to a RefPtr<Base>.
2019-07-21 11:37:24 +02:00
Andreas Kling
25e3d46502 AK: Delete bad pointer assignment operators and constructors.
We shouldn't allow constructing e.g an OwnPtr from a RefPtr, and similar
conversions. Instead just delete those functions so the compiler whines
loudly if you try to use them.

This patch also deletes constructing OwnPtr from a WeakPtr, even though
that *may* be a valid thing to do, it's sufficiently weird that we can
make the client jump through some hoops if he really wants it. :^)
2019-07-11 16:50:30 +02:00
Andreas Kling
eb64a4ca60 AK: Remove copy_ref().
This patch removes copy_ref() from RefPtr and NonnullRefPtr. This means that
it's now okay to simply copy these smart pointers instead:

- RefPtr = RefPtr // Okay!
- RefPtr = NonnullRefPtr // Okay!
- NonnullRefPtr = NonnullRefPtr // Okay!
- NonnullRefPtr = RefPtr // Not okay, since RefPtr can be null.
2019-07-11 16:05:51 +02:00
Andreas Kling
b0372883ff AK: Remove use of copy_ref(). 2019-07-11 15:45:11 +02:00
Andreas Kling
560d037c41 AK: Make it more more pleasant to copy RefPtr's.
I had a silly ambition that we would avoid unnecessary ref count churn by
forcing explicit use of "copy_ref()" wherever a copy was actually needed.
This was making RefPtr a bit clunky to work with, for no real benefit.

This patch adds the missing copy construction/assignment stuff to RefPtr.
2019-07-11 15:38:38 +02:00
Andreas Kling
32fb7ecef4 AK: Remove weird RefPtr(RefPtr&) constructor. 2019-07-11 15:19:16 +02:00
Andreas Kling
1b013ba699 AK: Move some of LogStream out of line & add overloads for smart pointers. 2019-07-04 07:05:58 +02:00
Andreas Kling
550b0b062b AK: Rename RetainPtr.h => RefPtr.h, Retained.h => NonnullRefPtr.h. 2019-06-21 18:45:59 +02:00