summaryrefslogtreecommitdiff
path: root/AK/NonnullRefPtr.h
AgeCommit message (Collapse)Author
2020-01-23AK: Let's call decrementing reference counts "unref" instead of "deref"Andreas Kling
It always bothered me that we're using the overloaded "dereference" term for this. Let's call it "unreference" instead. :^)
2020-01-19AK: Make it possible to swap() a NonnullRefPtr with itselfAndreas Kling
The generic swap() is not able to swap a NonnullRefPtr with itself, due to its use of a temporary and NonnullRefPtr asserting when trying to move() from an already move()'d instance.
2020-01-18AK: NonnullRefPtr should allow assigning owner to owneeAndreas Kling
Given the following situation: struct Object : public RefCounted<Object> { RefPtr<Object> parent; } NonnullRefPtr<Object> object = get_some_object(); object = *object->parent; We would previously crash if 'object' was the only strongly referencing pointer to 'parent'. This happened because NonnullRefPtr would unref the outgoing pointee before reffing the incoming pointee. This patch fixes that by implementing NonnullRefPtr assignments using pointer swaps, just like RefPtr already did.
2020-01-18Meta: Add license header to source filesAndreas Kling
As suggested by Joshua, this commit adds the 2-clause BSD license as a comment block to the top of every source file. For the first pass, I've just added myself for simplicity. I encourage everyone to add themselves as copyright holders of any file they've added or modified in some significant way. If I've added myself in error somewhere, feel free to replace it with the appropriate copyright holder instead. Going forward, all new source files should include a license header.
2019-11-07AK: Delete operator!() and operator bool() from the Nonnull pointersAndreas Kling
Since NonnullRefPtr and NonnullOwnPtr cannot be null, it is pointless to convert them to a bool, since it would always be true. This patch makes it an error to null-check one of these pointers.
2019-08-02AK: Simplify RefPtr and NonnullRefPtr's leak_ref() functionsAndreas Kling
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-02AK: Explicitly delete NonnullRefPtr::operator=(RefPtr).Andreas Kling
This gives us much better error messages when you try to use them. Without this change, it would complain about the absence of functions named ref() and deref() on RefPtr itself. With it, we instead get a "hey, this function is deleted" error. Change operator=(T&) to operator=T(const T&) also, to keep assigning a const T& to a NonnullRefPtr working.
2019-08-02AK: Fix ref leak in NonnullRefPtr::operator=(T&).Andreas Kling
We would leak a ref when assigning a T& to a NonnullRefPtr that already contains that same T.
2019-07-26AK: Fix NonnullRefPtr<T>::operator=(NonnullRefPtr<U>).Andreas Kling
2019-07-25AK: Allow NonnullRefPtr::ptr() when in "unknown" typestate.Andreas Kling
Clang loses the typestate when passing NonnullRefPtr's via lambda captures. This is unfortunate, but not much we can do about it. Allowing ptr() makes it possible to use captured NonnullRefPtrs as you'd expect.
2019-07-25AK: Simplify NonnullPtrVector template a bit.Andreas Kling
Add an "ElementType" typedef to NonnullOwnPtr and NonnullRefPtr to allow clients to easily find the pointee type. Then use this to remove a template argument from NonnullPtrVector. :^)
2019-07-24AK: Move clang-specific consumable annotation helpers to Platform.hAndreas Kling
2019-07-21AK: Make NonnullRefPtr::operator=(NonnullRefPtr<U>&&) cast incoming pointer.Andreas Kling
Same as the RefPtr issue I just fixed. This makes it possible to assign a NonnullRefPtr<Derived>&& to a NonnullRefPtr<Base>.
2019-07-11AK: Delete bad pointer assignment operators and constructors.Andreas Kling
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-11AK: Remove copy_ref().Andreas Kling
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-11AK: Remove weird NonnullRefPtr(NonnullRefPtr&) constructor.Andreas Kling
2019-07-04AK: Move some of LogStream out of line & add overloads for smart pointers.Andreas Kling
2019-06-24NonnullRefPtr: Simplify copy constructors.Andreas Kling
2019-06-24NonnullRefPtr: Some improvements.Andreas Kling
- Delete the default constructor instead of just making it private. It's never valid to create an empty NonnullRefPtr. - Add copy assignment operators. I originally omitted these to force use of .copy_ref() at call sites, but the hassle/gain ratio is minuscule. - Allow calling all the assignment operators in all consumable states. This codifies that it's okay to overwrite a moved-from NonnullRefPtr.
2019-06-21AK: Rename RetainPtr.h => RefPtr.h, Retained.h => NonnullRefPtr.h.Andreas Kling