diff --git a/source/Makefile.mk b/source/Makefile.mk index ddb1c1429..a27c1dc9b 100644 --- a/source/Makefile.mk +++ b/source/Makefile.mk @@ -61,7 +61,7 @@ ifeq ($(MACOS),true) # No C++11 support; force 32bit per default BUILD_C_FLAGS = $(BASE_FLAGS) $(32BIT_FLAGS) -std=gnu99 $(CFLAGS) BUILD_CXX_FLAGS = $(BASE_FLAGS) $(32BIT_FLAGS) $(CXXFLAGS) -LINK_FLAGS = $(LDFLAGS) +LINK_FLAGS = $(32BIT_FLAGS) $(LDFLAGS) endif # -------------------------------------------------------------- diff --git a/source/discovery/Makefile b/source/discovery/Makefile index 9b02f9030..bb3616d71 100644 --- a/source/discovery/Makefile +++ b/source/discovery/Makefile @@ -37,6 +37,10 @@ POSIX_32BIT_FLAGS = $(32BIT_FLAGS) -L/usr/lib32 -L/usr/lib/i386-linux-gnu POSIX_64BIT_FLAGS = $(64BIT_FLAGS) -L/usr/lib64 -L/usr/lib/x86_64-linux-gnu POSIX_LINK_FLAGS = $(LINK_FLAGS) $(EXTRA_LIBS) -ldl -lpthread +ifeq ($(MACOS),true) +POSIX_LINK_FLAGS += -framework Cocoa -framework IOKit +endif + WIN_BUILD_FLAGS = $(BUILD_CXX_FLAGS) WIN_32BIT_FLAGS = $(32BIT_FLAGS) WIN_64BIT_FLAGS = $(64BIT_FLAGS) diff --git a/source/modules/juce_audio_basics/buffers/juce_AudioDataConverters.h b/source/modules/juce_audio_basics/buffers/juce_AudioDataConverters.h index 706584700..b3f49a63d 100644 --- a/source/modules/juce_audio_basics/buffers/juce_AudioDataConverters.h +++ b/source/modules/juce_audio_basics/buffers/juce_AudioDataConverters.h @@ -71,9 +71,9 @@ public: { public: template static inline float getAsFloat (SampleFormatType& s) noexcept { return s.getAsFloatBE(); } - template static inline void setAsFloat (SampleFormatType& s, float newValue) noexcept { s.setAsFloatBE (newValue); } + template static inline void setAsFloat (SampleFormatType& s, float newValue) noexcept { s.setAsFloatBE (newValue); } template static inline int32 getAsInt32 (SampleFormatType& s) noexcept { return s.getAsInt32BE(); } - template static inline void setAsInt32 (SampleFormatType& s, int32 newValue) noexcept { s.setAsInt32BE (newValue); } + template static inline void setAsInt32 (SampleFormatType& s, int32 newValue) noexcept { s.setAsInt32BE (newValue); } template static inline void copyFrom (DestType& dest, SourceType& source) noexcept { dest.copyFromBE (source); } enum { isBigEndian = 1 }; }; @@ -82,9 +82,9 @@ public: { public: template static inline float getAsFloat (SampleFormatType& s) noexcept { return s.getAsFloatLE(); } - template static inline void setAsFloat (SampleFormatType& s, float newValue) noexcept { s.setAsFloatLE (newValue); } + template static inline void setAsFloat (SampleFormatType& s, float newValue) noexcept { s.setAsFloatLE (newValue); } template static inline int32 getAsInt32 (SampleFormatType& s) noexcept { return s.getAsInt32LE(); } - template static inline void setAsInt32 (SampleFormatType& s, int32 newValue) noexcept { s.setAsInt32LE (newValue); } + template static inline void setAsInt32 (SampleFormatType& s, int32 newValue) noexcept { s.setAsInt32LE (newValue); } template static inline void copyFrom (DestType& dest, SourceType& source) noexcept { dest.copyFromLE (source); } enum { isBigEndian = 0 }; }; @@ -205,11 +205,11 @@ public: inline void skip (int numSamples) noexcept { data += numSamples; } inline float getAsFloatLE() const noexcept { return (float) ((1.0 / (1.0 + maxValue)) * (int32) ByteOrder::swapIfBigEndian (*data)); } inline float getAsFloatBE() const noexcept { return (float) ((1.0 / (1.0 + maxValue)) * (int32) ByteOrder::swapIfLittleEndian (*data)); } - inline void setAsFloatLE (float newValue) noexcept { *data = ByteOrder::swapIfBigEndian ((uint32) (maxValue * jlimit (-1.0, 1.0, (double) newValue))); } + inline void setAsFloatLE (float newValue) noexcept { *data = ByteOrder::swapIfBigEndian ((uint32) (maxValue * jlimit (-1.0, 1.0, (double) newValue))); } inline void setAsFloatBE (float newValue) noexcept { *data = ByteOrder::swapIfLittleEndian ((uint32) (maxValue * jlimit (-1.0, 1.0, (double) newValue))); } - inline int32 getAsInt32LE() const noexcept { return (int32) ByteOrder::swapIfBigEndian (*data); } + inline int32 getAsInt32LE() const noexcept { return (int32) ByteOrder::swapIfBigEndian (*data); } inline int32 getAsInt32BE() const noexcept { return (int32) ByteOrder::swapIfLittleEndian (*data); } - inline void setAsInt32LE (int32 newValue) noexcept { *data = ByteOrder::swapIfBigEndian ((uint32) newValue); } + inline void setAsInt32LE (int32 newValue) noexcept { *data = ByteOrder::swapIfBigEndian ((uint32) newValue); } inline void setAsInt32BE (int32 newValue) noexcept { *data = ByteOrder::swapIfLittleEndian ((uint32) newValue); } inline void clear() noexcept { *data = 0; } inline void clearMultiple (int num) noexcept { zeromem (data, (size_t) (num * bytesPerSample)) ;} @@ -221,6 +221,27 @@ public: enum { bytesPerSample = 4, maxValue = 0x7fffffff, resolution = 1, isFloat = 0 }; }; + /** A 32-bit integer type, of which only the bottom 24 bits are used. */ + class Int24in32 : public Int32 + { + public: + inline Int24in32 (void* d) noexcept : Int32 (d) {} + + inline float getAsFloatLE() const noexcept { return (float) ((1.0 / (1.0 + maxValue)) * (int32) ByteOrder::swapIfBigEndian (*data)); } + inline float getAsFloatBE() const noexcept { return (float) ((1.0 / (1.0 + maxValue)) * (int32) ByteOrder::swapIfLittleEndian (*data)); } + inline void setAsFloatLE (float newValue) noexcept { *data = ByteOrder::swapIfBigEndian ((uint32) (maxValue * jlimit (-1.0, 1.0, (double) newValue))); } + inline void setAsFloatBE (float newValue) noexcept { *data = ByteOrder::swapIfLittleEndian ((uint32) (maxValue * jlimit (-1.0, 1.0, (double) newValue))); } + inline int32 getAsInt32LE() const noexcept { return (int32) ByteOrder::swapIfBigEndian (*data) << 8; } + inline int32 getAsInt32BE() const noexcept { return (int32) ByteOrder::swapIfLittleEndian (*data) << 8; } + inline void setAsInt32LE (int32 newValue) noexcept { *data = ByteOrder::swapIfBigEndian ((uint32) newValue >> 8); } + inline void setAsInt32BE (int32 newValue) noexcept { *data = ByteOrder::swapIfLittleEndian ((uint32) newValue >> 8); } + template inline void copyFromLE (SourceType& source) noexcept { setAsInt32LE (source.getAsInt32()); } + template inline void copyFromBE (SourceType& source) noexcept { setAsInt32BE (source.getAsInt32()); } + inline void copyFromSameType (Int24in32& source) noexcept { *data = *source.data; } + + enum { bytesPerSample = 4, maxValue = 0x7fffff, resolution = (1 << 8), isFloat = 0 }; + }; + class Float32 { public: @@ -591,9 +612,7 @@ public: : sourceChannels (numSourceChannels), destChannels (numDestChannels) {} - ~ConverterInstance() {} - - void convertSamples (void* dest, const void* source, int numSamples) const + void convertSamples (void* dest, const void* source, int numSamples) const override { SourceSampleType s (source, sourceChannels); DestSampleType d (dest, destChannels); @@ -601,7 +620,7 @@ public: } void convertSamples (void* dest, int destSubChannel, - const void* source, int sourceSubChannel, int numSamples) const + const void* source, int sourceSubChannel, int numSamples) const override { jassert (destSubChannel < destChannels && sourceSubChannel < sourceChannels); diff --git a/source/modules/juce_audio_basics/buffers/juce_AudioSampleBuffer.cpp b/source/modules/juce_audio_basics/buffers/juce_AudioSampleBuffer.cpp index ab670ae1a..1dd3e3c28 100644 --- a/source/modules/juce_audio_basics/buffers/juce_AudioSampleBuffer.cpp +++ b/source/modules/juce_audio_basics/buffers/juce_AudioSampleBuffer.cpp @@ -158,8 +158,8 @@ void AudioSampleBuffer::setSize (const int newNumChannels, if (newNumSamples != size || newNumChannels != numChannels) { - const size_t allocatedSamplesPerChannel = (newNumSamples + 3) & ~3; - const size_t channelListSize = ((sizeof (float*) * (size_t) (newNumChannels + 1)) + 15) & ~15; + const size_t allocatedSamplesPerChannel = ((size_t) newNumSamples + 3) & ~3u; + const size_t channelListSize = ((sizeof (float*) * (size_t) (newNumChannels + 1)) + 15) & ~15u; const size_t newTotalBytes = ((size_t) newNumChannels * (size_t) allocatedSamplesPerChannel * sizeof (float)) + channelListSize + 32; @@ -168,7 +168,7 @@ void AudioSampleBuffer::setSize (const int newNumChannels, HeapBlock newData; newData.allocate (newTotalBytes, clearExtraSpace); - const size_t numSamplesToCopy = jmin (newNumSamples, size); + const size_t numSamplesToCopy = (size_t) jmin (newNumSamples, size); float** const newChannels = reinterpret_cast (newData.getData()); float* newChan = reinterpret_cast (newData + channelListSize); diff --git a/source/modules/juce_audio_basics/buffers/juce_FloatVectorOperations.cpp b/source/modules/juce_audio_basics/buffers/juce_FloatVectorOperations.cpp index 37b408f9d..d863ba931 100644 --- a/source/modules/juce_audio_basics/buffers/juce_FloatVectorOperations.cpp +++ b/source/modules/juce_audio_basics/buffers/juce_FloatVectorOperations.cpp @@ -162,7 +162,7 @@ namespace FloatVectorHelpers void JUCE_CALLTYPE FloatVectorOperations::clear (float* dest, int num) noexcept { #if JUCE_USE_VDSP_FRAMEWORK - vDSP_vclr (dest, 1, num); + vDSP_vclr (dest, 1, (size_t) num); #else zeromem (dest, num * sizeof (float)); #endif @@ -171,7 +171,7 @@ void JUCE_CALLTYPE FloatVectorOperations::clear (float* dest, int num) noexcept void JUCE_CALLTYPE FloatVectorOperations::fill (float* dest, float valueToFill, int num) noexcept { #if JUCE_USE_VDSP_FRAMEWORK - vDSP_vfill (&valueToFill, dest, 1, num); + vDSP_vfill (&valueToFill, dest, 1, (size_t) num); #else #if JUCE_USE_SSE_INTRINSICS const __m128 val = _mm_load1_ps (&valueToFill); @@ -183,7 +183,7 @@ void JUCE_CALLTYPE FloatVectorOperations::fill (float* dest, float valueToFill, void JUCE_CALLTYPE FloatVectorOperations::copy (float* dest, const float* src, int num) noexcept { - memcpy (dest, src, num * sizeof (float)); + memcpy (dest, src, (size_t) num * sizeof (float)); } void JUCE_CALLTYPE FloatVectorOperations::copyWithMultiply (float* dest, const float* src, float multiplier, int num) noexcept diff --git a/source/modules/juce_audio_basics/effects/juce_Decibels.h b/source/modules/juce_audio_basics/effects/juce_Decibels.h index 2ea42a45e..6f4d2ebe3 100644 --- a/source/modules/juce_audio_basics/effects/juce_Decibels.h +++ b/source/modules/juce_audio_basics/effects/juce_Decibels.h @@ -25,6 +25,7 @@ #ifndef JUCE_DECIBELS_H_INCLUDED #define JUCE_DECIBELS_H_INCLUDED + //============================================================================== /** This class contains some helpful static methods for dealing with decibel values. diff --git a/source/modules/juce_audio_basics/effects/juce_IIRFilter.cpp b/source/modules/juce_audio_basics/effects/juce_IIRFilter.cpp index 4b2fd755c..908a69e0f 100644 --- a/source/modules/juce_audio_basics/effects/juce_IIRFilter.cpp +++ b/source/modules/juce_audio_basics/effects/juce_IIRFilter.cpp @@ -31,19 +31,19 @@ //============================================================================== IIRCoefficients::IIRCoefficients() noexcept { - zeromem (c, sizeof (c)); + zeromem (coefficients, sizeof (coefficients)); } IIRCoefficients::~IIRCoefficients() noexcept {} IIRCoefficients::IIRCoefficients (const IIRCoefficients& other) noexcept { - memcpy (c, other.c, sizeof (c)); + memcpy (coefficients, other.coefficients, sizeof (coefficients)); } IIRCoefficients& IIRCoefficients::operator= (const IIRCoefficients& other) noexcept { - memcpy (c, other.c, sizeof (c)); + memcpy (coefficients, other.coefficients, sizeof (coefficients)); return *this; } @@ -52,11 +52,11 @@ IIRCoefficients::IIRCoefficients (double c1, double c2, double c3, { const double a = 1.0 / c4; - c[0] = (float) (c1 * a); - c[1] = (float) (c2 * a); - c[2] = (float) (c3 * a); - c[3] = (float) (c5 * a); - c[4] = (float) (c6 * a); + coefficients[0] = (float) (c1 * a); + coefficients[1] = (float) (c2 * a); + coefficients[2] = (float) (c3 * a); + coefficients[3] = (float) (c5 * a); + coefficients[4] = (float) (c6 * a); } IIRCoefficients IIRCoefficients::makeLowPass (const double sampleRate, @@ -69,7 +69,7 @@ IIRCoefficients IIRCoefficients::makeLowPass (const double sampleRate, const double c1 = 1.0 / (1.0 + std::sqrt (2.0) * n + nSquared); return IIRCoefficients (c1, - c1 * 2.0f, + c1 * 2.0, c1, 1.0, c1 * 2.0 * (1.0 - nSquared), @@ -84,7 +84,7 @@ IIRCoefficients IIRCoefficients::makeHighPass (const double sampleRate, const double c1 = 1.0 / (1.0 + std::sqrt (2.0) * n + nSquared); return IIRCoefficients (c1, - c1 * -2.0f, + c1 * -2.0, c1, 1.0, c1 * 2.0 * (nSquared - 1.0), @@ -203,28 +203,27 @@ void IIRFilter::reset() noexcept float IIRFilter::processSingleSampleRaw (const float in) noexcept { - float out = coefficients.c[0] * in + v1; + float out = coefficients.coefficients[0] * in + v1; JUCE_SNAP_TO_ZERO (out); - v1 = coefficients.c[1] * in - coefficients.c[3] * out + v2; - v2 = coefficients.c[2] * in - coefficients.c[4] * out; + v1 = coefficients.coefficients[1] * in - coefficients.coefficients[3] * out + v2; + v2 = coefficients.coefficients[2] * in - coefficients.coefficients[4] * out; return out; } -void IIRFilter::processSamples (float* const samples, - const int numSamples) noexcept +void IIRFilter::processSamples (float* const samples, const int numSamples) noexcept { const SpinLock::ScopedLockType sl (processLock); if (active) { - const float c0 = coefficients.c[0]; - const float c1 = coefficients.c[1]; - const float c2 = coefficients.c[2]; - const float c3 = coefficients.c[3]; - const float c4 = coefficients.c[4]; + const float c0 = coefficients.coefficients[0]; + const float c1 = coefficients.coefficients[1]; + const float c2 = coefficients.coefficients[2]; + const float c3 = coefficients.coefficients[3]; + const float c4 = coefficients.coefficients[4]; float lv1 = v1, lv2 = v2; for (int i = 0; i < numSamples; ++i) diff --git a/source/modules/juce_audio_basics/effects/juce_IIRFilter.h b/source/modules/juce_audio_basics/effects/juce_IIRFilter.h index c7a029ea2..8269cf582 100644 --- a/source/modules/juce_audio_basics/effects/juce_IIRFilter.h +++ b/source/modules/juce_audio_basics/effects/juce_IIRFilter.h @@ -98,9 +98,11 @@ public: double Q, float gainFactor) noexcept; -private: - friend class IIRFilter; - float c[5]; + //============================================================================== + /** The raw coefficients. + You should leave these numbers alone unless you really know what you're doing. + */ + float coefficients[5]; }; //============================================================================== diff --git a/source/modules/juce_audio_basics/effects/juce_LagrangeInterpolator.cpp b/source/modules/juce_audio_basics/effects/juce_LagrangeInterpolator.cpp index 664996080..7bab3a576 100644 --- a/source/modules/juce_audio_basics/effects/juce_LagrangeInterpolator.cpp +++ b/source/modules/juce_audio_basics/effects/juce_LagrangeInterpolator.cpp @@ -83,7 +83,7 @@ int LagrangeInterpolator::process (const double actualRatio, const float* in, { if (actualRatio == 1.0) { - memcpy (out, in, numOut * sizeof (float)); + memcpy (out, in, (size_t) numOut * sizeof (float)); if (numOut >= 4) { diff --git a/source/modules/juce_audio_basics/effects/juce_LagrangeInterpolator.h b/source/modules/juce_audio_basics/effects/juce_LagrangeInterpolator.h index c43525dc8..caa4802ec 100644 --- a/source/modules/juce_audio_basics/effects/juce_LagrangeInterpolator.h +++ b/source/modules/juce_audio_basics/effects/juce_LagrangeInterpolator.h @@ -25,6 +25,7 @@ #ifndef JUCE_LAGRANGEINTERPOLATOR_H_INCLUDED #define JUCE_LAGRANGEINTERPOLATOR_H_INCLUDED + //============================================================================== /** Interpolator for resampling a stream of floats using 4-point lagrange interpolation. diff --git a/source/modules/juce_audio_basics/juce_audio_basics.cpp b/source/modules/juce_audio_basics/juce_audio_basics.cpp index 0726b6e8b..2bdd5a490 100644 --- a/source/modules/juce_audio_basics/juce_audio_basics.cpp +++ b/source/modules/juce_audio_basics/juce_audio_basics.cpp @@ -48,19 +48,24 @@ #include #endif -#if JUCE_MAC || JUCE_IOS +#ifndef JUCE_USE_VDSP_FRAMEWORK #define JUCE_USE_VDSP_FRAMEWORK 1 +#endif + +#if (JUCE_MAC || JUCE_IOS) && JUCE_USE_VDSP_FRAMEWORK #include +#else + #undef JUCE_USE_VDSP_FRAMEWORK #endif namespace juce { -// START_AUTOINCLUDE buffers/*.cpp, effects/*.cpp, midi/*.cpp, sources/*.cpp, synthesisers/*.cpp #include "buffers/juce_AudioDataConverters.cpp" #include "buffers/juce_AudioSampleBuffer.cpp" #include "buffers/juce_FloatVectorOperations.cpp" #include "effects/juce_IIRFilter.cpp" +#include "effects/juce_IIRFilterOld.cpp" #include "effects/juce_LagrangeInterpolator.cpp" #include "midi/juce_MidiBuffer.cpp" #include "midi/juce_MidiFile.cpp" @@ -75,6 +80,5 @@ namespace juce #include "sources/juce_ReverbAudioSource.cpp" #include "sources/juce_ToneGeneratorAudioSource.cpp" #include "synthesisers/juce_Synthesiser.cpp" -// END_AUTOINCLUDE } diff --git a/source/modules/juce_audio_basics/juce_audio_basics.h b/source/modules/juce_audio_basics/juce_audio_basics.h index ddd042186..c9ce9abb2 100644 --- a/source/modules/juce_audio_basics/juce_audio_basics.h +++ b/source/modules/juce_audio_basics/juce_audio_basics.h @@ -31,30 +31,29 @@ namespace juce { -// START_AUTOINCLUDE buffers, effects, midi, sources, synthesisers #include "buffers/juce_AudioDataConverters.h" #include "buffers/juce_AudioSampleBuffer.h" #include "buffers/juce_FloatVectorOperations.h" #include "effects/juce_Decibels.h" #include "effects/juce_IIRFilter.h" +#include "effects/juce_IIRFilterOld.h" #include "effects/juce_LagrangeInterpolator.h" #include "effects/juce_Reverb.h" +#include "midi/juce_MidiMessage.h" #include "midi/juce_MidiBuffer.h" +#include "midi/juce_MidiMessageSequence.h" #include "midi/juce_MidiFile.h" #include "midi/juce_MidiKeyboardState.h" -#include "midi/juce_MidiMessage.h" -#include "midi/juce_MidiMessageSequence.h" #include "sources/juce_AudioSource.h" +#include "sources/juce_PositionableAudioSource.h" #include "sources/juce_BufferingAudioSource.h" #include "sources/juce_ChannelRemappingAudioSource.h" #include "sources/juce_IIRFilterAudioSource.h" #include "sources/juce_MixerAudioSource.h" -#include "sources/juce_PositionableAudioSource.h" #include "sources/juce_ResamplingAudioSource.h" #include "sources/juce_ReverbAudioSource.h" #include "sources/juce_ToneGeneratorAudioSource.h" #include "synthesisers/juce_Synthesiser.h" -// END_AUTOINCLUDE } diff --git a/source/modules/juce_audio_basics/midi/juce_MidiBuffer.h b/source/modules/juce_audio_basics/midi/juce_MidiBuffer.h index 3275cf243..7c8e51c73 100644 --- a/source/modules/juce_audio_basics/midi/juce_MidiBuffer.h +++ b/source/modules/juce_audio_basics/midi/juce_MidiBuffer.h @@ -25,8 +25,6 @@ #ifndef JUCE_MIDIBUFFER_H_INCLUDED #define JUCE_MIDIBUFFER_H_INCLUDED -#include "juce_MidiMessage.h" - //============================================================================== /** diff --git a/source/modules/juce_audio_basics/midi/juce_MidiFile.h b/source/modules/juce_audio_basics/midi/juce_MidiFile.h index 716bec8a6..53476a87e 100644 --- a/source/modules/juce_audio_basics/midi/juce_MidiFile.h +++ b/source/modules/juce_audio_basics/midi/juce_MidiFile.h @@ -25,8 +25,6 @@ #ifndef JUCE_MIDIFILE_H_INCLUDED #define JUCE_MIDIFILE_H_INCLUDED -#include "juce_MidiMessageSequence.h" - //============================================================================== /** diff --git a/source/modules/juce_audio_basics/midi/juce_MidiKeyboardState.h b/source/modules/juce_audio_basics/midi/juce_MidiKeyboardState.h index 4fde455d1..885b7d88f 100644 --- a/source/modules/juce_audio_basics/midi/juce_MidiKeyboardState.h +++ b/source/modules/juce_audio_basics/midi/juce_MidiKeyboardState.h @@ -25,7 +25,6 @@ #ifndef JUCE_MIDIKEYBOARDSTATE_H_INCLUDED #define JUCE_MIDIKEYBOARDSTATE_H_INCLUDED -#include "juce_MidiBuffer.h" class MidiKeyboardState; diff --git a/source/modules/juce_audio_basics/midi/juce_MidiMessageSequence.h b/source/modules/juce_audio_basics/midi/juce_MidiMessageSequence.h index 8b52a6259..c44e448be 100644 --- a/source/modules/juce_audio_basics/midi/juce_MidiMessageSequence.h +++ b/source/modules/juce_audio_basics/midi/juce_MidiMessageSequence.h @@ -25,8 +25,6 @@ #ifndef JUCE_MIDIMESSAGESEQUENCE_H_INCLUDED #define JUCE_MIDIMESSAGESEQUENCE_H_INCLUDED -#include "juce_MidiMessage.h" - //============================================================================== /** diff --git a/source/modules/juce_audio_basics/sources/juce_AudioSource.h b/source/modules/juce_audio_basics/sources/juce_AudioSource.h index 92c2eb88f..e50b2acb6 100644 --- a/source/modules/juce_audio_basics/sources/juce_AudioSource.h +++ b/source/modules/juce_audio_basics/sources/juce_AudioSource.h @@ -25,8 +25,6 @@ #ifndef JUCE_AUDIOSOURCE_H_INCLUDED #define JUCE_AUDIOSOURCE_H_INCLUDED -#include "../buffers/juce_AudioSampleBuffer.h" - //============================================================================== /** diff --git a/source/modules/juce_audio_basics/sources/juce_BufferingAudioSource.h b/source/modules/juce_audio_basics/sources/juce_BufferingAudioSource.h index 78b891c64..b0ab4d2f7 100644 --- a/source/modules/juce_audio_basics/sources/juce_BufferingAudioSource.h +++ b/source/modules/juce_audio_basics/sources/juce_BufferingAudioSource.h @@ -25,8 +25,6 @@ #ifndef JUCE_BUFFERINGAUDIOSOURCE_H_INCLUDED #define JUCE_BUFFERINGAUDIOSOURCE_H_INCLUDED -#include "juce_PositionableAudioSource.h" - //============================================================================== /** @@ -76,7 +74,7 @@ public: void releaseResources() override; /** Implementation of the AudioSource method. */ - void getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill) override; + void getNextAudioBlock (const AudioSourceChannelInfo&) override; //============================================================================== /** Implements the PositionableAudioSource method. */ @@ -104,7 +102,7 @@ private: bool readNextBufferChunk(); void readBufferSection (int64 start, int length, int bufferOffset); - int useTimeSlice(); + int useTimeSlice() override; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BufferingAudioSource) }; diff --git a/source/modules/juce_audio_basics/sources/juce_ChannelRemappingAudioSource.h b/source/modules/juce_audio_basics/sources/juce_ChannelRemappingAudioSource.h index a26fa98cc..483fe99de 100644 --- a/source/modules/juce_audio_basics/sources/juce_ChannelRemappingAudioSource.h +++ b/source/modules/juce_audio_basics/sources/juce_ChannelRemappingAudioSource.h @@ -25,8 +25,6 @@ #ifndef JUCE_CHANNELREMAPPINGAUDIOSOURCE_H_INCLUDED #define JUCE_CHANNELREMAPPINGAUDIOSOURCE_H_INCLUDED -#include "juce_AudioSource.h" - //============================================================================== /** @@ -113,32 +111,29 @@ public: //============================================================================== /** Returns an XML object to encapsulate the state of the mappings. - @see restoreFromXml */ XmlElement* createXml() const; /** Restores the mappings from an XML object created by createXML(). - @see createXml */ - void restoreFromXml (const XmlElement& e); + void restoreFromXml (const XmlElement&); //============================================================================== - void prepareToPlay (int samplesPerBlockExpected, double sampleRate); - void releaseResources(); - void getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill); + void prepareToPlay (int samplesPerBlockExpected, double sampleRate) override; + void releaseResources() override; + void getNextAudioBlock (const AudioSourceChannelInfo&) override; private: //============================================================================== OptionalScopedPointer source; - Array remappedInputs, remappedOutputs; + Array remappedInputs, remappedOutputs; int requiredNumberOfChannels; AudioSampleBuffer buffer; AudioSourceChannelInfo remappedInfo; - CriticalSection lock; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ChannelRemappingAudioSource) diff --git a/source/modules/juce_audio_basics/sources/juce_IIRFilterAudioSource.h b/source/modules/juce_audio_basics/sources/juce_IIRFilterAudioSource.h index 5c34c8dc5..40844c568 100644 --- a/source/modules/juce_audio_basics/sources/juce_IIRFilterAudioSource.h +++ b/source/modules/juce_audio_basics/sources/juce_IIRFilterAudioSource.h @@ -25,9 +25,6 @@ #ifndef JUCE_IIRFILTERAUDIOSOURCE_H_INCLUDED #define JUCE_IIRFILTERAUDIOSOURCE_H_INCLUDED -#include "juce_AudioSource.h" -#include "../effects/juce_IIRFilter.h" - //============================================================================== /** @@ -57,14 +54,14 @@ public: void makeInactive(); //============================================================================== - void prepareToPlay (int samplesPerBlockExpected, double sampleRate); - void releaseResources(); - void getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill); + void prepareToPlay (int samplesPerBlockExpected, double sampleRate) override; + void releaseResources() override; + void getNextAudioBlock (const AudioSourceChannelInfo&) override; private: //============================================================================== OptionalScopedPointer input; - OwnedArray iirFilters; + OwnedArray iirFilters; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (IIRFilterAudioSource) }; diff --git a/source/modules/juce_audio_basics/sources/juce_MixerAudioSource.h b/source/modules/juce_audio_basics/sources/juce_MixerAudioSource.h index 2cb68fde3..f581ac31e 100644 --- a/source/modules/juce_audio_basics/sources/juce_MixerAudioSource.h +++ b/source/modules/juce_audio_basics/sources/juce_MixerAudioSource.h @@ -25,8 +25,6 @@ #ifndef JUCE_MIXERAUDIOSOURCE_H_INCLUDED #define JUCE_MIXERAUDIOSOURCE_H_INCLUDED -#include "juce_AudioSource.h" - //============================================================================== /** @@ -76,20 +74,20 @@ public: /** Implementation of the AudioSource method. This will call prepareToPlay() on all its input sources. */ - void prepareToPlay (int samplesPerBlockExpected, double sampleRate); + void prepareToPlay (int samplesPerBlockExpected, double sampleRate) override; /** Implementation of the AudioSource method. This will call releaseResources() on all its input sources. */ - void releaseResources(); + void releaseResources() override; /** Implementation of the AudioSource method. */ - void getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill); + void getNextAudioBlock (const AudioSourceChannelInfo&) override; private: //============================================================================== - Array inputs; + Array inputs; BigInteger inputsToDelete; CriticalSection lock; AudioSampleBuffer tempBuffer; diff --git a/source/modules/juce_audio_basics/sources/juce_PositionableAudioSource.h b/source/modules/juce_audio_basics/sources/juce_PositionableAudioSource.h index 066ab9902..2213722bd 100644 --- a/source/modules/juce_audio_basics/sources/juce_PositionableAudioSource.h +++ b/source/modules/juce_audio_basics/sources/juce_PositionableAudioSource.h @@ -25,8 +25,6 @@ #ifndef JUCE_POSITIONABLEAUDIOSOURCE_H_INCLUDED #define JUCE_POSITIONABLEAUDIOSOURCE_H_INCLUDED -#include "juce_AudioSource.h" - //============================================================================== /** diff --git a/source/modules/juce_audio_basics/sources/juce_ResamplingAudioSource.h b/source/modules/juce_audio_basics/sources/juce_ResamplingAudioSource.h index a4dadab9b..76e79ef15 100644 --- a/source/modules/juce_audio_basics/sources/juce_ResamplingAudioSource.h +++ b/source/modules/juce_audio_basics/sources/juce_ResamplingAudioSource.h @@ -25,8 +25,6 @@ #ifndef JUCE_RESAMPLINGAUDIOSOURCE_H_INCLUDED #define JUCE_RESAMPLINGAUDIOSOURCE_H_INCLUDED -#include "juce_AudioSource.h" - //============================================================================== /** @@ -69,9 +67,9 @@ public: double getResamplingRatio() const noexcept { return ratio; } //============================================================================== - void prepareToPlay (int samplesPerBlockExpected, double sampleRate); - void releaseResources(); - void getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill); + void prepareToPlay (int samplesPerBlockExpected, double sampleRate) override; + void releaseResources() override; + void getNextAudioBlock (const AudioSourceChannelInfo&) override; private: //============================================================================== diff --git a/source/modules/juce_audio_basics/sources/juce_ReverbAudioSource.h b/source/modules/juce_audio_basics/sources/juce_ReverbAudioSource.h index dab1f0eed..6b90e184a 100644 --- a/source/modules/juce_audio_basics/sources/juce_ReverbAudioSource.h +++ b/source/modules/juce_audio_basics/sources/juce_ReverbAudioSource.h @@ -25,9 +25,6 @@ #ifndef JUCE_REVERBAUDIOSOURCE_H_INCLUDED #define JUCE_REVERBAUDIOSOURCE_H_INCLUDED -#include "juce_AudioSource.h" -#include "../effects/juce_Reverb.h" - //============================================================================== /** @@ -61,9 +58,9 @@ public: bool isBypassed() const noexcept { return bypass; } //============================================================================== - void prepareToPlay (int samplesPerBlockExpected, double sampleRate); - void releaseResources(); - void getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill); + void prepareToPlay (int samplesPerBlockExpected, double sampleRate) override; + void releaseResources() override; + void getNextAudioBlock (const AudioSourceChannelInfo&) override; private: //============================================================================== diff --git a/source/modules/juce_audio_basics/sources/juce_ToneGeneratorAudioSource.h b/source/modules/juce_audio_basics/sources/juce_ToneGeneratorAudioSource.h index 2f0429052..5d09ad8ee 100644 --- a/source/modules/juce_audio_basics/sources/juce_ToneGeneratorAudioSource.h +++ b/source/modules/juce_audio_basics/sources/juce_ToneGeneratorAudioSource.h @@ -25,8 +25,6 @@ #ifndef JUCE_TONEGENERATORAUDIOSOURCE_H_INCLUDED #define JUCE_TONEGENERATORAUDIOSOURCE_H_INCLUDED -#include "juce_AudioSource.h" - //============================================================================== /** @@ -53,13 +51,13 @@ public: //============================================================================== /** Implementation of the AudioSource method. */ - void prepareToPlay (int samplesPerBlockExpected, double sampleRate); + void prepareToPlay (int samplesPerBlockExpected, double sampleRate) override; /** Implementation of the AudioSource method. */ - void releaseResources(); + void releaseResources() override; /** Implementation of the AudioSource method. */ - void getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill); + void getNextAudioBlock (const AudioSourceChannelInfo&) override; private: diff --git a/source/modules/juce_audio_basics/synthesisers/juce_Synthesiser.h b/source/modules/juce_audio_basics/synthesisers/juce_Synthesiser.h index 5044ef160..eac8ddd08 100644 --- a/source/modules/juce_audio_basics/synthesisers/juce_Synthesiser.h +++ b/source/modules/juce_audio_basics/synthesisers/juce_Synthesiser.h @@ -25,9 +25,6 @@ #ifndef JUCE_SYNTHESISER_H_INCLUDED #define JUCE_SYNTHESISER_H_INCLUDED -#include "../buffers/juce_AudioSampleBuffer.h" -#include "../midi/juce_MidiBuffer.h" - //============================================================================== /** diff --git a/source/modules/juce_core/containers/juce_AbstractFifo.h b/source/modules/juce_core/containers/juce_AbstractFifo.h index f656a107d..02feac74e 100644 --- a/source/modules/juce_core/containers/juce_AbstractFifo.h +++ b/source/modules/juce_core/containers/juce_AbstractFifo.h @@ -29,8 +29,6 @@ #ifndef JUCE_ABSTRACTFIFO_H_INCLUDED #define JUCE_ABSTRACTFIFO_H_INCLUDED -#include "../memory/juce_Atomic.h" - //============================================================================== /** diff --git a/source/modules/juce_core/containers/juce_Array.h b/source/modules/juce_core/containers/juce_Array.h index 710dcba83..21d3f86c2 100644 --- a/source/modules/juce_core/containers/juce_Array.h +++ b/source/modules/juce_core/containers/juce_Array.h @@ -29,10 +29,6 @@ #ifndef JUCE_ARRAY_H_INCLUDED #define JUCE_ARRAY_H_INCLUDED -#include "juce_ArrayAllocationBase.h" -#include "juce_ElementComparator.h" -#include "../threads/juce_CriticalSection.h" - //============================================================================== /** @@ -1025,9 +1021,11 @@ public: //============================================================================== + #ifndef DOXYGEN // Note that the swapWithArray method has been replaced by a more flexible templated version, // and renamed "swapWith" to be more consistent with the names used in other classes. JUCE_DEPRECATED_WITH_BODY (void swapWithArray (Array& other) noexcept, { swapWith (other); }) + #endif private: //============================================================================== diff --git a/source/modules/juce_core/containers/juce_ArrayAllocationBase.h b/source/modules/juce_core/containers/juce_ArrayAllocationBase.h index 31aa256a6..cfbe46467 100644 --- a/source/modules/juce_core/containers/juce_ArrayAllocationBase.h +++ b/source/modules/juce_core/containers/juce_ArrayAllocationBase.h @@ -29,8 +29,6 @@ #ifndef JUCE_ARRAYALLOCATIONBASE_H_INCLUDED #define JUCE_ARRAYALLOCATIONBASE_H_INCLUDED -#include "../memory/juce_HeapBlock.h" - //============================================================================== /** diff --git a/source/modules/juce_core/containers/juce_DynamicObject.h b/source/modules/juce_core/containers/juce_DynamicObject.h index 2b14aa587..38bc227e9 100644 --- a/source/modules/juce_core/containers/juce_DynamicObject.h +++ b/source/modules/juce_core/containers/juce_DynamicObject.h @@ -29,9 +29,6 @@ #ifndef JUCE_DYNAMICOBJECT_H_INCLUDED #define JUCE_DYNAMICOBJECT_H_INCLUDED -#include "juce_NamedValueSet.h" -#include "../memory/juce_ReferenceCountedObject.h" - //============================================================================== /** diff --git a/source/modules/juce_core/containers/juce_ElementComparator.h b/source/modules/juce_core/containers/juce_ElementComparator.h index f2b0b55c4..01dc5b703 100644 --- a/source/modules/juce_core/containers/juce_ElementComparator.h +++ b/source/modules/juce_core/containers/juce_ElementComparator.h @@ -29,6 +29,27 @@ #ifndef JUCE_ELEMENTCOMPARATOR_H_INCLUDED #define JUCE_ELEMENTCOMPARATOR_H_INCLUDED +#ifndef DOXYGEN + +/** This is an internal helper class which converts a juce ElementComparator style + class (using a "compareElements" method) into a class that's compatible with + std::sort (i.e. using an operator() to compare the elements) +*/ +template +struct SortFunctionConverter +{ + SortFunctionConverter (ElementComparator& e) : comparator (e) {} + + template + bool operator() (Type a, Type b) { return comparator.compareElements (a, b) < 0; } + +private: + ElementComparator& comparator; + SortFunctionConverter& operator= (const SortFunctionConverter&) JUCE_DELETED_FUNCTION; +}; + +#endif + //============================================================================== /** @@ -65,117 +86,12 @@ static void sortArray (ElementComparator& comparator, int lastElement, const bool retainOrderOfEquivalentItems) { - (void) comparator; // if you pass in an object with a static compareElements() method, this - // avoids getting warning messages about the parameter being unused - - if (lastElement > firstElement) - { - if (retainOrderOfEquivalentItems) - { - for (int i = firstElement; i < lastElement; ++i) - { - if (comparator.compareElements (array[i], array [i + 1]) > 0) - { - std::swap (array[i], array[i + 1]); - - if (i > firstElement) - i -= 2; - } - } - } - else - { - int fromStack[30], toStack[30]; - int stackIndex = 0; + SortFunctionConverter converter (comparator); - for (;;) - { - const int size = (lastElement - firstElement) + 1; - - if (size <= 8) - { - int j = lastElement; - int maxIndex; - - while (j > firstElement) - { - maxIndex = firstElement; - for (int k = firstElement + 1; k <= j; ++k) - if (comparator.compareElements (array[k], array [maxIndex]) > 0) - maxIndex = k; - - std::swap (array[j], array[maxIndex]); - --j; - } - } - else - { - const int mid = firstElement + (size >> 1); - std::swap (array[mid], array[firstElement]); - - int i = firstElement; - int j = lastElement + 1; - - for (;;) - { - while (++i <= lastElement - && comparator.compareElements (array[i], array [firstElement]) <= 0) - {} - - while (--j > firstElement - && comparator.compareElements (array[j], array [firstElement]) >= 0) - {} - - if (j < i) - break; - - std::swap (array[i], array[j]); - } - - std::swap (array[j], array[firstElement]); - - if (j - 1 - firstElement >= lastElement - i) - { - if (firstElement + 1 < j) - { - fromStack [stackIndex] = firstElement; - toStack [stackIndex] = j - 1; - ++stackIndex; - } - - if (i < lastElement) - { - firstElement = i; - continue; - } - } - else - { - if (i < lastElement) - { - fromStack [stackIndex] = i; - toStack [stackIndex] = lastElement; - ++stackIndex; - } - - if (firstElement + 1 < j) - { - lastElement = j - 1; - continue; - } - } - } - - if (--stackIndex < 0) - break; - - jassert (stackIndex < numElementsInArray (fromStack)); - - firstElement = fromStack [stackIndex]; - lastElement = toStack [stackIndex]; - } - } - } + if (retainOrderOfEquivalentItems) + std::stable_sort (array + firstElement, array + lastElement + 1, converter); + else + std::sort (array + firstElement, array + lastElement + 1, converter); } diff --git a/source/modules/juce_core/containers/juce_HashMap.h b/source/modules/juce_core/containers/juce_HashMap.h index 2608ad5c3..a10942195 100644 --- a/source/modules/juce_core/containers/juce_HashMap.h +++ b/source/modules/juce_core/containers/juce_HashMap.h @@ -29,10 +29,6 @@ #ifndef JUCE_HASHMAP_H_INCLUDED #define JUCE_HASHMAP_H_INCLUDED -#include "juce_OwnedArray.h" -#include "juce_LinkedListPointer.h" -#include "../memory/juce_ScopedPointer.h" - //============================================================================== /** @@ -109,11 +105,10 @@ public: //============================================================================== /** Creates an empty hash-map. - The numberOfSlots parameter specifies the number of hash entries the map will - use. This will be the "upperLimit" parameter that is passed to your generateHash() - function. The number of hash slots will grow automatically if necessary, or - it can be remapped manually using remapTable(). - + @param numberOfSlots Specifies the number of hash entries the map will use. This will be + the "upperLimit" parameter that is passed to your generateHash() + function. The number of hash slots will grow automatically if necessary, + or it can be remapped manually using remapTable(). @param hashFunction An instance of HashFunctionType, which will be copied and stored to use with the HashMap. This parameter can be omitted if HashFunctionType has a default constructor. diff --git a/source/modules/juce_core/containers/juce_NamedValueSet.h b/source/modules/juce_core/containers/juce_NamedValueSet.h index f1c4c35c9..699d2fef7 100644 --- a/source/modules/juce_core/containers/juce_NamedValueSet.h +++ b/source/modules/juce_core/containers/juce_NamedValueSet.h @@ -29,13 +29,6 @@ #ifndef JUCE_NAMEDVALUESET_H_INCLUDED #define JUCE_NAMEDVALUESET_H_INCLUDED -#include "juce_Variant.h" -#include "../containers/juce_LinkedListPointer.h" -class XmlElement; -#ifndef DOXYGEN - class JSONFormatter; -#endif - //============================================================================== /** Holds a set of named var objects. diff --git a/source/modules/juce_core/containers/juce_OwnedArray.h b/source/modules/juce_core/containers/juce_OwnedArray.h index b59e25d23..5a29fa3c2 100644 --- a/source/modules/juce_core/containers/juce_OwnedArray.h +++ b/source/modules/juce_core/containers/juce_OwnedArray.h @@ -29,10 +29,6 @@ #ifndef JUCE_OWNEDARRAY_H_INCLUDED #define JUCE_OWNEDARRAY_H_INCLUDED -#include "juce_ArrayAllocationBase.h" -#include "juce_ElementComparator.h" -#include "../threads/juce_CriticalSection.h" - //============================================================================== /** An array designed for holding objects. @@ -389,7 +385,7 @@ public: { if (indexToChange >= 0) { - ObjectClass* toDelete = nullptr; + ScopedPointer toDelete; { const ScopedLockType lock (getLock()); @@ -401,7 +397,7 @@ public: toDelete = data.elements [indexToChange]; if (toDelete == newObject) - toDelete = nullptr; + toDelete.release(); } data.elements [indexToChange] = const_cast (newObject); @@ -412,10 +408,6 @@ public: data.elements [numUsed++] = const_cast (newObject); } } - - delete toDelete; // don't want to use a ScopedPointer here because if the - // object has a private destructor, both OwnedArray and - // ScopedPointer would need to be friend classes.. } else { @@ -575,7 +567,7 @@ public: void remove (const int indexToRemove, const bool deleteObject = true) { - ObjectClass* toDelete = nullptr; + ScopedPointer toDelete; { const ScopedLockType lock (getLock()); @@ -595,10 +587,6 @@ public: } } - delete toDelete; // don't want to use a ScopedPointer here because if the - // object has a private destructor, both OwnedArray and - // ScopedPointer would need to be friend classes.. - if ((numUsed << 1) < data.numAllocated) minimiseStorageOverheads(); } @@ -686,7 +674,7 @@ public: { for (int i = startIndex; i < endIndex; ++i) { - delete data.elements [i]; + ContainerDeletePolicy::destroy (data.elements [i]); data.elements [i] = nullptr; // (in case one of the destructors accesses this array and hits a dangling pointer) } } @@ -875,9 +863,11 @@ public: //============================================================================== + #ifndef DOXYGEN // Note that the swapWithArray method has been replaced by a more flexible templated version, // and renamed "swapWith" to be more consistent with the names used in other classes. JUCE_DEPRECATED_WITH_BODY (void swapWithArray (OwnedArray& other) noexcept, { swapWith (other); }) + #endif private: //============================================================================== @@ -887,7 +877,7 @@ private: void deleteAllObjects() { while (numUsed > 0) - delete data.elements [--numUsed]; + ContainerDeletePolicy::destroy (data.elements [--numUsed]); } JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OwnedArray) diff --git a/source/modules/juce_core/containers/juce_PropertySet.h b/source/modules/juce_core/containers/juce_PropertySet.h index 20ea4a160..4ddf4d817 100644 --- a/source/modules/juce_core/containers/juce_PropertySet.h +++ b/source/modules/juce_core/containers/juce_PropertySet.h @@ -29,10 +29,6 @@ #ifndef JUCE_PROPERTYSET_H_INCLUDED #define JUCE_PROPERTYSET_H_INCLUDED -#include "../text/juce_StringPairArray.h" -#include "../xml/juce_XmlElement.h" -#include "../containers/juce_Variant.h" - //============================================================================== /** diff --git a/source/modules/juce_core/containers/juce_ReferenceCountedArray.h b/source/modules/juce_core/containers/juce_ReferenceCountedArray.h index 0e0e5cd4d..fba2fa413 100644 --- a/source/modules/juce_core/containers/juce_ReferenceCountedArray.h +++ b/source/modules/juce_core/containers/juce_ReferenceCountedArray.h @@ -29,15 +29,18 @@ #ifndef JUCE_REFERENCECOUNTEDARRAY_H_INCLUDED #define JUCE_REFERENCECOUNTEDARRAY_H_INCLUDED -#include "../memory/juce_ReferenceCountedObject.h" -#include "juce_ArrayAllocationBase.h" -#include "juce_ElementComparator.h" -#include "../threads/juce_CriticalSection.h" - //============================================================================== /** - Holds a list of objects derived from ReferenceCountedObject. + Holds a list of objects derived from ReferenceCountedObject, or which implement basic + reference-count handling methods. + + The template parameter specifies the class of the object you want to point to - the easiest + way to make a class reference-countable is to simply make it inherit from ReferenceCountedObject + or SingleThreadedReferenceCountedObject, but if you need to, you can roll your own reference-countable + class by implementing a set of mathods called incReferenceCount(), decReferenceCount(), and + decReferenceCountWithoutDeleting(). See ReferenceCountedObject for examples of how these methods + should behave. A ReferenceCountedArray holds objects derived from ReferenceCountedObject, and takes care of incrementing and decrementing their ref counts when they @@ -130,7 +133,7 @@ public: while (numUsed > 0) if (ObjectClass* o = data.elements [--numUsed]) - o->decReferenceCount(); + releaseObject (o); jassert (numUsed == 0); data.setAllocatedSize (0); @@ -392,7 +395,7 @@ public: if (indexToChange < numUsed) { if (ObjectClass* o = data.elements [indexToChange]) - o->decReferenceCount(); + releaseObject (o); data.elements [indexToChange] = newObject; } @@ -542,7 +545,7 @@ public: ObjectClass** const e = data.elements + indexToRemove; if (ObjectClass* o = *e) - o->decReferenceCount(); + releaseObject (o); --numUsed; const int numberToShift = numUsed - indexToRemove; @@ -576,7 +579,7 @@ public: if (ObjectClass* o = *e) { removedItem = o; - o->decReferenceCount(); + releaseObject (o); } --numUsed; @@ -636,7 +639,7 @@ public: { if (ObjectClass* o = data.elements[i]) { - o->decReferenceCount(); + releaseObject (o); data.elements[i] = nullptr; // (in case one of the destructors accesses this array and hits a dangling pointer) } } @@ -858,14 +861,22 @@ public: //============================================================================== + #ifndef DOXYGEN // Note that the swapWithArray method has been replaced by a more flexible templated version, // and renamed "swapWith" to be more consistent with the names used in other classes. JUCE_DEPRECATED_WITH_BODY (void swapWithArray (ReferenceCountedArray& other) noexcept, { swapWith (other); }) + #endif private: //============================================================================== ArrayAllocationBase data; int numUsed; + + static void releaseObject (ObjectClass* o) + { + if (o->decReferenceCountWithoutDeleting()) + ContainerDeletePolicy::destroy (o); + } }; diff --git a/source/modules/juce_core/containers/juce_SortedSet.h b/source/modules/juce_core/containers/juce_SortedSet.h index b7fa061d5..c07201ce6 100644 --- a/source/modules/juce_core/containers/juce_SortedSet.h +++ b/source/modules/juce_core/containers/juce_SortedSet.h @@ -29,15 +29,11 @@ #ifndef JUCE_SORTEDSET_H_INCLUDED #define JUCE_SORTEDSET_H_INCLUDED -#include "juce_ArrayAllocationBase.h" -#include "../threads/juce_CriticalSection.h" - #if JUCE_MSVC - #pragma warning (push) - #pragma warning (disable: 4512) + #pragma warning (push) + #pragma warning (disable: 4512) #endif - //============================================================================== /** Holds a set of unique primitive objects, such as ints or doubles. @@ -491,7 +487,7 @@ private: }; #if JUCE_MSVC - #pragma warning (pop) + #pragma warning (pop) #endif #endif // JUCE_SORTEDSET_H_INCLUDED diff --git a/source/modules/juce_core/containers/juce_SparseSet.h b/source/modules/juce_core/containers/juce_SparseSet.h index 5064ae0cc..b0019523e 100644 --- a/source/modules/juce_core/containers/juce_SparseSet.h +++ b/source/modules/juce_core/containers/juce_SparseSet.h @@ -29,9 +29,6 @@ #ifndef JUCE_SPARSESET_H_INCLUDED #define JUCE_SPARSESET_H_INCLUDED -#include "../maths/juce_Range.h" -#include "../threads/juce_CriticalSection.h" - //============================================================================== /** diff --git a/source/modules/juce_core/containers/juce_Variant.cpp b/source/modules/juce_core/containers/juce_Variant.cpp index a302d363d..9ae4ee013 100644 --- a/source/modules/juce_core/containers/juce_Variant.cpp +++ b/source/modules/juce_core/containers/juce_Variant.cpp @@ -678,12 +678,12 @@ var var::readFromStream (InputStream& input) case varMarker_Binary: { - MemoryBlock mb (numBytes - 1); + MemoryBlock mb ((size_t) numBytes - 1); if (numBytes > 1) { const int numRead = input.read (mb.getData(), numBytes - 1); - mb.setSize (numRead); + mb.setSize ((size_t) numRead); } return var (mb); diff --git a/source/modules/juce_core/containers/juce_Variant.h b/source/modules/juce_core/containers/juce_Variant.h index 92a75b9dc..2651c9506 100644 --- a/source/modules/juce_core/containers/juce_Variant.h +++ b/source/modules/juce_core/containers/juce_Variant.h @@ -29,15 +29,6 @@ #ifndef JUCE_VARIANT_H_INCLUDED #define JUCE_VARIANT_H_INCLUDED -#include "../text/juce_Identifier.h" -#include "../streams/juce_OutputStream.h" -#include "../streams/juce_InputStream.h" -#include "../containers/juce_Array.h" - -#ifndef DOXYGEN - class ReferenceCountedObject; - class DynamicObject; -#endif //============================================================================== /** diff --git a/source/modules/juce_core/files/juce_DirectoryIterator.cpp b/source/modules/juce_core/files/juce_DirectoryIterator.cpp index 7da018e1a..7d6dd4b13 100644 --- a/source/modules/juce_core/files/juce_DirectoryIterator.cpp +++ b/source/modules/juce_core/files/juce_DirectoryIterator.cpp @@ -109,8 +109,8 @@ bool DirectoryIterator::next (bool* const isDirResult, bool* const isHiddenResul matches = (whatToLookFor & File::findFiles) != 0; } - // if recursive, we're not relying on the OS iterator to do the wildcard match, so do it now.. - if (matches && isRecursive) + // if we're not relying on the OS iterator to do the wildcard match, do it now.. + if (matches && (isRecursive || wildCards.size() > 1)) matches = fileMatches (wildCards, filename); if (matches && (whatToLookFor & File::ignoreHiddenFiles) != 0) diff --git a/source/modules/juce_core/files/juce_DirectoryIterator.h b/source/modules/juce_core/files/juce_DirectoryIterator.h index fcc50569c..b297c5ebc 100644 --- a/source/modules/juce_core/files/juce_DirectoryIterator.h +++ b/source/modules/juce_core/files/juce_DirectoryIterator.h @@ -29,9 +29,6 @@ #ifndef JUCE_DIRECTORYITERATOR_H_INCLUDED #define JUCE_DIRECTORYITERATOR_H_INCLUDED -#include "juce_File.h" -#include "../memory/juce_ScopedPointer.h" - //============================================================================== /** @@ -135,13 +132,13 @@ private: private: friend class DirectoryIterator; - friend class ScopedPointer; + friend struct ContainerDeletePolicy; ScopedPointer pimpl; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (NativeIterator) }; - friend class ScopedPointer; + friend struct ContainerDeletePolicy; StringArray wildCards; NativeIterator fileFinder; String wildCard, path; @@ -150,7 +147,7 @@ private: const int whatToLookFor; const bool isRecursive; bool hasBeenAdvanced; - ScopedPointer subIterator; + ScopedPointer subIterator; File currentFile; static StringArray parseWildcards (const String& pattern); diff --git a/source/modules/juce_core/files/juce_File.cpp b/source/modules/juce_core/files/juce_File.cpp index 5c8a8352f..f93f880a0 100644 --- a/source/modules/juce_core/files/juce_File.cpp +++ b/source/modules/juce_core/files/juce_File.cpp @@ -665,7 +665,7 @@ FileInputStream* File::createInputStream() const return nullptr; } -FileOutputStream* File::createOutputStream (const int bufferSize) const +FileOutputStream* File::createOutputStream (const size_t bufferSize) const { ScopedPointer out (new FileOutputStream (*this, bufferSize)); diff --git a/source/modules/juce_core/files/juce_File.h b/source/modules/juce_core/files/juce_File.h index ad3cb19fb..6780e11d2 100644 --- a/source/modules/juce_core/files/juce_File.h +++ b/source/modules/juce_core/files/juce_File.h @@ -29,15 +29,6 @@ #ifndef JUCE_FILE_H_INCLUDED #define JUCE_FILE_H_INCLUDED -#include "../containers/juce_Array.h" -#include "../time/juce_Time.h" -#include "../text/juce_StringArray.h" -#include "../memory/juce_MemoryBlock.h" -#include "../memory/juce_ScopedPointer.h" -#include "../misc/juce_Result.h" -class FileInputStream; -class FileOutputStream; - //============================================================================== /** @@ -589,7 +580,7 @@ public: end of the file), or nullptr if the file can't be opened for some reason @see createInputStream, appendData, appendText */ - FileOutputStream* createOutputStream (int bufferSize = 0x8000) const; + FileOutputStream* createOutputStream (size_t bufferSize = 0x8000) const; //============================================================================== /** Loads a file's contents into memory as a block of binary data. @@ -771,6 +762,15 @@ public: /** The folder that contains the user's desktop objects. */ userDesktopDirectory, + /** The most likely place where a user might store their music files. */ + userMusicDirectory, + + /** The most likely place where a user might store their movie files. */ + userMoviesDirectory, + + /** The most likely place where a user might store their picture files. */ + userPicturesDirectory, + /** The folder in which applications store their persistent user-specific settings. On Windows, this might be "\Documents and Settings\username\Application Data". On the Mac, it might be "~/Library". If you're going to store your settings in here, @@ -788,6 +788,13 @@ public: */ commonApplicationDataDirectory, + /** A place to put documents which are shared by all users of the machine. + On Windows this may be somewhere like "C:\Users\Public\Documents", on OSX it + will be something like "/Users/Shared". Other OSes may have no such concept + though, so be careful. + */ + commonDocumentsDirectory, + /** The folder that should be used for temporary files. Always delete them when you're finished, to keep the user's computer tidy! */ @@ -830,16 +837,7 @@ public: So on windows, this would be something like "c:\program files", on the Mac "/Applications", or "/usr" on linux. */ - globalApplicationsDirectory, - - /** The most likely place where a user might store their music files. */ - userMusicDirectory, - - /** The most likely place where a user might store their movie files. */ - userMoviesDirectory, - - /** The most likely place where a user might store their picture files. */ - userPicturesDirectory + globalApplicationsDirectory }; /** Finds the location of a special type of file or directory, such as a home folder or diff --git a/source/modules/juce_core/files/juce_FileInputStream.h b/source/modules/juce_core/files/juce_FileInputStream.h index 6a452f71c..fd5a5c613 100644 --- a/source/modules/juce_core/files/juce_FileInputStream.h +++ b/source/modules/juce_core/files/juce_FileInputStream.h @@ -29,9 +29,6 @@ #ifndef JUCE_FILEINPUTSTREAM_H_INCLUDED #define JUCE_FILEINPUTSTREAM_H_INCLUDED -#include "juce_File.h" -#include "../streams/juce_InputStream.h" - //============================================================================== /** diff --git a/source/modules/juce_core/files/juce_FileOutputStream.cpp b/source/modules/juce_core/files/juce_FileOutputStream.cpp index fd14a4a9d..c4dd84aeb 100644 --- a/source/modules/juce_core/files/juce_FileOutputStream.cpp +++ b/source/modules/juce_core/files/juce_FileOutputStream.cpp @@ -29,14 +29,14 @@ int64 juce_fileSetPosition (void* handle, int64 pos); //============================================================================== -FileOutputStream::FileOutputStream (const File& f, const int bufferSize_) +FileOutputStream::FileOutputStream (const File& f, const size_t bufferSizeToUse) : file (f), fileHandle (nullptr), status (Result::ok()), currentPosition (0), - bufferSize (bufferSize_), + bufferSize (bufferSizeToUse), bytesInBuffer (0), - buffer ((size_t) jmax (bufferSize_, 16)) + buffer (jmax (bufferSizeToUse, (size_t) 16)) { openHandle(); } diff --git a/source/modules/juce_core/files/juce_FileOutputStream.h b/source/modules/juce_core/files/juce_FileOutputStream.h index 73ad20d49..f80705f23 100644 --- a/source/modules/juce_core/files/juce_FileOutputStream.h +++ b/source/modules/juce_core/files/juce_FileOutputStream.h @@ -29,9 +29,6 @@ #ifndef JUCE_FILEOUTPUTSTREAM_H_INCLUDED #define JUCE_FILEOUTPUTSTREAM_H_INCLUDED -#include "juce_File.h" -#include "../streams/juce_OutputStream.h" - //============================================================================== /** @@ -57,7 +54,7 @@ public: @see TemporaryFile */ FileOutputStream (const File& fileToWriteTo, - int bufferSizeToUse = 16384); + size_t bufferSizeToUse = 16384); /** Destructor. */ ~FileOutputStream(); diff --git a/source/modules/juce_core/files/juce_FileSearchPath.cpp b/source/modules/juce_core/files/juce_FileSearchPath.cpp index 053e92a1a..ce0af7eda 100644 --- a/source/modules/juce_core/files/juce_FileSearchPath.cpp +++ b/source/modules/juce_core/files/juce_FileSearchPath.cpp @@ -26,9 +26,8 @@ ============================================================================== */ -FileSearchPath::FileSearchPath() -{ -} +FileSearchPath::FileSearchPath() {} +FileSearchPath::~FileSearchPath() {} FileSearchPath::FileSearchPath (const String& path) { @@ -36,12 +35,14 @@ FileSearchPath::FileSearchPath (const String& path) } FileSearchPath::FileSearchPath (const FileSearchPath& other) - : directories (other.directories) + : directories (other.directories) { } -FileSearchPath::~FileSearchPath() +FileSearchPath& FileSearchPath::operator= (const FileSearchPath& other) { + directories = other.directories; + return *this; } FileSearchPath& FileSearchPath::operator= (const String& path) diff --git a/source/modules/juce_core/files/juce_FileSearchPath.h b/source/modules/juce_core/files/juce_FileSearchPath.h index a35f5aed4..fcd069310 100644 --- a/source/modules/juce_core/files/juce_FileSearchPath.h +++ b/source/modules/juce_core/files/juce_FileSearchPath.h @@ -29,13 +29,10 @@ #ifndef JUCE_FILESEARCHPATH_H_INCLUDED #define JUCE_FILESEARCHPATH_H_INCLUDED -#include "juce_File.h" -#include "../text/juce_StringArray.h" - //============================================================================== /** - Encapsulates a set of folders that make up a search path. + Represents a set of folders that make up a search path. @see File */ @@ -56,7 +53,10 @@ public: FileSearchPath (const String& path); /** Creates a copy of another search path. */ - FileSearchPath (const FileSearchPath& other); + FileSearchPath (const FileSearchPath&); + + /** Copies another search path. */ + FileSearchPath& operator= (const FileSearchPath&); /** Destructor. */ ~FileSearchPath(); @@ -70,15 +70,12 @@ public: //============================================================================== /** Returns the number of folders in this search path. - @see operator[] */ int getNumPaths() const; /** Returns one of the folders in this search path. - The file returned isn't guaranteed to actually be a valid directory. - @see getNumPaths */ File operator[] (int index) const; @@ -102,7 +99,6 @@ public: void remove (int indexToRemove); /** Merges another search path into this one. - This will remove any duplicate directories. */ void addPath (const FileSearchPath& other); @@ -161,7 +157,7 @@ private: //============================================================================== StringArray directories; - void init (const String& path); + void init (const String&); JUCE_LEAK_DETECTOR (FileSearchPath) }; diff --git a/source/modules/juce_core/files/juce_MemoryMappedFile.h b/source/modules/juce_core/files/juce_MemoryMappedFile.h index 943edb63d..8a79185f4 100644 --- a/source/modules/juce_core/files/juce_MemoryMappedFile.h +++ b/source/modules/juce_core/files/juce_MemoryMappedFile.h @@ -29,7 +29,6 @@ #ifndef JUCE_MEMORYMAPPEDFILE_H_INCLUDED #define JUCE_MEMORYMAPPEDFILE_H_INCLUDED -#include "juce_File.h" //============================================================================== /** diff --git a/source/modules/juce_core/files/juce_TemporaryFile.h b/source/modules/juce_core/files/juce_TemporaryFile.h index d33dc36a2..ef489039c 100644 --- a/source/modules/juce_core/files/juce_TemporaryFile.h +++ b/source/modules/juce_core/files/juce_TemporaryFile.h @@ -29,8 +29,6 @@ #ifndef JUCE_TEMPORARYFILE_H_INCLUDED #define JUCE_TEMPORARYFILE_H_INCLUDED -#include "juce_File.h" - //============================================================================== /** diff --git a/source/modules/juce_core/json/juce_JSON.cpp b/source/modules/juce_core/json/juce_JSON.cpp index b49a39ceb..319dba47a 100644 --- a/source/modules/juce_core/json/juce_JSON.cpp +++ b/source/modules/juce_core/json/juce_JSON.cpp @@ -316,7 +316,7 @@ private: buffer.appendUTF8Char (c); } - result = buffer.toString(); + result = buffer.toUTF8(); return Result::ok(); } }; @@ -526,7 +526,7 @@ String JSON::toString (const var& data, const bool allOnOneLine) { MemoryOutputStream mo (1024); JSONFormatter::write (mo, data, 0, allOnOneLine); - return mo.toString(); + return mo.toUTF8(); } void JSON::writeToStream (OutputStream& output, const var& data, const bool allOnOneLine) diff --git a/source/modules/juce_core/json/juce_JSON.h b/source/modules/juce_core/json/juce_JSON.h index a443c7a96..ad1ced86d 100644 --- a/source/modules/juce_core/json/juce_JSON.h +++ b/source/modules/juce_core/json/juce_JSON.h @@ -29,12 +29,6 @@ #ifndef JUCE_JSON_H_INCLUDED #define JUCE_JSON_H_INCLUDED -#include "../misc/juce_Result.h" -#include "../containers/juce_Variant.h" -class InputStream; -class OutputStream; -class File; - //============================================================================== /** diff --git a/source/modules/juce_core/juce_core.h b/source/modules/juce_core/juce_core.h index f7af33bbe..582700dac 100644 --- a/source/modules/juce_core/juce_core.h +++ b/source/modules/juce_core/juce_core.h @@ -125,6 +125,10 @@ //#define JUCE_CATCH_UNHANDLED_EXCEPTIONS 1 #endif +#ifndef JUCE_STRING_UTF_TYPE + #define JUCE_STRING_UTF_TYPE 8 +#endif + //============================================================================= //============================================================================= #if JUCE_MSVC @@ -141,108 +145,128 @@ namespace juce { -// START_AUTOINCLUDE containers, files, json, logging, maths, memory, misc, network, -// streams, system, text, threads, time, unit_tests, xml, zip -#include "containers/juce_AbstractFifo.h" -#include "containers/juce_Array.h" -#include "containers/juce_ArrayAllocationBase.h" -#include "containers/juce_DynamicObject.h" +class MemoryBlock; +class File; +class InputStream; +class OutputStream; +class DynamicObject; +class FileInputStream; +class FileOutputStream; +class XmlElement; +class JSONFormatter; + +extern JUCE_API bool JUCE_CALLTYPE juce_isRunningUnderDebugger(); +extern JUCE_API void JUCE_CALLTYPE logAssertion (const char* file, int line) noexcept; + +#include "memory/juce_Memory.h" +#include "maths/juce_MathsFunctions.h" +#include "memory/juce_ByteOrder.h" +#include "memory/juce_Atomic.h" +#include "text/juce_CharacterFunctions.h" + +#if JUCE_MSVC + #pragma warning (push) + #pragma warning (disable: 4514 4996) +#endif + +#include "text/juce_CharPointer_UTF8.h" +#include "text/juce_CharPointer_UTF16.h" +#include "text/juce_CharPointer_UTF32.h" +#include "text/juce_CharPointer_ASCII.h" + +#if JUCE_MSVC + #pragma warning (pop) +#endif + +#include "text/juce_String.h" +#include "logging/juce_Logger.h" +#include "memory/juce_LeakedObjectDetector.h" +#include "memory/juce_ContainerDeletePolicy.h" +#include "memory/juce_HeapBlock.h" +#include "memory/juce_MemoryBlock.h" +#include "memory/juce_ReferenceCountedObject.h" +#include "memory/juce_ScopedPointer.h" +#include "memory/juce_OptionalScopedPointer.h" +#include "memory/juce_Singleton.h" +#include "memory/juce_WeakReference.h" +#include "threads/juce_ScopedLock.h" +#include "threads/juce_CriticalSection.h" +#include "maths/juce_Range.h" #include "containers/juce_ElementComparator.h" -#include "containers/juce_HashMap.h" +#include "containers/juce_ArrayAllocationBase.h" +#include "containers/juce_Array.h" #include "containers/juce_LinkedListPointer.h" -#include "containers/juce_NamedValueSet.h" #include "containers/juce_OwnedArray.h" -#include "containers/juce_PropertySet.h" #include "containers/juce_ReferenceCountedArray.h" #include "containers/juce_ScopedValueSetter.h" #include "containers/juce_SortedSet.h" #include "containers/juce_SparseSet.h" +#include "containers/juce_AbstractFifo.h" +#include "text/juce_NewLine.h" +#include "text/juce_StringPool.h" +#include "text/juce_Identifier.h" +#include "text/juce_StringArray.h" +#include "text/juce_StringPairArray.h" +#include "text/juce_TextDiff.h" +#include "text/juce_LocalisedStrings.h" +#include "misc/juce_Result.h" #include "containers/juce_Variant.h" -#include "files/juce_DirectoryIterator.h" +#include "containers/juce_NamedValueSet.h" +#include "containers/juce_DynamicObject.h" +#include "containers/juce_HashMap.h" +#include "time/juce_RelativeTime.h" +#include "time/juce_Time.h" +#include "streams/juce_InputStream.h" +#include "streams/juce_OutputStream.h" +#include "streams/juce_BufferedInputStream.h" +#include "streams/juce_MemoryInputStream.h" +#include "streams/juce_MemoryOutputStream.h" +#include "streams/juce_SubregionStream.h" +#include "streams/juce_InputSource.h" #include "files/juce_File.h" +#include "files/juce_DirectoryIterator.h" #include "files/juce_FileInputStream.h" #include "files/juce_FileOutputStream.h" #include "files/juce_FileSearchPath.h" #include "files/juce_MemoryMappedFile.h" #include "files/juce_TemporaryFile.h" -#include "json/juce_JSON.h" +#include "streams/juce_FileInputSource.h" #include "logging/juce_FileLogger.h" -#include "logging/juce_Logger.h" +#include "json/juce_JSON.h" #include "maths/juce_BigInteger.h" #include "maths/juce_Expression.h" -#include "maths/juce_MathsFunctions.h" #include "maths/juce_Random.h" -#include "maths/juce_Range.h" -#include "memory/juce_Atomic.h" -#include "memory/juce_ByteOrder.h" -#include "memory/juce_HeapBlock.h" -#include "memory/juce_LeakedObjectDetector.h" -#include "memory/juce_Memory.h" -#include "memory/juce_MemoryBlock.h" -#include "memory/juce_OptionalScopedPointer.h" -#include "memory/juce_ReferenceCountedObject.h" -#include "memory/juce_ScopedPointer.h" -#include "memory/juce_Singleton.h" -#include "memory/juce_WeakReference.h" -#include "misc/juce_Result.h" #include "misc/juce_Uuid.h" #include "misc/juce_WindowsRegistry.h" -#include "network/juce_IPAddress.h" -#include "network/juce_MACAddress.h" -#include "network/juce_NamedPipe.h" -#include "network/juce_Socket.h" -#include "network/juce_URL.h" -#include "streams/juce_BufferedInputStream.h" -#include "streams/juce_FileInputSource.h" -#include "streams/juce_InputSource.h" -#include "streams/juce_InputStream.h" -#include "streams/juce_MemoryInputStream.h" -#include "streams/juce_MemoryOutputStream.h" -#include "streams/juce_OutputStream.h" -#include "streams/juce_SubregionStream.h" #include "system/juce_PlatformDefs.h" -#include "system/juce_StandardHeader.h" #include "system/juce_SystemStats.h" -#include "system/juce_TargetPlatform.h" -#include "text/juce_CharacterFunctions.h" -#include "text/juce_CharPointer_ASCII.h" -#include "text/juce_CharPointer_UTF16.h" -#include "text/juce_CharPointer_UTF32.h" -#include "text/juce_CharPointer_UTF8.h" -#include "text/juce_Identifier.h" -#include "text/juce_LocalisedStrings.h" -#include "text/juce_NewLine.h" -#include "text/juce_String.h" -#include "text/juce_StringArray.h" -#include "text/juce_StringPairArray.h" -#include "text/juce_StringPool.h" -#include "text/juce_TextDiff.h" #include "threads/juce_ChildProcess.h" -#include "threads/juce_CriticalSection.h" #include "threads/juce_DynamicLibrary.h" #include "threads/juce_HighResolutionTimer.h" #include "threads/juce_InterProcessLock.h" #include "threads/juce_Process.h" -#include "threads/juce_ReadWriteLock.h" -#include "threads/juce_ScopedLock.h" -#include "threads/juce_ScopedReadLock.h" -#include "threads/juce_ScopedWriteLock.h" #include "threads/juce_SpinLock.h" +#include "threads/juce_WaitableEvent.h" #include "threads/juce_Thread.h" #include "threads/juce_ThreadLocalValue.h" #include "threads/juce_ThreadPool.h" #include "threads/juce_TimeSliceThread.h" -#include "threads/juce_WaitableEvent.h" +#include "threads/juce_ReadWriteLock.h" +#include "threads/juce_ScopedReadLock.h" +#include "threads/juce_ScopedWriteLock.h" +#include "network/juce_IPAddress.h" +#include "network/juce_MACAddress.h" +#include "network/juce_NamedPipe.h" +#include "network/juce_Socket.h" +#include "network/juce_URL.h" #include "time/juce_PerformanceCounter.h" -#include "time/juce_RelativeTime.h" -#include "time/juce_Time.h" #include "unit_tests/juce_UnitTest.h" #include "xml/juce_XmlDocument.h" #include "xml/juce_XmlElement.h" #include "zip/juce_GZIPCompressorOutputStream.h" #include "zip/juce_GZIPDecompressorInputStream.h" #include "zip/juce_ZipFile.h" -// END_AUTOINCLUDE +#include "containers/juce_PropertySet.h" } diff --git a/source/modules/juce_core/logging/juce_FileLogger.h b/source/modules/juce_core/logging/juce_FileLogger.h index 87cb7cdfc..6be1668cb 100644 --- a/source/modules/juce_core/logging/juce_FileLogger.h +++ b/source/modules/juce_core/logging/juce_FileLogger.h @@ -29,10 +29,6 @@ #ifndef JUCE_FILELOGGER_H_INCLUDED #define JUCE_FILELOGGER_H_INCLUDED -#include "juce_Logger.h" -#include "../files/juce_File.h" -#include "../memory/juce_ScopedPointer.h" - //============================================================================== /** diff --git a/source/modules/juce_core/logging/juce_Logger.h b/source/modules/juce_core/logging/juce_Logger.h index 142ed338c..d0d3af57f 100644 --- a/source/modules/juce_core/logging/juce_Logger.h +++ b/source/modules/juce_core/logging/juce_Logger.h @@ -29,8 +29,6 @@ #ifndef JUCE_LOGGER_H_INCLUDED #define JUCE_LOGGER_H_INCLUDED -#include "../text/juce_String.h" - //============================================================================== /** diff --git a/source/modules/juce_core/maths/juce_BigInteger.cpp b/source/modules/juce_core/maths/juce_BigInteger.cpp index 398fbc354..0cfc5646b 100644 --- a/source/modules/juce_core/maths/juce_BigInteger.cpp +++ b/source/modules/juce_core/maths/juce_BigInteger.cpp @@ -956,7 +956,9 @@ String BigInteger::toString (const int base, const int minimumNumCharacters) con void BigInteger::parseString (const String& text, const int base) { clear(); - String::CharPointerType t (text.getCharPointer()); + String::CharPointerType t (text.getCharPointer().findEndOfWhitespace()); + + setNegative (*t == (juce_wchar) '-'); if (base == 2 || base == 8 || base == 16) { @@ -997,8 +999,6 @@ void BigInteger::parseString (const String& text, const int base) } } } - - setNegative (text.trimStart().startsWithChar ('-')); } MemoryBlock BigInteger::toMemoryBlock() const diff --git a/source/modules/juce_core/maths/juce_BigInteger.h b/source/modules/juce_core/maths/juce_BigInteger.h index abf48a224..e79182034 100644 --- a/source/modules/juce_core/maths/juce_BigInteger.h +++ b/source/modules/juce_core/maths/juce_BigInteger.h @@ -29,10 +29,6 @@ #ifndef JUCE_BIGINTEGER_H_INCLUDED #define JUCE_BIGINTEGER_H_INCLUDED -#include "../text/juce_String.h" -#include "../memory/juce_HeapBlock.h" -class MemoryBlock; - //============================================================================== /** diff --git a/source/modules/juce_core/maths/juce_Expression.h b/source/modules/juce_core/maths/juce_Expression.h index 3b08bef62..e6443c89a 100644 --- a/source/modules/juce_core/maths/juce_Expression.h +++ b/source/modules/juce_core/maths/juce_Expression.h @@ -29,10 +29,6 @@ #ifndef JUCE_EXPRESSION_H_INCLUDED #define JUCE_EXPRESSION_H_INCLUDED -#include "../memory/juce_ReferenceCountedObject.h" -#include "../containers/juce_Array.h" -#include "../memory/juce_ScopedPointer.h" - //============================================================================== /** @@ -264,7 +260,7 @@ private: struct Helpers; friend class Term; friend struct Helpers; - friend class ScopedPointer; + friend struct ContainerDeletePolicy; friend class ReferenceCountedObjectPtr; ReferenceCountedObjectPtr term; diff --git a/source/modules/juce_core/maths/juce_MathsFunctions.h b/source/modules/juce_core/maths/juce_MathsFunctions.h index 2e008170a..4c39ac8f0 100644 --- a/source/modules/juce_core/maths/juce_MathsFunctions.h +++ b/source/modules/juce_core/maths/juce_MathsFunctions.h @@ -443,6 +443,13 @@ IntegerType negativeAwareModulo (IntegerType dividend, const IntegerType divisor return (dividend < 0) ? (dividend + divisor) : dividend; } +/** Returns the square of its argument. */ +template +NumericType square (NumericType n) noexcept +{ + return n * n; +} + //============================================================================== #if (JUCE_INTEL && JUCE_32BIT) || defined (DOXYGEN) /** This macro can be applied to a float variable to check whether it contains a denormalised diff --git a/source/modules/juce_core/maths/juce_Random.h b/source/modules/juce_core/maths/juce_Random.h index 67d6a59cd..060b08472 100644 --- a/source/modules/juce_core/maths/juce_Random.h +++ b/source/modules/juce_core/maths/juce_Random.h @@ -29,8 +29,6 @@ #ifndef JUCE_RANDOM_H_INCLUDED #define JUCE_RANDOM_H_INCLUDED -#include "juce_BigInteger.h" - //============================================================================== /** diff --git a/source/modules/juce_core/memory/juce_ByteOrder.h b/source/modules/juce_core/memory/juce_ByteOrder.h index fedbeac7b..4d3ba0e89 100644 --- a/source/modules/juce_core/memory/juce_ByteOrder.h +++ b/source/modules/juce_core/memory/juce_ByteOrder.h @@ -39,65 +39,71 @@ class JUCE_API ByteOrder public: //============================================================================== /** Swaps the upper and lower bytes of a 16-bit integer. */ - static uint16 swap (uint16 value); + static uint16 swap (uint16 value) noexcept; /** Reverses the order of the 4 bytes in a 32-bit integer. */ - static uint32 swap (uint32 value); + static uint32 swap (uint32 value) noexcept; /** Reverses the order of the 8 bytes in a 64-bit integer. */ - static uint64 swap (uint64 value); + static uint64 swap (uint64 value) noexcept; //============================================================================== /** Swaps the byte order of a 16-bit int if the CPU is big-endian */ - static uint16 swapIfBigEndian (uint16 value); + static uint16 swapIfBigEndian (uint16 value) noexcept; /** Swaps the byte order of a 32-bit int if the CPU is big-endian */ - static uint32 swapIfBigEndian (uint32 value); + static uint32 swapIfBigEndian (uint32 value) noexcept; /** Swaps the byte order of a 64-bit int if the CPU is big-endian */ - static uint64 swapIfBigEndian (uint64 value); + static uint64 swapIfBigEndian (uint64 value) noexcept; /** Swaps the byte order of a 16-bit int if the CPU is little-endian */ - static uint16 swapIfLittleEndian (uint16 value); + static uint16 swapIfLittleEndian (uint16 value) noexcept; /** Swaps the byte order of a 32-bit int if the CPU is little-endian */ - static uint32 swapIfLittleEndian (uint32 value); + static uint32 swapIfLittleEndian (uint32 value) noexcept; /** Swaps the byte order of a 64-bit int if the CPU is little-endian */ - static uint64 swapIfLittleEndian (uint64 value); + static uint64 swapIfLittleEndian (uint64 value) noexcept; //============================================================================== /** Turns 4 bytes into a little-endian integer. */ - static uint32 littleEndianInt (const void* bytes); + static uint32 littleEndianInt (const void* bytes) noexcept; + + /** Turns 8 bytes into a little-endian integer. */ + static uint64 littleEndianInt64 (const void* bytes) noexcept; /** Turns 2 bytes into a little-endian integer. */ - static uint16 littleEndianShort (const void* bytes); + static uint16 littleEndianShort (const void* bytes) noexcept; /** Turns 4 bytes into a big-endian integer. */ - static uint32 bigEndianInt (const void* bytes); + static uint32 bigEndianInt (const void* bytes) noexcept; + + /** Turns 8 bytes into a big-endian integer. */ + static uint64 bigEndianInt64 (const void* bytes) noexcept; /** Turns 2 bytes into a big-endian integer. */ - static uint16 bigEndianShort (const void* bytes); + static uint16 bigEndianShort (const void* bytes) noexcept; //============================================================================== /** Converts 3 little-endian bytes into a signed 24-bit value (which is sign-extended to 32 bits). */ - static int littleEndian24Bit (const char* bytes); + static int littleEndian24Bit (const char* bytes) noexcept; /** Converts 3 big-endian bytes into a signed 24-bit value (which is sign-extended to 32 bits). */ - static int bigEndian24Bit (const char* bytes); + static int bigEndian24Bit (const char* bytes) noexcept; /** Copies a 24-bit number to 3 little-endian bytes. */ - static void littleEndian24BitToChars (int value, char* destBytes); + static void littleEndian24BitToChars (int value, char* destBytes) noexcept; /** Copies a 24-bit number to 3 big-endian bytes. */ - static void bigEndian24BitToChars (int value, char* destBytes); + static void bigEndian24BitToChars (int value, char* destBytes) noexcept; //============================================================================== /** Returns true if the current CPU is big-endian. */ - static bool isBigEndian(); + static bool isBigEndian() noexcept; private: - ByteOrder(); + ByteOrder() JUCE_DELETED_FUNCTION; JUCE_DECLARE_NON_COPYABLE (ByteOrder) }; @@ -108,7 +114,7 @@ private: #pragma intrinsic (_byteswap_ulong) #endif -inline uint16 ByteOrder::swap (uint16 n) +inline uint16 ByteOrder::swap (uint16 n) noexcept { #if JUCE_USE_INTRINSICSxxx // agh - the MS compiler has an internal error when you try to use this intrinsic! return static_cast (_byteswap_ushort (n)); @@ -117,7 +123,7 @@ inline uint16 ByteOrder::swap (uint16 n) #endif } -inline uint32 ByteOrder::swap (uint32 n) +inline uint32 ByteOrder::swap (uint32 n) noexcept { #if JUCE_MAC || JUCE_IOS return OSSwapInt32 (n); @@ -140,7 +146,7 @@ inline uint32 ByteOrder::swap (uint32 n) #endif } -inline uint64 ByteOrder::swap (uint64 value) +inline uint64 ByteOrder::swap (uint64 value) noexcept { #if JUCE_MAC || JUCE_IOS return OSSwapInt64 (value); @@ -152,35 +158,39 @@ inline uint64 ByteOrder::swap (uint64 value) } #if JUCE_LITTLE_ENDIAN - inline uint16 ByteOrder::swapIfBigEndian (const uint16 v) { return v; } - inline uint32 ByteOrder::swapIfBigEndian (const uint32 v) { return v; } - inline uint64 ByteOrder::swapIfBigEndian (const uint64 v) { return v; } - inline uint16 ByteOrder::swapIfLittleEndian (const uint16 v) { return swap (v); } - inline uint32 ByteOrder::swapIfLittleEndian (const uint32 v) { return swap (v); } - inline uint64 ByteOrder::swapIfLittleEndian (const uint64 v) { return swap (v); } - inline uint32 ByteOrder::littleEndianInt (const void* const bytes) { return *static_cast (bytes); } - inline uint16 ByteOrder::littleEndianShort (const void* const bytes) { return *static_cast (bytes); } - inline uint32 ByteOrder::bigEndianInt (const void* const bytes) { return swap (*static_cast (bytes)); } - inline uint16 ByteOrder::bigEndianShort (const void* const bytes) { return swap (*static_cast (bytes)); } - inline bool ByteOrder::isBigEndian() { return false; } + inline uint16 ByteOrder::swapIfBigEndian (const uint16 v) noexcept { return v; } + inline uint32 ByteOrder::swapIfBigEndian (const uint32 v) noexcept { return v; } + inline uint64 ByteOrder::swapIfBigEndian (const uint64 v) noexcept { return v; } + inline uint16 ByteOrder::swapIfLittleEndian (const uint16 v) noexcept { return swap (v); } + inline uint32 ByteOrder::swapIfLittleEndian (const uint32 v) noexcept { return swap (v); } + inline uint64 ByteOrder::swapIfLittleEndian (const uint64 v) noexcept { return swap (v); } + inline uint32 ByteOrder::littleEndianInt (const void* const bytes) noexcept { return *static_cast (bytes); } + inline uint64 ByteOrder::littleEndianInt64 (const void* const bytes) noexcept { return *static_cast (bytes); } + inline uint16 ByteOrder::littleEndianShort (const void* const bytes) noexcept { return *static_cast (bytes); } + inline uint32 ByteOrder::bigEndianInt (const void* const bytes) noexcept { return swap (*static_cast (bytes)); } + inline uint64 ByteOrder::bigEndianInt64 (const void* const bytes) noexcept { return swap (*static_cast (bytes)); } + inline uint16 ByteOrder::bigEndianShort (const void* const bytes) noexcept { return swap (*static_cast (bytes)); } + inline bool ByteOrder::isBigEndian() noexcept { return false; } #else - inline uint16 ByteOrder::swapIfBigEndian (const uint16 v) { return swap (v); } - inline uint32 ByteOrder::swapIfBigEndian (const uint32 v) { return swap (v); } - inline uint64 ByteOrder::swapIfBigEndian (const uint64 v) { return swap (v); } - inline uint16 ByteOrder::swapIfLittleEndian (const uint16 v) { return v; } - inline uint32 ByteOrder::swapIfLittleEndian (const uint32 v) { return v; } - inline uint64 ByteOrder::swapIfLittleEndian (const uint64 v) { return v; } - inline uint32 ByteOrder::littleEndianInt (const void* const bytes) { return swap (*static_cast (bytes)); } - inline uint16 ByteOrder::littleEndianShort (const void* const bytes) { return swap (*static_cast (bytes)); } - inline uint32 ByteOrder::bigEndianInt (const void* const bytes) { return *static_cast (bytes); } - inline uint16 ByteOrder::bigEndianShort (const void* const bytes) { return *static_cast (bytes); } - inline bool ByteOrder::isBigEndian() { return true; } + inline uint16 ByteOrder::swapIfBigEndian (const uint16 v) noexcept { return swap (v); } + inline uint32 ByteOrder::swapIfBigEndian (const uint32 v) noexcept { return swap (v); } + inline uint64 ByteOrder::swapIfBigEndian (const uint64 v) noexcept { return swap (v); } + inline uint16 ByteOrder::swapIfLittleEndian (const uint16 v) noexcept { return v; } + inline uint32 ByteOrder::swapIfLittleEndian (const uint32 v) noexcept { return v; } + inline uint64 ByteOrder::swapIfLittleEndian (const uint64 v) noexcept { return v; } + inline uint32 ByteOrder::littleEndianInt (const void* const bytes) noexcept { return swap (*static_cast (bytes)); } + inline uint64 ByteOrder::littleEndianInt64 (const void* const bytes) noexcept { return swap (*static_cast (bytes)); } + inline uint16 ByteOrder::littleEndianShort (const void* const bytes) noexcept { return swap (*static_cast (bytes)); } + inline uint32 ByteOrder::bigEndianInt (const void* const bytes) noexcept { return *static_cast (bytes); } + inline uint64 ByteOrder::bigEndianInt64 (const void* const bytes) noexcept { return *static_cast (bytes); } + inline uint16 ByteOrder::bigEndianShort (const void* const bytes) noexcept { return *static_cast (bytes); } + inline bool ByteOrder::isBigEndian() noexcept { return true; } #endif -inline int ByteOrder::littleEndian24Bit (const char* const bytes) { return (((int) bytes[2]) << 16) | (((int) (uint8) bytes[1]) << 8) | ((int) (uint8) bytes[0]); } -inline int ByteOrder::bigEndian24Bit (const char* const bytes) { return (((int) bytes[0]) << 16) | (((int) (uint8) bytes[1]) << 8) | ((int) (uint8) bytes[2]); } -inline void ByteOrder::littleEndian24BitToChars (const int value, char* const destBytes) { destBytes[0] = (char)(value & 0xff); destBytes[1] = (char)((value >> 8) & 0xff); destBytes[2] = (char)((value >> 16) & 0xff); } -inline void ByteOrder::bigEndian24BitToChars (const int value, char* const destBytes) { destBytes[0] = (char)((value >> 16) & 0xff); destBytes[1] = (char)((value >> 8) & 0xff); destBytes[2] = (char)(value & 0xff); } +inline int ByteOrder::littleEndian24Bit (const char* const bytes) noexcept { return (((int) bytes[2]) << 16) | (((int) (uint8) bytes[1]) << 8) | ((int) (uint8) bytes[0]); } +inline int ByteOrder::bigEndian24Bit (const char* const bytes) noexcept { return (((int) bytes[0]) << 16) | (((int) (uint8) bytes[1]) << 8) | ((int) (uint8) bytes[2]); } +inline void ByteOrder::littleEndian24BitToChars (const int value, char* const destBytes) noexcept { destBytes[0] = (char)(value & 0xff); destBytes[1] = (char)((value >> 8) & 0xff); destBytes[2] = (char)((value >> 16) & 0xff); } +inline void ByteOrder::bigEndian24BitToChars (const int value, char* const destBytes) noexcept { destBytes[0] = (char)((value >> 16) & 0xff); destBytes[1] = (char)((value >> 8) & 0xff); destBytes[2] = (char)(value & 0xff); } #endif // JUCE_BYTEORDER_H_INCLUDED diff --git a/source/modules/juce_core/memory/juce_ContainerDeletePolicy.h b/source/modules/juce_core/memory/juce_ContainerDeletePolicy.h new file mode 100644 index 000000000..60cddaa75 --- /dev/null +++ b/source/modules/juce_core/memory/juce_ContainerDeletePolicy.h @@ -0,0 +1,53 @@ +/* + ============================================================================== + + This file is part of the juce_core module of the JUCE library. + Copyright (c) 2013 - Raw Material Software Ltd. + + Permission to use, copy, modify, and/or distribute this software for any purpose with + or without fee is hereby granted, provided that the above copyright notice and this + permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD + TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN + NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER + IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + ------------------------------------------------------------------------------ + + NOTE! This permissive ISC license applies ONLY to files within the juce_core module! + All other JUCE modules are covered by a dual GPL/commercial license, so if you are + using any other modules, be sure to check that you also comply with their license. + + For more details, visit www.juce.com + + ============================================================================== +*/ + +#ifndef JUCE_CONTAINERDELETEPOLICY_H_INCLUDED +#define JUCE_CONTAINERDELETEPOLICY_H_INCLUDED + +//============================================================================== +/** + Used by container classes as an indirect way to delete an object of a + particular type. + + The generic implementation of this class simply calls 'delete', but you can + 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 +*/ +template +struct ContainerDeletePolicy +{ + static void destroy (ObjectType* object) + { + delete object; + } +}; + + +#endif // JUCE_CONTAINERDELETEPOLICY_H_INCLUDED diff --git a/source/modules/juce_core/memory/juce_LeakedObjectDetector.h b/source/modules/juce_core/memory/juce_LeakedObjectDetector.h index 56e4a670c..248e7bcfb 100644 --- a/source/modules/juce_core/memory/juce_LeakedObjectDetector.h +++ b/source/modules/juce_core/memory/juce_LeakedObjectDetector.h @@ -29,9 +29,6 @@ #ifndef JUCE_LEAKEDOBJECTDETECTOR_H_INCLUDED #define JUCE_LEAKEDOBJECTDETECTOR_H_INCLUDED -#include "../text/juce_String.h" -#include "juce_Atomic.h" - //============================================================================== /** diff --git a/source/modules/juce_core/memory/juce_MemoryBlock.cpp b/source/modules/juce_core/memory/juce_MemoryBlock.cpp index 29f930798..16438f6de 100644 --- a/source/modules/juce_core/memory/juce_MemoryBlock.cpp +++ b/source/modules/juce_core/memory/juce_MemoryBlock.cpp @@ -88,14 +88,14 @@ MemoryBlock& MemoryBlock::operator= (const MemoryBlock& other) #if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS MemoryBlock::MemoryBlock (MemoryBlock&& other) noexcept - : data (static_cast &&> (other.data)), + : data (static_cast &&> (other.data)), size (other.size) { } MemoryBlock& MemoryBlock::operator= (MemoryBlock&& other) noexcept { - data = static_cast &&> (other.data); + data = static_cast &&> (other.data); size = other.size; return *this; } @@ -229,12 +229,12 @@ void MemoryBlock::copyFrom (const void* const src, int offset, size_t num) noexc if (offset < 0) { d -= offset; - num -= offset; + num += (size_t) -offset; offset = 0; } - if (offset + num > size) - num = size - offset; + if ((size_t) offset + num > size) + num = size - (size_t) offset; if (num > 0) memcpy (data + offset, d, num); @@ -248,14 +248,13 @@ void MemoryBlock::copyTo (void* const dst, int offset, size_t num) const noexcep { zeromem (d, (size_t) -offset); d -= offset; - - num += offset; + num -= (size_t) -offset; offset = 0; } - if (offset + num > size) + if ((size_t) offset + num > size) { - const size_t newNum = size - offset; + const size_t newNum = size - (size_t) offset; zeromem (d + newNum, num - newNum); num = newNum; } @@ -275,12 +274,12 @@ int MemoryBlock::getBitRange (const size_t bitRangeStart, size_t numBits) const int res = 0; size_t byte = bitRangeStart >> 3; - int offsetInByte = (int) bitRangeStart & 7; + size_t offsetInByte = bitRangeStart & 7; size_t bitsSoFar = 0; while (numBits > 0 && (size_t) byte < size) { - const int bitsThisTime = jmin ((int) numBits, 8 - offsetInByte); + const size_t bitsThisTime = jmin (numBits, 8 - offsetInByte); const int mask = (0xff >> (8 - bitsThisTime)) << offsetInByte; res |= (((data[byte] & mask) >> offsetInByte) << bitsSoFar); @@ -297,17 +296,17 @@ int MemoryBlock::getBitRange (const size_t bitRangeStart, size_t numBits) const void MemoryBlock::setBitRange (const size_t bitRangeStart, size_t numBits, int bitsToSet) noexcept { size_t byte = bitRangeStart >> 3; - int offsetInByte = (int) bitRangeStart & 7; - unsigned int mask = ~((((unsigned int) 0xffffffff) << (32 - numBits)) >> (32 - numBits)); + size_t offsetInByte = bitRangeStart & 7; + uint32 mask = ~((((uint32) 0xffffffff) << (32 - numBits)) >> (32 - numBits)); while (numBits > 0 && (size_t) byte < size) { - const int bitsThisTime = jmin ((int) numBits, 8 - offsetInByte); + const size_t bitsThisTime = jmin (numBits, 8 - offsetInByte); - const unsigned int tempMask = (mask << offsetInByte) | ~((((unsigned int) 0xffffffff) >> offsetInByte) << offsetInByte); - const unsigned int tempBits = (unsigned int) bitsToSet << offsetInByte; + const uint32 tempMask = (mask << offsetInByte) | ~((((uint32) 0xffffffff) >> offsetInByte) << offsetInByte); + const uint32 tempBits = (uint32) bitsToSet << offsetInByte; - data[byte] = (char) ((data[byte] & tempMask) | tempBits); + data[byte] = (char) (((uint32) data[byte] & tempMask) | tempBits); ++byte; numBits -= bitsThisTime; @@ -336,22 +335,11 @@ void MemoryBlock::loadFromHexString (const String& hex) { const juce_wchar c = t.getAndAdvance(); - if (c >= '0' && c <= '9') - { - byte |= c - '0'; - break; - } - else if (c >= 'a' && c <= 'z') - { - byte |= c - ('a' - 10); - break; - } - else if (c >= 'A' && c <= 'Z') - { - byte |= c - ('A' - 10); - break; - } - else if (c == 0) + if (c >= '0' && c <= '9') { byte |= c - '0'; break; } + if (c >= 'a' && c <= 'z') { byte |= c - ('a' - 10); break; } + if (c >= 'A' && c <= 'Z') { byte |= c - ('A' - 10); break; } + + if (c == 0) { setSize (static_cast (dest - data)); return; @@ -364,7 +352,7 @@ void MemoryBlock::loadFromHexString (const String& hex) } //============================================================================== -const char* const MemoryBlock::encodingTable = ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+"; +static const char* const base64EncodingTable = ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+"; String MemoryBlock::toBase64Encoding() const { @@ -372,14 +360,14 @@ String MemoryBlock::toBase64Encoding() const String destString ((unsigned int) size); // store the length, followed by a '.', and then the data. const int initialLen = destString.length(); - destString.preallocateBytes (sizeof (String::CharPointerType::CharType) * (size_t) (initialLen + 2 + numChars)); + destString.preallocateBytes (sizeof (String::CharPointerType::CharType) * (size_t) initialLen + 2 + numChars); String::CharPointerType d (destString.getCharPointer()); d += initialLen; d.write ('.'); for (size_t i = 0; i < numChars; ++i) - d.write ((juce_wchar) (uint8) encodingTable [getBitRange (i * 6, 6)]); + d.write ((juce_wchar) (uint8) base64EncodingTable [getBitRange (i * 6, 6)]); d.writeNull(); return destString; @@ -408,7 +396,7 @@ bool MemoryBlock::fromBase64Encoding (const String& s) for (int j = 0; j < 64; ++j) { - if (encodingTable[j] == c) + if (base64EncodingTable[j] == c) { setBitRange ((size_t) pos, 6, j); pos += 6; diff --git a/source/modules/juce_core/memory/juce_MemoryBlock.h b/source/modules/juce_core/memory/juce_MemoryBlock.h index b5adcab94..62eeec9fd 100644 --- a/source/modules/juce_core/memory/juce_MemoryBlock.h +++ b/source/modules/juce_core/memory/juce_MemoryBlock.h @@ -29,9 +29,6 @@ #ifndef JUCE_MEMORYBLOCK_H_INCLUDED #define JUCE_MEMORYBLOCK_H_INCLUDED -#include "../text/juce_String.h" -#include "../memory/juce_HeapBlock.h" - //============================================================================== /** @@ -54,7 +51,7 @@ public: bool initialiseToZero = false); /** Creates a copy of another memory block. */ - MemoryBlock (const MemoryBlock& other); + MemoryBlock (const MemoryBlock&); /** Creates a memory block using a copy of a block of data. @@ -67,31 +64,27 @@ public: ~MemoryBlock() noexcept; /** Copies another memory block onto this one. - This block will be resized and copied to exactly match the other one. */ - MemoryBlock& operator= (const MemoryBlock& other); + MemoryBlock& operator= (const MemoryBlock&); #if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS - MemoryBlock (MemoryBlock&& other) noexcept; - MemoryBlock& operator= (MemoryBlock&& other) noexcept; + MemoryBlock (MemoryBlock&&) noexcept; + MemoryBlock& operator= (MemoryBlock&&) noexcept; #endif //============================================================================== /** Compares two memory blocks. - @returns true only if the two blocks are the same size and have identical contents. */ bool operator== (const MemoryBlock& other) const noexcept; /** Compares two memory blocks. - @returns true if the two blocks are different sizes or have different contents. */ bool operator!= (const MemoryBlock& other) const noexcept; - /** Returns true if the data in this MemoryBlock matches the raw bytes passed-in. - */ + /** Returns true if the data in this MemoryBlock matches the raw bytes passed-in. */ bool matches (const void* data, size_t dataSize) const noexcept; //============================================================================== @@ -103,7 +96,6 @@ public: 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 @@ -143,7 +135,6 @@ public: //============================================================================== /** Fills the entire memory block with a repeated byte value. - This is handy for clearing a block of memory to zero. */ void fillWith (uint8 valueToUse) noexcept; @@ -249,9 +240,8 @@ public: private: //============================================================================== - HeapBlock data; + HeapBlock data; size_t size; - static const char* const encodingTable; JUCE_LEAK_DETECTOR (MemoryBlock) }; diff --git a/source/modules/juce_core/memory/juce_OptionalScopedPointer.h b/source/modules/juce_core/memory/juce_OptionalScopedPointer.h index cc5531ea0..a633dca1b 100644 --- a/source/modules/juce_core/memory/juce_OptionalScopedPointer.h +++ b/source/modules/juce_core/memory/juce_OptionalScopedPointer.h @@ -29,8 +29,6 @@ #ifndef JUCE_OPTIONALSCOPEDPOINTER_H_INCLUDED #define JUCE_OPTIONALSCOPEDPOINTER_H_INCLUDED -#include "juce_ScopedPointer.h" - //============================================================================== /** diff --git a/source/modules/juce_core/memory/juce_ReferenceCountedObject.h b/source/modules/juce_core/memory/juce_ReferenceCountedObject.h index 751a45fee..4243f4aa0 100644 --- a/source/modules/juce_core/memory/juce_ReferenceCountedObject.h +++ b/source/modules/juce_core/memory/juce_ReferenceCountedObject.h @@ -29,12 +29,10 @@ #ifndef JUCE_REFERENCECOUNTEDOBJECT_H_INCLUDED #define JUCE_REFERENCECOUNTEDOBJECT_H_INCLUDED -#include "juce_Atomic.h" - //============================================================================== /** - Adds reference-counting to an object. + A base class which provides methods for reference-counting. To add reference-counting to a class, derive it from this class, and use the ReferenceCountedObjectPtr class to point to it. @@ -73,16 +71,15 @@ public: This is done automatically by the smart pointer, but is public just in case it's needed for nefarious purposes. */ - inline void incReferenceCount() noexcept + void incReferenceCount() noexcept { ++refCount; } /** Decreases the object's reference count. - If the count gets to zero, the object will be deleted. */ - inline void decReferenceCount() noexcept + void decReferenceCount() noexcept { jassert (getReferenceCount() > 0); @@ -90,16 +87,24 @@ public: delete this; } + /** Decreases the object's reference count. + If the count gets to zero, the object will not be deleted, but this method + will return true, allowing the caller to take care of deletion. + */ + bool decReferenceCountWithoutDeleting() noexcept + { + jassert (getReferenceCount() > 0); + return --refCount == 0; + } + /** Returns the object's current reference count. */ - inline int getReferenceCount() const noexcept { return refCount.get(); } + int getReferenceCount() const noexcept { return refCount.get(); } protected: //============================================================================== /** Creates the reference-counted object (with an initial ref count of zero). */ - ReferenceCountedObject() - { - } + ReferenceCountedObject() {} /** Destructor. */ virtual ~ReferenceCountedObject() @@ -120,6 +125,7 @@ private: //============================================================================== Atomic refCount; + friend struct ContainerDeletePolicy; JUCE_DECLARE_NON_COPYABLE (ReferenceCountedObject) }; @@ -144,16 +150,15 @@ public: This is done automatically by the smart pointer, but is public just in case it's needed for nefarious purposes. */ - inline void incReferenceCount() noexcept + void incReferenceCount() noexcept { ++refCount; } /** Decreases the object's reference count. - If the count gets to zero, the object will be deleted. */ - inline void decReferenceCount() noexcept + void decReferenceCount() noexcept { jassert (getReferenceCount() > 0); @@ -161,8 +166,18 @@ public: delete this; } + /** Decreases the object's reference count. + If the count gets to zero, the object will not be deleted, but this method + will return true, allowing the caller to take care of deletion. + */ + bool decReferenceCountWithoutDeleting() noexcept + { + jassert (getReferenceCount() > 0); + return --refCount == 0; + } + /** Returns the object's current reference count. */ - inline int getReferenceCount() const noexcept { return refCount; } + int getReferenceCount() const noexcept { return refCount; } protected: @@ -181,6 +196,7 @@ private: //============================================================================== int refCount; + friend struct ContainerDeletePolicy; JUCE_DECLARE_NON_COPYABLE (SingleThreadedReferenceCountedObject) }; @@ -190,13 +206,20 @@ private: A smart-pointer class which points to a reference-counted object. The template parameter specifies the class of the object you want to point to - the easiest - way to make a class reference-countable is to simply make it inherit from ReferenceCountedObject, - but if you need to, you could roll your own reference-countable class by implementing a pair of - mathods called incReferenceCount() and decReferenceCount(). + way to make a class reference-countable is to simply make it inherit from ReferenceCountedObject + or SingleThreadedReferenceCountedObject, but if you need to, you can roll your own reference-countable + class by implementing a set of mathods called incReferenceCount(), decReferenceCount(), and + decReferenceCountWithoutDeleting(). See ReferenceCountedObject for examples of how these methods + should behave. When using this class, you'll probably want to create a typedef to abbreviate the full templated name - e.g. - @code typedef ReferenceCountedObjectPtr MyClassPtr;@endcode + @code + struct MyClass : public ReferenceCountedObject + { + typedef ReferenceCountedObjectPtr Ptr; + ... + @endcode @see ReferenceCountedObject, ReferenceCountedObjectArray */ @@ -209,54 +232,40 @@ public: //============================================================================== /** Creates a pointer to a null object. */ - inline ReferenceCountedObjectPtr() noexcept + ReferenceCountedObjectPtr() noexcept : referencedObject (nullptr) { } /** Creates a pointer to an object. - - This will increment the object's reference-count if it is non-null. + This will increment the object's reference-count. */ - inline ReferenceCountedObjectPtr (ReferenceCountedObjectClass* const refCountedObject) noexcept + ReferenceCountedObjectPtr (ReferencedType* refCountedObject) noexcept : referencedObject (refCountedObject) { - if (refCountedObject != nullptr) - refCountedObject->incReferenceCount(); + incIfNotNull (refCountedObject); } /** Copies another pointer. - This will increment the object's reference-count (if it is non-null). + This will increment the object's reference-count. */ - inline ReferenceCountedObjectPtr (const ReferenceCountedObjectPtr& other) noexcept - : referencedObject (other.referencedObject) - { - if (referencedObject != nullptr) - referencedObject->incReferenceCount(); - } - - #if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS - /** Takes-over the object from another pointer. */ - inline ReferenceCountedObjectPtr (ReferenceCountedObjectPtr&& other) noexcept + ReferenceCountedObjectPtr (const ReferenceCountedObjectPtr& other) noexcept : referencedObject (other.referencedObject) { - other.referencedObject = nullptr; + incIfNotNull (referencedObject); } - #endif /** Copies another pointer. This will increment the object's reference-count (if it is non-null). */ - template - inline ReferenceCountedObjectPtr (const ReferenceCountedObjectPtr& other) noexcept - : referencedObject (static_cast (other.get())) + template + ReferenceCountedObjectPtr (const ReferenceCountedObjectPtr& other) noexcept + : referencedObject (static_cast (other.get())) { - if (referencedObject != nullptr) - referencedObject->incReferenceCount(); + incIfNotNull (referencedObject); } /** Changes this pointer to point at a different object. - The reference count of the old object is decremented, and it might be deleted if it hits zero. The new object's count is incremented. */ @@ -266,94 +275,100 @@ public: } /** Changes this pointer to point at a different object. - The reference count of the old object is decremented, and it might be deleted if it hits zero. The new object's count is incremented. */ - template - ReferenceCountedObjectPtr& operator= (const ReferenceCountedObjectPtr& other) + template + ReferenceCountedObjectPtr& operator= (const ReferenceCountedObjectPtr& other) { - return operator= (static_cast (other.get())); + return operator= (static_cast (other.get())); } - #if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS - /** Takes-over the object from another pointer. */ - ReferenceCountedObjectPtr& operator= (ReferenceCountedObjectPtr&& other) - { - std::swap (referencedObject, other.referencedObject); - return *this; - } - #endif - /** Changes this pointer to point at a different object. The reference count of the old object is decremented, and it might be deleted if it hits zero. The new object's count is incremented. */ - ReferenceCountedObjectPtr& operator= (ReferenceCountedObjectClass* const newObject) + ReferenceCountedObjectPtr& operator= (ReferencedType* const newObject) { if (referencedObject != newObject) { - if (newObject != nullptr) - newObject->incReferenceCount(); - - ReferenceCountedObjectClass* const oldObject = referencedObject; + incIfNotNull (newObject); + ReferencedType* const oldObject = referencedObject; referencedObject = newObject; - - if (oldObject != nullptr) - oldObject->decReferenceCount(); + decIfNotNull (oldObject); } return *this; } - /** Destructor. - - This will decrement the object's reference-count, and may delete it if it - gets to zero. - */ - inline ~ReferenceCountedObjectPtr() + #if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS + /** Takes-over the object from another pointer. */ + ReferenceCountedObjectPtr (ReferenceCountedObjectPtr&& other) noexcept + : referencedObject (other.referencedObject) { - if (referencedObject != nullptr) - referencedObject->decReferenceCount(); + other.referencedObject = nullptr; } - /** Returns the object that this pointer references. - The pointer returned may be zero, of course. - */ - inline operator ReferenceCountedObjectClass*() const noexcept + /** Takes-over the object from another pointer. */ + ReferenceCountedObjectPtr& operator= (ReferenceCountedObjectPtr&& other) { - return referencedObject; + std::swap (referencedObject, other.referencedObject); + return *this; } + #endif - // the -> operator is called on the referenced object - inline ReferenceCountedObjectClass* operator->() const noexcept + /** Destructor. + This will decrement the object's reference-count, which will cause the + object to be deleted when the ref-count hits zero. + */ + ~ReferenceCountedObjectPtr() { - return referencedObject; + decIfNotNull (referencedObject); } + //============================================================================== /** Returns the object that this pointer references. The pointer returned may be zero, of course. */ - inline ReferenceCountedObjectClass* get() const noexcept - { - return referencedObject; - } + operator ReferencedType*() const noexcept { return referencedObject; } + + /** Returns the object that this pointer references. + The pointer returned may be zero, of course. + */ + ReferencedType* get() const noexcept { return referencedObject; } /** Returns the object that this pointer references. The pointer returned may be zero, of course. */ - inline ReferenceCountedObjectClass* getObject() const noexcept + ReferencedType* getObject() const noexcept { return referencedObject; } + + // the -> operator is called on the referenced object + ReferencedType* operator->() const noexcept { + jassert (referencedObject != nullptr); // null pointer method call! return referencedObject; } private: //============================================================================== - ReferenceCountedObjectClass* referencedObject; + ReferencedType* referencedObject; + + static void incIfNotNull (ReferencedType* o) noexcept + { + if (o != nullptr) + o->incReferenceCount(); + } + + static void decIfNotNull (ReferencedType* o) noexcept + { + if (o != nullptr && o->decReferenceCountWithoutDeleting()) + ContainerDeletePolicy::destroy (o); + } }; +//============================================================================== /** Compares two ReferenceCountedObjectPointers. */ template bool operator== (const ReferenceCountedObjectPtr& object1, ReferenceCountedObjectClass* const object2) noexcept @@ -370,7 +385,7 @@ bool operator== (const ReferenceCountedObjectPtr& o /** Compares two ReferenceCountedObjectPointers. */ template -bool operator== (ReferenceCountedObjectClass* object1, ReferenceCountedObjectPtr& object2) noexcept +bool operator== (ReferenceCountedObjectClass* object1, const ReferenceCountedObjectPtr& object2) noexcept { return object1 == object2.get(); } @@ -384,14 +399,14 @@ bool operator!= (const ReferenceCountedObjectPtr& o /** Compares two ReferenceCountedObjectPointers. */ template -bool operator!= (const ReferenceCountedObjectPtr& object1, ReferenceCountedObjectPtr& object2) noexcept +bool operator!= (const ReferenceCountedObjectPtr& object1, const ReferenceCountedObjectPtr& object2) noexcept { return object1.get() != object2.get(); } /** Compares two ReferenceCountedObjectPointers. */ template -bool operator!= (ReferenceCountedObjectClass* object1, ReferenceCountedObjectPtr& object2) noexcept +bool operator!= (ReferenceCountedObjectClass* object1, const ReferenceCountedObjectPtr& object2) noexcept { return object1 != object2.get(); } diff --git a/source/modules/juce_core/memory/juce_ScopedPointer.h b/source/modules/juce_core/memory/juce_ScopedPointer.h index 7f9580411..a7fcff0dd 100644 --- a/source/modules/juce_core/memory/juce_ScopedPointer.h +++ b/source/modules/juce_core/memory/juce_ScopedPointer.h @@ -97,7 +97,7 @@ public: /** Destructor. This will delete the object that this ScopedPointer currently refers to. */ - inline ~ScopedPointer() { delete object; } + inline ~ScopedPointer() { ContainerDeletePolicy::destroy (object); } /** Changes this ScopedPointer to point to a new object. @@ -119,7 +119,7 @@ public: ObjectType* const oldObject = object; object = objectToTransferFrom.object; objectToTransferFrom.object = nullptr; - delete oldObject; + ContainerDeletePolicy::destroy (oldObject); } return *this; @@ -138,7 +138,7 @@ public: { ObjectType* const oldObject = object; object = newObjectToTakePossessionOf; - delete oldObject; + ContainerDeletePolicy::destroy (oldObject); } return *this; diff --git a/source/modules/juce_core/memory/juce_WeakReference.h b/source/modules/juce_core/memory/juce_WeakReference.h index ac2048a07..b56808ad6 100644 --- a/source/modules/juce_core/memory/juce_WeakReference.h +++ b/source/modules/juce_core/memory/juce_WeakReference.h @@ -29,8 +29,6 @@ #ifndef JUCE_WEAKREFERENCE_H_INCLUDED #define JUCE_WEAKREFERENCE_H_INCLUDED -#include "juce_ReferenceCountedObject.h" - //============================================================================== /** diff --git a/source/modules/juce_core/misc/juce_Result.h b/source/modules/juce_core/misc/juce_Result.h index be88580bf..7c320ac33 100644 --- a/source/modules/juce_core/misc/juce_Result.h +++ b/source/modules/juce_core/misc/juce_Result.h @@ -29,8 +29,6 @@ #ifndef JUCE_RESULT_H_INCLUDED #define JUCE_RESULT_H_INCLUDED -#include "../text/juce_String.h" - //============================================================================== /** diff --git a/source/modules/juce_core/misc/juce_Uuid.h b/source/modules/juce_core/misc/juce_Uuid.h index 9358de008..29974dec6 100644 --- a/source/modules/juce_core/misc/juce_Uuid.h +++ b/source/modules/juce_core/misc/juce_Uuid.h @@ -29,8 +29,6 @@ #ifndef JUCE_UUID_H_INCLUDED #define JUCE_UUID_H_INCLUDED -#include "../text/juce_String.h" - //============================================================================== /** diff --git a/source/modules/juce_core/misc/juce_WindowsRegistry.h b/source/modules/juce_core/misc/juce_WindowsRegistry.h index 47730acd3..716c1a198 100644 --- a/source/modules/juce_core/misc/juce_WindowsRegistry.h +++ b/source/modules/juce_core/misc/juce_WindowsRegistry.h @@ -38,65 +38,69 @@ class WindowsRegistry { public: + /** These values can be used to specify whether the 32- or 64-bit registry should be used. + When running on a 32-bit OS, there is no 64-bit registry, so the mode will be ignored. + */ + enum WoW64Mode + { + /** Default handling: 32-bit apps will use the 32-bit registry, and 64-bit apps + will use the 64-bit registry. */ + WoW64_Default = 0, + + /** Always use the 64-bit registry store. (KEY_WOW64_64KEY). */ + WoW64_64bit = 0x100, + + /** Always use the 32-bit registry store. (KEY_WOW64_32KEY). */ + WoW64_32bit = 0x200 + }; + //============================================================================== /** Returns a string from the registry. The path is a string for the entire path of a value in the registry, e.g. "HKEY_CURRENT_USER\Software\foo\bar" */ static String getValue (const String& regValuePath, - const String& defaultValue = String::empty); - - /** Returns a string from the WOW64 registry. - The path is a string for the entire path of a value in the registry, - e.g. "HKEY_CURRENT_USER\Software\foo\bar" - */ - static String getValueWow64 (const String& regValuePath, - const String& defaultValue = String::empty); + const String& defaultValue = String::empty, + WoW64Mode mode = WoW64_Default); /** Reads a binary block from the registry. The path is a string for the entire path of a value in the registry, e.g. "HKEY_CURRENT_USER\Software\foo\bar" @returns a DWORD indicating the type of the key. */ - static uint32 getBinaryValue (const String& regValuePath, MemoryBlock& resultData); + static uint32 getBinaryValue (const String& regValuePath, MemoryBlock& resultData, WoW64Mode mode = WoW64_Default); /** Sets a registry value as a string. This will take care of creating any groups needed to get to the given registry value. */ - static bool setValue (const String& regValuePath, const String& value); + static bool setValue (const String& regValuePath, const String& value, WoW64Mode mode = WoW64_Default); /** Sets a registry value as a DWORD. This will take care of creating any groups needed to get to the given registry value. */ - static bool setValue (const String& regValuePath, uint32 value); + static bool setValue (const String& regValuePath, uint32 value, WoW64Mode mode = WoW64_Default); /** Sets a registry value as a QWORD. This will take care of creating any groups needed to get to the given registry value. */ - static bool setValue (const String& regValuePath, uint64 value); + static bool setValue (const String& regValuePath, uint64 value, WoW64Mode mode = WoW64_Default); /** Sets a registry value as a binary block. This will take care of creating any groups needed to get to the given registry value. */ - static bool setValue (const String& regValuePath, const MemoryBlock& value); - - /** Returns true if the given value exists in the registry. */ - static bool valueExists (const String& regValuePath); + static bool setValue (const String& regValuePath, const MemoryBlock& value, WoW64Mode mode = WoW64_Default); /** Returns true if the given value exists in the registry. */ - static bool valueExistsWow64 (const String& regValuePath); + static bool valueExists (const String& regValuePath, WoW64Mode mode = WoW64_Default); /** Returns true if the given key exists in the registry. */ - static bool keyExists (const String& regValuePath); - - /** Returns true if the given key exists in the registry. */ - static bool keyExistsWow64 (const String& regValuePath); + static bool keyExists (const String& regValuePath, WoW64Mode mode = WoW64_Default); /** Deletes a registry value. */ - static void deleteValue (const String& regValuePath); + static void deleteValue (const String& regValuePath, WoW64Mode mode = WoW64_Default); /** Deletes a registry key (which is registry-talk for 'folder'). */ - static void deleteKey (const String& regKeyPath); + static void deleteKey (const String& regKeyPath, WoW64Mode mode = WoW64_Default); /** Creates a file association in the registry. @@ -113,16 +117,23 @@ public: for all users (you might not have permission to do this unless running in an installer). If true, it will register the association in HKEY_CURRENT_USER. + @param mode the WoW64 mode to use for choosing the database */ static bool registerFileAssociation (const String& fileExtension, const String& symbolicDescription, const String& fullDescription, const File& targetExecutable, int iconResourceNumber, - bool registerForCurrentUserOnly); + bool registerForCurrentUserOnly, + WoW64Mode mode = WoW64_Default); + + // DEPRECATED: use the other methods with a WoW64Mode parameter of WoW64_64bit instead. + JUCE_DEPRECATED (static String getValueWow64 (const String&, const String& defaultValue = String::empty)); + JUCE_DEPRECATED (static bool valueExistsWow64 (const String&)); + JUCE_DEPRECATED (static bool keyExistsWow64 (const String&)); private: - WindowsRegistry(); + WindowsRegistry() JUCE_DELETED_FUNCTION; JUCE_DECLARE_NON_COPYABLE (WindowsRegistry) }; diff --git a/source/modules/juce_core/native/juce_BasicNativeHeaders.h b/source/modules/juce_core/native/juce_BasicNativeHeaders.h index aecfc4042..d294abbfe 100644 --- a/source/modules/juce_core/native/juce_BasicNativeHeaders.h +++ b/source/modules/juce_core/native/juce_BasicNativeHeaders.h @@ -87,7 +87,7 @@ #define STRICT 1 #define WIN32_LEAN_AND_MEAN 1 #if JUCE_MINGW - #define _WIN32_WINNT 0x0501 + #define _WIN32_WINNT 0x0502 #else #define _WIN32_WINNT 0x0600 #endif diff --git a/source/modules/juce_core/native/juce_android_Files.cpp b/source/modules/juce_core/native/juce_android_Files.cpp index 15f90886d..5727581a8 100644 --- a/source/modules/juce_core/native/juce_android_Files.cpp +++ b/source/modules/juce_core/native/juce_android_Files.cpp @@ -112,13 +112,13 @@ File File::getSpecialLocation (const SpecialLocationType type) return File (android.appDataDir); case commonApplicationDataDirectory: + case commonDocumentsDirectory: return File (android.appDataDir); case globalApplicationsDirectory: return File ("/system/app"); case tempDirectory: - //return File (AndroidStatsHelpers::getSystemProperty ("java.io.tmpdir")); return File (android.appDataDir).getChildFile (".temp"); case invokedExecutableFile: @@ -230,10 +230,11 @@ bool DirectoryIterator::NativeIterator::next (String& filenameFound, //============================================================================== -bool Process::openDocument (const String& fileName, const String& parameters) +JUCE_API bool JUCE_CALLTYPE Process::openDocument (const String& fileName, const String& parameters) { const LocalRef t (javaString (fileName)); android.activity.callVoidMethod (JuceAppActivity.launchURL, t.get()); + return true; } void File::revealToUser() const diff --git a/source/modules/juce_core/native/juce_android_Misc.cpp b/source/modules/juce_core/native/juce_android_Misc.cpp index b9d5f733c..d26adc185 100644 --- a/source/modules/juce_core/native/juce_android_Misc.cpp +++ b/source/modules/juce_core/native/juce_android_Misc.cpp @@ -28,5 +28,5 @@ void Logger::outputDebugString (const String& text) { - __android_log_print (ANDROID_LOG_INFO, "JUCE", text.toUTF8()); + __android_log_print (ANDROID_LOG_INFO, "JUCE", "%s", text.toUTF8().getAddress()); } diff --git a/source/modules/juce_core/native/juce_android_Network.cpp b/source/modules/juce_core/native/juce_android_Network.cpp index 92fc2cc8e..c551edaa1 100644 --- a/source/modules/juce_core/native/juce_android_Network.cpp +++ b/source/modules/juce_core/native/juce_android_Network.cpp @@ -54,10 +54,10 @@ void MACAddress::findAllAddresses (Array& result) } -bool Process::openEmailWithAttachments (const String& targetEmailAddress, - const String& emailSubject, - const String& bodyText, - const StringArray& filesToAttach) +JUCE_API bool JUCE_CALLTYPE Process::openEmailWithAttachments (const String& targetEmailAddress, + const String& emailSubject, + const String& bodyText, + const StringArray& filesToAttach) { // TODO return false; diff --git a/source/modules/juce_core/native/juce_android_Threads.cpp b/source/modules/juce_core/native/juce_android_Threads.cpp index 7eab46517..981be9ae4 100644 --- a/source/modules/juce_core/native/juce_android_Threads.cpp +++ b/source/modules/juce_core/native/juce_android_Threads.cpp @@ -33,7 +33,7 @@ //============================================================================== // sets the process to 0=low priority, 1=normal, 2=high, 3=realtime -void Process::setPriority (ProcessPriority prior) +JUCE_API void JUCE_CALLTYPE Process::setPriority (ProcessPriority prior) { // TODO @@ -62,11 +62,6 @@ void Process::setPriority (ProcessPriority prior) pthread_setschedparam (pthread_self(), policy, ¶m); } -void Process::terminate() -{ - std::exit (EXIT_FAILURE); -} - JUCE_API bool JUCE_CALLTYPE juce_isRunningUnderDebugger() { return false; @@ -77,5 +72,5 @@ JUCE_API bool JUCE_CALLTYPE Process::isRunningUnderDebugger() return juce_isRunningUnderDebugger(); } -void Process::raisePrivilege() {} -void Process::lowerPrivilege() {} +JUCE_API void JUCE_CALLTYPE Process::raisePrivilege() {} +JUCE_API void JUCE_CALLTYPE Process::lowerPrivilege() {} diff --git a/source/modules/juce_core/native/juce_linux_Files.cpp b/source/modules/juce_core/native/juce_linux_Files.cpp index a953cba2b..63682460f 100644 --- a/source/modules/juce_core/native/juce_linux_Files.cpp +++ b/source/modules/juce_core/native/juce_linux_Files.cpp @@ -168,11 +168,8 @@ File File::getSpecialLocation (const SpecialLocationType type) const char* homeDir = getenv ("HOME"); if (homeDir == nullptr) - { - struct passwd* const pw = getpwuid (getuid()); - if (pw != nullptr) + if (struct passwd* const pw = getpwuid (getuid())) homeDir = pw->pw_dir; - } return File (CharPointer_UTF8 (homeDir)); } @@ -183,6 +180,7 @@ File File::getSpecialLocation (const SpecialLocationType type) case userPicturesDirectory: return resolveXDGFolder ("XDG_PICTURES_DIR", "~"); case userDesktopDirectory: return resolveXDGFolder ("XDG_DESKTOP_DIR", "~/Desktop"); case userApplicationDataDirectory: return File ("~"); + case commonDocumentsDirectory: case commonApplicationDataDirectory: return File ("/var"); case globalApplicationsDirectory: return File ("/usr"); diff --git a/source/modules/juce_core/native/juce_linux_Network.cpp b/source/modules/juce_core/native/juce_linux_Network.cpp index 30badf80e..bc2f13a13 100644 --- a/source/modules/juce_core/native/juce_linux_Network.cpp +++ b/source/modules/juce_core/native/juce_linux_Network.cpp @@ -55,13 +55,12 @@ void MACAddress::findAllAddresses (Array& result) } -bool Process::openEmailWithAttachments (const String& /* targetEmailAddress */, - const String& /* emailSubject */, - const String& /* bodyText */, - const StringArray& /* filesToAttach */) +bool JUCE_CALLTYPE Process::openEmailWithAttachments (const String& /* targetEmailAddress */, + const String& /* emailSubject */, + const String& /* bodyText */, + const StringArray& /* filesToAttach */) { jassertfalse; // xxx todo - return false; } diff --git a/source/modules/juce_core/native/juce_linux_Threads.cpp b/source/modules/juce_core/native/juce_linux_Threads.cpp index cf406658a..a75094a8a 100644 --- a/source/modules/juce_core/native/juce_linux_Threads.cpp +++ b/source/modules/juce_core/native/juce_linux_Threads.cpp @@ -32,7 +32,7 @@ */ //============================================================================== -void Process::setPriority (const ProcessPriority prior) +JUCE_API void JUCE_CALLTYPE Process::setPriority (const ProcessPriority prior) { const int policy = (prior <= NormalPriority) ? SCHED_OTHER : SCHED_RR; const int minp = sched_get_priority_min (policy); @@ -52,11 +52,6 @@ void Process::setPriority (const ProcessPriority prior) pthread_setschedparam (pthread_self(), policy, ¶m); } -void Process::terminate() -{ - std::exit (EXIT_FAILURE); -} - JUCE_API bool JUCE_CALLTYPE juce_isRunningUnderDebugger() { #if JUCE_BSD @@ -90,5 +85,5 @@ static void swapUserAndEffectiveUser() (void) setregid (getegid(), getgid()); } -void Process::raisePrivilege() { if (geteuid() != 0 && getuid() == 0) swapUserAndEffectiveUser(); } -void Process::lowerPrivilege() { if (geteuid() == 0 && getuid() != 0) swapUserAndEffectiveUser(); } +JUCE_API void JUCE_CALLTYPE Process::raisePrivilege() { if (geteuid() != 0 && getuid() == 0) swapUserAndEffectiveUser(); } +JUCE_API void JUCE_CALLTYPE Process::lowerPrivilege() { if (geteuid() == 0 && getuid() != 0) swapUserAndEffectiveUser(); } diff --git a/source/modules/juce_core/native/juce_mac_Files.mm b/source/modules/juce_core/native/juce_mac_Files.mm index ccd30df2d..d2be92e35 100644 --- a/source/modules/juce_core/native/juce_mac_Files.mm +++ b/source/modules/juce_core/native/juce_mac_Files.mm @@ -213,6 +213,7 @@ File File::getSpecialLocation (const SpecialLocationType type) case userPicturesDirectory: resultPath = "~/Pictures"; break; case userApplicationDataDirectory: resultPath = "~/Library"; break; case commonApplicationDataDirectory: resultPath = "/Library"; break; + case commonDocumentsDirectory: resultPath = "/Users/Shared"; break; case globalApplicationsDirectory: resultPath = "/Applications"; break; case invokedExecutableFile: @@ -391,45 +392,48 @@ bool DirectoryIterator::NativeIterator::next (String& filenameFound, //============================================================================== -bool Process::openDocument (const String& fileName, const String& parameters) +bool JUCE_CALLTYPE Process::openDocument (const String& fileName, const String& parameters) { - #if JUCE_IOS - return [[UIApplication sharedApplication] openURL: [NSURL URLWithString: juceStringToNS (fileName)]]; - #else JUCE_AUTORELEASEPOOL { + NSURL* filenameAsURL = [NSURL URLWithString: juceStringToNS (fileName)]; + + #if JUCE_IOS + return [[UIApplication sharedApplication] openURL: filenameAsURL]; + #else + NSWorkspace* workspace = [NSWorkspace sharedWorkspace]; + if (parameters.isEmpty()) - { - return [[NSWorkspace sharedWorkspace] openFile: juceStringToNS (fileName)] - || [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: juceStringToNS (fileName)]]; - } + return [workspace openFile: juceStringToNS (fileName)] + || [workspace openURL: filenameAsURL]; - bool ok = false; const File file (fileName); if (file.isBundle()) { - NSMutableArray* urls = [NSMutableArray array]; - - StringArray docs; - docs.addTokens (parameters, true); - for (int i = 0; i < docs.size(); ++i) - [urls addObject: juceStringToNS (docs[i])]; - - ok = [[NSWorkspace sharedWorkspace] openURLs: urls - withAppBundleIdentifier: [[NSBundle bundleWithPath: juceStringToNS (fileName)] bundleIdentifier] - options: 0 - additionalEventParamDescriptor: nil - launchIdentifiers: nil]; - } - else if (file.exists()) - { - ok = FileHelpers::launchExecutable ("\"" + fileName + "\" " + parameters); + StringArray params; + params.addTokens (parameters, true); + + NSMutableArray* paramArray = [[[NSMutableArray alloc] init] autorelease]; + for (int i = 0; i < params.size(); ++i) + [paramArray addObject: juceStringToNS (params[i])]; + + NSMutableDictionary* dict = [[[NSMutableDictionary alloc] init] autorelease]; + [dict setObject: paramArray + forKey: nsStringLiteral ("NSWorkspaceLaunchConfigurationArguments")]; + + return [workspace launchApplicationAtURL: filenameAsURL + options: NSWorkspaceLaunchDefault | NSWorkspaceLaunchNewInstance + configuration: dict + error: nil]; } - return ok; + if (file.exists()) + return FileHelpers::launchExecutable ("\"" + fileName + "\" " + parameters); + + return false; + #endif } - #endif } void File::revealToUser() const diff --git a/source/modules/juce_core/native/juce_mac_Network.mm b/source/modules/juce_core/native/juce_mac_Network.mm index 88845df36..9d38c36a7 100644 --- a/source/modules/juce_core/native/juce_mac_Network.mm +++ b/source/modules/juce_core/native/juce_mac_Network.mm @@ -53,10 +53,10 @@ void MACAddress::findAllAddresses (Array& result) } //============================================================================== -bool Process::openEmailWithAttachments (const String& targetEmailAddress, - const String& emailSubject, - const String& bodyText, - const StringArray& filesToAttach) +bool JUCE_CALLTYPE Process::openEmailWithAttachments (const String& targetEmailAddress, + const String& emailSubject, + const String& bodyText, + const StringArray& filesToAttach) { #if JUCE_IOS //xxx probably need to use MFMailComposeViewController diff --git a/source/modules/juce_core/native/juce_mac_Threads.mm b/source/modules/juce_core/native/juce_mac_Threads.mm index b739d9645..142c325e2 100644 --- a/source/modules/juce_core/native/juce_mac_Threads.mm +++ b/source/modules/juce_core/native/juce_mac_Threads.mm @@ -32,7 +32,7 @@ */ //============================================================================== -bool Process::isForegroundProcess() +JUCE_API bool JUCE_CALLTYPE Process::isForegroundProcess() { #if JUCE_MAC return [NSApp isActive]; @@ -41,36 +41,31 @@ bool Process::isForegroundProcess() #endif } -void Process::makeForegroundProcess() +JUCE_API void JUCE_CALLTYPE Process::makeForegroundProcess() { #if JUCE_MAC [NSApp activateIgnoringOtherApps: YES]; #endif } -void Process::hide() +JUCE_API void JUCE_CALLTYPE Process::hide() { #if JUCE_MAC [NSApp hide: nil]; #endif } -void Process::raisePrivilege() +JUCE_API void JUCE_CALLTYPE Process::raisePrivilege() { jassertfalse; } -void Process::lowerPrivilege() +JUCE_API void JUCE_CALLTYPE Process::lowerPrivilege() { jassertfalse; } -void Process::terminate() -{ - std::exit (EXIT_FAILURE); -} - -void Process::setPriority (ProcessPriority) +JUCE_API void JUCE_CALLTYPE Process::setPriority (ProcessPriority) { // xxx } diff --git a/source/modules/juce_core/native/juce_osx_ObjCHelpers.h b/source/modules/juce_core/native/juce_osx_ObjCHelpers.h index 008311421..10878d042 100644 --- a/source/modules/juce_core/native/juce_osx_ObjCHelpers.h +++ b/source/modules/juce_core/native/juce_osx_ObjCHelpers.h @@ -56,6 +56,7 @@ namespace return [NSString string]; } + #if JUCE_MAC template static NSRect makeNSRect (const RectangleType& r) noexcept { @@ -64,6 +65,7 @@ namespace static_cast (r.getWidth()), static_cast (r.getHeight())); } + #endif } //============================================================================== diff --git a/source/modules/juce_core/native/juce_posix_SharedCode.h b/source/modules/juce_core/native/juce_posix_SharedCode.h index 8db1f521a..ad77359f3 100644 --- a/source/modules/juce_core/native/juce_posix_SharedCode.h +++ b/source/modules/juce_core/native/juce_posix_SharedCode.h @@ -150,6 +150,14 @@ void JUCE_CALLTYPE Thread::sleep (int millisecs) nanosleep (&time, nullptr); } +void JUCE_CALLTYPE Process::terminate() +{ + #if JUCE_ANDROID + _exit (EXIT_FAILURE); + #else + std::_Exit (EXIT_FAILURE); + #endif +} //============================================================================== const juce_wchar File::separator = '/'; @@ -882,7 +890,7 @@ void Thread::killThread() } } -void Thread::setCurrentThreadName (const String& name) +void JUCE_CALLTYPE Thread::setCurrentThreadName (const String& name) { #if JUCE_IOS || (JUCE_MAC && defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5) JUCE_AUTORELEASEPOOL @@ -919,12 +927,12 @@ bool Thread::setThreadPriority (void* handle, int priority) return pthread_setschedparam ((pthread_t) handle, policy, ¶m) == 0; } -Thread::ThreadID Thread::getCurrentThreadId() +Thread::ThreadID JUCE_CALLTYPE Thread::getCurrentThreadId() { return (ThreadID) pthread_self(); } -void Thread::yield() +void JUCE_CALLTYPE Thread::yield() { sched_yield(); } @@ -938,7 +946,7 @@ void Thread::yield() #define SUPPORT_AFFINITIES 1 #endif -void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask) +void JUCE_CALLTYPE Thread::setCurrentThreadAffinityMask (const uint32 affinityMask) { #if SUPPORT_AFFINITIES cpu_set_t affinity; @@ -1143,7 +1151,7 @@ struct HighResolutionTimer::Pimpl shouldStop = false; if (pthread_create (&thread, nullptr, timerThread, this) == 0) - setThreadToRealtime (thread, newPeriod); + setThreadToRealtime (thread, (uint64) newPeriod); else jassertfalse; } diff --git a/source/modules/juce_core/native/juce_win32_Files.cpp b/source/modules/juce_core/native/juce_win32_Files.cpp index 61015f603..8c8ab918c 100644 --- a/source/modules/juce_core/native/juce_win32_Files.cpp +++ b/source/modules/juce_core/native/juce_win32_Files.cpp @@ -518,6 +518,7 @@ File JUCE_CALLTYPE File::getSpecialLocation (const SpecialLocationType type) case userDesktopDirectory: csidlType = CSIDL_DESKTOP; break; case userApplicationDataDirectory: csidlType = CSIDL_APPDATA; break; case commonApplicationDataDirectory: csidlType = CSIDL_COMMON_APPDATA; break; + case commonDocumentsDirectory: csidlType = CSIDL_COMMON_DOCUMENTS; break; case globalApplicationsDirectory: csidlType = CSIDL_PROGRAM_FILES; break; case userMusicDirectory: csidlType = 0x0d; /*CSIDL_MYMUSIC*/ break; case userMoviesDirectory: csidlType = 0x0e; /*CSIDL_MYVIDEO*/ break; @@ -704,7 +705,7 @@ bool DirectoryIterator::NativeIterator::next (String& filenameFound, //============================================================================== -bool Process::openDocument (const String& fileName, const String& parameters) +bool JUCE_CALLTYPE Process::openDocument (const String& fileName, const String& parameters) { HINSTANCE hInstance = 0; diff --git a/source/modules/juce_core/native/juce_win32_Network.cpp b/source/modules/juce_core/native/juce_win32_Network.cpp index 11b305750..b9803d9f3 100644 --- a/source/modules/juce_core/native/juce_win32_Network.cpp +++ b/source/modules/juce_core/native/juce_win32_Network.cpp @@ -428,10 +428,10 @@ void IPAddress::findAllAddresses (Array& result) } //============================================================================== -bool Process::openEmailWithAttachments (const String& targetEmailAddress, - const String& emailSubject, - const String& bodyText, - const StringArray& filesToAttach) +bool JUCE_CALLTYPE Process::openEmailWithAttachments (const String& targetEmailAddress, + const String& emailSubject, + const String& bodyText, + const StringArray& filesToAttach) { DynamicLibrary dll ("MAPI32.dll"); JUCE_LOAD_WINAPI_FUNCTION (dll, MAPISendMail, mapiSendMail, diff --git a/source/modules/juce_core/native/juce_win32_Registry.cpp b/source/modules/juce_core/native/juce_win32_Registry.cpp index c740745aa..f96ecbd3d 100644 --- a/source/modules/juce_core/native/juce_win32_Registry.cpp +++ b/source/modules/juce_core/native/juce_win32_Registry.cpp @@ -64,9 +64,9 @@ struct RegistryKeyWrapper } static bool setValue (const String& regValuePath, const DWORD type, - const void* data, size_t dataSize) + const void* data, size_t dataSize, const DWORD wow64Flags) { - const RegistryKeyWrapper key (regValuePath, true, 0); + const RegistryKeyWrapper key (regValuePath, true, wow64Flags); return key.key != 0 && RegSetValueEx (key.key, key.wideCharValueName, 0, type, @@ -144,73 +144,58 @@ struct RegistryKeyWrapper JUCE_DECLARE_NON_COPYABLE (RegistryKeyWrapper) }; -uint32 WindowsRegistry::getBinaryValue (const String& regValuePath, MemoryBlock& result) +uint32 WindowsRegistry::getBinaryValue (const String& regValuePath, MemoryBlock& result, WoW64Mode mode) { - return RegistryKeyWrapper::getBinaryValue (regValuePath, result, 0); + return RegistryKeyWrapper::getBinaryValue (regValuePath, result, (DWORD) mode); } -String WindowsRegistry::getValue (const String& regValuePath, const String& defaultValue) +String WindowsRegistry::getValue (const String& regValuePath, const String& defaultValue, WoW64Mode mode) { - return RegistryKeyWrapper::getValue (regValuePath, defaultValue, 0); + return RegistryKeyWrapper::getValue (regValuePath, defaultValue, (DWORD) mode); } -String WindowsRegistry::getValueWow64 (const String& regValuePath, const String& defaultValue) -{ - return RegistryKeyWrapper::getValue (regValuePath, defaultValue, 0x100 /*KEY_WOW64_64KEY*/); -} - -bool WindowsRegistry::valueExistsWow64 (const String& regValuePath) -{ - return RegistryKeyWrapper::valueExists (regValuePath, 0x100 /*KEY_WOW64_64KEY*/); -} - -bool WindowsRegistry::keyExistsWow64 (const String& regValuePath) -{ - return RegistryKeyWrapper::keyExists (regValuePath, 0x100 /*KEY_WOW64_64KEY*/); -} - -bool WindowsRegistry::setValue (const String& regValuePath, const String& value) +bool WindowsRegistry::setValue (const String& regValuePath, const String& value, WoW64Mode mode) { return RegistryKeyWrapper::setValue (regValuePath, REG_SZ, value.toWideCharPointer(), - CharPointer_UTF16::getBytesRequiredFor (value.getCharPointer())); + CharPointer_UTF16::getBytesRequiredFor (value.getCharPointer()), mode); } -bool WindowsRegistry::setValue (const String& regValuePath, const uint32 value) +bool WindowsRegistry::setValue (const String& regValuePath, const uint32 value, WoW64Mode mode) { - return RegistryKeyWrapper::setValue (regValuePath, REG_DWORD, &value, sizeof (value)); + return RegistryKeyWrapper::setValue (regValuePath, REG_DWORD, &value, sizeof (value), (DWORD) mode); } -bool WindowsRegistry::setValue (const String& regValuePath, const uint64 value) +bool WindowsRegistry::setValue (const String& regValuePath, const uint64 value, WoW64Mode mode) { - return RegistryKeyWrapper::setValue (regValuePath, REG_QWORD, &value, sizeof (value)); + return RegistryKeyWrapper::setValue (regValuePath, REG_QWORD, &value, sizeof (value), (DWORD) mode); } -bool WindowsRegistry::setValue (const String& regValuePath, const MemoryBlock& value) +bool WindowsRegistry::setValue (const String& regValuePath, const MemoryBlock& value, WoW64Mode mode) { - return RegistryKeyWrapper::setValue (regValuePath, REG_BINARY, value.getData(), value.getSize()); + return RegistryKeyWrapper::setValue (regValuePath, REG_BINARY, value.getData(), value.getSize(), (DWORD) mode); } -bool WindowsRegistry::valueExists (const String& regValuePath) +bool WindowsRegistry::valueExists (const String& regValuePath, WoW64Mode mode) { - return RegistryKeyWrapper::valueExists (regValuePath, 0); + return RegistryKeyWrapper::valueExists (regValuePath, (DWORD) mode); } -bool WindowsRegistry::keyExists (const String& regValuePath) +bool WindowsRegistry::keyExists (const String& regValuePath, WoW64Mode mode) { - return RegistryKeyWrapper::keyExists (regValuePath, 0); + return RegistryKeyWrapper::keyExists (regValuePath, (DWORD) mode); } -void WindowsRegistry::deleteValue (const String& regValuePath) +void WindowsRegistry::deleteValue (const String& regValuePath, WoW64Mode mode) { - const RegistryKeyWrapper key (regValuePath, true, 0); + const RegistryKeyWrapper key (regValuePath, true, (DWORD) mode); if (key.key != 0) RegDeleteValue (key.key, key.wideCharValueName); } -void WindowsRegistry::deleteKey (const String& regKeyPath) +void WindowsRegistry::deleteKey (const String& regKeyPath, WoW64Mode mode) { - const RegistryKeyWrapper key (regKeyPath, true, 0); + const RegistryKeyWrapper key (regKeyPath, true, (DWORD) mode); if (key.key != 0) RegDeleteKey (key.key, key.wideCharValueName); @@ -221,16 +206,22 @@ bool WindowsRegistry::registerFileAssociation (const String& fileExtension, const String& fullDescription, const File& targetExecutable, const int iconResourceNumber, - const bool registerForCurrentUserOnly) + const bool registerForCurrentUserOnly, + WoW64Mode mode) { const char* const root = registerForCurrentUserOnly ? "HKEY_CURRENT_USER\\Software\\Classes\\" : "HKEY_CLASSES_ROOT\\"; const String key (root + symbolicDescription); - return setValue (root + fileExtension + "\\", symbolicDescription) - && setValue (key + "\\", fullDescription) - && setValue (key + "\\shell\\open\\command\\", targetExecutable.getFullPathName() + " \"%1\"") + return setValue (root + fileExtension + "\\", symbolicDescription, mode) + && setValue (key + "\\", fullDescription, mode) + && setValue (key + "\\shell\\open\\command\\", targetExecutable.getFullPathName() + " \"%1\"", mode) && (iconResourceNumber == 0 || setValue (key + "\\DefaultIcon\\", targetExecutable.getFullPathName() + "," + String (-iconResourceNumber))); } + +// These methods are deprecated: +String WindowsRegistry::getValueWow64 (const String& p, const String& defVal) { return getValue (p, defVal, WoW64_64bit); } +bool WindowsRegistry::valueExistsWow64 (const String& p) { return valueExists (p, WoW64_64bit); } +bool WindowsRegistry::keyExistsWow64 (const String& p) { return keyExists (p, WoW64_64bit); } diff --git a/source/modules/juce_core/native/juce_win32_Threads.cpp b/source/modules/juce_core/native/juce_win32_Threads.cpp index 7ea9a348f..22e5134b1 100644 --- a/source/modules/juce_core/native/juce_win32_Threads.cpp +++ b/source/modules/juce_core/native/juce_win32_Threads.cpp @@ -150,7 +150,7 @@ void Thread::killThread() } } -void Thread::setCurrentThreadName (const String& name) +void JUCE_CALLTYPE Thread::setCurrentThreadName (const String& name) { #if JUCE_DEBUG && JUCE_MSVC struct @@ -177,7 +177,7 @@ void Thread::setCurrentThreadName (const String& name) #endif } -Thread::ThreadID Thread::getCurrentThreadId() +Thread::ThreadID JUCE_CALLTYPE Thread::getCurrentThreadId() { return (ThreadID) (pointer_sized_int) GetCurrentThreadId(); } @@ -199,7 +199,7 @@ bool Thread::setThreadPriority (void* handle, int priority) return SetThreadPriority (handle, pri) != FALSE; } -void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask) +void JUCE_CALLTYPE Thread::setCurrentThreadAffinityMask (const uint32 affinityMask) { SetThreadAffinityMask (GetCurrentThread(), affinityMask); } @@ -271,7 +271,7 @@ void juce_repeatLastProcessPriority() } } -void Process::setPriority (ProcessPriority prior) +void JUCE_CALLTYPE Process::setPriority (ProcessPriority prior) { if (lastProcessPriority != (int) prior) { @@ -292,7 +292,7 @@ bool JUCE_CALLTYPE Process::isRunningUnderDebugger() static void* currentModuleHandle = nullptr; -void* Process::getCurrentModuleInstanceHandle() noexcept +void* JUCE_CALLTYPE Process::getCurrentModuleInstanceHandle() noexcept { if (currentModuleHandle == nullptr) currentModuleHandle = GetModuleHandleA (nullptr); @@ -300,22 +300,22 @@ void* Process::getCurrentModuleInstanceHandle() noexcept return currentModuleHandle; } -void Process::setCurrentModuleInstanceHandle (void* const newHandle) noexcept +void JUCE_CALLTYPE Process::setCurrentModuleInstanceHandle (void* const newHandle) noexcept { currentModuleHandle = newHandle; } -void Process::raisePrivilege() +void JUCE_CALLTYPE Process::raisePrivilege() { jassertfalse; // xxx not implemented } -void Process::lowerPrivilege() +void JUCE_CALLTYPE Process::lowerPrivilege() { jassertfalse; // xxx not implemented } -void Process::terminate() +void JUCE_CALLTYPE Process::terminate() { #if JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS _CrtDumpMemoryLeaks(); diff --git a/source/modules/juce_core/network/juce_IPAddress.cpp b/source/modules/juce_core/network/juce_IPAddress.cpp index 0a7bd41f7..ced207d98 100644 --- a/source/modules/juce_core/network/juce_IPAddress.cpp +++ b/source/modules/juce_core/network/juce_IPAddress.cpp @@ -101,12 +101,12 @@ static void findIPAddresses (int sock, Array& result) { ifconf cfg; HeapBlock buffer; - size_t bufferSize = 1024; + int bufferSize = 1024; do { bufferSize *= 2; - buffer.calloc (bufferSize); + buffer.calloc ((size_t) bufferSize); cfg.ifc_len = bufferSize; cfg.ifc_buf = buffer; @@ -114,7 +114,7 @@ static void findIPAddresses (int sock, Array& result) if (ioctl (sock, SIOCGIFCONF, &cfg) < 0 && errno != EINVAL) return; - } while (bufferSize < cfg.ifc_len + 2 * (IFNAMSIZ + sizeof (struct sockaddr_in6))); + } while (bufferSize < cfg.ifc_len + 2 * (int) (IFNAMSIZ + sizeof (struct sockaddr_in6))); #if JUCE_MAC || JUCE_IOS while (cfg.ifc_len >= (int) (IFNAMSIZ + sizeof (struct sockaddr_in))) @@ -126,7 +126,7 @@ static void findIPAddresses (int sock, Array& result) cfg.ifc_buf += IFNAMSIZ + cfg.ifc_req->ifr_addr.sa_len; } #else - for (int i = 0; i < cfg.ifc_len / sizeof (struct ifreq); ++i) + for (size_t i = 0; i < cfg.ifc_len / sizeof (struct ifreq); ++i) { const ifreq& item = cfg.ifc_req[i]; diff --git a/source/modules/juce_core/network/juce_MACAddress.h b/source/modules/juce_core/network/juce_MACAddress.h index c07e1d2cf..0fa9d9dd2 100644 --- a/source/modules/juce_core/network/juce_MACAddress.h +++ b/source/modules/juce_core/network/juce_MACAddress.h @@ -29,8 +29,6 @@ #ifndef JUCE_MACADDRESS_H_INCLUDED #define JUCE_MACADDRESS_H_INCLUDED -#include "../containers/juce_Array.h" - //============================================================================== /** diff --git a/source/modules/juce_core/network/juce_NamedPipe.h b/source/modules/juce_core/network/juce_NamedPipe.h index 961b2157f..d2029bd02 100644 --- a/source/modules/juce_core/network/juce_NamedPipe.h +++ b/source/modules/juce_core/network/juce_NamedPipe.h @@ -29,7 +29,6 @@ #ifndef JUCE_NAMEDPIPE_H_INCLUDED #define JUCE_NAMEDPIPE_H_INCLUDED -#include "../threads/juce_ReadWriteLock.h" //============================================================================== /** diff --git a/source/modules/juce_core/network/juce_Socket.h b/source/modules/juce_core/network/juce_Socket.h index 0780a1b83..616d2db09 100644 --- a/source/modules/juce_core/network/juce_Socket.h +++ b/source/modules/juce_core/network/juce_Socket.h @@ -29,8 +29,6 @@ #ifndef JUCE_SOCKET_H_INCLUDED #define JUCE_SOCKET_H_INCLUDED -#include "../text/juce_String.h" - //============================================================================== /** diff --git a/source/modules/juce_core/network/juce_URL.h b/source/modules/juce_core/network/juce_URL.h index 5578a439e..9381fa6ec 100644 --- a/source/modules/juce_core/network/juce_URL.h +++ b/source/modules/juce_core/network/juce_URL.h @@ -29,11 +29,6 @@ #ifndef JUCE_URL_H_INCLUDED #define JUCE_URL_H_INCLUDED -#include "../text/juce_StringPairArray.h" -#include "../files/juce_File.h" -class InputStream; -class XmlElement; - //============================================================================== /** diff --git a/source/modules/juce_core/streams/juce_BufferedInputStream.h b/source/modules/juce_core/streams/juce_BufferedInputStream.h index 47035a85f..8f1e633be 100644 --- a/source/modules/juce_core/streams/juce_BufferedInputStream.h +++ b/source/modules/juce_core/streams/juce_BufferedInputStream.h @@ -29,10 +29,6 @@ #ifndef JUCE_BUFFEREDINPUTSTREAM_H_INCLUDED #define JUCE_BUFFEREDINPUTSTREAM_H_INCLUDED -#include "juce_InputStream.h" -#include "../memory/juce_OptionalScopedPointer.h" -#include "../memory/juce_HeapBlock.h" - //============================================================================== /** Wraps another input stream, and reads from it using an intermediate buffer diff --git a/source/modules/juce_core/streams/juce_FileInputSource.h b/source/modules/juce_core/streams/juce_FileInputSource.h index 7ce8ae9cb..d2e6d862f 100644 --- a/source/modules/juce_core/streams/juce_FileInputSource.h +++ b/source/modules/juce_core/streams/juce_FileInputSource.h @@ -29,9 +29,6 @@ #ifndef JUCE_FILEINPUTSOURCE_H_INCLUDED #define JUCE_FILEINPUTSOURCE_H_INCLUDED -#include "juce_InputSource.h" -#include "../files/juce_File.h" - //============================================================================== /** diff --git a/source/modules/juce_core/streams/juce_InputSource.h b/source/modules/juce_core/streams/juce_InputSource.h index 8e214c487..0e13ac520 100644 --- a/source/modules/juce_core/streams/juce_InputSource.h +++ b/source/modules/juce_core/streams/juce_InputSource.h @@ -29,7 +29,6 @@ #ifndef JUCE_INPUTSOURCE_H_INCLUDED #define JUCE_INPUTSOURCE_H_INCLUDED -#include "juce_InputStream.h" //============================================================================== /** diff --git a/source/modules/juce_core/streams/juce_InputStream.cpp b/source/modules/juce_core/streams/juce_InputStream.cpp index 08ff61ccd..162293c8d 100644 --- a/source/modules/juce_core/streams/juce_InputStream.cpp +++ b/source/modules/juce_core/streams/juce_InputStream.cpp @@ -175,7 +175,8 @@ String InputStream::readString() } } - return String::fromUTF8 (data, (int) i); + return String (CharPointer_UTF8 (data), + CharPointer_UTF8 (data + i)); } String InputStream::readNextLine() diff --git a/source/modules/juce_core/streams/juce_InputStream.h b/source/modules/juce_core/streams/juce_InputStream.h index d29df065a..0c7e2dc50 100644 --- a/source/modules/juce_core/streams/juce_InputStream.h +++ b/source/modules/juce_core/streams/juce_InputStream.h @@ -29,9 +29,6 @@ #ifndef JUCE_INPUTSTREAM_H_INCLUDED #define JUCE_INPUTSTREAM_H_INCLUDED -#include "../text/juce_String.h" -class MemoryBlock; - //============================================================================== /** The base class for streams that read data. diff --git a/source/modules/juce_core/streams/juce_MemoryInputStream.h b/source/modules/juce_core/streams/juce_MemoryInputStream.h index 509c3eb29..013bc39f6 100644 --- a/source/modules/juce_core/streams/juce_MemoryInputStream.h +++ b/source/modules/juce_core/streams/juce_MemoryInputStream.h @@ -29,9 +29,6 @@ #ifndef JUCE_MEMORYINPUTSTREAM_H_INCLUDED #define JUCE_MEMORYINPUTSTREAM_H_INCLUDED -#include "juce_InputStream.h" -#include "../memory/juce_HeapBlock.h" - //============================================================================== /** diff --git a/source/modules/juce_core/streams/juce_MemoryOutputStream.h b/source/modules/juce_core/streams/juce_MemoryOutputStream.h index 06c08d606..95d7be40c 100644 --- a/source/modules/juce_core/streams/juce_MemoryOutputStream.h +++ b/source/modules/juce_core/streams/juce_MemoryOutputStream.h @@ -29,10 +29,6 @@ #ifndef JUCE_MEMORYOUTPUTSTREAM_H_INCLUDED #define JUCE_MEMORYOUTPUTSTREAM_H_INCLUDED -#include "juce_OutputStream.h" -#include "../memory/juce_MemoryBlock.h" -#include "../memory/juce_ScopedPointer.h" - //============================================================================== /** diff --git a/source/modules/juce_core/streams/juce_OutputStream.cpp b/source/modules/juce_core/streams/juce_OutputStream.cpp index 5a1093874..b965f3be8 100644 --- a/source/modules/juce_core/streams/juce_OutputStream.cpp +++ b/source/modules/juce_core/streams/juce_OutputStream.cpp @@ -129,7 +129,7 @@ bool OutputStream::writeCompressedInt (int value) if (value < 0) data[0] |= 0x80; - return write (data, num + 1); + return write (data, (size_t) num + 1); } bool OutputStream::writeInt64 (int64 value) @@ -219,7 +219,7 @@ bool OutputStream::writeText (const String& text, const bool asUTF16, if (*t == '\n') { if (t > src) - if (! write (src, (int) (t - src))) + if (! write (src, (size_t) (t - src))) return false; if (! write ("\r\n", 2)) @@ -235,7 +235,7 @@ bool OutputStream::writeText (const String& text, const bool asUTF16, else if (*t == 0) { if (t > src) - if (! write (src, (int) (t - src))) + if (! write (src, (size_t) (t - src))) return false; break; @@ -263,7 +263,7 @@ int OutputStream::writeFromInputStream (InputStream& source, int64 numBytesToWri if (num <= 0) break; - write (buffer, num); + write (buffer, (size_t) num); numBytesToWrite -= num; numWritten += num; diff --git a/source/modules/juce_core/streams/juce_OutputStream.h b/source/modules/juce_core/streams/juce_OutputStream.h index beb7d3b90..ead633b5a 100644 --- a/source/modules/juce_core/streams/juce_OutputStream.h +++ b/source/modules/juce_core/streams/juce_OutputStream.h @@ -29,12 +29,6 @@ #ifndef JUCE_OUTPUTSTREAM_H_INCLUDED #define JUCE_OUTPUTSTREAM_H_INCLUDED -#include "../text/juce_String.h" -#include "../text/juce_NewLine.h" -class InputStream; -class MemoryBlock; -class File; - //============================================================================== /** diff --git a/source/modules/juce_core/streams/juce_SubregionStream.h b/source/modules/juce_core/streams/juce_SubregionStream.h index 323c24921..d291a03c3 100644 --- a/source/modules/juce_core/streams/juce_SubregionStream.h +++ b/source/modules/juce_core/streams/juce_SubregionStream.h @@ -29,9 +29,6 @@ #ifndef JUCE_SUBREGIONSTREAM_H_INCLUDED #define JUCE_SUBREGIONSTREAM_H_INCLUDED -#include "juce_InputStream.h" -#include "../memory/juce_OptionalScopedPointer.h" - //============================================================================== /** Wraps another input stream, and reads from a specific part of it. diff --git a/source/modules/juce_core/system/juce_PlatformDefs.h b/source/modules/juce_core/system/juce_PlatformDefs.h index b082f8ba7..0608acbca 100644 --- a/source/modules/juce_core/system/juce_PlatformDefs.h +++ b/source/modules/juce_core/system/juce_PlatformDefs.h @@ -175,8 +175,8 @@ namespace juce };@endcode */ #define JUCE_DECLARE_NON_COPYABLE(className) \ - className (const className&);\ - className& operator= (const className&); + className (const className&) JUCE_DELETED_FUNCTION;\ + className& operator= (const className&) JUCE_DELETED_FUNCTION; /** This is a shorthand way of writing both a JUCE_DECLARE_NON_COPYABLE and JUCE_LEAK_DETECTOR macro for a class. @@ -190,8 +190,8 @@ namespace juce */ #define JUCE_PREVENT_HEAP_ALLOCATION \ private: \ - static void* operator new (size_t); \ - static void operator delete (void*); + static void* operator new (size_t) JUCE_DELETED_FUNCTION; \ + static void operator delete (void*) JUCE_DELETED_FUNCTION; //============================================================================== @@ -313,6 +313,10 @@ namespace juce #if (__GNUC__ * 100 + __GNUC_MINOR__) >= 407 && ! defined (JUCE_COMPILER_SUPPORTS_OVERRIDE_AND_FINAL) #define JUCE_COMPILER_SUPPORTS_OVERRIDE_AND_FINAL 1 #endif + + #if (__GNUC__ * 100 + __GNUC_MINOR__) >= 407 && ! defined (JUCE_DELETED_FUNCTION) + #define JUCE_DELETED_FUNCTION = delete + #endif #endif #if JUCE_CLANG && defined (__has_feature) @@ -328,6 +332,10 @@ namespace juce #define JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS 1 #endif + #if __has_feature (cxx_deleted_functions) + #define JUCE_DELETED_FUNCTION = delete + #endif + #ifndef JUCE_COMPILER_SUPPORTS_OVERRIDE_AND_FINAL #define JUCE_COMPILER_SUPPORTS_OVERRIDE_AND_FINAL 1 #endif @@ -346,6 +354,10 @@ namespace juce #define JUCE_COMPILER_SUPPORTS_OVERRIDE_AND_FINAL 1 #endif +#ifndef JUCE_DELETED_FUNCTION + #define JUCE_DELETED_FUNCTION +#endif + //============================================================================== // Declare some fake versions of nullptr and noexcept, for older compilers: #if ! (DOXYGEN || JUCE_COMPILER_SUPPORTS_NOEXCEPT) diff --git a/source/modules/juce_core/system/juce_StandardHeader.h b/source/modules/juce_core/system/juce_StandardHeader.h index d2c880e62..657bf7d82 100644 --- a/source/modules/juce_core/system/juce_StandardHeader.h +++ b/source/modules/juce_core/system/juce_StandardHeader.h @@ -50,7 +50,6 @@ //============================================================================== -#include "juce_TargetPlatform.h" // (sets up the various JUCE_WINDOWS, JUCE_MAC, etc flags) #include "juce_PlatformDefs.h" //============================================================================== @@ -72,6 +71,7 @@ #include #include #include +#include #if JUCE_USE_INTRINSICS #include @@ -154,18 +154,4 @@ #define JUCE_NAMESPACE juce // This old macro is deprecated: you should just use the juce namespace directly. #endif -//============================================================================== -// Now include some common headers... -namespace juce -{ - extern JUCE_API bool JUCE_CALLTYPE juce_isRunningUnderDebugger(); - extern JUCE_API void JUCE_CALLTYPE logAssertion (const char* file, int line) noexcept; - - #include "../memory/juce_Memory.h" - #include "../maths/juce_MathsFunctions.h" - #include "../memory/juce_ByteOrder.h" - #include "../logging/juce_Logger.h" - #include "../memory/juce_LeakedObjectDetector.h" -} - #endif // JUCE_STANDARDHEADER_H_INCLUDED diff --git a/source/modules/juce_core/system/juce_SystemStats.h b/source/modules/juce_core/system/juce_SystemStats.h index 838f68dfe..dd40674d0 100644 --- a/source/modules/juce_core/system/juce_SystemStats.h +++ b/source/modules/juce_core/system/juce_SystemStats.h @@ -29,8 +29,6 @@ #ifndef JUCE_SYSTEMSTATS_H_INCLUDED #define JUCE_SYSTEMSTATS_H_INCLUDED -#include "../text/juce_StringArray.h" - //============================================================================== /** diff --git a/source/modules/juce_core/text/juce_CharPointer_UTF16.h b/source/modules/juce_core/text/juce_CharPointer_UTF16.h index c4de13bc9..e68d0edee 100644 --- a/source/modules/juce_core/text/juce_CharPointer_UTF16.h +++ b/source/modules/juce_core/text/juce_CharPointer_UTF16.h @@ -483,6 +483,30 @@ public: byteOrderMarkLE2 = 0xfe }; + /** Returns true if the first pair of bytes in this pointer are the UTF16 byte-order mark (big endian). + The pointer must not be null, and must contain at least two valid bytes. + */ + static bool isByteOrderMarkBigEndian (const void* possibleByteOrder) noexcept + { + jassert (possibleByteOrder != nullptr); + const uint8* const c = static_cast (possibleByteOrder); + + return c[0] == (uint8) byteOrderMarkBE1 + && c[1] == (uint8) byteOrderMarkBE2; + } + + /** Returns true if the first pair of bytes in this pointer are the UTF16 byte-order mark (little endian). + The pointer must not be null, and must contain at least two valid bytes. + */ + static bool isByteOrderMarkLittleEndian (const void* possibleByteOrder) noexcept + { + jassert (possibleByteOrder != nullptr); + const uint8* const c = static_cast (possibleByteOrder); + + return c[0] == (uint8) byteOrderMarkLE1 + && c[1] == (uint8) byteOrderMarkLE2; + } + private: CharType* data; diff --git a/source/modules/juce_core/text/juce_CharPointer_UTF8.h b/source/modules/juce_core/text/juce_CharPointer_UTF8.h index 25d004077..43117f49c 100644 --- a/source/modules/juce_core/text/juce_CharPointer_UTF8.h +++ b/source/modules/juce_core/text/juce_CharPointer_UTF8.h @@ -550,7 +550,7 @@ public: return CharPointer_UTF8 (reinterpret_cast &> (data).exchange (newValue.data)); } - /** These values are the byte-order-mark (BOM) values for a UTF-8 stream. */ + /** These values are the byte-order mark (BOM) values for a UTF-8 stream. */ enum { byteOrderMark1 = 0xef, @@ -558,6 +558,19 @@ public: byteOrderMark3 = 0xbf }; + /** Returns true if the first three bytes in this pointer are the UTF8 byte-order mark (BOM). + The pointer must not be null, and must point to at least 3 valid bytes. + */ + static bool isByteOrderMark (const void* possibleByteOrder) noexcept + { + jassert (possibleByteOrder != nullptr); + const uint8* const c = static_cast (possibleByteOrder); + + return c[0] == (uint8) byteOrderMark1 + && c[1] == (uint8) byteOrderMark2 + && c[2] == (uint8) byteOrderMark3; + } + private: CharType* data; }; diff --git a/source/modules/juce_core/text/juce_Identifier.h b/source/modules/juce_core/text/juce_Identifier.h index 8ab1fd81f..74c6a74b2 100644 --- a/source/modules/juce_core/text/juce_Identifier.h +++ b/source/modules/juce_core/text/juce_Identifier.h @@ -29,8 +29,6 @@ #ifndef JUCE_IDENTIFIER_H_INCLUDED #define JUCE_IDENTIFIER_H_INCLUDED -class StringPool; - //============================================================================== /** diff --git a/source/modules/juce_core/text/juce_LocalisedStrings.cpp b/source/modules/juce_core/text/juce_LocalisedStrings.cpp index 553474245..f2098a0b2 100644 --- a/source/modules/juce_core/text/juce_LocalisedStrings.cpp +++ b/source/modules/juce_core/text/juce_LocalisedStrings.cpp @@ -143,6 +143,14 @@ void LocalisedStrings::loadFromText (const String& fileContents, bool ignoreCase } } +void LocalisedStrings::addStrings (const LocalisedStrings& other) +{ + jassert (languageName == other.languageName); + jassert (countryCodes == other.countryCodes); + + translations.addArray (other.translations); +} + //============================================================================== void LocalisedStrings::setCurrentMappings (LocalisedStrings* newTranslations) { @@ -155,26 +163,12 @@ LocalisedStrings* LocalisedStrings::getCurrentMappings() return currentMappings; } -String LocalisedStrings::translateWithCurrentMappings (const String& text) -{ - return juce::translate (text); -} - -String LocalisedStrings::translateWithCurrentMappings (const char* text) -{ - return juce::translate (String (text)); -} +String LocalisedStrings::translateWithCurrentMappings (const String& text) { return juce::translate (text); } +String LocalisedStrings::translateWithCurrentMappings (const char* text) { return juce::translate (text); } -String translate (const String& text) -{ - return translate (text, text); -} - -String translate (const char* const literal) -{ - const String text (literal); - return translate (text, text); -} +String translate (const String& text) { return juce::translate (text, text); } +String translate (const char* text) { return juce::translate (String (text)); } +String translate (CharPointer_UTF8 text) { return juce::translate (String (text)); } String translate (const String& text, const String& resultIfNotFound) { diff --git a/source/modules/juce_core/text/juce_LocalisedStrings.h b/source/modules/juce_core/text/juce_LocalisedStrings.h index 0781a8a91..69e9df9b7 100644 --- a/source/modules/juce_core/text/juce_LocalisedStrings.h +++ b/source/modules/juce_core/text/juce_LocalisedStrings.h @@ -29,8 +29,6 @@ #ifndef JUCE_LOCALISEDSTRINGS_H_INCLUDED #define JUCE_LOCALISEDSTRINGS_H_INCLUDED -#include "juce_StringPairArray.h" -#include "../files/juce_File.h" //============================================================================== /** @@ -174,6 +172,17 @@ public: /** Provides access to the actual list of mappings. */ const StringPairArray& getMappings() const { return translations; } + //============================================================================== + /** Adds and merges another set of translations into this set. + + Note that the language name and country codes of the new LocalisedStrings + object must match that of this object - an assertion will be thrown if they + don't match. + + Any existing values will have their mappings overwritten by the new ones. + */ + void addStrings (const LocalisedStrings&); + private: //============================================================================== String languageName; @@ -215,6 +224,11 @@ String translate (const String& stringLiteral); */ String translate (const char* stringLiteral); +/** Uses the LocalisedStrings class to translate the given string literal. + @see LocalisedStrings +*/ +String translate (CharPointer_UTF8 stringLiteral); + /** Uses the LocalisedStrings class to translate the given string literal. @see LocalisedStrings */ diff --git a/source/modules/juce_core/text/juce_String.cpp b/source/modules/juce_core/text/juce_String.cpp index 56c3926b8..14c0225fd 100644 --- a/source/modules/juce_core/text/juce_String.cpp +++ b/source/modules/juce_core/text/juce_String.cpp @@ -363,6 +363,12 @@ String String::charToString (const juce_wchar character) //============================================================================== namespace NumberToStringConverters { + enum + { + charsNeededForInt = 32, + charsNeededForDouble = 48 + }; + template static char* printDigits (char* t, Type v) noexcept { @@ -413,6 +419,29 @@ namespace NumberToStringConverters return printDigits (t, v); } + struct StackArrayStream : public std::basic_streambuf > + { + explicit StackArrayStream (char* d) + { + imbue (std::locale::classic()); + setp (d, d + charsNeededForDouble); + } + + size_t writeDouble (double n, int numDecPlaces) + { + { + std::ostream o (this); + + if (numDecPlaces > 0) + o.precision ((std::streamsize) numDecPlaces); + + o << n; + } + + return (size_t) (pptr() - pbase()); + } + }; + static char* doubleToString (char* buffer, const int numChars, double n, int numDecPlaces, size_t& len) noexcept { if (numDecPlaces > 0 && numDecPlaces < 7 && n > -1.0e20 && n < 1.0e20) @@ -440,27 +469,16 @@ namespace NumberToStringConverters return t; } - // Use a locale-free sprintf where possible (not available on linux AFAICT) - #if JUCE_MSVC - static _locale_t cLocale = _create_locale (LC_NUMERIC, "C"); - - len = (size_t) (numDecPlaces > 0 ? _sprintf_l (buffer, "%.*f", cLocale, numDecPlaces, n) - : _sprintf_l (buffer, "%.9g", cLocale, n)); - #elif JUCE_MAC || JUCE_IOS - len = (size_t) (numDecPlaces > 0 ? sprintf_l (buffer, nullptr, "%.*f", numDecPlaces, n) - : sprintf_l (buffer, nullptr, "%.9g", n)); - #else - len = (size_t) (numDecPlaces > 0 ? sprintf (buffer, "%.*f", numDecPlaces, n) - : sprintf (buffer, "%.9g", n)); - #endif - + StackArrayStream strm (buffer); + len = strm.writeDouble (n, numDecPlaces); + jassert (len <= charsNeededForDouble); return buffer; } template static String::CharPointerType createFromInteger (const IntegerType number) { - char buffer [32]; + char buffer [charsNeededForInt]; char* const end = buffer + numElementsInArray (buffer); char* const start = numberToString (end, number); return StringHolder::createFromFixedLength (start, (size_t) (end - start - 1)); @@ -468,7 +486,7 @@ namespace NumberToStringConverters static String::CharPointerType createFromDouble (const double number, const int numberOfDecimalPlaces) { - char buffer [48]; + char buffer [charsNeededForDouble]; size_t len; char* const start = doubleToString (buffer, numElementsInArray (buffer), (double) number, numberOfDecimalPlaces, len); return StringHolder::createFromFixedLength (start, len); @@ -587,6 +605,31 @@ void String::append (const String& textToAppend, size_t maxCharsToTake) appendCharPointer (textToAppend.text, maxCharsToTake); } +void String::appendCharPointer (const CharPointerType textToAppend) +{ + appendCharPointer (textToAppend, textToAppend.findTerminatingNull()); +} + +void String::appendCharPointer (const CharPointerType startOfTextToAppend, + const CharPointerType endOfTextToAppend) +{ + jassert (startOfTextToAppend.getAddress() != nullptr && endOfTextToAppend.getAddress() != nullptr); + + const int extraBytesNeeded = getAddressDifference (endOfTextToAppend.getAddress(), + startOfTextToAppend.getAddress()); + jassert (extraBytesNeeded >= 0); + + if (extraBytesNeeded > 0) + { + const size_t byteOffsetOfNull = getByteOffsetOfEnd(); + preallocateBytes (byteOffsetOfNull + (size_t) extraBytesNeeded); + + CharPointerType::CharType* const newStringStart = addBytesToPointer (text.getAddress(), (int) byteOffsetOfNull); + memcpy (newStringStart, startOfTextToAppend.getAddress(), extraBytesNeeded); + CharPointerType (addBytesToPointer (newStringStart, extraBytesNeeded)).writeNull(); + } +} + String& String::operator+= (const wchar_t* const t) { appendCharPointer (castToCharPointer_wchar_t (t)); @@ -610,7 +653,7 @@ String& String::operator+= (const char* const t) */ jassert (t == nullptr || CharPointer_ASCII::isValidString (t, std::numeric_limits::max())); - appendCharPointer (CharPointer_ASCII (t)); + appendCharPointer (CharPointer_UTF8 (t)); // (using UTF8 here triggers a faster code-path than ascii) return *this; } @@ -668,50 +711,38 @@ String& String::operator+= (const int number) } //============================================================================== -JUCE_API String JUCE_CALLTYPE operator+ (const char* const string1, const String& string2) -{ - String s (string1); - return s += string2; -} +JUCE_API String JUCE_CALLTYPE operator+ (const char* const s1, const String& s2) { String s (s1); return s += s2; } +JUCE_API String JUCE_CALLTYPE operator+ (const wchar_t* const s1, const String& s2) { String s (s1); return s += s2; } -JUCE_API String JUCE_CALLTYPE operator+ (const wchar_t* const string1, const String& string2) -{ - String s (string1); - return s += string2; -} +JUCE_API String JUCE_CALLTYPE operator+ (const char s1, const String& s2) { return String::charToString ((juce_wchar) (uint8) s1) + s2; } +JUCE_API String JUCE_CALLTYPE operator+ (const wchar_t s1, const String& s2) { return String::charToString (s1) + s2; } -JUCE_API String JUCE_CALLTYPE operator+ (const char s1, const String& s2) { return String::charToString ((juce_wchar) (uint8) s1) + s2; } -JUCE_API String JUCE_CALLTYPE operator+ (const wchar_t s1, const String& s2) { return String::charToString (s1) + s2; } -#if ! JUCE_NATIVE_WCHAR_IS_UTF32 -JUCE_API String JUCE_CALLTYPE operator+ (const juce_wchar s1, const String& s2) { return String::charToString (s1) + s2; } -#endif +JUCE_API String JUCE_CALLTYPE operator+ (String s1, const String& s2) { return s1 += s2; } +JUCE_API String JUCE_CALLTYPE operator+ (String s1, const char* const s2) { return s1 += s2; } +JUCE_API String JUCE_CALLTYPE operator+ (String s1, const wchar_t* s2) { return s1 += s2; } -JUCE_API String JUCE_CALLTYPE operator+ (String s1, const String& s2) { return s1 += s2; } -JUCE_API String JUCE_CALLTYPE operator+ (String s1, const char* const s2) { return s1 += s2; } -JUCE_API String JUCE_CALLTYPE operator+ (String s1, const wchar_t* s2) { return s1 += s2; } +JUCE_API String JUCE_CALLTYPE operator+ (String s1, const char s2) { return s1 += s2; } +JUCE_API String JUCE_CALLTYPE operator+ (String s1, const wchar_t s2) { return s1 += s2; } -JUCE_API String JUCE_CALLTYPE operator+ (String s1, const char s2) { return s1 += s2; } -JUCE_API String JUCE_CALLTYPE operator+ (String s1, const wchar_t s2) { return s1 += s2; } #if ! JUCE_NATIVE_WCHAR_IS_UTF32 -JUCE_API String JUCE_CALLTYPE operator+ (String s1, const juce_wchar s2) { return s1 += s2; } +JUCE_API String JUCE_CALLTYPE operator+ (const juce_wchar s1, const String& s2) { return String::charToString (s1) + s2; } +JUCE_API String JUCE_CALLTYPE operator+ (String s1, const juce_wchar s2) { return s1 += s2; } +JUCE_API String& JUCE_CALLTYPE operator<< (String& s1, const juce_wchar s2) { return s1 += s2; } #endif -JUCE_API String& JUCE_CALLTYPE operator<< (String& s1, const char s2) { return s1 += s2; } -JUCE_API String& JUCE_CALLTYPE operator<< (String& s1, const wchar_t s2) { return s1 += s2; } -#if ! JUCE_NATIVE_WCHAR_IS_UTF32 -JUCE_API String& JUCE_CALLTYPE operator<< (String& s1, const juce_wchar s2) { return s1 += s2; } -#endif +JUCE_API String& JUCE_CALLTYPE operator<< (String& s1, const char s2) { return s1 += s2; } +JUCE_API String& JUCE_CALLTYPE operator<< (String& s1, const wchar_t s2) { return s1 += s2; } -JUCE_API String& JUCE_CALLTYPE operator<< (String& s1, const char* const s2) { return s1 += s2; } -JUCE_API String& JUCE_CALLTYPE operator<< (String& s1, const wchar_t* const s2) { return s1 += s2; } -JUCE_API String& JUCE_CALLTYPE operator<< (String& s1, const String& s2) { return s1 += s2; } +JUCE_API String& JUCE_CALLTYPE operator<< (String& s1, const char* const s2) { return s1 += s2; } +JUCE_API String& JUCE_CALLTYPE operator<< (String& s1, const wchar_t* const s2) { return s1 += s2; } +JUCE_API String& JUCE_CALLTYPE operator<< (String& s1, const String& s2) { return s1 += s2; } -JUCE_API String& JUCE_CALLTYPE operator<< (String& s1, const short number) { return s1 += (int) number; } -JUCE_API String& JUCE_CALLTYPE operator<< (String& s1, const int number) { return s1 += number; } -JUCE_API String& JUCE_CALLTYPE operator<< (String& s1, const long number) { return s1 += (int) number; } -JUCE_API String& JUCE_CALLTYPE operator<< (String& s1, const int64 number) { return s1 << String (number); } -JUCE_API String& JUCE_CALLTYPE operator<< (String& s1, const float number) { return s1 += String (number); } -JUCE_API String& JUCE_CALLTYPE operator<< (String& s1, const double number) { return s1 += String (number); } +JUCE_API String& JUCE_CALLTYPE operator<< (String& s1, const int number) { return s1 += number; } +JUCE_API String& JUCE_CALLTYPE operator<< (String& s1, const short number) { return s1 += (int) number; } +JUCE_API String& JUCE_CALLTYPE operator<< (String& s1, const long number) { return s1 += (int) number; } +JUCE_API String& JUCE_CALLTYPE operator<< (String& s1, const int64 number) { return s1 += String (number); } +JUCE_API String& JUCE_CALLTYPE operator<< (String& s1, const float number) { return s1 += String (number); } +JUCE_API String& JUCE_CALLTYPE operator<< (String& s1, const double number) { return s1 += String (number); } JUCE_API OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const String& text) { @@ -1884,9 +1915,9 @@ int String::getHexValue32() const noexcept { return HexConverter ::st int64 String::getHexValue64() const noexcept { return HexConverter::stringToHex (text); } //============================================================================== -String String::createStringFromData (const void* const data_, const int size) +String String::createStringFromData (const void* const unknownData, const int size) { - const uint8* const data = static_cast (data_); + const uint8* const data = static_cast (unknownData); if (size <= 0 || data == nullptr) return empty; @@ -1894,17 +1925,16 @@ String String::createStringFromData (const void* const data_, const int size) if (size == 1) return charToString ((juce_wchar) data[0]); - if ((data[0] == (uint8) CharPointer_UTF16::byteOrderMarkBE1 && data[1] == (uint8) CharPointer_UTF16::byteOrderMarkBE2) - || (data[0] == (uint8) CharPointer_UTF16::byteOrderMarkLE1 && data[1] == (uint8) CharPointer_UTF16::byteOrderMarkLE2)) + if (CharPointer_UTF16::isByteOrderMarkBigEndian (data) + || CharPointer_UTF16::isByteOrderMarkLittleEndian (data)) { - const bool bigEndian = (data[0] == (uint8) CharPointer_UTF16::byteOrderMarkBE1); const int numChars = size / 2 - 1; StringCreationHelper builder ((size_t) numChars); const uint16* const src = (const uint16*) (data + 2); - if (bigEndian) + if (CharPointer_UTF16::isByteOrderMarkBigEndian (data)) { for (int i = 0; i < numChars; ++i) builder.write ((juce_wchar) ByteOrder::swapIfLittleEndian (src[i])); @@ -1920,16 +1950,12 @@ String String::createStringFromData (const void* const data_, const int size) } const uint8* start = data; - const uint8* end = data + size; - if (size >= 3 - && data[0] == (uint8) CharPointer_UTF8::byteOrderMark1 - && data[1] == (uint8) CharPointer_UTF8::byteOrderMark2 - && data[2] == (uint8) CharPointer_UTF8::byteOrderMark3) + if (size >= 3 && CharPointer_UTF8::isByteOrderMark (data)) start += 3; return String (CharPointer_UTF8 ((const char*) start), - CharPointer_UTF8 ((const char*) end)); + CharPointer_UTF8 ((const char*) (data + size))); } //============================================================================== diff --git a/source/modules/juce_core/text/juce_String.h b/source/modules/juce_core/text/juce_String.h index e1012a5c8..a25f479ec 100644 --- a/source/modules/juce_core/text/juce_String.h +++ b/source/modules/juce_core/text/juce_String.h @@ -29,28 +29,6 @@ #ifndef JUCE_STRING_H_INCLUDED #define JUCE_STRING_H_INCLUDED -#include "juce_CharacterFunctions.h" - -#ifndef JUCE_STRING_UTF_TYPE - #define JUCE_STRING_UTF_TYPE 8 -#endif - -#if JUCE_MSVC - #pragma warning (push) - #pragma warning (disable: 4514 4996) -#endif - -#include "../memory/juce_Atomic.h" -#include "juce_CharPointer_UTF8.h" -#include "juce_CharPointer_UTF16.h" -#include "juce_CharPointer_UTF32.h" -#include "juce_CharPointer_ASCII.h" - -#if JUCE_MSVC - #pragma warning (pop) -#endif - -class OutputStream; //============================================================================== /** @@ -239,6 +217,17 @@ public: */ void append (const String& textToAppend, size_t maxCharsToTake); + /** Appends a string to the end of this one. + + @param startOfTextToAppend the start of the string to add. This must not be a nullptr + @param endOfTextToAppend the end of the string to add. This must not be a nullptr + */ + void appendCharPointer (const CharPointerType startOfTextToAppend, + const CharPointerType endOfTextToAppend); + + /** Appends a string to the end of this one. */ + void appendCharPointer (const CharPointerType textToAppend); + /** Appends a string to the end of this one. @param textToAppend the string to add diff --git a/source/modules/juce_core/text/juce_StringArray.h b/source/modules/juce_core/text/juce_StringArray.h index f39c9feec..e3c0de66c 100644 --- a/source/modules/juce_core/text/juce_StringArray.h +++ b/source/modules/juce_core/text/juce_StringArray.h @@ -29,9 +29,6 @@ #ifndef JUCE_STRINGARRAY_H_INCLUDED #define JUCE_STRINGARRAY_H_INCLUDED -#include "juce_String.h" -#include "../containers/juce_Array.h" - //============================================================================== /** diff --git a/source/modules/juce_core/text/juce_StringPairArray.h b/source/modules/juce_core/text/juce_StringPairArray.h index b6ace332b..f9c1bb1db 100644 --- a/source/modules/juce_core/text/juce_StringPairArray.h +++ b/source/modules/juce_core/text/juce_StringPairArray.h @@ -29,8 +29,6 @@ #ifndef JUCE_STRINGPAIRARRAY_H_INCLUDED #define JUCE_STRINGPAIRARRAY_H_INCLUDED -#include "juce_StringArray.h" - //============================================================================== /** diff --git a/source/modules/juce_core/text/juce_StringPool.h b/source/modules/juce_core/text/juce_StringPool.h index d4aa05823..fc4dde327 100644 --- a/source/modules/juce_core/text/juce_StringPool.h +++ b/source/modules/juce_core/text/juce_StringPool.h @@ -29,9 +29,6 @@ #ifndef JUCE_STRINGPOOL_H_INCLUDED #define JUCE_STRINGPOOL_H_INCLUDED -#include "juce_String.h" -#include "../containers/juce_Array.h" - //============================================================================== /** diff --git a/source/modules/juce_core/threads/juce_ChildProcess.h b/source/modules/juce_core/threads/juce_ChildProcess.h index 574ac9fa6..f8522e7e7 100644 --- a/source/modules/juce_core/threads/juce_ChildProcess.h +++ b/source/modules/juce_core/threads/juce_ChildProcess.h @@ -95,7 +95,7 @@ public: private: //============================================================================== class ActiveProcess; - friend class ScopedPointer; + friend struct ContainerDeletePolicy; ScopedPointer activeProcess; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ChildProcess) diff --git a/source/modules/juce_core/threads/juce_CriticalSection.h b/source/modules/juce_core/threads/juce_CriticalSection.h index 8677f4e71..4228b2c9c 100644 --- a/source/modules/juce_core/threads/juce_CriticalSection.h +++ b/source/modules/juce_core/threads/juce_CriticalSection.h @@ -29,8 +29,6 @@ #ifndef JUCE_CRITICALSECTION_H_INCLUDED #define JUCE_CRITICALSECTION_H_INCLUDED -#include "juce_ScopedLock.h" - //============================================================================== /** diff --git a/source/modules/juce_core/threads/juce_HighResolutionTimer.h b/source/modules/juce_core/threads/juce_HighResolutionTimer.h index aae8390f9..21022adc6 100644 --- a/source/modules/juce_core/threads/juce_HighResolutionTimer.h +++ b/source/modules/juce_core/threads/juce_HighResolutionTimer.h @@ -99,7 +99,7 @@ public: private: struct Pimpl; friend struct Pimpl; - friend class ScopedPointer; + friend struct ContainerDeletePolicy; ScopedPointer pimpl; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (HighResolutionTimer) diff --git a/source/modules/juce_core/threads/juce_InterProcessLock.h b/source/modules/juce_core/threads/juce_InterProcessLock.h index 654c2e8a5..dc903b02b 100644 --- a/source/modules/juce_core/threads/juce_InterProcessLock.h +++ b/source/modules/juce_core/threads/juce_InterProcessLock.h @@ -29,9 +29,6 @@ #ifndef JUCE_INTERPROCESSLOCK_H_INCLUDED #define JUCE_INTERPROCESSLOCK_H_INCLUDED -#include "../text/juce_String.h" -#include "../memory/juce_ScopedPointer.h" - //============================================================================== /** @@ -118,8 +115,8 @@ public: private: //============================================================================== class Pimpl; - friend class ScopedPointer ; - ScopedPointer pimpl; + friend struct ContainerDeletePolicy; + ScopedPointer pimpl; CriticalSection lock; String name; diff --git a/source/modules/juce_core/threads/juce_Process.h b/source/modules/juce_core/threads/juce_Process.h index 56a1ad10e..20ad152c7 100644 --- a/source/modules/juce_core/threads/juce_Process.h +++ b/source/modules/juce_core/threads/juce_Process.h @@ -29,8 +29,6 @@ #ifndef JUCE_PROCESS_H_INCLUDED #define JUCE_PROCESS_H_INCLUDED -#include "../text/juce_String.h" - //============================================================================== /** Represents the current executable's process. @@ -57,7 +55,7 @@ public: @param priority the process priority, where 0=low, 1=normal, 2=high, 3=realtime */ - static void setPriority (const ProcessPriority priority); + static void JUCE_CALLTYPE setPriority (const ProcessPriority priority); /** Kills the current process immediately. @@ -67,21 +65,21 @@ public: @see JUCEApplication::quit */ - static void terminate(); + static void JUCE_CALLTYPE terminate(); //============================================================================== /** Returns true if this application process is the one that the user is currently using. */ - static bool isForegroundProcess(); + static bool JUCE_CALLTYPE isForegroundProcess(); /** Attempts to make the current process the active one. (This is not possible on some platforms). */ - static void makeForegroundProcess(); + static void JUCE_CALLTYPE makeForegroundProcess(); /** Hides the application (on an OS that supports this, e.g. OSX) */ - static void hide(); + static void JUCE_CALLTYPE hide(); //============================================================================== /** Raises the current process's privilege level. @@ -89,14 +87,14 @@ public: Does nothing if this isn't supported by the current OS, or if process privilege level is fixed. */ - static void raisePrivilege(); + static void JUCE_CALLTYPE raisePrivilege(); /** Lowers the current process's privilege level. Does nothing if this isn't supported by the current OS, or if process privilege level is fixed. */ - static void lowerPrivilege(); + static void JUCE_CALLTYPE lowerPrivilege(); //============================================================================== /** Returns true if this process is being hosted by a debugger. */ @@ -105,13 +103,13 @@ public: //============================================================================== /** Tries to launch the OS's default reader application for a given file or URL. */ - static bool openDocument (const String& documentURL, const String& parameters); + static bool JUCE_CALLTYPE openDocument (const String& documentURL, const String& parameters); /** Tries to launch the OS's default email application to let the user create a message. */ - static bool openEmailWithAttachments (const String& targetEmailAddress, - const String& emailSubject, - const String& bodyText, - const StringArray& filesToAttach); + static bool JUCE_CALLTYPE openEmailWithAttachments (const String& targetEmailAddress, + const String& emailSubject, + const String& bodyText, + const StringArray& filesToAttach); #if JUCE_WINDOWS || DOXYGEN //============================================================================== diff --git a/source/modules/juce_core/threads/juce_ReadWriteLock.h b/source/modules/juce_core/threads/juce_ReadWriteLock.h index c5be7c77a..ab0509960 100644 --- a/source/modules/juce_core/threads/juce_ReadWriteLock.h +++ b/source/modules/juce_core/threads/juce_ReadWriteLock.h @@ -29,12 +29,6 @@ #ifndef JUCE_READWRITELOCK_H_INCLUDED #define JUCE_READWRITELOCK_H_INCLUDED -#include "juce_CriticalSection.h" -#include "juce_SpinLock.h" -#include "juce_WaitableEvent.h" -#include "juce_Thread.h" -#include "../containers/juce_Array.h" - //============================================================================== /** diff --git a/source/modules/juce_core/threads/juce_ScopedReadLock.h b/source/modules/juce_core/threads/juce_ScopedReadLock.h index 874195be4..107e838a5 100644 --- a/source/modules/juce_core/threads/juce_ScopedReadLock.h +++ b/source/modules/juce_core/threads/juce_ScopedReadLock.h @@ -29,8 +29,6 @@ #ifndef JUCE_SCOPEDREADLOCK_H_INCLUDED #define JUCE_SCOPEDREADLOCK_H_INCLUDED -#include "juce_ReadWriteLock.h" - //============================================================================== /** diff --git a/source/modules/juce_core/threads/juce_ScopedWriteLock.h b/source/modules/juce_core/threads/juce_ScopedWriteLock.h index f4a8e329a..44e3198a5 100644 --- a/source/modules/juce_core/threads/juce_ScopedWriteLock.h +++ b/source/modules/juce_core/threads/juce_ScopedWriteLock.h @@ -29,8 +29,6 @@ #ifndef JUCE_SCOPEDWRITELOCK_H_INCLUDED #define JUCE_SCOPEDWRITELOCK_H_INCLUDED -#include "juce_ReadWriteLock.h" - //============================================================================== /** diff --git a/source/modules/juce_core/threads/juce_SpinLock.h b/source/modules/juce_core/threads/juce_SpinLock.h index e7a450560..664cc3c0a 100644 --- a/source/modules/juce_core/threads/juce_SpinLock.h +++ b/source/modules/juce_core/threads/juce_SpinLock.h @@ -29,8 +29,6 @@ #ifndef JUCE_SPINLOCK_H_INCLUDED #define JUCE_SPINLOCK_H_INCLUDED -#include "juce_ScopedLock.h" - //============================================================================== /** diff --git a/source/modules/juce_core/threads/juce_Thread.cpp b/source/modules/juce_core/threads/juce_Thread.cpp index 20d25398d..70318dc3a 100644 --- a/source/modules/juce_core/threads/juce_Thread.cpp +++ b/source/modules/juce_core/threads/juce_Thread.cpp @@ -47,7 +47,7 @@ Thread::~Thread() */ jassert (! isThreadRunning()); - stopThread (100); + stopThread (-1); } //============================================================================== @@ -65,10 +65,15 @@ struct CurrentThreadHolder : public ReferenceCountedObject static char currentThreadHolderLock [sizeof (SpinLock)]; // (statically initialised to zeros). +static SpinLock* castToSpinLockWithoutAliasingWarning (void* s) +{ + return static_cast (s); +} + static CurrentThreadHolder::Ptr getCurrentThreadHolder() { static CurrentThreadHolder::Ptr currentThreadHolder; - SpinLock::ScopedLockType lock (*reinterpret_cast (currentThreadHolderLock)); + SpinLock::ScopedLockType lock (*castToSpinLockWithoutAliasingWarning (currentThreadHolderLock)); if (currentThreadHolder == nullptr) currentThreadHolder = new CurrentThreadHolder(); @@ -143,7 +148,7 @@ bool Thread::isThreadRunning() const return threadHandle != nullptr; } -Thread* Thread::getCurrentThread() +Thread* JUCE_CALLTYPE Thread::getCurrentThread() { return getCurrentThreadHolder()->value.get(); } @@ -172,7 +177,7 @@ bool Thread::waitForThreadToExit (const int timeOutMilliseconds) const return true; } -void Thread::stopThread (const int timeOutMilliseconds) +bool Thread::stopThread (const int timeOutMilliseconds) { // agh! You can't stop the thread that's calling this method! How on earth // would that work?? @@ -199,8 +204,11 @@ void Thread::stopThread (const int timeOutMilliseconds) threadHandle = nullptr; threadId = 0; + return false; } } + + return true; } //============================================================================== diff --git a/source/modules/juce_core/threads/juce_Thread.h b/source/modules/juce_core/threads/juce_Thread.h index 1f6cff304..aef96b7dc 100644 --- a/source/modules/juce_core/threads/juce_Thread.h +++ b/source/modules/juce_core/threads/juce_Thread.h @@ -29,9 +29,6 @@ #ifndef JUCE_THREAD_H_INCLUDED #define JUCE_THREAD_H_INCLUDED -#include "juce_WaitableEvent.h" -#include "juce_CriticalSection.h" - //============================================================================== /** @@ -61,10 +58,10 @@ public: /** Destructor. - Deleting a Thread object that is running will only give the thread a - brief opportunity to stop itself cleanly, so it's recommended that you - should always call stopThread() with a decent timeout before deleting, - to avoid the thread being forcibly killed (which is a Bad Thing). + You must never attempt to delete a Thread object while it's still running - + always call stopThread() and make sure your thread has stopped before deleting + the object. Failing to do so will throw an assertion, and put you firmly into + undefined behaviour territory. */ virtual ~Thread(); @@ -84,8 +81,8 @@ public: /** Starts the thread running. - This will start the thread's run() method. - (if it's already started, startThread() won't do anything). + This will cause the thread's run() method to be called by a new thread. + If this thread is already running, startThread() won't do anything. @see stopThread */ @@ -116,9 +113,11 @@ public: @param timeOutMilliseconds The number of milliseconds to wait for the thread to finish before killing it by force. A negative value in here will wait forever. + @returns true if the thread was cleanly stopped before the timeout, or false + if it had to be killed by force. @see signalThreadShouldExit, threadShouldExit, waitForThreadToExit, isThreadRunning */ - void stopThread (int timeOutMilliseconds); + bool stopThread (int timeOutMilliseconds); //============================================================================== /** Returns true if the thread is currently active */ @@ -186,12 +185,10 @@ public: void setAffinityMask (uint32 affinityMask); /** Changes the affinity mask for the caller thread. - This will change the affinity mask for the thread that calls this static method. - @see setAffinityMask */ - static void setCurrentThreadAffinityMask (uint32 affinityMask); + static void JUCE_CALLTYPE setCurrentThreadAffinityMask (uint32 affinityMask); //============================================================================== // this can be called from any thread that needs to pause.. @@ -233,14 +230,14 @@ public: @returns a unique identifier that identifies the calling thread. @see getThreadId */ - static ThreadID getCurrentThreadId(); + static ThreadID JUCE_CALLTYPE getCurrentThreadId(); /** Finds the thread object that is currently running. Note that the main UI thread (or other non-Juce threads) don't have a Thread object associated with them, so this will return 0. */ - static Thread* getCurrentThread(); + static Thread* JUCE_CALLTYPE getCurrentThread(); /** Returns the ID of this thread. @@ -262,7 +259,7 @@ public: /** Changes the name of the caller thread. Different OSes may place different length or content limits on this name. */ - static void setCurrentThreadName (const String& newThreadName); + static void JUCE_CALLTYPE setCurrentThreadName (const String& newThreadName); private: diff --git a/source/modules/juce_core/threads/juce_ThreadPool.h b/source/modules/juce_core/threads/juce_ThreadPool.h index f91bb5492..566d19ea2 100644 --- a/source/modules/juce_core/threads/juce_ThreadPool.h +++ b/source/modules/juce_core/threads/juce_ThreadPool.h @@ -29,10 +29,6 @@ #ifndef JUCE_THREADPOOL_H_INCLUDED #define JUCE_THREADPOOL_H_INCLUDED -#include "juce_Thread.h" -#include "../text/juce_StringArray.h" -#include "../containers/juce_Array.h" -#include "../containers/juce_OwnedArray.h" class ThreadPool; class ThreadPoolThread; @@ -295,8 +291,8 @@ private: class ThreadPoolThread; friend class ThreadPoolThread; - friend class OwnedArray ; - OwnedArray threads; + friend struct ContainerDeletePolicy; + OwnedArray threads; CriticalSection lock; WaitableEvent jobFinishedSignal; diff --git a/source/modules/juce_core/threads/juce_TimeSliceThread.h b/source/modules/juce_core/threads/juce_TimeSliceThread.h index b98fb3361..8c3056750 100644 --- a/source/modules/juce_core/threads/juce_TimeSliceThread.h +++ b/source/modules/juce_core/threads/juce_TimeSliceThread.h @@ -29,9 +29,6 @@ #ifndef JUCE_TIMESLICETHREAD_H_INCLUDED #define JUCE_TIMESLICETHREAD_H_INCLUDED -#include "juce_Thread.h" -#include "../containers/juce_Array.h" -#include "../time/juce_Time.h" class TimeSliceThread; diff --git a/source/modules/juce_core/threads/juce_WaitableEvent.h b/source/modules/juce_core/threads/juce_WaitableEvent.h index f0f1ad105..cf41d9262 100644 --- a/source/modules/juce_core/threads/juce_WaitableEvent.h +++ b/source/modules/juce_core/threads/juce_WaitableEvent.h @@ -29,8 +29,6 @@ #ifndef JUCE_WAITABLEEVENT_H_INCLUDED #define JUCE_WAITABLEEVENT_H_INCLUDED -#include "../text/juce_String.h" - //============================================================================== /** diff --git a/source/modules/juce_core/time/juce_PerformanceCounter.h b/source/modules/juce_core/time/juce_PerformanceCounter.h index d4088a24c..9d629ea2d 100644 --- a/source/modules/juce_core/time/juce_PerformanceCounter.h +++ b/source/modules/juce_core/time/juce_PerformanceCounter.h @@ -29,8 +29,6 @@ #ifndef JUCE_PERFORMANCECOUNTER_H_INCLUDED #define JUCE_PERFORMANCECOUNTER_H_INCLUDED -#include "../files/juce_File.h" - //============================================================================== /** A timer for measuring performance of code and dumping the results to a file. diff --git a/source/modules/juce_core/time/juce_RelativeTime.cpp b/source/modules/juce_core/time/juce_RelativeTime.cpp index 8d4804911..6fca4fede 100644 --- a/source/modules/juce_core/time/juce_RelativeTime.cpp +++ b/source/modules/juce_core/time/juce_RelativeTime.cpp @@ -26,32 +26,33 @@ ============================================================================== */ -RelativeTime::RelativeTime (const double secs) noexcept : seconds (secs) {} -RelativeTime::RelativeTime (const RelativeTime& other) noexcept : seconds (other.seconds) {} +RelativeTime::RelativeTime (const double secs) noexcept : numSeconds (secs) {} +RelativeTime::RelativeTime (const RelativeTime& other) noexcept : numSeconds (other.numSeconds) {} RelativeTime::~RelativeTime() noexcept {} //============================================================================== RelativeTime RelativeTime::milliseconds (const int milliseconds) noexcept { return RelativeTime (milliseconds * 0.001); } RelativeTime RelativeTime::milliseconds (const int64 milliseconds) noexcept { return RelativeTime (milliseconds * 0.001); } +RelativeTime RelativeTime::seconds (double s) noexcept { return RelativeTime (s); } RelativeTime RelativeTime::minutes (const double numberOfMinutes) noexcept { return RelativeTime (numberOfMinutes * 60.0); } RelativeTime RelativeTime::hours (const double numberOfHours) noexcept { return RelativeTime (numberOfHours * (60.0 * 60.0)); } RelativeTime RelativeTime::days (const double numberOfDays) noexcept { return RelativeTime (numberOfDays * (60.0 * 60.0 * 24.0)); } RelativeTime RelativeTime::weeks (const double numberOfWeeks) noexcept { return RelativeTime (numberOfWeeks * (60.0 * 60.0 * 24.0 * 7.0)); } //============================================================================== -int64 RelativeTime::inMilliseconds() const noexcept { return (int64) (seconds * 1000.0); } -double RelativeTime::inMinutes() const noexcept { return seconds / 60.0; } -double RelativeTime::inHours() const noexcept { return seconds / (60.0 * 60.0); } -double RelativeTime::inDays() const noexcept { return seconds / (60.0 * 60.0 * 24.0); } -double RelativeTime::inWeeks() const noexcept { return seconds / (60.0 * 60.0 * 24.0 * 7.0); } +int64 RelativeTime::inMilliseconds() const noexcept { return (int64) (numSeconds * 1000.0); } +double RelativeTime::inMinutes() const noexcept { return numSeconds / 60.0; } +double RelativeTime::inHours() const noexcept { return numSeconds / (60.0 * 60.0); } +double RelativeTime::inDays() const noexcept { return numSeconds / (60.0 * 60.0 * 24.0); } +double RelativeTime::inWeeks() const noexcept { return numSeconds / (60.0 * 60.0 * 24.0 * 7.0); } //============================================================================== -RelativeTime& RelativeTime::operator= (const RelativeTime& other) noexcept { seconds = other.seconds; return *this; } +RelativeTime& RelativeTime::operator= (const RelativeTime& other) noexcept { numSeconds = other.numSeconds; return *this; } -RelativeTime RelativeTime::operator+= (RelativeTime t) noexcept { seconds += t.seconds; return *this; } -RelativeTime RelativeTime::operator-= (RelativeTime t) noexcept { seconds -= t.seconds; return *this; } -RelativeTime RelativeTime::operator+= (const double secs) noexcept { seconds += secs; return *this; } -RelativeTime RelativeTime::operator-= (const double secs) noexcept { seconds -= secs; return *this; } +RelativeTime RelativeTime::operator+= (RelativeTime t) noexcept { numSeconds += t.numSeconds; return *this; } +RelativeTime RelativeTime::operator-= (RelativeTime t) noexcept { numSeconds -= t.numSeconds; return *this; } +RelativeTime RelativeTime::operator+= (const double secs) noexcept { numSeconds += secs; return *this; } +RelativeTime RelativeTime::operator-= (const double secs) noexcept { numSeconds -= secs; return *this; } RelativeTime operator+ (RelativeTime t1, RelativeTime t2) noexcept { return t1 += t2; } RelativeTime operator- (RelativeTime t1, RelativeTime t2) noexcept { return t1 -= t2; } @@ -73,13 +74,13 @@ static void translateTimeField (String& result, int n, const char* singular, con String RelativeTime::getDescription (const String& returnValueForZeroTime) const { - if (seconds < 0.001 && seconds > -0.001) + if (numSeconds < 0.001 && numSeconds > -0.001) return returnValueForZeroTime; String result; result.preallocateBytes (32); - if (seconds < 0) + if (numSeconds < 0) result << '-'; int fieldsShown = 0; diff --git a/source/modules/juce_core/time/juce_RelativeTime.h b/source/modules/juce_core/time/juce_RelativeTime.h index 7116230bd..7e39d2117 100644 --- a/source/modules/juce_core/time/juce_RelativeTime.h +++ b/source/modules/juce_core/time/juce_RelativeTime.h @@ -29,8 +29,6 @@ #ifndef JUCE_RELATIVETIME_H_INCLUDED #define JUCE_RELATIVETIME_H_INCLUDED -#include "../text/juce_String.h" - //============================================================================== /** A relative measure of time. @@ -62,15 +60,20 @@ public: //============================================================================== /** Creates a new RelativeTime object representing a number of milliseconds. - @see minutes, hours, days, weeks + @see seconds, minutes, hours, days, weeks */ static RelativeTime milliseconds (int milliseconds) noexcept; /** Creates a new RelativeTime object representing a number of milliseconds. - @see minutes, hours, days, weeks + @see seconds, minutes, hours, days, weeks */ static RelativeTime milliseconds (int64 milliseconds) noexcept; + /** Creates a new RelativeTime object representing a number of seconds. + @see milliseconds, minutes, hours, days, weeks + */ + static RelativeTime seconds (double seconds) noexcept; + /** Creates a new RelativeTime object representing a number of minutes. @see milliseconds, hours, days, weeks */ @@ -100,7 +103,7 @@ public: /** Returns the number of seconds this time represents. @see inMilliseconds, inMinutes, inHours, inDays, inWeeks */ - double inSeconds() const noexcept { return seconds; } + double inSeconds() const noexcept { return numSeconds; } /** Returns the number of minutes this time represents. @see inMilliseconds, inSeconds, inHours, inDays, inWeeks @@ -153,7 +156,7 @@ public: private: //============================================================================== - double seconds; + double numSeconds; }; //============================================================================== diff --git a/source/modules/juce_core/time/juce_Time.h b/source/modules/juce_core/time/juce_Time.h index 5fa7cee47..f72fb2ce0 100644 --- a/source/modules/juce_core/time/juce_Time.h +++ b/source/modules/juce_core/time/juce_Time.h @@ -29,8 +29,6 @@ #ifndef JUCE_TIME_H_INCLUDED #define JUCE_TIME_H_INCLUDED -#include "juce_RelativeTime.h" - //============================================================================== /** diff --git a/source/modules/juce_core/unit_tests/juce_UnitTest.h b/source/modules/juce_core/unit_tests/juce_UnitTest.h index 522c8f9b8..cfbb77b8e 100644 --- a/source/modules/juce_core/unit_tests/juce_UnitTest.h +++ b/source/modules/juce_core/unit_tests/juce_UnitTest.h @@ -29,8 +29,6 @@ #ifndef JUCE_UNITTEST_H_INCLUDED #define JUCE_UNITTEST_H_INCLUDED -#include "../text/juce_StringArray.h" -#include "../containers/juce_OwnedArray.h" class UnitTestRunner; diff --git a/source/modules/juce_core/xml/juce_XmlDocument.cpp b/source/modules/juce_core/xml/juce_XmlDocument.cpp index 0c0a422da..e118b31dc 100644 --- a/source/modules/juce_core/xml/juce_XmlDocument.cpp +++ b/source/modules/juce_core/xml/juce_XmlDocument.cpp @@ -101,55 +101,54 @@ namespace XmlIdentifierChars DBG (s); }*/ + + static String::CharPointerType findEndOfToken (String::CharPointerType p) + { + while (isIdentifierChar (*p)) + ++p; + + return p; + } } XmlElement* XmlDocument::getDocumentElement (const bool onlyReadOuterDocumentElement) { - String textToParse (originalText); - - if (textToParse.isEmpty() && inputSource != nullptr) + if (originalText.isEmpty() && inputSource != nullptr) { - ScopedPointer in (inputSource->createInputStream()); + ScopedPointer in (inputSource->createInputStream()); if (in != nullptr) { MemoryOutputStream data; data.writeFromInputStream (*in, onlyReadOuterDocumentElement ? 8192 : -1); - textToParse = data.toString(); - - if (! onlyReadOuterDocumentElement) - originalText = textToParse; - } - } - - input = textToParse.getCharPointer(); - lastError = String::empty; - errorOccurred = false; - outOfData = false; - needToLoadDTD = true; - if (textToParse.isEmpty()) - { - lastError = "not enough input"; - } - else - { - skipHeader(); + #if JUCE_STRING_UTF_TYPE == 8 + if (data.getDataSize() > 2) + { + data.writeByte (0); + const char* text = static_cast (data.getData()); - if (input.getAddress() != nullptr) - { - ScopedPointer result (readNextElement (! onlyReadOuterDocumentElement)); + if (CharPointer_UTF16::isByteOrderMarkBigEndian (text) + || CharPointer_UTF16::isByteOrderMarkLittleEndian (text)) + { + originalText = data.toString(); + } + else + { + if (CharPointer_UTF8::isByteOrderMark (text)) + text += 3; - if (! errorOccurred) - return result.release(); - } - else - { - lastError = "incorrect xml header"; + // parse the input buffer directly to avoid copying it all to a string.. + return parseDocumentElement (String::CharPointerType (text), onlyReadOuterDocumentElement); + } + } + #else + originalText = data.toString(); + #endif } } - return nullptr; + return parseDocumentElement (originalText.getCharPointer(), onlyReadOuterDocumentElement); } const String& XmlDocument::getLastParseError() const noexcept @@ -167,7 +166,7 @@ String XmlDocument::getFileContents (const String& filename) const { if (inputSource != nullptr) { - const ScopedPointer in (inputSource->createInputStreamFor (filename.trim().unquoted())); + const ScopedPointer in (inputSource->createInputStreamFor (filename.trim().unquoted())); if (in != nullptr) return in->readEntireStreamAsString(); @@ -189,33 +188,56 @@ juce_wchar XmlDocument::readNextChar() noexcept return c; } -int XmlDocument::findNextTokenLength() noexcept +XmlElement* XmlDocument::parseDocumentElement (String::CharPointerType textToParse, + const bool onlyReadOuterDocumentElement) { - int len = 0; - juce_wchar c = *input; + input = textToParse; + errorOccurred = false; + outOfData = false; + needToLoadDTD = true; - while (XmlIdentifierChars::isIdentifierChar (c)) - c = input [++len]; + if (textToParse.isEmpty()) + { + lastError = "not enough input"; + } + else if (! parseHeader()) + { + lastError = "malformed header"; + } + else if (! parseDTD()) + { + lastError = "malformed DTD"; + } + else + { + lastError = String::empty; + + ScopedPointer result (readNextElement (! onlyReadOuterDocumentElement)); + + if (! errorOccurred) + return result.release(); + } - return len; + return nullptr; } -void XmlDocument::skipHeader() +bool XmlDocument::parseHeader() { - const int headerStart = input.indexOf (CharPointer_UTF8 ("= 0) + if (CharacterFunctions::compareUpTo (input, CharPointer_ASCII ("")); - if (headerEnd < 0) - return; + const String::CharPointerType headerEnd (CharacterFunctions::find (input, CharPointer_ASCII ("?>"))); + + if (headerEnd.isEmpty()) + return false; #if JUCE_DEBUG - const String header (input + headerStart, (size_t) (headerEnd - headerStart)); - const String encoding (header.fromFirstOccurrenceOf ("encoding", false, true) - .fromFirstOccurrenceOf ("=", false, false) - .fromFirstOccurrenceOf ("\"", false, false) - .upToFirstOccurrenceOf ("\"", false, false).trim()); + const String encoding (String (input, headerEnd) + .fromFirstOccurrenceOf ("encoding", false, true) + .fromFirstOccurrenceOf ("=", false, false) + .fromFirstOccurrenceOf ("\"", false, false) + .upToFirstOccurrenceOf ("\"", false, false).trim()); /* If you load an XML document with a non-UTF encoding type, it may have been loaded wrongly.. Since all the files are read via the normal juce file streams, @@ -227,58 +249,59 @@ void XmlDocument::skipHeader() jassert (encoding.isEmpty() || encoding.startsWithIgnoreCase ("utf-")); #endif - input += headerEnd + 2; + input = headerEnd + 2; + skipNextWhiteSpace(); } - skipNextWhiteSpace(); - - const int docTypeIndex = input.indexOf (CharPointer_UTF8 (" 0;) + { + const juce_wchar c = readNextChar(); - while (n > 0) - { - const juce_wchar c = readNextChar(); + if (outOfData) + return false; - if (outOfData) - return; + if (c == '<') + ++n; + else if (c == '>') + --n; + } - if (c == '<') - ++n; - else if (c == '>') - --n; + dtdText = String (dtdStart, input - 1).trim(); } - dtdText = String (docType, (size_t) (input.getAddress() - (docType.getAddress() + 1))).trim(); + return true; } void XmlDocument::skipNextWhiteSpace() { for (;;) { - juce_wchar c = *input; - - while (CharacterFunctions::isWhitespace (c)) - c = *++input; + input = input.findEndOfWhitespace(); - if (c == 0) + if (input.isEmpty()) { outOfData = true; break; } - else if (c == '<') + + if (*input == '<') { if (input[1] == '!' && input[2] == '-' && input[3] == '-') { input += 4; - const int closeComment = input.indexOf (CharPointer_UTF8 ("-->")); + const int closeComment = input.indexOf (CharPointer_ASCII ("-->")); if (closeComment < 0) { @@ -292,7 +315,7 @@ void XmlDocument::skipNextWhiteSpace() else if (input[1] == '?') { input += 2; - const int closeBracket = input.indexOf (CharPointer_UTF8 ("?>")); + const int closeBracket = input.indexOf (CharPointer_ASCII ("?>")); if (closeBracket < 0) { @@ -329,7 +352,6 @@ void XmlDocument::readQuotedString (String& result) else { const String::CharPointerType start (input); - size_t numChars = 0; for (;;) { @@ -337,13 +359,13 @@ void XmlDocument::readQuotedString (String& result) if (character == quote) { - result.appendCharPointer (start, numChars); + result.appendCharPointer (start, input); ++input; return; } else if (character == '&') { - result.appendCharPointer (start, numChars); + result.appendCharPointer (start, input); break; } else if (character == 0) @@ -354,7 +376,6 @@ void XmlDocument::readQuotedString (String& result) } ++input; - ++numChars; } } } @@ -368,28 +389,26 @@ XmlElement* XmlDocument::readNextElement (const bool alsoParseSubElements) if (outOfData) return nullptr; - const int openBracket = input.indexOf ((juce_wchar) '<'); - - if (openBracket >= 0) + if (*input == '<') { - input += openBracket + 1; - int tagLen = findNextTokenLength(); + ++input; + String::CharPointerType endOfToken (XmlIdentifierChars::findEndOfToken (input)); - if (tagLen == 0) + if (endOfToken == input) { // no tag name - but allow for a gap after the '<' before giving an error skipNextWhiteSpace(); - tagLen = findNextTokenLength(); + endOfToken = XmlIdentifierChars::findEndOfToken (input); - if (tagLen == 0) + if (endOfToken == input) { setLastError ("tag name missing", false); return node; } } - node = new XmlElement (String (input, (size_t) tagLen)); - input += tagLen; + node = new XmlElement (String (input, endOfToken)); + input = endOfToken; LinkedListPointer::Appender attributeAppender (node->attributes); // look for attributes @@ -420,12 +439,12 @@ XmlElement* XmlDocument::readNextElement (const bool alsoParseSubElements) // get an attribute.. if (XmlIdentifierChars::isIdentifierChar (c)) { - const int attNameLen = findNextTokenLength(); + String::CharPointerType attNameEnd (XmlIdentifierChars::findEndOfToken (input)); - if (attNameLen > 0) + if (attNameEnd != input) { const String::CharPointerType attNameStart (input); - input += attNameLen; + input = attNameEnd; skipNextWhiteSpace(); @@ -438,7 +457,7 @@ XmlElement* XmlDocument::readNextElement (const bool alsoParseSubElements) if (nextChar == '"' || nextChar == '\'') { XmlElement::XmlAttributeNode* const newAtt - = new XmlElement::XmlAttributeNode (String (attNameStart, (size_t) attNameLen), + = new XmlElement::XmlAttributeNode (String (attNameStart, attNameEnd), String::empty); readQuotedString (newAtt->value); @@ -446,6 +465,12 @@ XmlElement* XmlDocument::readNextElement (const bool alsoParseSubElements) continue; } } + else + { + setLastError ("expected '=' after attribute '" + + String (attNameStart, attNameEnd) + "'", false); + return node; + } } } else @@ -478,7 +503,9 @@ void XmlDocument::readChildElements (XmlElement* parent) if (*input == '<') { - if (input[1] == '/') + const juce_wchar c1 = input[1]; + + if (c1 == '/') { // our close tag.. const int closeTag = input.indexOf ((juce_wchar) '>'); @@ -488,41 +515,32 @@ void XmlDocument::readChildElements (XmlElement* parent) break; } - else if (input[1] == '!' - && input[2] == '[' - && input[3] == 'C' - && input[4] == 'D' - && input[5] == 'A' - && input[6] == 'T' - && input[7] == 'A' - && input[8] == '[') + else if (c1 == '!' && CharacterFunctions::compareUpTo (input + 2, CharPointer_ASCII ("[CDATA["), 7) == 0) { input += 9; const String::CharPointerType inputStart (input); - size_t len = 0; - for (;;) { - if (*input == 0) + const juce_wchar c0 = *input; + + if (c0 == 0) { setLastError ("unterminated CDATA section", false); outOfData = true; break; } - else if (input[0] == ']' + else if (c0 == ']' && input[1] == ']' && input[2] == '>') { + childAppender.append (XmlElement::createTextElement (String (inputStart, input))); input += 3; break; } ++input; - ++len; } - - childAppender.append (XmlElement::createTextElement (String (inputStart, len))); } else { @@ -586,17 +604,15 @@ void XmlDocument::readChildElements (XmlElement* parent) else { const String::CharPointerType start (input); - size_t len = 0; for (;;) { const juce_wchar nextChar = *input; if (nextChar == '<' || nextChar == '&') - { break; - } - else if (nextChar == 0) + + if (nextChar == 0) { setLastError ("unmatched tags", false); outOfData = true; @@ -604,17 +620,14 @@ void XmlDocument::readChildElements (XmlElement* parent) } ++input; - ++len; } - textElementContent.appendCharPointer (start, len); + textElementContent.appendCharPointer (start, input); } } if ((! ignoreEmptyTextElements) || textElementContent.containsNonWhitespaceChars()) - { childAppender.append (XmlElement::createTextElement (textElementContent)); - } } } } @@ -624,27 +637,27 @@ void XmlDocument::readEntity (String& result) // skip over the ampersand ++input; - if (input.compareIgnoreCaseUpTo (CharPointer_UTF8 ("amp;"), 4) == 0) + if (input.compareIgnoreCaseUpTo (CharPointer_ASCII ("amp;"), 4) == 0) { input += 4; result += '&'; } - else if (input.compareIgnoreCaseUpTo (CharPointer_UTF8 ("quot;"), 5) == 0) + else if (input.compareIgnoreCaseUpTo (CharPointer_ASCII ("quot;"), 5) == 0) { input += 5; result += '"'; } - else if (input.compareIgnoreCaseUpTo (CharPointer_UTF8 ("apos;"), 5) == 0) + else if (input.compareIgnoreCaseUpTo (CharPointer_ASCII ("apos;"), 5) == 0) { input += 5; result += '\''; } - else if (input.compareIgnoreCaseUpTo (CharPointer_UTF8 ("lt;"), 3) == 0) + else if (input.compareIgnoreCaseUpTo (CharPointer_ASCII ("lt;"), 3) == 0) { input += 3; result += '<'; } - else if (input.compareIgnoreCaseUpTo (CharPointer_UTF8 ("gt;"), 3) == 0) + else if (input.compareIgnoreCaseUpTo (CharPointer_ASCII ("gt;"), 3) == 0) { input += 3; result += '>'; diff --git a/source/modules/juce_core/xml/juce_XmlDocument.h b/source/modules/juce_core/xml/juce_XmlDocument.h index 48a6c3f5f..582c23f39 100644 --- a/source/modules/juce_core/xml/juce_XmlDocument.h +++ b/source/modules/juce_core/xml/juce_XmlDocument.h @@ -29,12 +29,6 @@ #ifndef JUCE_XMLDOCUMENT_H_INCLUDED #define JUCE_XMLDOCUMENT_H_INCLUDED -#include "juce_XmlElement.h" -#include "../text/juce_StringArray.h" -#include "../files/juce_File.h" -#include "../memory/juce_ScopedPointer.h" -class InputSource; - //============================================================================== /** @@ -164,13 +158,14 @@ private: bool needToLoadDTD, ignoreEmptyTextElements; ScopedPointer inputSource; + XmlElement* parseDocumentElement (String::CharPointerType, bool outer); void setLastError (const String& desc, bool carryOn); - void skipHeader(); + bool parseHeader(); + bool parseDTD(); void skipNextWhiteSpace(); juce_wchar readNextChar() noexcept; XmlElement* readNextElement (bool alsoParseSubElements); void readChildElements (XmlElement* parent); - int findNextTokenLength() noexcept; void readQuotedString (String& result); void readEntity (String& result); diff --git a/source/modules/juce_core/xml/juce_XmlElement.cpp b/source/modules/juce_core/xml/juce_XmlElement.cpp index 7b34f59f3..eb06df3f7 100644 --- a/source/modules/juce_core/xml/juce_XmlElement.cpp +++ b/source/modules/juce_core/xml/juce_XmlElement.cpp @@ -209,7 +209,7 @@ namespace XmlOutputFunctions } } - static void writeSpaces (OutputStream& out, const int numSpaces) + static void writeSpaces (OutputStream& out, const size_t numSpaces) { out.writeRepeatedByte (' ', numSpaces); } @@ -222,7 +222,7 @@ void XmlElement::writeElementAsText (OutputStream& outputStream, using namespace XmlOutputFunctions; if (indentationLevel >= 0) - writeSpaces (outputStream, indentationLevel); + writeSpaces (outputStream, (size_t) indentationLevel); if (! isTextElement()) { @@ -230,7 +230,7 @@ void XmlElement::writeElementAsText (OutputStream& outputStream, outputStream << tagName; { - const int attIndent = indentationLevel + tagName.length() + 1; + const size_t attIndent = (size_t) (indentationLevel + tagName.length() + 1); int lineLen = 0; for (const XmlAttributeNode* att = attributes; att != nullptr; att = att->nextListItem) @@ -279,7 +279,7 @@ void XmlElement::writeElementAsText (OutputStream& outputStream, if (indentationLevel >= 0 && ! lastWasTextNode) { outputStream << newLine; - writeSpaces (outputStream, indentationLevel); + writeSpaces (outputStream, (size_t) indentationLevel); } outputStream.write ("hasName (attributeName)) { - juce_wchar firstChar = att->value[0]; - - if (CharacterFunctions::isWhitespace (firstChar)) - firstChar = att->value.trimStart() [0]; + const juce_wchar firstChar = *(att->value.getCharPointer().findEndOfWhitespace()); return firstChar == '1' || firstChar == 't' @@ -531,7 +528,7 @@ void XmlElement::setAttribute (const String& attributeName, const int number) void XmlElement::setAttribute (const String& attributeName, const double number) { - setAttribute (attributeName, String (number)); + setAttribute (attributeName, String (number, 20)); } void XmlElement::removeAttribute (const String& attributeName) noexcept @@ -791,7 +788,7 @@ String XmlElement::getAllSubText() const for (const XmlElement* child = firstChildElement; child != nullptr; child = child->nextListItem) mem << child->getAllSubText(); - return mem.toString(); + return mem.toUTF8(); } String XmlElement::getChildElementAllSubText (const String& childTagName, diff --git a/source/modules/juce_core/xml/juce_XmlElement.h b/source/modules/juce_core/xml/juce_XmlElement.h index 89c97c178..415308882 100644 --- a/source/modules/juce_core/xml/juce_XmlElement.h +++ b/source/modules/juce_core/xml/juce_XmlElement.h @@ -29,11 +29,6 @@ #ifndef JUCE_XMLELEMENT_H_INCLUDED #define JUCE_XMLELEMENT_H_INCLUDED -#include "../text/juce_String.h" -#include "../streams/juce_OutputStream.h" -#include "../files/juce_File.h" -#include "../containers/juce_LinkedListPointer.h" - //============================================================================== /** A handy macro to make it easy to iterate all the child elements in an XmlElement. diff --git a/source/modules/juce_core/zip/juce_GZIPCompressorOutputStream.cpp b/source/modules/juce_core/zip/juce_GZIPCompressorOutputStream.cpp index feea3f7f0..7f99ef5aa 100644 --- a/source/modules/juce_core/zip/juce_GZIPCompressorOutputStream.cpp +++ b/source/modules/juce_core/zip/juce_GZIPCompressorOutputStream.cpp @@ -103,7 +103,7 @@ private: { data += dataSize - stream.avail_in; dataSize = stream.avail_in; - const ssize_t bytesDone = sizeof (buffer) - (ssize_t) stream.avail_out; + const ssize_t bytesDone = (ssize_t) sizeof (buffer) - (ssize_t) stream.avail_out; return bytesDone <= 0 || out.write (buffer, (size_t) bytesDone); } diff --git a/source/modules/juce_core/zip/juce_GZIPCompressorOutputStream.h b/source/modules/juce_core/zip/juce_GZIPCompressorOutputStream.h index 9a2b93681..fe484b08e 100644 --- a/source/modules/juce_core/zip/juce_GZIPCompressorOutputStream.h +++ b/source/modules/juce_core/zip/juce_GZIPCompressorOutputStream.h @@ -29,10 +29,6 @@ #ifndef JUCE_GZIPCOMPRESSOROUTPUTSTREAM_H_INCLUDED #define JUCE_GZIPCOMPRESSOROUTPUTSTREAM_H_INCLUDED -#include "../streams/juce_OutputStream.h" -#include "../memory/juce_OptionalScopedPointer.h" -#include "../memory/juce_HeapBlock.h" - //============================================================================== /** @@ -96,8 +92,8 @@ private: OptionalScopedPointer destStream; class GZIPCompressorHelper; - friend class ScopedPointer ; - ScopedPointer helper; + friend struct ContainerDeletePolicy; + ScopedPointer helper; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (GZIPCompressorOutputStream) }; diff --git a/source/modules/juce_core/zip/juce_GZIPDecompressorInputStream.cpp b/source/modules/juce_core/zip/juce_GZIPDecompressorInputStream.cpp index d67c6a557..4a72305be 100644 --- a/source/modules/juce_core/zip/juce_GZIPDecompressorInputStream.cpp +++ b/source/modules/juce_core/zip/juce_GZIPDecompressorInputStream.cpp @@ -165,29 +165,29 @@ private: }; //============================================================================== -GZIPDecompressorInputStream::GZIPDecompressorInputStream (InputStream* const sourceStream_, +GZIPDecompressorInputStream::GZIPDecompressorInputStream (InputStream* const source, const bool deleteSourceWhenDestroyed, const bool noWrap_, const int64 uncompressedStreamLength_) - : sourceStream (sourceStream_, deleteSourceWhenDestroyed), + : sourceStream (source, deleteSourceWhenDestroyed), uncompressedStreamLength (uncompressedStreamLength_), noWrap (noWrap_), isEof (false), activeBufferSize (0), - originalSourcePos (sourceStream_->getPosition()), + originalSourcePos (source->getPosition()), currentPos (0), buffer ((size_t) GZIPDecompressHelper::gzipDecompBufferSize), helper (new GZIPDecompressHelper (noWrap_)) { } -GZIPDecompressorInputStream::GZIPDecompressorInputStream (InputStream& sourceStream_) - : sourceStream (&sourceStream_, false), +GZIPDecompressorInputStream::GZIPDecompressorInputStream (InputStream& source) + : sourceStream (&source, false), uncompressedStreamLength (-1), noWrap (false), isEof (false), activeBufferSize (0), - originalSourcePos (sourceStream_.getPosition()), + originalSourcePos (source.getPosition()), currentPos (0), buffer ((size_t) GZIPDecompressHelper::gzipDecompBufferSize), helper (new GZIPDecompressHelper (false)) diff --git a/source/modules/juce_core/zip/juce_GZIPDecompressorInputStream.h b/source/modules/juce_core/zip/juce_GZIPDecompressorInputStream.h index bc859d488..78a0b77b7 100644 --- a/source/modules/juce_core/zip/juce_GZIPDecompressorInputStream.h +++ b/source/modules/juce_core/zip/juce_GZIPDecompressorInputStream.h @@ -29,10 +29,6 @@ #ifndef JUCE_GZIPDECOMPRESSORINPUTSTREAM_H_INCLUDED #define JUCE_GZIPDECOMPRESSORINPUTSTREAM_H_INCLUDED -#include "../streams/juce_InputStream.h" -#include "../memory/juce_OptionalScopedPointer.h" -#include "../memory/juce_HeapBlock.h" - //============================================================================== /** @@ -92,8 +88,8 @@ private: HeapBlock buffer; class GZIPDecompressHelper; - friend class ScopedPointer ; - ScopedPointer helper; + friend struct ContainerDeletePolicy; + ScopedPointer helper; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (GZIPDecompressorInputStream) }; diff --git a/source/modules/juce_core/zip/juce_ZipFile.h b/source/modules/juce_core/zip/juce_ZipFile.h index 1b8f120e4..23f87d373 100644 --- a/source/modules/juce_core/zip/juce_ZipFile.h +++ b/source/modules/juce_core/zip/juce_ZipFile.h @@ -29,11 +29,6 @@ #ifndef JUCE_ZIPFILE_H_INCLUDED #define JUCE_ZIPFILE_H_INCLUDED -#include "../files/juce_File.h" -#include "../streams/juce_InputSource.h" -#include "../threads/juce_CriticalSection.h" -#include "../containers/juce_OwnedArray.h" - //============================================================================== /** @@ -210,7 +205,7 @@ public: //============================================================================== private: class Item; - friend class OwnedArray; + friend struct ContainerDeletePolicy; OwnedArray items; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Builder)