diff --git a/modules/juce_audio_plugin_client/RTAS/juce_RTAS_Wrapper.cpp b/modules/juce_audio_plugin_client/RTAS/juce_RTAS_Wrapper.cpp index b77cda1e13..1a5bd3b435 100644 --- a/modules/juce_audio_plugin_client/RTAS/juce_RTAS_Wrapper.cpp +++ b/modules/juce_audio_plugin_client/RTAS/juce_RTAS_Wrapper.cpp @@ -175,9 +175,8 @@ class JucePlugInProcess : public CEffectProcessMIDI, public: //============================================================================== JucePlugInProcess() - : sampleRate (44100.0) { - juceFilter = createPluginFilterOfType (AudioProcessor::wrapperType_RTAS); + juceFilter.reset (createPluginFilterOfType (AudioProcessor::wrapperType_RTAS)); AddChunk (juceChunkType, "Juce Audio Plugin Data"); @@ -191,13 +190,13 @@ public: if (mLoggedIn) MIDILogOut(); - midiBufferNode = nullptr; - midiTransport = nullptr; + midiBufferNode.reset(); + midiTransport.reset(); if (juceFilter != nullptr) { juceFilter->releaseResources(); - juceFilter = nullptr; + juceFilter.reset(); } if (--numInstances == 0) @@ -235,7 +234,7 @@ public: { if (editorComp == nullptr) { - editorComp = filter->createEditorIfNeeded(); + editorComp.reset (filter->createEditorIfNeeded()); jassert (editorComp != nullptr); } @@ -277,12 +276,12 @@ public: updateSize(); #if JUCE_WINDOWS - void* const hostWindow = (void*) ASI_GethWnd ((WindowPtr) port); + auto hostWindow = (void*) ASI_GethWnd ((WindowPtr) port); #else - void* const hostWindow = (void*) GetWindowFromPort (port); + auto hostWindow = (void*) GetWindowFromPort (port); #endif - wrapper = nullptr; - wrapper = new EditorCompWrapper (hostWindow, editorComp, this); + wrapper.reset(); + wrapper.reset (new EditorCompWrapper (hostWindow, editorComp.get(), this)); } } else @@ -295,10 +294,8 @@ public: { #if JUCE_WINDOWS if (wrapper != nullptr) - { - if (ComponentPeer* const peer = wrapper->getPeer()) + if (auto peer = wrapper->getPeer()) peer->repaint (wrapper->getLocalBounds()); // (seems to be required in PT6.4, but not in 7.x) - } #endif } @@ -308,8 +305,8 @@ public: private: AudioProcessor* const filter; JucePlugInProcess* const process; - ScopedPointer wrapper; - ScopedPointer editorComp; + std::unique_ptr wrapper; + std::unique_ptr editorComp; void deleteEditorComp() { @@ -324,8 +321,8 @@ public: filter->editorBeingDeleted (editorComp); - editorComp = nullptr; - wrapper = nullptr; + editorComp.reset(); + wrapper.reset(); } } } @@ -339,9 +336,9 @@ public: #endif { public: - EditorCompWrapper (void* const hostWindow_, - Component* const editorComp, - JuceCustomUIView* const owner_) + EditorCompWrapper (void* hostWindow_, + Component* editorComp, + JuceCustomUIView* owner_) : hostWindow (hostWindow_), owner (owner_), titleW (0), @@ -355,7 +352,7 @@ public: setBroughtToFrontOnMouseClick (true); setBounds (editorComp->getBounds()); editorComp->setTopLeftPosition (0, 0); - addAndMakeVisible (editorComp); + addAndMakeVisible (*editorComp); #if JUCE_WINDOWS attachSubWindow (hostWindow, titleW, titleH, this); @@ -452,7 +449,7 @@ public: CPlugInView* CreateCPlugInView() override { - return new JuceCustomUIView (juceFilter, this); + return new JuceCustomUIView (juceFilter.get(), this); } void SetViewPort (GrafPtr port) override @@ -513,18 +510,18 @@ public: type->GetProcessTypeName (63, nodeName); nodeName[nodeName[0] + 1] = 0; - midiBufferNode = new CEffectMIDIOtherBufferedNode (&mMIDIWorld, - 8192, - eLocalNode, - nodeName + 1, - midiBuffer); + midiBufferNode.reset (new CEffectMIDIOtherBufferedNode (&mMIDIWorld, + 8192, + eLocalNode, + nodeName + 1, + midiBuffer)); midiBufferNode->Initialize (0xffff, true); } #endif } - midiTransport = new CEffectMIDITransport (&mMIDIWorld); + midiTransport.reset (new CEffectMIDITransport (&mMIDIWorld)); midiEvents.ensureSize (2048); channels.calloc (jmax (juceFilter->getTotalNumInputChannels(), @@ -814,15 +811,15 @@ public: } private: - ScopedPointer juceFilter; + std::unique_ptr juceFilter; MidiBuffer midiEvents; - ScopedPointer midiBufferNode; - ScopedPointer midiTransport; + std::unique_ptr midiBufferNode; + std::unique_ptr midiTransport; DirectMidiPacket midiBuffer [midiBufferSize]; juce::MemoryBlock tempFilterData; HeapBlock channels; - double sampleRate; + double sampleRate = 44100.0; static float longToFloat (const long n) noexcept { @@ -955,7 +952,7 @@ public: //============================================================================== void CreateEffectTypes() { - ScopedPointer plugin = createPluginFilterOfType (AudioProcessor::wrapperType_RTAS); + std::unique_ptr plugin (createPluginFilterOfType (AudioProcessor::wrapperType_RTAS)); const short channelConfigs[][2] = { JucePlugin_PreferredChannelConfigurations }; const int numConfigs = numElementsInArray (channelConfigs); diff --git a/modules/juce_core/memory/juce_ContainerDeletePolicy.h b/modules/juce_core/memory/juce_ContainerDeletePolicy.h index bd3fd39ce1..212b7cca22 100644 --- a/modules/juce_core/memory/juce_ContainerDeletePolicy.h +++ b/modules/juce_core/memory/juce_ContainerDeletePolicy.h @@ -32,7 +32,7 @@ namespace juce create a specialised version of it for a particular class if you need to delete that type of object in a more appropriate way. - @see ScopedPointer, OwnedArray + @see OwnedArray @tags{Core} */ @@ -45,8 +45,8 @@ struct ContainerDeletePolicy // an incomplete type for ObjectType (for example, a type that is declared // but not defined). This is a problem because then the following delete is // undefined behaviour. The purpose of the sizeof is to capture this situation. - // If this was caused by a ScopedPointer to a forward-declared type, move the - // implementation of all methods trying to use the ScopedPointer (e.g. the destructor + // If this was caused by a OwnedArray of a forward-declared type, move the + // implementation of all methods trying to use the OwnedArray (e.g. the destructor // of the class owning it) into cpp files where they can see to the definition // of ObjectType. This should fix the error. ignoreUnused (sizeof (ObjectType)); diff --git a/modules/juce_core/memory/juce_OptionalScopedPointer.h b/modules/juce_core/memory/juce_OptionalScopedPointer.h index fa7362c263..ad8081db57 100644 --- a/modules/juce_core/memory/juce_OptionalScopedPointer.h +++ b/modules/juce_core/memory/juce_OptionalScopedPointer.h @@ -28,11 +28,9 @@ namespace juce Holds a pointer to an object which can optionally be deleted when this pointer goes out of scope. - This acts in many ways like a ScopedPointer, but allows you to specify whether or + This acts in many ways like a std::unique_ptr, but allows you to specify whether or not the object is deleted. - @see ScopedPointer - @tags{Core} */ template @@ -46,7 +44,7 @@ public: /** Creates an OptionalScopedPointer to point to a given object, and specifying whether the OptionalScopedPointer will delete it. - If takeOwnership is true, then the OptionalScopedPointer will act like a ScopedPointer, + If takeOwnership is true, then the OptionalScopedPointer will act like a std::unique_ptr, deleting the object when it is itself deleted. If this parameter is false, then the OptionalScopedPointer just holds a normal pointer to the object, and won't delete it. */ @@ -57,7 +55,7 @@ public: /** Takes ownership of the object that another OptionalScopedPointer holds. - Like a normal ScopedPointer, the objectToTransferFrom object will become null, + Like a normal std::unique_ptr, the objectToTransferFrom object will become null, as ownership of the managed object is transferred to this object. The flag to indicate whether or not to delete the managed object is also @@ -71,7 +69,7 @@ public: /** Takes ownership of the object that another OptionalScopedPointer holds. - Like a normal ScopedPointer, the objectToTransferFrom object will become null, + Like a normal std::unique_ptr, the objectToTransferFrom object will become null, as ownership of the managed object is transferred to this object. The ownership flag that says whether or not to delete the managed object is also @@ -132,7 +130,7 @@ public: /** Makes this OptionalScopedPointer point at a new object, specifying whether the OptionalScopedPointer will take ownership of the object. - If takeOwnership is true, then the OptionalScopedPointer will act like a ScopedPointer, + If takeOwnership is true, then the OptionalScopedPointer will act like a std::unique_ptr, deleting the object when it is itself deleted. If this parameter is false, then the OptionalScopedPointer just holds a normal pointer to the object, and won't delete it. */ @@ -176,14 +174,8 @@ public: private: //============================================================================== - ScopedPointer object; + std::unique_ptr object; bool shouldDelete = false; - - // This is here to avoid people accidentally taking a second owned copy of - // a scoped pointer, which is almost certainly not what you intended to do! - // If you hit a problem with this, you probably meant to say - // myPointer.setOwned (myScopedPointer.release()) - void setOwned (const ScopedPointer&) = delete; }; } // namespace juce diff --git a/modules/juce_core/memory/juce_ScopedPointer.h b/modules/juce_core/memory/juce_ScopedPointer.h index 977d2e0473..1ca6ff8f2f 100644 --- a/modules/juce_core/memory/juce_ScopedPointer.h +++ b/modules/juce_core/memory/juce_ScopedPointer.h @@ -20,82 +20,41 @@ ============================================================================== */ +#ifndef DOXYGEN + namespace juce { //============================================================================== /** This class is deprecated. You should use std::unique_ptr instead. - - - A ScopedPointer holds a pointer that is automatically deleted when the ScopedPointer - goes out of scope. - - Once a pointer has been passed to a ScopedPointer, it will make sure that the pointer - gets deleted when the ScopedPointer is deleted. Using the ScopedPointer on the stack or - as member variables is a good way to use RAII to avoid accidentally leaking dynamically - created objects. - - A ScopedPointer can be used in pretty much the same way that you'd use a normal pointer - to an object. If you use the assignment operator to assign a different object to a - ScopedPointer, the old one will be automatically deleted. - - Important note: The class is designed to hold a pointer to an object, NOT to an array! - It calls delete on its payload, not delete[], so do not give it an array to hold! For - that kind of purpose, you should be using HeapBlock or Array instead. - - A const ScopedPointer is guaranteed not to lose ownership of its object or change the - object to which it points during its lifetime. This means that making a copy of a const - ScopedPointer is impossible, as that would involve the new copy taking ownership from the - old one. - - If you need to get a pointer out of a ScopedPointer without it being deleted, you - can use the release() method. - - @tags{Core} */ template class ScopedPointer { public: //============================================================================== - /** Creates a ScopedPointer containing a null pointer. */ - inline ScopedPointer() = default; + // ScopedPointer is deprecated! You should use std::unique_ptr instead. + JUCE_DEPRECATED_ATTRIBUTE inline ScopedPointer() = default; - /** Creates a ScopedPointer containing a null pointer. */ - inline ScopedPointer (decltype (nullptr)) noexcept {} + // ScopedPointer is deprecated! You should use std::unique_ptr instead. + JUCE_DEPRECATED_ATTRIBUTE inline ScopedPointer (decltype (nullptr)) noexcept {} - /** Creates a ScopedPointer that owns the specified object. */ - inline ScopedPointer (ObjectType* objectToTakePossessionOf) noexcept + // ScopedPointer is deprecated! You should use std::unique_ptr instead. + JUCE_DEPRECATED_ATTRIBUTE inline ScopedPointer (ObjectType* objectToTakePossessionOf) noexcept : object (objectToTakePossessionOf) { } - /** Creates a ScopedPointer that takes its pointer from another ScopedPointer. - - Because a pointer can only belong to one ScopedPointer, this transfers - the pointer from the other object to this one, and the other object is reset to - be a null pointer. - */ + // ScopedPointer is deprecated! You should use std::unique_ptr instead. ScopedPointer (ScopedPointer& objectToTransferFrom) noexcept : object (objectToTransferFrom.release()) { } - /** Destructor. - If the ScopedPointer currently refers to an object, it'll be deleted. - */ - inline ~ScopedPointer() { reset(); } + // ScopedPointer is deprecated! You should use std::unique_ptr instead. + JUCE_DEPRECATED_ATTRIBUTE inline ~ScopedPointer() { reset(); } - /** Changes this ScopedPointer to point to a new object. - - Because a pointer can only belong to one ScopedPointer, this transfers - the pointer from the other object to this one, and the other object is reset to - be a null pointer. - - If this ScopedPointer already points to an object, that object - will first be deleted. - */ ScopedPointer& operator= (ScopedPointer& objectToTransferFrom) { if (this != objectToTransferFrom.getAddress()) @@ -109,23 +68,17 @@ public: return *this; } - /** Changes this ScopedPointer to point to a new object. - If this ScopedPointer already points to an object, that object will first be deleted. - The pointer that you pass in may be a nullptr. - */ ScopedPointer& operator= (ObjectType* newObjectToTakePossessionOf) { reset (newObjectToTakePossessionOf); return *this; } - /** Take ownership of another ScopedPointer */ ScopedPointer (ScopedPointer&& other) noexcept : object (other.object) { other.object = nullptr; } - /** Take ownership of another ScopedPointer */ ScopedPointer& operator= (ScopedPointer&& other) noexcept { reset (other.release()); @@ -133,20 +86,11 @@ public: } //============================================================================== - /** Returns the object that this ScopedPointer refers to. */ inline operator ObjectType*() const noexcept { return object; } - - /** Returns the object that this ScopedPointer refers to. */ inline ObjectType* get() const noexcept { return object; } - - /** Returns the object that this ScopedPointer refers to. */ inline ObjectType& operator*() const noexcept { return *object; } - - /** Lets you access methods and properties of the object that this ScopedPointer refers to. */ inline ObjectType* operator->() const noexcept { return object; } - //============================================================================== - /** Clears this pointer, deleting the object it points to if there is one. */ void reset() { auto* oldObject = object; @@ -154,7 +98,6 @@ public: ContainerDeletePolicy::destroy (oldObject); } - /** Sets this pointer to a new object, deleting the old object that it was previously pointing to if there was one. */ void reset (ObjectType* newObject) { if (object != newObject) @@ -171,21 +114,14 @@ public: } } - /** Sets this pointer to a new object, deleting the old object that it was previously pointing to if there was one. */ void reset (ScopedPointer& newObject) { reset (newObject.release()); } - /** Detaches and returns the current object from this ScopedPointer without deleting it. - This will return the current object, and set the ScopedPointer to a null pointer. - */ - ObjectType* release() noexcept { auto* o = object; object = {}; return o; } + ObjectType* release() noexcept { auto* o = object; object = {}; return o; } //============================================================================== - /** Swaps this object with that of another ScopedPointer. - The two objects simply exchange their pointers. - */ void swapWith (ScopedPointer& other) noexcept { // Two ScopedPointers should never be able to refer to the same object - if @@ -195,10 +131,7 @@ public: std::swap (object, other.object); } - /** If the pointer is non-null, this will attempt to return a new copy of the object that is pointed to. - If the pointer is null, this will safely return a nullptr. - */ - inline ObjectType* createCopy() const { return createCopyIfNotNull (object); } + inline ObjectType* createCopy() const { return createCopyIfNotNull (object); } private: //============================================================================== @@ -213,70 +146,60 @@ private: }; //============================================================================== -/** Compares a ScopedPointer with another pointer. */ template bool operator== (ObjectType1* pointer1, const ScopedPointer& pointer2) noexcept { return pointer1 == pointer2.get(); } -/** Compares a ScopedPointer with another pointer. */ template bool operator!= (ObjectType1* pointer1, const ScopedPointer& pointer2) noexcept { return pointer1 != pointer2.get(); } -/** Compares a ScopedPointer with another pointer. */ template bool operator== (const ScopedPointer& pointer1, ObjectType2* pointer2) noexcept { return pointer1.get() == pointer2; } -/** Compares a ScopedPointer with another pointer. */ template bool operator!= (const ScopedPointer& pointer1, ObjectType2* pointer2) noexcept { return pointer1.get() != pointer2; } -/** Compares a ScopedPointer with another pointer. */ template bool operator== (const ScopedPointer& pointer1, const ScopedPointer& pointer2) noexcept { return pointer1.get() == pointer2.get(); } -/** Compares a ScopedPointer with another pointer. */ template bool operator!= (const ScopedPointer& pointer1, const ScopedPointer& pointer2) noexcept { return pointer1.get() != pointer2.get(); } -/** Compares a ScopedPointer with a nullptr. */ template bool operator== (decltype (nullptr), const ScopedPointer& pointer) noexcept { return pointer.get() == nullptr; } -/** Compares a ScopedPointer with a nullptr. */ template bool operator!= (decltype (nullptr), const ScopedPointer& pointer) noexcept { return pointer.get() != nullptr; } -/** Compares a ScopedPointer with a nullptr. */ template bool operator== (const ScopedPointer& pointer, decltype (nullptr)) noexcept { return pointer.get() == nullptr; } -/** Compares a ScopedPointer with a nullptr. */ template bool operator!= (const ScopedPointer& pointer, decltype (nullptr)) noexcept { @@ -284,11 +207,11 @@ bool operator!= (const ScopedPointer& pointer, decltype (nullptr)) n } //============================================================================== -#ifndef DOXYGEN // NB: This is just here to prevent any silly attempts to call deleteAndZero() on a ScopedPointer. template void deleteAndZero (ScopedPointer&) { static_assert (sizeof (Type) == 12345, "Attempt to call deleteAndZero() on a ScopedPointer"); } -#endif } // namespace juce + +#endif