diff --git a/examples/Assets/WavefrontObjParser.h b/examples/Assets/WavefrontObjParser.h index 696214ce57..e97d89687a 100644 --- a/examples/Assets/WavefrontObjParser.h +++ b/examples/Assets/WavefrontObjParser.h @@ -243,7 +243,7 @@ private: }; static Shape* parseFaceGroup (const Mesh& srcMesh, - const Array& faceGroup, + Array& faceGroup, const Material& material, const String& name) { diff --git a/examples/Audio/MPEDemo.h b/examples/Audio/MPEDemo.h index f7e445bf96..c519ccc411 100644 --- a/examples/Audio/MPEDemo.h +++ b/examples/Audio/MPEDemo.h @@ -263,7 +263,7 @@ public: private: //============================================================================== - MPENote* findActiveNote (int noteID) const noexcept + const MPENote* findActiveNote (int noteID) const noexcept { for (auto& note : activeNotes) if (note.noteID == noteID) diff --git a/examples/GUI/HelloWorldDemo.h b/examples/GUI/HelloWorldDemo.h index a16425360b..8acc465bcb 100644 --- a/examples/GUI/HelloWorldDemo.h +++ b/examples/GUI/HelloWorldDemo.h @@ -64,7 +64,7 @@ public: helloWorldLabel.setColour (TextEditor::backgroundColourId, Colour (0x00000000)); addAndMakeVisible (quitButton); - quitButton.onClick = [this] { JUCEApplication::quit(); }; + quitButton.onClick = [] { JUCEApplication::quit(); }; setSize (600, 300); } diff --git a/examples/Plugins/AUv3SynthPluginDemo.h b/examples/Plugins/AUv3SynthPluginDemo.h index 9d0dbae8ca..1dc742342d 100644 --- a/examples/Plugins/AUv3SynthPluginDemo.h +++ b/examples/Plugins/AUv3SynthPluginDemo.h @@ -191,7 +191,7 @@ public: recordButton.onClick = [this] { startRecording(); }; addAndMakeVisible (recordButton); - roomSizeSlider.onValueChange = [this] { setParameterValue ("roomSize", roomSizeSlider.getValue()); }; + roomSizeSlider.onValueChange = [this] { setParameterValue ("roomSize", (float) roomSizeSlider.getValue()); }; roomSizeSlider.setRange (0.0, 1.0); addAndMakeVisible (roomSizeSlider); @@ -260,7 +260,7 @@ private: { if (auto* processor = getAudioProcessor()) { - const OwnedArray& params = processor->getParameters(); + auto& params = processor->getParameters(); for (auto p : params) { diff --git a/examples/Plugins/InterAppAudioEffectPluginDemo.h b/examples/Plugins/InterAppAudioEffectPluginDemo.h index 821476c4fe..c159dd5820 100644 --- a/examples/Plugins/InterAppAudioEffectPluginDemo.h +++ b/examples/Plugins/InterAppAudioEffectPluginDemo.h @@ -94,7 +94,7 @@ private: { auto callbackLevel = maxLevel.exchange (0.0); - auto decayFactor = 0.95; + float decayFactor = 0.95f; if (callbackLevel > level) level = callbackLevel; @@ -265,13 +265,13 @@ public: // meter values directly from the audio thread. struct MeterListener { - virtual ~MeterListener() {}; + virtual ~MeterListener() {} virtual void handleNewMeterValue (int, float) = 0; }; - void addMeterListener (MeterListener& listener) { meterListeners.add (&listener); }; - void removeMeterListener (MeterListener& listener) { meterListeners.remove (&listener); }; + void addMeterListener (MeterListener& listener) { meterListeners.add (&listener); } + void removeMeterListener (MeterListener& listener) { meterListeners.remove (&listener); } private: diff --git a/examples/Plugins/SamplerPluginDemo.h b/examples/Plugins/SamplerPluginDemo.h index 9201bf59a6..7e68eb55c3 100644 --- a/examples/Plugins/SamplerPluginDemo.h +++ b/examples/Plugins/SamplerPluginDemo.h @@ -100,7 +100,7 @@ class MoveOnlyFifo final { public: explicit MoveOnlyFifo (int size) - : buffer (size), + : buffer ((size_t) size), abstractFifo (size) {} @@ -115,12 +115,12 @@ public: if (writer.blockSize1 == 1) { - buffer[writer.startIndex1] = move (item); + buffer[(size_t) writer.startIndex1] = move (item); item = {}; } else if (writer.blockSize2 == 1) { - buffer[writer.startIndex2] = move (item); + buffer[(size_t) writer.startIndex2] = move (item); item = {}; } @@ -132,10 +132,10 @@ public: auto reader = abstractFifo.read (1); if (reader.blockSize1 == 1) - return move (buffer[reader.startIndex1]); + return move (buffer[(size_t) reader.startIndex1]); if (reader.blockSize2 == 1) - return move (buffer[reader.startIndex2]); + return move (buffer[(size_t) reader.startIndex2]); return {}; } @@ -2178,14 +2178,14 @@ public: auto numVoices = synthesiser.getNumVoices(); // Update the current playback positions - for (auto i = 0; i != maxVoices; ++i) + for (auto i = 0; i < maxVoices; ++i) { auto* voicePtr = dynamic_cast (synthesiser.getVoice (i)); if (i < numVoices && voicePtr != nullptr) - playbackPositions[i] = static_cast (voicePtr->getCurrentSamplePosition() / loadedSamplerSound->getSample()->getSampleRate()); + playbackPositions[(size_t) i] = static_cast (voicePtr->getCurrentSamplePosition() / loadedSamplerSound->getSample()->getSampleRate()); else - playbackPositions[i] = 0.0f; + playbackPositions[(size_t) i] = 0.0f; } } @@ -2207,8 +2207,8 @@ public: void operator() (SamplerAudioProcessor& proc) { proc.readerFactory = move (readerFactory); - auto samplerSound = proc.samplerSound.load(); - samplerSound->setSample (move (sample)); + auto sound = proc.samplerSound.load(); + sound->setSample (move (sample)); auto numberOfVoices = proc.synthesiser.getNumVoices(); proc.synthesiser.clearVoices(); @@ -2322,15 +2322,11 @@ public: void operator() (SamplerAudioProcessor& proc) { - if (newVoices.size() < proc.synthesiser.getNumVoices()) + if (newVoices.size() < (size_t) proc.synthesiser.getNumVoices()) proc.synthesiser.reduceNumVoices (int (newVoices.size())); else - { - for (auto it = begin (newVoices); proc.synthesiser.getNumVoices() < newVoices.size(); ++it) - { + for (auto it = begin (newVoices); (size_t) proc.synthesiser.getNumVoices() < newVoices.size(); ++it) proc.synthesiser.addVoice (it->release()); - } - } } private: @@ -2340,7 +2336,7 @@ public: numberOfVoices = std::min (maxVoices, numberOfVoices); auto loadedSamplerSound = samplerSound.load(); std::vector> newSamplerVoices; - newSamplerVoices.reserve (numberOfVoices); + newSamplerVoices.reserve ((size_t) numberOfVoices); for (auto i = 0; i != numberOfVoices; ++i) newSamplerVoices.emplace_back (new MPESamplerVoice (loadedSamplerSound)); @@ -2355,7 +2351,7 @@ public: // been updated to remove some voices in the meantime, so the returned // value won't correspond to an existing voice. int getNumVoices() const { return synthesiser.getNumVoices(); } - float getPlaybackPosition (int voice) const { return playbackPositions.at (voice); } + float getPlaybackPosition (int voice) const { return playbackPositions.at ((size_t) voice); } private: //============================================================================== @@ -2373,7 +2369,7 @@ private: { std::vector ret; auto voices = p.getNumVoices(); - ret.reserve (voices); + ret.reserve ((size_t) voices); for (auto i = 0; i != voices; ++i) ret.emplace_back (p.getPlaybackPosition (i)); diff --git a/extras/Projucer/Source/LiveBuildEngine/jucer_ClassDatabase.h b/extras/Projucer/Source/LiveBuildEngine/jucer_ClassDatabase.h index aefbbc6fc9..7fafdf2244 100644 --- a/extras/Projucer/Source/LiveBuildEngine/jucer_ClassDatabase.h +++ b/extras/Projucer/Source/LiveBuildEngine/jucer_ClassDatabase.h @@ -524,12 +524,16 @@ struct ClassDatabase void findClassesDeclaredInFile (Array& results, const File& file) { - for (auto& c : components) + for (int i = 0; i < components.size(); ++i) + { + auto c = components.getReference (i); + if (c.isDeclaredInFile (file)) results.add (&c); + } - for (auto& n : namespaces) - n.findClassesDeclaredInFile (results, file); + for (int i = 0; i < namespaces.size(); ++i) + namespaces.getReference (i).findClassesDeclaredInFile (results, file); } void merge (const Namespace& other) @@ -560,9 +564,13 @@ struct ClassDatabase Namespace* findNamespace (const String& targetName) { - for (auto& n : namespaces) + for (int i = 0; i < namespaces.size(); ++i) + { + auto& n = namespaces.getReference (i); + if (n.name == targetName) return &n; + } return nullptr; } @@ -575,7 +583,7 @@ struct ClassDatabase Namespace* getOrCreateNamespace (const String& newName) { - if (Namespace* existing = findNamespace (newName)) + if (auto* existing = findNamespace (newName)) return existing; return createNamespace (newName); @@ -600,14 +608,20 @@ struct ClassDatabase void nudgeAllCodeRanges (const String& file, int index, int delta) { - for (auto& c : components) c.nudgeAllCodeRanges (file, index, delta); - for (auto& n : namespaces) n.nudgeAllCodeRanges (file, index, delta); + for (int i = 0; i < components.size(); ++i) + components.getReference (i).nudgeAllCodeRanges (file, index, delta); + + for (int i = 0; i < namespaces.size(); ++i) + namespaces.getReference (i).nudgeAllCodeRanges (file, index, delta); } void fileContentChanged (const String& file) { - for (auto& c : components) c.fileContentChanged (file); - for (auto& n : namespaces) n.fileContentChanged (file); + for (int i = 0; i < components.size(); ++i) + components.getReference (i).fileContentChanged (file); + + for (int i = 0; i < namespaces.size(); ++i) + namespaces.getReference (i).fileContentChanged (file); } bool matches (const Namespace& other) const @@ -617,7 +631,7 @@ struct ClassDatabase && namespaces.size() == other.namespaces.size()) { for (int i = namespaces.size(); --i >= 0;) - if (! namespaces.getReference (i).matches (other.namespaces.getReference(i))) + if (! namespaces.getReference (i).matches (other.namespaces.getReference (i))) return false; return true; diff --git a/extras/Projucer/Source/Utility/Helpers/jucer_MiscUtilities.cpp b/extras/Projucer/Source/Utility/Helpers/jucer_MiscUtilities.cpp index a74f7770cd..c8879ca9e0 100644 --- a/extras/Projucer/Source/Utility/Helpers/jucer_MiscUtilities.cpp +++ b/extras/Projucer/Source/Utility/Helpers/jucer_MiscUtilities.cpp @@ -419,14 +419,14 @@ static var parseJUCEHeaderMetadata (const StringArray& lines) for (auto& line : lines) { - line = trimCommentCharsFromStartOfLine (line); + auto trimmedLine = trimCommentCharsFromStartOfLine (line); - auto colon = line.indexOfChar (':'); + auto colon = trimmedLine.indexOfChar (':'); if (colon >= 0) { - auto key = line.substring (0, colon).trim(); - auto value = line.substring (colon + 1).trim(); + auto key = trimmedLine.substring (0, colon).trim(); + auto value = trimmedLine.substring (colon + 1).trim(); o->setProperty (key, value); } diff --git a/modules/juce_audio_basics/midi/juce_MidiMessageSequence.cpp b/modules/juce_audio_basics/midi/juce_MidiMessageSequence.cpp index c89908cf03..f58fd788af 100644 --- a/modules/juce_audio_basics/midi/juce_MidiMessageSequence.cpp +++ b/modules/juce_audio_basics/midi/juce_MidiMessageSequence.cpp @@ -87,8 +87,10 @@ MidiMessageSequence::MidiEventHolder* MidiMessageSequence::getEventPointer (int return list[index]; } -MidiMessageSequence::MidiEventHolder** MidiMessageSequence::begin() const noexcept { return list.begin(); } -MidiMessageSequence::MidiEventHolder** MidiMessageSequence::end() const noexcept { return list.end(); } +MidiMessageSequence::MidiEventHolder** MidiMessageSequence::begin() noexcept { return list.begin(); } +MidiMessageSequence::MidiEventHolder* const* MidiMessageSequence::begin() const noexcept { return list.begin(); } +MidiMessageSequence::MidiEventHolder** MidiMessageSequence::end() noexcept { return list.end(); } +MidiMessageSequence::MidiEventHolder* const* MidiMessageSequence::end() const noexcept { return list.end(); } double MidiMessageSequence::getTimeOfMatchingKeyUp (int index) const noexcept { diff --git a/modules/juce_audio_basics/midi/juce_MidiMessageSequence.h b/modules/juce_audio_basics/midi/juce_MidiMessageSequence.h index d4f4f9265c..5d4187ea38 100644 --- a/modules/juce_audio_basics/midi/juce_MidiMessageSequence.h +++ b/modules/juce_audio_basics/midi/juce_MidiMessageSequence.h @@ -103,10 +103,16 @@ public: MidiEventHolder* getEventPointer (int index) const noexcept; /** Iterator for the list of MidiEventHolders */ - MidiEventHolder** begin() const noexcept; + MidiEventHolder** begin() noexcept; /** Iterator for the list of MidiEventHolders */ - MidiEventHolder** end() const noexcept; + MidiEventHolder* const* begin() const noexcept; + + /** Iterator for the list of MidiEventHolders */ + MidiEventHolder** end() noexcept; + + /** Iterator for the list of MidiEventHolders */ + MidiEventHolder* const* end() const noexcept; /** Returns the time of the note-up that matches the note-on at this index. If the event at this index isn't a note-on, it'll just return 0. diff --git a/modules/juce_audio_basics/mpe/juce_MPEInstrument.cpp b/modules/juce_audio_basics/mpe/juce_MPEInstrument.cpp index 55d03fdd2c..df2e4660f3 100644 --- a/modules/juce_audio_basics/mpe/juce_MPEInstrument.cpp +++ b/modules/juce_audio_basics/mpe/juce_MPEInstrument.cpp @@ -726,7 +726,7 @@ MPENote* MPEInstrument::getLastNotePlayedPtr (int midiChannel) noexcept const MPENote* MPEInstrument::getHighestNotePtr (int midiChannel) const noexcept { int initialNoteMax = -1; - MPENote* result = nullptr; + const MPENote* result = nullptr; for (auto i = notes.size(); --i >= 0;) { @@ -752,7 +752,7 @@ MPENote* MPEInstrument::getHighestNotePtr (int midiChannel) noexcept const MPENote* MPEInstrument::getLowestNotePtr (int midiChannel) const noexcept { int initialNoteMin = 128; - MPENote* result = nullptr; + const MPENote* result = nullptr; for (auto i = notes.size(); --i >= 0;) { diff --git a/modules/juce_audio_formats/format/juce_AudioFormatManager.h b/modules/juce_audio_formats/format/juce_AudioFormatManager.h index 610b749e68..36140e839f 100644 --- a/modules/juce_audio_formats/format/juce_AudioFormatManager.h +++ b/modules/juce_audio_formats/format/juce_AudioFormatManager.h @@ -81,10 +81,16 @@ public: AudioFormat* getKnownFormat (int index) const; /** Iterator access to the list of known formats. */ - AudioFormat** begin() const noexcept { return knownFormats.begin(); } + AudioFormat** begin() noexcept { return knownFormats.begin(); } /** Iterator access to the list of known formats. */ - AudioFormat** end() const noexcept { return knownFormats.end(); } + AudioFormat* const* begin() const noexcept { return knownFormats.begin(); } + + /** Iterator access to the list of known formats. */ + AudioFormat** end() noexcept { return knownFormats.end(); } + + /** Iterator access to the list of known formats. */ + AudioFormat* const* end() const noexcept { return knownFormats.end(); } /** Looks for which of the known formats is listed as being for a given file extension. diff --git a/modules/juce_audio_processors/format_types/juce_VST3PluginFormat.cpp b/modules/juce_audio_processors/format_types/juce_VST3PluginFormat.cpp index 2ff41f85c9..d958ff5252 100644 --- a/modules/juce_audio_processors/format_types/juce_VST3PluginFormat.cpp +++ b/modules/juce_audio_processors/format_types/juce_VST3PluginFormat.cpp @@ -2298,7 +2298,8 @@ public: bool setStateFromPresetFile (const MemoryBlock& rawData) { - ComSmartPtr memoryStream = new Steinberg::MemoryStream (rawData.getData(), (int) rawData.getSize()); + MemoryBlock rawDataCopy (rawData); + ComSmartPtr memoryStream = new Steinberg::MemoryStream (rawDataCopy.getData(), (int) rawDataCopy.getSize()); if (memoryStream == nullptr || holder->component == nullptr) return false; diff --git a/modules/juce_audio_processors/processors/juce_AudioProcessorParameterGroup.cpp b/modules/juce_audio_processors/processors/juce_AudioProcessorParameterGroup.cpp index 01c1238b61..030ce7065f 100644 --- a/modules/juce_audio_processors/processors/juce_AudioProcessorParameterGroup.cpp +++ b/modules/juce_audio_processors/processors/juce_AudioProcessorParameterGroup.cpp @@ -97,8 +97,8 @@ String AudioProcessorParameterGroup::getName() const String AudioProcessorParameterGroup::getSeparator() const { return separator; } const AudioProcessorParameterGroup* AudioProcessorParameterGroup::getParent() const noexcept { return parent; } -const AudioProcessorParameterGroup::AudioProcessorParameterNode** AudioProcessorParameterGroup::begin() const noexcept { return const_cast (children.begin()); } -const AudioProcessorParameterGroup::AudioProcessorParameterNode** AudioProcessorParameterGroup::end() const noexcept { return const_cast (children.end()); } +const AudioProcessorParameterGroup::AudioProcessorParameterNode* const* AudioProcessorParameterGroup::begin() const noexcept { return const_cast (children.begin()); } +const AudioProcessorParameterGroup::AudioProcessorParameterNode* const* AudioProcessorParameterGroup::end() const noexcept { return const_cast (children.end()); } void AudioProcessorParameterGroup::append (std::unique_ptr newParameter) { diff --git a/modules/juce_audio_processors/processors/juce_AudioProcessorParameterGroup.h b/modules/juce_audio_processors/processors/juce_AudioProcessorParameterGroup.h index 082e2c6d56..f0137f9244 100644 --- a/modules/juce_audio_processors/processors/juce_AudioProcessorParameterGroup.h +++ b/modules/juce_audio_processors/processors/juce_AudioProcessorParameterGroup.h @@ -162,8 +162,8 @@ public: const AudioProcessorParameterGroup* getParent() const noexcept; //============================================================================== - const AudioProcessorParameterNode** begin() const noexcept; - const AudioProcessorParameterNode** end() const noexcept; + const AudioProcessorParameterNode* const* begin() const noexcept; + const AudioProcessorParameterNode* const* end() const noexcept; //============================================================================== /** Returns all subgroups of this group. diff --git a/modules/juce_audio_processors/scanning/juce_KnownPluginList.h b/modules/juce_audio_processors/scanning/juce_KnownPluginList.h index aa0eea9b29..c3022a608d 100644 --- a/modules/juce_audio_processors/scanning/juce_KnownPluginList.h +++ b/modules/juce_audio_processors/scanning/juce_KnownPluginList.h @@ -210,9 +210,12 @@ public: // These methods have been deprecated! When getting the list of plugin types you should instead use // the getTypes() method which returns a copy of the internal PluginDescription array and can be accessed // in a thread-safe way. - JUCE_DEPRECATED_WITH_BODY (PluginDescription* getType (int index) const noexcept, { return &types.getReference (index); }) - JUCE_DEPRECATED_WITH_BODY (PluginDescription** begin() const noexcept, { jassertfalse; return nullptr; }) - JUCE_DEPRECATED_WITH_BODY (PluginDescription** end() const noexcept, { jassertfalse; return nullptr; }) + JUCE_DEPRECATED_WITH_BODY (PluginDescription* getType (int index) noexcept, { return &types.getReference (index); }) + JUCE_DEPRECATED_WITH_BODY (const PluginDescription* getType (int index) const noexcept, { return &types.getReference (index); }) + JUCE_DEPRECATED_WITH_BODY (PluginDescription** begin() noexcept, { jassertfalse; return nullptr; }) + JUCE_DEPRECATED_WITH_BODY (PluginDescription* const* begin() const noexcept, { jassertfalse; return nullptr; }) + JUCE_DEPRECATED_WITH_BODY (PluginDescription** end() noexcept, { jassertfalse; return nullptr; }) + JUCE_DEPRECATED_WITH_BODY (PluginDescription* const* end() const noexcept, { jassertfalse; return nullptr; }) private: //============================================================================== diff --git a/modules/juce_blocks_basics/topology/internal/juce_ConnectedDeviceGroup.cpp b/modules/juce_blocks_basics/topology/internal/juce_ConnectedDeviceGroup.cpp index 6dd0a35daa..4f7d1b614a 100644 --- a/modules/juce_blocks_basics/topology/internal/juce_ConnectedDeviceGroup.cpp +++ b/modules/juce_blocks_basics/topology/internal/juce_ConnectedDeviceGroup.cpp @@ -555,7 +555,7 @@ private: return -1; } - DeviceInfo* getDeviceInfoFromUID (Block::UID uid) const noexcept + DeviceInfo* getDeviceInfoFromUID (Block::UID uid) noexcept { for (auto& d : currentDeviceInfo) if (d.uid == uid) @@ -564,7 +564,7 @@ private: return nullptr; } - DeviceInfo* getDeviceInfoFromIndex (BlocksProtocol::TopologyIndex index) const noexcept + DeviceInfo* getDeviceInfoFromIndex (BlocksProtocol::TopologyIndex index) noexcept { for (auto& d : currentDeviceInfo) if (d.index == index) diff --git a/modules/juce_core/containers/juce_Array.h b/modules/juce_core/containers/juce_Array.h index 6a8c736eac..3b516751f4 100644 --- a/modules/juce_core/containers/juce_Array.h +++ b/modules/juce_core/containers/juce_Array.h @@ -264,7 +264,21 @@ public: @param index the index of the element being requested (0 is the first element in the array) @see operator[], getFirst, getLast */ - inline ElementType& getReference (int index) const noexcept + inline ElementType& getReference (int index) noexcept + { + const ScopedLockType lock (getLock()); + return values[index]; + } + + /** Returns a direct reference to one of the elements in the array, without checking the index passed in. + + This is like getUnchecked, but returns a direct reference to the element. Obviously + this can be dangerous, so only use it when absolutely necessary. + + @param index the index of the element being requested (0 is the first element in the array) + @see operator[], getFirst, getLast + */ + inline const ElementType& getReference (int index) const noexcept { const ScopedLockType lock (getLock()); return values[index]; @@ -298,11 +312,28 @@ public: return values.begin(); } + /** Returns a pointer to the actual array data. + This pointer will only be valid until the next time a non-const method + is called on the array. + */ + inline const ElementType* getRawDataPointer() const noexcept + { + return values.begin(); + } + //============================================================================== /** Returns a pointer to the first element in the array. This method is provided for compatibility with standard C++ iteration mechanisms. */ - inline ElementType* begin() const noexcept + inline ElementType* begin() noexcept + { + return values.begin(); + } + + /** Returns a pointer to the first element in the array. + This method is provided for compatibility with standard C++ iteration mechanisms. + */ + inline const ElementType* begin() const noexcept { return values.begin(); } @@ -310,7 +341,15 @@ public: /** Returns a pointer to the element which follows the last element in the array. This method is provided for compatibility with standard C++ iteration mechanisms. */ - inline ElementType* end() const noexcept + inline ElementType* end() noexcept + { + return values.end(); + } + + /** Returns a pointer to the element which follows the last element in the array. + This method is provided for compatibility with standard C++ iteration mechanisms. + */ + inline const ElementType* end() const noexcept { return values.end(); } @@ -318,7 +357,15 @@ public: /** Returns a pointer to the first element in the array. This method is provided for compatibility with the standard C++ containers. */ - inline ElementType* data() const noexcept + inline ElementType* data() noexcept + { + return begin(); + } + + /** Returns a pointer to the first element in the array. + This method is provided for compatibility with the standard C++ containers. + */ + inline const ElementType* data() const noexcept { return begin(); } diff --git a/modules/juce_core/containers/juce_ArrayBase.h b/modules/juce_core/containers/juce_ArrayBase.h index 2294c54757..bacc8819a5 100644 --- a/modules/juce_core/containers/juce_ArrayBase.h +++ b/modules/juce_core/containers/juce_ArrayBase.h @@ -136,7 +136,14 @@ public: } //============================================================================== - inline ElementType& operator[] (const int index) const noexcept + inline ElementType& operator[] (const int index) noexcept + { + jassert (elements != nullptr); + jassert (isPositiveAndBelow (index, numUsed)); + return elements[index]; + } + + inline const ElementType& operator[] (const int index) const noexcept { jassert (elements != nullptr); jassert (isPositiveAndBelow (index, numUsed)); @@ -159,17 +166,32 @@ public: } //============================================================================== - inline ElementType* begin() const noexcept + inline ElementType* begin() noexcept + { + return elements; + } + + inline const ElementType* begin() const noexcept { return elements; } - inline ElementType* end() const noexcept + inline ElementType* end() noexcept + { + return elements + numUsed; + } + + inline const ElementType* end() const noexcept { return elements + numUsed; } - inline ElementType* data() const noexcept + inline ElementType* data() noexcept + { + return elements; + } + + inline const ElementType* data() const noexcept { return elements; } diff --git a/modules/juce_core/containers/juce_NamedValueSet.cpp b/modules/juce_core/containers/juce_NamedValueSet.cpp index 339e60ed01..b6b9828619 100644 --- a/modules/juce_core/containers/juce_NamedValueSet.cpp +++ b/modules/juce_core/containers/juce_NamedValueSet.cpp @@ -147,7 +147,16 @@ var NamedValueSet::getWithDefault (const Identifier& name, const var& defaultRet return defaultReturnValue; } -var* NamedValueSet::getVarPointer (const Identifier& name) const noexcept +var* NamedValueSet::getVarPointer (const Identifier& name) noexcept +{ + for (auto& i : values) + if (i.name == name) + return &(i.value); + + return {}; +} + +const var* NamedValueSet::getVarPointer (const Identifier& name) const noexcept { for (auto& i : values) if (i.name == name) @@ -236,7 +245,15 @@ const var& NamedValueSet::getValueAt (const int index) const noexcept return getNullVarRef(); } -var* NamedValueSet::getVarPointerAt (int index) const noexcept +var* NamedValueSet::getVarPointerAt (int index) noexcept +{ + if (isPositiveAndBelow (index, values.size())) + return &(values.getReference (index).value); + + return {}; +} + +const var* NamedValueSet::getVarPointerAt (int index) const noexcept { if (isPositiveAndBelow (index, values.size())) return &(values.getReference (index).value); diff --git a/modules/juce_core/containers/juce_NamedValueSet.h b/modules/juce_core/containers/juce_NamedValueSet.h index d76651d1cc..c307fc7351 100644 --- a/modules/juce_core/containers/juce_NamedValueSet.h +++ b/modules/juce_core/containers/juce_NamedValueSet.h @@ -132,7 +132,17 @@ public: Also note that the pointer returned may become invalid as soon as any subsequent methods are called on the NamedValueSet. */ - var* getVarPointer (const Identifier& name) const noexcept; + var* getVarPointer (const Identifier& name) noexcept; + + /** Returns a pointer to the var that holds a named value, or null if there is + no value with this name. + + Do not use this method unless you really need access to the internal var object + for some reason - for normal reading and writing always prefer operator[]() and set(). + Also note that the pointer returned may become invalid as soon as any subsequent + methods are called on the NamedValueSet. + */ + const var* getVarPointer (const Identifier& name) const noexcept; /** Returns the value of the item at a given index. The index must be between 0 and size() - 1. @@ -144,7 +154,14 @@ public: Also note that the pointer returned may become invalid as soon as any subsequent methods are called on the NamedValueSet. */ - var* getVarPointerAt (int index) const noexcept; + var* getVarPointerAt (int index) noexcept; + + /** Returns the value of the item at a given index. + The index must be between 0 and size() - 1, or this will return a nullptr + Also note that the pointer returned may become invalid as soon as any subsequent + methods are called on the NamedValueSet. + */ + const var* getVarPointerAt (int index) const noexcept; /** Returns the index of the given name, or -1 if it's not found. */ int indexOf (const Identifier& name) const noexcept; diff --git a/modules/juce_core/containers/juce_OwnedArray.h b/modules/juce_core/containers/juce_OwnedArray.h index 7a70e567c0..4f2cfa9f23 100644 --- a/modules/juce_core/containers/juce_OwnedArray.h +++ b/modules/juce_core/containers/juce_OwnedArray.h @@ -198,15 +198,31 @@ public: /** Returns a pointer to the first element in the array. This method is provided for compatibility with standard C++ iteration mechanisms. */ - inline ObjectClass** begin() const noexcept + inline ObjectClass** begin() noexcept { return values.begin(); } + /** Returns a pointer to the first element in the array. + This method is provided for compatibility with standard C++ iteration mechanisms. + */ + inline ObjectClass* const* begin() const noexcept + { + return values.begin(); + } + + /** Returns a pointer to the element which follows the last element in the array. + This method is provided for compatibility with standard C++ iteration mechanisms. + */ + inline ObjectClass** end() noexcept + { + return values.end(); + } + /** Returns a pointer to the element which follows the last element in the array. This method is provided for compatibility with standard C++ iteration mechanisms. */ - inline ObjectClass** end() const noexcept + inline ObjectClass* const* end() const noexcept { return values.end(); } @@ -228,7 +244,7 @@ public: int indexOf (const ObjectClass* objectToLookFor) const noexcept { const ScopedLockType lock (getLock()); - auto** e = values.begin(); + auto* e = values.begin(); for (; e != values.end(); ++e) if (objectToLookFor == *e) @@ -245,7 +261,7 @@ public: bool contains (const ObjectClass* objectToLookFor) const noexcept { const ScopedLockType lock (getLock()); - auto** e = values.begin(); + auto* e = values.begin(); for (; e != values.end(); ++e) if (objectToLookFor == *e) @@ -795,7 +811,7 @@ public: */ template void sort (ElementComparator& comparator, - bool retainOrderOfEquivalentItems = false) const noexcept + bool retainOrderOfEquivalentItems = false) noexcept { // If you pass in an object with a static compareElements() method, this // avoids getting warning messages about the parameter being unused diff --git a/modules/juce_core/containers/juce_ReferenceCountedArray.h b/modules/juce_core/containers/juce_ReferenceCountedArray.h index 92a156a645..20bfdc4031 100644 --- a/modules/juce_core/containers/juce_ReferenceCountedArray.h +++ b/modules/juce_core/containers/juce_ReferenceCountedArray.h @@ -240,7 +240,15 @@ public: /** Returns a pointer to the first element in the array. This method is provided for compatibility with standard C++ iteration mechanisms. */ - inline ObjectClass** begin() const noexcept + inline ObjectClass** begin() noexcept + { + return values.begin(); + } + + /** Returns a pointer to the first element in the array. + This method is provided for compatibility with standard C++ iteration mechanisms. + */ + inline ObjectClass* const* begin() const noexcept { return values.begin(); } @@ -248,15 +256,31 @@ public: /** Returns a pointer to the element which follows the last element in the array. This method is provided for compatibility with standard C++ iteration mechanisms. */ - inline ObjectClass** end() const noexcept + inline ObjectClass** end() noexcept { return values.end(); } + /** Returns a pointer to the element which follows the last element in the array. + This method is provided for compatibility with standard C++ iteration mechanisms. + */ + inline ObjectClass* const* end() const noexcept + { + return values.end(); + } + + /** Returns a pointer to the first element in the array. + This method is provided for compatibility with the standard C++ containers. + */ + inline ObjectClass** data() noexcept + { + return begin(); + } + /** Returns a pointer to the first element in the array. This method is provided for compatibility with the standard C++ containers. */ - inline ObjectClass** data() const noexcept + inline ObjectClass* const* data() const noexcept { return begin(); } @@ -270,8 +294,8 @@ public: int indexOf (const ObjectClass* objectToLookFor) const noexcept { const ScopedLockType lock (getLock()); - auto** e = values.begin(); - auto** endPointer = values.end(); + auto* e = values.begin(); + auto* endPointer = values.end(); while (e != endPointer) { @@ -299,8 +323,8 @@ public: bool contains (const ObjectClass* objectToLookFor) const noexcept { const ScopedLockType lock (getLock()); - auto** e = values.begin(); - auto** endPointer = values.end(); + auto* e = values.begin(); + auto* endPointer = values.end(); while (e != endPointer) { diff --git a/modules/juce_core/containers/juce_SortedSet.h b/modules/juce_core/containers/juce_SortedSet.h index ef7e3a976c..f73f180187 100644 --- a/modules/juce_core/containers/juce_SortedSet.h +++ b/modules/juce_core/containers/juce_SortedSet.h @@ -58,7 +58,6 @@ class SortedSet public: //============================================================================== /** Creates an empty set. */ - // VS2013 doesn't allow defaulted noexcept constructors. SortedSet() = default; /** Creates a copy of another set. */ @@ -169,7 +168,16 @@ public: @param index the index of the element being requested (0 is the first element in the array) */ - inline ElementType& getReference (const int index) const noexcept + inline ElementType& getReference (const int index) noexcept + { + return data.getReference (index); + } + + /** Returns a direct reference to one of the elements in the set, without checking the index passed in. + + @param index the index of the element being requested (0 is the first element in the array) + */ + inline const ElementType& getReference (const int index) const noexcept { return data.getReference (index); } @@ -194,7 +202,7 @@ public: /** Returns a pointer to the first element in the set. This method is provided for compatibility with standard C++ iteration mechanisms. */ - inline ElementType* begin() const noexcept + inline const ElementType* begin() const noexcept { return data.begin(); } @@ -202,7 +210,7 @@ public: /** Returns a pointer to the element which follows the last element in the set. This method is provided for compatibility with standard C++ iteration mechanisms. */ - inline ElementType* end() const noexcept + inline const ElementType* end() const noexcept { return data.end(); } diff --git a/modules/juce_core/memory/juce_MemoryBlock.h b/modules/juce_core/memory/juce_MemoryBlock.h index b94223356e..ceb2851348 100644 --- a/modules/juce_core/memory/juce_MemoryBlock.h +++ b/modules/juce_core/memory/juce_MemoryBlock.h @@ -88,19 +88,36 @@ public: Note that the pointer returned will probably become invalid when the block is resized. */ - void* getData() const noexcept { return data; } + void* getData() noexcept { return data; } + + /** Returns a void pointer to the data. + + Note that the pointer returned will probably become invalid when the + block is resized. + */ + const void* getData() const noexcept { return data; } /** Returns a byte from the memory block. This returns a reference, so you can also use it to set a byte. */ template - char& operator[] (const Type offset) const noexcept { return data [offset]; } + char& operator[] (const Type offset) noexcept { return data [offset]; } + + /** Returns a byte from the memory block. */ + template + const char& operator[] (const Type offset) const noexcept { return data [offset]; } + + /** Returns an iterator for the data. */ + char* begin() noexcept { return data; } /** Returns an iterator for the data. */ - char* begin() const noexcept { return data; } + const char* begin() const noexcept { return data; } + + /** Returns an end-iterator for the data. */ + char* end() noexcept { return begin() + getSize(); } /** Returns an end-iterator for the data. */ - char* end() const noexcept { return begin() + getSize(); } + const char* end() const noexcept { return begin() + getSize(); } //============================================================================== /** Returns the block's current allocated size, in bytes. */ diff --git a/modules/juce_core/text/juce_StringArray.h b/modules/juce_core/text/juce_StringArray.h index f00e3a79f2..f6292540e4 100644 --- a/modules/juce_core/text/juce_StringArray.h +++ b/modules/juce_core/text/juce_StringArray.h @@ -155,12 +155,23 @@ public: /** Returns a pointer to the first String in the array. This method is provided for compatibility with standard C++ iteration mechanisms. */ - inline String* begin() const noexcept { return strings.begin(); } + inline String* begin() noexcept { return strings.begin(); } + + /** Returns a pointer to the first String in the array. + This method is provided for compatibility with standard C++ iteration mechanisms. + */ + inline const String* begin() const noexcept { return strings.begin(); } /** Returns a pointer to the String which follows the last element in the array. This method is provided for compatibility with standard C++ iteration mechanisms. */ - inline String* end() const noexcept { return strings.end(); } + inline String* end() noexcept { return strings.end(); } + + /** Returns a pointer to the String which follows the last element in the array. + This method is provided for compatibility with standard C++ iteration mechanisms. + */ + inline const String* end() const noexcept { return strings.end(); } + /** Searches for a string in the array. diff --git a/modules/juce_gui_basics/desktop/juce_Displays.cpp b/modules/juce_gui_basics/desktop/juce_Displays.cpp index 3e4c42a9a7..ad226c4fe2 100644 --- a/modules/juce_gui_basics/desktop/juce_Displays.cpp +++ b/modules/juce_gui_basics/desktop/juce_Displays.cpp @@ -40,7 +40,7 @@ void Displays::init (Desktop& desktop) const Displays::Display& Displays::findDisplayForRect (Rectangle rect, bool isPhysical) const noexcept { int maxArea = -1; - Display* retVal = nullptr; + const Display* retVal = nullptr; for (auto& display : displays) { @@ -65,7 +65,7 @@ const Displays::Display& Displays::findDisplayForRect (Rectangle rect, bool const Displays::Display& Displays::findDisplayForPoint (Point point, bool isPhysical) const noexcept { auto minDistance = std::numeric_limits::max(); - Display* retVal = nullptr; + const Display* retVal = nullptr; for (auto& display : displays) { @@ -198,7 +198,7 @@ bool operator!= (const Displays::Display& d1, const Displays::Display& d2) noexc const Displays::Display& Displays::getDisplayContaining (Point position) const noexcept { JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED - auto* best = &displays.getReference (0); + const auto* best = &displays.getReference (0); auto bestDistance = std::numeric_limits::max(); for (auto& d : displays) @@ -249,7 +249,7 @@ struct DisplayNode }; /** Recursive - will calculate and set the logicalArea member of current. */ -static void processDisplay (DisplayNode* currentNode, const Array& allNodes) +static void processDisplay (DisplayNode* currentNode, Array& allNodes) { const auto physicalArea = currentNode->display->totalArea.toDouble(); const auto scale = currentNode->display->scale; diff --git a/modules/juce_gui_basics/layout/juce_ConcertinaPanel.cpp b/modules/juce_gui_basics/layout/juce_ConcertinaPanel.cpp index 73a29cf2b0..292cf32097 100644 --- a/modules/juce_gui_basics/layout/juce_ConcertinaPanel.cpp +++ b/modules/juce_gui_basics/layout/juce_ConcertinaPanel.cpp @@ -66,7 +66,8 @@ struct ConcertinaPanel::PanelSizes Array sizes; - Panel& get (const int index) const noexcept { return sizes.getReference(index); } + Panel& get (const int index) noexcept { return sizes.getReference (index); } + const Panel& get (const int index) const noexcept { return sizes.getReference (index); } PanelSizes withMovedPanel (const int index, int targetPosition, int totalSpace) const { diff --git a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.cpp b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.cpp index 89fd792503..d75790179b 100644 --- a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.cpp +++ b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.cpp @@ -81,7 +81,7 @@ Colour LookAndFeel::findColour (int colourID) const noexcept auto index = colours.indexOf (c); if (index >= 0) - return colours.getReference (index).colour; + return colours[index].colour; jassertfalse; return Colours::black; diff --git a/modules/juce_gui_basics/mouse/juce_MouseInputSource.cpp b/modules/juce_gui_basics/mouse/juce_MouseInputSource.cpp index b38a02ad4a..e9c378a468 100644 --- a/modules/juce_gui_basics/mouse/juce_MouseInputSource.cpp +++ b/modules/juce_gui_basics/mouse/juce_MouseInputSource.cpp @@ -682,7 +682,7 @@ struct MouseInputSource::SourceList : public Timer return &sourceArray.getReference (sourceArray.size() - 1); } - MouseInputSource* getMouseSource (int index) const noexcept + MouseInputSource* getMouseSource (int index) noexcept { return isPositiveAndBelow (index, sourceArray.size()) ? &sourceArray.getReference (index) : nullptr; @@ -724,7 +724,7 @@ struct MouseInputSource::SourceList : public Timer return num; } - MouseInputSource* getDraggingMouseSource (int index) const noexcept + MouseInputSource* getDraggingMouseSource (int index) noexcept { int num = 0; diff --git a/modules/juce_gui_basics/mouse/juce_SelectedItemSet.h b/modules/juce_gui_basics/mouse/juce_SelectedItemSet.h index 723cc2beb1..40f9bb598a 100644 --- a/modules/juce_gui_basics/mouse/juce_SelectedItemSet.h +++ b/modules/juce_gui_basics/mouse/juce_SelectedItemSet.h @@ -274,10 +274,15 @@ public: const ItemArray& getItemArray() const noexcept { return selectedItems; } /** Provides iterator access to the array of items. */ - SelectableItemType* begin() const noexcept { return selectedItems.begin(); } + SelectableItemType* begin() noexcept { return selectedItems.begin(); } + + const SelectableItemType* begin() const noexcept { return selectedItems.begin(); } + + /** Provides iterator access to the array of items. */ + SelectableItemType* end() noexcept { return selectedItems.end(); } /** Provides iterator access to the array of items. */ - SelectableItemType* end() const noexcept { return selectedItems.end(); } + const SelectableItemType* end() const noexcept { return selectedItems.end(); } //============================================================================== /** Can be overridden to do special handling when an item is selected. diff --git a/modules/juce_gui_basics/native/juce_win32_Windowing.cpp b/modules/juce_gui_basics/native/juce_win32_Windowing.cpp index 7397e9bf52..1365d945e0 100644 --- a/modules/juce_gui_basics/native/juce_win32_Windowing.cpp +++ b/modules/juce_gui_basics/native/juce_win32_Windowing.cpp @@ -4457,7 +4457,7 @@ void Desktop::allowedOrientationsChanged() {} //============================================================================== static const Displays::Display* getCurrentDisplayFromScaleFactor (HWND hwnd) { - Array candidateDisplays; + Array candidateDisplays; double scaleToLookFor = -1.0; if (auto* peer = HWNDComponentPeer::getOwnerOfWindow (hwnd)) @@ -4483,7 +4483,7 @@ static const Displays::Display* getCurrentDisplayFromScaleFactor (HWND hwnd) else bounds = Desktop::getInstance().getDisplays().physicalToLogical (rectangleFromRECT (getWindowRect (hwnd))); - Displays::Display* retVal = nullptr; + const Displays::Display* retVal = nullptr; int maxArea = -1; for (auto* d : candidateDisplays) diff --git a/modules/juce_osc/osc/juce_OSCBundle.h b/modules/juce_osc/osc/juce_OSCBundle.h index 5120757d19..a569da7ae0 100644 --- a/modules/juce_osc/osc/juce_OSCBundle.h +++ b/modules/juce_osc/osc/juce_OSCBundle.h @@ -127,10 +127,16 @@ public: void addElement (const OSCBundle::Element& element) { elements.add (element); } /** Returns a pointer to the first element of the OSCBundle. */ - OSCBundle::Element* begin() const noexcept { return elements.begin(); } + OSCBundle::Element* begin() noexcept { return elements.begin(); } + + /** Returns a pointer to the first element of the OSCBundle. */ + const OSCBundle::Element* begin() const noexcept { return elements.begin(); } + + /** Returns a pointer past the last element of the OSCBundle. */ + OSCBundle::Element* end() noexcept { return elements.end(); } /** Returns a pointer past the last element of the OSCBundle. */ - OSCBundle::Element* end() const noexcept { return elements.end(); } + const OSCBundle::Element* end() const noexcept { return elements.end(); } private: //============================================================================== diff --git a/modules/juce_osc/osc/juce_OSCMessage.cpp b/modules/juce_osc/osc/juce_OSCMessage.cpp index 07f6d0429f..693342762d 100644 --- a/modules/juce_osc/osc/juce_OSCMessage.cpp +++ b/modules/juce_osc/osc/juce_OSCMessage.cpp @@ -63,12 +63,22 @@ const OSCArgument& OSCMessage::operator[] (const int i) const noexcept return arguments.getReference (i); } -OSCArgument* OSCMessage::begin() const noexcept +OSCArgument* OSCMessage::begin() noexcept { return arguments.begin(); } -OSCArgument* OSCMessage::end() const noexcept +const OSCArgument* OSCMessage::begin() const noexcept +{ + return arguments.begin(); +} + +OSCArgument* OSCMessage::end() noexcept +{ + return arguments.end(); +} + +const OSCArgument* OSCMessage::end() const noexcept { return arguments.end(); } diff --git a/modules/juce_osc/osc/juce_OSCMessage.h b/modules/juce_osc/osc/juce_OSCMessage.h index 7cbf99bc00..99357111c7 100644 --- a/modules/juce_osc/osc/juce_OSCMessage.h +++ b/modules/juce_osc/osc/juce_OSCMessage.h @@ -99,12 +99,22 @@ public: /** Returns a pointer to the first OSCArgument in the OSCMessage object. This method is provided for compatibility with standard C++ iteration mechanisms. */ - OSCArgument* begin() const noexcept; + OSCArgument* begin() noexcept; + + /** Returns a pointer to the first OSCArgument in the OSCMessage object. + This method is provided for compatibility with standard C++ iteration mechanisms. + */ + const OSCArgument* begin() const noexcept; + + /** Returns a pointer to the last OSCArgument in the OSCMessage object. + This method is provided for compatibility with standard C++ iteration mechanisms. + */ + OSCArgument* end() noexcept; /** Returns a pointer to the last OSCArgument in the OSCMessage object. This method is provided for compatibility with standard C++ iteration mechanisms. */ - OSCArgument* end() const noexcept; + const OSCArgument* end() const noexcept; /** Removes all arguments from the OSCMessage. */ void clear();