From b67c077f0d0746385a24a2fc857559d667d950b8 Mon Sep 17 00:00:00 2001 From: Julian Storer Date: Sat, 27 Mar 2010 18:29:09 +0000 Subject: [PATCH] Minor code clean-ups. --- juce_amalgamated.cpp | 234 +++++++++--------- juce_amalgamated.h | 166 +++++++------ src/application/juce_ApplicationCommandInfo.h | 2 +- .../juce_AudioThumbnailCache.h | 2 +- src/audio/devices/juce_AudioIODeviceType.h | 2 +- src/audio/devices/juce_MidiInput.h | 2 +- src/audio/dsp/juce_AudioDataConverters.h | 5 + src/audio/midi/juce_MidiBuffer.cpp | 67 ++--- src/audio/midi/juce_MidiBuffer.h | 7 +- src/audio/midi/juce_MidiMessage.cpp | 54 ++-- src/audio/midi/juce_MidiMessage.h | 8 +- src/containers/juce_HeapBlock.h | 16 +- src/containers/juce_ValueTree.h | 2 +- src/core/juce_ByteOrder.h | 24 +- src/core/juce_Random.h | 2 +- src/cryptography/juce_MD5.h | 6 +- src/cryptography/juce_Primes.h | 6 + src/cryptography/juce_RSAKey.h | 2 +- src/gui/components/buttons/juce_Button.h | 2 +- src/gui/components/buttons/juce_ImageButton.h | 2 +- src/gui/components/controls/juce_ComboBox.h | 2 +- .../components/controls/juce_ProgressBar.h | 2 +- src/gui/components/controls/juce_Slider.h | 2 +- src/gui/components/controls/juce_TextEditor.h | 4 +- src/gui/components/juce_Component.h | 2 +- .../keyboard/juce_KeyPressMappingSet.h | 2 +- .../components/layout/juce_TabbedComponent.h | 2 +- src/gui/components/layout/juce_Viewport.h | 2 +- .../components/mouse/juce_LassoComponent.h | 2 +- .../special/juce_WebBrowserComponent.h | 2 +- .../components/windows/juce_TooltipWindow.h | 4 +- src/gui/graphics/colour/juce_PixelFormats.h | 4 + src/gui/graphics/contexts/juce_Graphics.h | 2 +- .../juce_LowLevelGraphicsSoftwareRenderer.cpp | 8 +- src/gui/graphics/fonts/juce_Typeface.h | 4 +- src/gui/graphics/geometry/juce_BorderSize.h | 2 +- src/io/files/juce_FileInputStream.h | 2 +- src/io/streams/juce_InputStream.cpp | 22 +- src/native/linux/juce_linux_Audio.cpp | 4 +- src/native/linux/juce_linux_Windowing.cpp | 20 +- src/native/mac/juce_mac_CoreMidi.cpp | 2 +- src/native/windows/juce_win32_Messaging.cpp | 2 +- src/text/juce_String.cpp | 53 ++-- src/text/juce_XmlElement.h | 2 +- src/threads/juce_InterProcessLock.h | 2 +- src/threads/juce_Process.h | 6 + src/threads/juce_ScopedLock.h | 8 +- src/threads/juce_ScopedReadLock.h | 4 +- src/threads/juce_ScopedTryLock.h | 6 +- src/threads/juce_ScopedWriteLock.h | 4 +- src/threads/juce_Thread.h | 4 +- src/threads/juce_ThreadPool.h | 2 +- src/threads/juce_TimeSliceThread.h | 2 +- src/utilities/juce_SelectedItemSet.h | 2 +- 54 files changed, 441 insertions(+), 363 deletions(-) diff --git a/juce_amalgamated.cpp b/juce_amalgamated.cpp index e7791a1517..183cd5ecb4 100644 --- a/juce_amalgamated.cpp +++ b/juce_amalgamated.cpp @@ -5085,35 +5085,37 @@ int InputStream::readCompressedInt() int64 InputStream::readInt64() { - char temp[8]; + union { uint8 asBytes[8]; uint64 asInt64; } n; - if (read (temp, 8) == 8) - return (int64) ByteOrder::swapIfBigEndian (*reinterpret_cast (temp)); + if (read (n.asBytes, 8) == 8) + return (int64) ByteOrder::swapIfBigEndian (n.asInt64); return 0; } int64 InputStream::readInt64BigEndian() { - char temp[8]; + union { uint8 asBytes[8]; uint64 asInt64; } n; - if (read (temp, 8) == 8) - return (int64) ByteOrder::swapIfLittleEndian (*reinterpret_cast (temp)); + if (read (n.asBytes, 8) == 8) + return (int64) ByteOrder::swapIfLittleEndian (n.asInt64); return 0; } float InputStream::readFloat() { - union { int asInt; float asFloat; } n; - n.asInt = readInt(); + // the union below relies on these types being the same size... + static_jassert (sizeof (int32) == sizeof (float)); + union { int32 asInt; float asFloat; } n; + n.asInt = (int32) readInt(); return n.asFloat; } float InputStream::readFloatBigEndian() { - union { int asInt; float asFloat; } n; - n.asInt = readIntBigEndian(); + union { int32 asInt; float asFloat; } n; + n.asInt = (int32) readIntBigEndian(); return n.asFloat; } @@ -10322,10 +10324,10 @@ public: static StringHolder empty; private: - static inline StringHolder* bufferFromText (juce_wchar* const text) throw() + static inline StringHolder* bufferFromText (void* const text) throw() { // (Can't use offsetof() here because of warnings about this not being a POD) - return reinterpret_cast (reinterpret_cast (text) + return reinterpret_cast (static_cast (text) - (reinterpret_cast (reinterpret_cast (1)->text) - 1)); } }; @@ -11533,9 +11535,7 @@ const String String::substring (int start, int end) const return empty; int len = 0; - const juce_wchar* const t = text; - - while (len <= end && t [len] != 0) + while (len <= end && text [len] != 0) ++len; if (end >= len) @@ -11558,8 +11558,8 @@ const String String::substring (const int start) const if (start >= len) return empty; - else - return String (text + start, len - start); + + return String (text + start, len - start); } const String String::dropLastCharacters (const int numberToDrop) const @@ -11578,11 +11578,10 @@ const String String::fromFirstOccurrenceOf (const String& sub, { const int i = ignoreCase ? indexOfIgnoreCase (sub) : indexOf (sub); - if (i < 0) return empty; - else - return substring (includeSubString ? i : i + sub.length()); + + return substring (includeSubString ? i : i + sub.length()); } const String String::fromLastOccurrenceOf (const String& sub, @@ -11591,7 +11590,6 @@ const String String::fromLastOccurrenceOf (const String& sub, { const int i = ignoreCase ? lastIndexOfIgnoreCase (sub) : lastIndexOf (sub); - if (i < 0) return *this; @@ -11604,7 +11602,6 @@ const String String::upToFirstOccurrenceOf (const String& sub, { const int i = ignoreCase ? indexOfIgnoreCase (sub) : indexOf (sub); - if (i < 0) return *this; @@ -11685,8 +11682,8 @@ const String String::trim() const return empty; else if (start > 0 || end < len) return String (text + start, end - start); - else - return *this; + + return *this; } const String String::trimStart() const @@ -11701,8 +11698,8 @@ const String String::trimStart() const if (t == text) return *this; - else - return String (t); + + return String (t); } const String String::trimEnd() const @@ -11720,9 +11717,6 @@ const String String::trimEnd() const const String String::trimCharactersAtStart (const String& charactersToTrim) const { - if (isEmpty()) - return empty; - const juce_wchar* t = text; while (charactersToTrim.containsChar (*t)) @@ -11730,8 +11724,8 @@ const String String::trimCharactersAtStart (const String& charactersToTrim) cons if (t == text) return *this; - else - return String (t); + + return String (t); } const String String::trimCharactersAtEnd (const String& charactersToTrim) const @@ -11791,7 +11785,17 @@ const String String::removeCharacters (const String& charactersToRemove) const const String String::initialSectionContainingOnly (const String& permittedCharacters) const { - return substring (0, CharacterFunctions::getIntialSectionContainingOnly (text, permittedCharacters.text)); + int i = 0; + + for (;;) + { + if (! permittedCharacters.containsChar (text[i])) + break; + + ++i; + } + + return substring (0, i); } const String String::initialSectionNotContaining (const String& charactersToStopAt) const @@ -12104,7 +12108,7 @@ const char* String::toUTF8() const String* const mutableThis = const_cast (this); mutableThis->text = StringHolder::makeUniqueWithSize (mutableThis->text, currentLen + 1 + utf8BytesNeeded / sizeof (juce_wchar)); - char* const otherCopy = (char*) (text + currentLen); + char* const otherCopy = reinterpret_cast (text + currentLen); copyToUTF8 (otherCopy, std::numeric_limits::max()); return otherCopy; @@ -12291,12 +12295,11 @@ const char* String::toCString() const } else { - int len = length(); - + const int len = length(); String* const mutableThis = const_cast (this); mutableThis->text = StringHolder::makeUniqueWithSize (mutableThis->text, (len + 1) * 2); - char* otherCopy = (char*) (text + len + 1); + char* otherCopy = reinterpret_cast (text + len + 1); CharacterFunctions::copy (otherCopy, text, len); otherCopy [len] = 0; return otherCopy; @@ -26339,6 +26342,26 @@ MidiBuffer::~MidiBuffer() throw() { } +inline uint8* MidiBuffer::getData() const throw() +{ + return static_cast (data.getData()); +} + +inline int MidiBuffer::getEventTime (const void* const d) throw() +{ + return *static_cast (d); +} + +inline uint16 MidiBuffer::getEventDataSize (const void* const d) throw() +{ + return *reinterpret_cast (static_cast (d) + sizeof (int)); +} + +inline uint16 MidiBuffer::getEventTotalSize (const void* const d) throw() +{ + return getEventDataSize (d) + sizeof (int) + sizeof (uint16); +} + void MidiBuffer::clear() throw() { bytesUsed = 0; @@ -26406,23 +26429,23 @@ void MidiBuffer::addEvent (const uint8* const newData, if (numBytes > 0) { - int spaceNeeded = bytesUsed + numBytes + 6; + int spaceNeeded = bytesUsed + numBytes + sizeof (int) + sizeof (uint16); data.ensureSize ((spaceNeeded + spaceNeeded / 2 + 8) & ~7); uint8* d = findEventAfter (getData(), sampleNumber); const int bytesToMove = bytesUsed - (int) (d - getData()); if (bytesToMove > 0) - memmove (d + numBytes + 6, d, bytesToMove); + memmove (d + numBytes + sizeof (int) + sizeof (uint16), d, bytesToMove); *reinterpret_cast (d) = sampleNumber; - d += 4; + d += sizeof (int); *reinterpret_cast (d) = (uint16) numBytes; - d += 2; + d += sizeof (uint16); memcpy (d, newData, numBytes); - bytesUsed += numBytes + 6; + bytesUsed += numBytes + sizeof (int) + sizeof (uint16); } } @@ -26457,8 +26480,7 @@ int MidiBuffer::getNumEvents() const throw() while (d < end) { - d += 4; - d += 2 + *reinterpret_cast (d); + d += getEventTotalSize (d); ++n; } @@ -26467,7 +26489,7 @@ int MidiBuffer::getNumEvents() const throw() int MidiBuffer::getFirstEventTime() const throw() { - return (bytesUsed > 0) ? *reinterpret_cast (data.getData()) : 0; + return bytesUsed > 0 ? getEventTime (data.getData()) : 0; } int MidiBuffer::getLastEventTime() const throw() @@ -26480,10 +26502,10 @@ int MidiBuffer::getLastEventTime() const throw() for (;;) { - const uint8* nextOne = d + 6 + *reinterpret_cast (d + 4); + const uint8* const nextOne = d + getEventTotalSize (d); if (nextOne >= endData) - return *reinterpret_cast (d); + return getEventTime (d); d = nextOne; } @@ -26493,11 +26515,8 @@ uint8* MidiBuffer::findEventAfter (uint8* d, const int samplePosition) const thr { const uint8* const endData = getData() + bytesUsed; - while (d < endData && *reinterpret_cast (d) <= samplePosition) - { - d += 4; - d += 2 + *reinterpret_cast (d); - } + while (d < endData && getEventTime (d) <= samplePosition) + d += getEventTotalSize (d); return d; } @@ -26517,11 +26536,8 @@ void MidiBuffer::Iterator::setNextSamplePosition (const int samplePosition) thro data = buffer.getData(); const uint8* dataEnd = data + buffer.bytesUsed; - while (data < dataEnd && *reinterpret_cast (data) < samplePosition) - { - data += 4; - data += 2 + *(uint16*) data; - } + while (data < dataEnd && getEventTime (data) < samplePosition) + data += getEventTotalSize (data); } bool MidiBuffer::Iterator::getNextEvent (const uint8* &midiData, int& numBytes, int& samplePosition) throw() @@ -26529,10 +26545,9 @@ bool MidiBuffer::Iterator::getNextEvent (const uint8* &midiData, int& numBytes, if (data >= buffer.getData() + buffer.bytesUsed) return false; - samplePosition = *reinterpret_cast (data); - data += 4; - numBytes = *reinterpret_cast (data); - data += 2; + samplePosition = getEventTime (data); + numBytes = getEventDataSize (data); + data += sizeof (int) + sizeof (uint16); midiData = data; data += numBytes; @@ -26544,10 +26559,9 @@ bool MidiBuffer::Iterator::getNextEvent (MidiMessage& result, int& samplePositio if (data >= buffer.getData() + buffer.bytesUsed) return false; - samplePosition = *reinterpret_cast (data); - data += 4; - const int numBytes = *reinterpret_cast (data); - data += 2; + samplePosition = getEventTime (data); + const int numBytes = getEventDataSize (data); + data += sizeof (int) + sizeof (uint16); result = MidiMessage (data, numBytes, samplePosition); data += numBytes; @@ -27189,26 +27203,24 @@ int MidiMessage::getMessageLengthFromFirstByte (const uint8 firstByte) throw() MidiMessage::MidiMessage (const void* const d, const int dataSize, const double t) : timeStamp (t), - message (0), size (dataSize) { jassert (dataSize > 0); if (dataSize <= 4) - data = (uint8*) &message; + data = static_cast (preallocatedData.asBytes); else - data = (uint8*) juce_malloc (dataSize); + data = static_cast (juce_malloc (dataSize)); memcpy (data, d, dataSize); // check that the length matches the data.. - jassert (size > 3 || *reinterpret_cast (d) >= 0xf0 - || getMessageLengthFromFirstByte (*reinterpret_cast (d)) == size); + jassert (size > 3 || data[0] >= 0xf0 || getMessageLengthFromFirstByte (data[0]) == size); } MidiMessage::MidiMessage (const int byte1, const double t) throw() : timeStamp (t), - data ((uint8*) &message), + data (static_cast (preallocatedData.asBytes)), size (1) { data[0] = (uint8) byte1; @@ -27219,7 +27231,7 @@ MidiMessage::MidiMessage (const int byte1, const double t) throw() MidiMessage::MidiMessage (const int byte1, const int byte2, const double t) throw() : timeStamp (t), - data ((uint8*) &message), + data (static_cast (preallocatedData.asBytes)), size (2) { data[0] = (uint8) byte1; @@ -27231,7 +27243,7 @@ MidiMessage::MidiMessage (const int byte1, const int byte2, const double t) thro MidiMessage::MidiMessage (const int byte1, const int byte2, const int byte3, const double t) throw() : timeStamp (t), - data ((uint8*) &message), + data (static_cast (preallocatedData.asBytes)), size (3) { data[0] = (uint8) byte1; @@ -27244,40 +27256,39 @@ MidiMessage::MidiMessage (const int byte1, const int byte2, const int byte3, con MidiMessage::MidiMessage (const MidiMessage& other) : timeStamp (other.timeStamp), - message (other.message), size (other.size) { - if (other.data != (uint8*) &other.message) + if (other.data != static_cast (other.preallocatedData.asBytes)) { - data = (uint8*) juce_malloc (size); + data = static_cast (juce_malloc (size)); memcpy (data, other.data, size); } else { - data = (uint8*) &message; + data = static_cast (preallocatedData.asBytes); + preallocatedData.asInt32 = other.preallocatedData.asInt32; } } MidiMessage::MidiMessage (const MidiMessage& other, const double newTimeStamp) : timeStamp (newTimeStamp), - message (other.message), size (other.size) { - if (other.data != (uint8*) &other.message) + if (other.data != static_cast (other.preallocatedData.asBytes)) { - data = (uint8*) juce_malloc (size); + data = static_cast (juce_malloc (size)); memcpy (data, other.data, size); } else { - data = (uint8*) &message; + data = static_cast (preallocatedData.asBytes); + preallocatedData.asInt32 = other.preallocatedData.asInt32; } } MidiMessage::MidiMessage (const void* src_, int sz, int& numBytesUsed, const uint8 lastStatusByte, double t) : timeStamp (t), - data ((uint8*) &message), - message (0) + data (static_cast (preallocatedData.asBytes)) { const uint8* src = static_cast (src_); unsigned int byte = (unsigned int) *src; @@ -27315,7 +27326,7 @@ MidiMessage::MidiMessage (const void* src_, int sz, int& numBytesUsed, const uin size = 1 + (int) (d - src); - data = (uint8*) juce_malloc (size); + data = static_cast (juce_malloc (size)); *data = (uint8) byte; memcpy (data + 1, src, size - 1); } @@ -27325,14 +27336,15 @@ MidiMessage::MidiMessage (const void* src_, int sz, int& numBytesUsed, const uin const int bytesLeft = readVariableLengthVal (src + 1, n); size = jmin (sz + 1, n + 2 + bytesLeft); - data = (uint8*) juce_malloc (size); + data = static_cast (juce_malloc (size)); *data = (uint8) byte; memcpy (data + 1, src, size - 1); } else { + preallocatedData.asInt32 = 0; size = getMessageLengthFromFirstByte ((uint8) byte); - *data = (uint8) byte; + data[0] = (uint8) byte; if (size > 1) { @@ -27347,7 +27359,7 @@ MidiMessage::MidiMessage (const void* src_, int sz, int& numBytesUsed, const uin } else { - message = 0; + preallocatedData.asInt32 = 0; size = 0; } } @@ -27358,19 +27370,19 @@ MidiMessage& MidiMessage::operator= (const MidiMessage& other) { timeStamp = other.timeStamp; size = other.size; - message = other.message; - if (data != (uint8*) &message) + if (data != static_cast (preallocatedData.asBytes)) juce_free (data); - if (other.data != (uint8*) &other.message) + if (other.data != static_cast (other.preallocatedData.asBytes)) { - data = (uint8*) juce_malloc (size); + data = static_cast (juce_malloc (size)); memcpy (data, other.data, size); } else { - data = (uint8*) &message; + data = static_cast (preallocatedData.asBytes); + preallocatedData.asInt32 = other.preallocatedData.asInt32; } } @@ -27379,7 +27391,7 @@ MidiMessage& MidiMessage::operator= (const MidiMessage& other) MidiMessage::~MidiMessage() { - if (data != (uint8*) &message) + if (data != static_cast (preallocatedData.asBytes)) juce_free (data); } @@ -81506,11 +81518,9 @@ public: y = y_; generate (scratchBuffer, x, width); - const uint8* mask = reinterpret_cast (scratchBuffer.getData()); - if (sizeof (SrcPixelType) == sizeof (PixelARGB)) - mask += PixelARGB::indexA; - - et.clipLineToMask (x, y_, mask, sizeof (SrcPixelType), width); + et.clipLineToMask (x, y_, + reinterpret_cast (scratchBuffer.getData()) + SrcPixelType::indexA, + sizeof (SrcPixelType), width); } private: @@ -213585,7 +213595,7 @@ void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* call static BOOL CALLBACK BroadcastEnumWindowProc (HWND hwnd, LPARAM lParam) { if (hwnd != juce_messageWindowHandle) - (reinterpret_cast (lParam))->add ((void*) hwnd); + reinterpret_cast (lParam)->add ((void*) hwnd); return TRUE; } @@ -231933,15 +231943,15 @@ public: const int width = image.getWidth(); const int height = image.getHeight(); - HeapBlock colour (width * height); + HeapBlock colour (width * height); int index = 0; for (int y = 0; y < height; ++y) for (int x = 0; x < width; ++x) - colour[index++] = image.getPixelAt (x, y).getARGB(); + colour[index++] = static_cast (image.getPixelAt (x, y).getARGB()); XImage* ximage = XCreateImage (display, CopyFromParent, 24, ZPixmap, - 0, reinterpret_cast (colour.getData()), + 0, colour.getData(), width, height, 32, 0); Pixmap pixmap = XCreatePixmap (display, DefaultRootWindow (display), @@ -231961,7 +231971,7 @@ public: const int width = image.getWidth(); const int height = image.getHeight(); const int stride = (width + 7) >> 3; - HeapBlock mask; + HeapBlock mask; mask.calloc (stride * height); const bool msbfirst = (BitmapBitOrder (display) == MSBFirst); @@ -231969,7 +231979,7 @@ public: { for (int x = 0; x < width; ++x) { - const uint8 bit = (uint8) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7))); + const char bit = (char) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7))); const int offset = y * stride + (x >> 3); if (image.getPixelAt (x, y).getAlpha() >= 128) @@ -231978,7 +231988,7 @@ public: } return XCreatePixmapFromBitmapData (display, DefaultRootWindow (display), - reinterpret_cast (mask.getData()), width, height, 1, 0, 1); + mask.getData(), width, height, 1, 0, 1); } void setIcon (const Image& newIcon) @@ -233824,7 +233834,7 @@ void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hot } const int stride = (cursorW + 7) >> 3; - HeapBlock maskPlane, sourcePlane; + HeapBlock maskPlane, sourcePlane; maskPlane.calloc (stride * cursorH); sourcePlane.calloc (stride * cursorH); @@ -233834,7 +233844,7 @@ void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hot { for (int x = cursorW; --x >= 0;) { - const uint8 mask = (uint8) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7))); + const char mask = (char) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7))); const int offset = y * stride + (x >> 3); const Colour c (im.getPixelAt (x, y)); @@ -233847,8 +233857,8 @@ void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hot } } - Pixmap sourcePixmap = XCreatePixmapFromBitmapData (display, root, reinterpret_cast (sourcePlane.getData()), cursorW, cursorH, 0xffff, 0, 1); - Pixmap maskPixmap = XCreatePixmapFromBitmapData (display, root, reinterpret_cast (maskPlane.getData()), cursorW, cursorH, 0xffff, 0, 1); + Pixmap sourcePixmap = XCreatePixmapFromBitmapData (display, root, sourcePlane.getData(), cursorW, cursorH, 0xffff, 0, 1); + Pixmap maskPixmap = XCreatePixmapFromBitmapData (display, root, maskPlane.getData(), cursorW, cursorH, 0xffff, 0, 1); XColor white, black; black.red = black.green = black.blue = 0; @@ -234512,7 +234522,7 @@ public: if (isInterleaved) { scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false); - float* interleaved = reinterpret_cast (scratch.getData()); + float* interleaved = static_cast (scratch.getData()); AudioDataConverters::interleaveSamples ((const float**) data, interleaved, numSamples, numChannelsRunning); AudioDataConverters::convertFloatToFormat (sampleFormat, interleaved, interleaved, numSamples * numChannelsRunning); @@ -234550,7 +234560,7 @@ public: if (isInterleaved) { scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false); - float* interleaved = reinterpret_cast (scratch.getData()); + float* interleaved = static_cast (scratch.getData()); snd_pcm_sframes_t num = snd_pcm_readi (handle, (void*) interleaved, numSamples); @@ -243259,7 +243269,7 @@ static const String getConnectedEndpointName (MIDIEndpointRef endpoint) if (s.isNotEmpty()) { if (result.isNotEmpty()) - result += (", "); + result += ", "; result += s; } @@ -251422,7 +251432,7 @@ static const String getConnectedEndpointName (MIDIEndpointRef endpoint) if (s.isNotEmpty()) { if (result.isNotEmpty()) - result += (", "); + result += ", "; result += s; } diff --git a/juce_amalgamated.h b/juce_amalgamated.h index 0da61887db..db4ea1704a 100644 --- a/juce_amalgamated.h +++ b/juce_amalgamated.h @@ -870,13 +870,13 @@ public: static uint64 swapIfLittleEndian (uint64 value); - static uint32 littleEndianInt (const char* bytes); + static uint32 littleEndianInt (const void* bytes); - static uint16 littleEndianShort (const char* bytes); + static uint16 littleEndianShort (const void* bytes); - static uint32 bigEndianInt (const char* bytes); + static uint32 bigEndianInt (const void* bytes); - static uint16 bigEndianShort (const char* bytes); + static uint16 bigEndianShort (const void* bytes); static int littleEndian24Bit (const char* bytes); @@ -944,10 +944,10 @@ inline uint64 ByteOrder::swap (uint64 value) 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 char* const bytes) { return *reinterpret_cast (bytes); } - inline uint16 ByteOrder::littleEndianShort (const char* const bytes) { return *reinterpret_cast (bytes); } - inline uint32 ByteOrder::bigEndianInt (const char* const bytes) { return swap (*reinterpret_cast (bytes)); } - inline uint16 ByteOrder::bigEndianShort (const char* const bytes) { return swap (*reinterpret_cast (bytes)); } + 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; } #else inline uint16 ByteOrder::swapIfBigEndian (const uint16 v) { return swap (v); } @@ -956,10 +956,10 @@ inline uint64 ByteOrder::swap (uint64 value) 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 char* const bytes) { return swap (*reinterpret_cast (bytes)); } - inline uint16 ByteOrder::littleEndianShort (const char* const bytes) { return swap (*reinterpret_cast (bytes)); } - inline uint32 ByteOrder::bigEndianInt (const char* const bytes) { return *reinterpret_cast (bytes); } - inline uint16 ByteOrder::bigEndianShort (const char* const bytes) { return *reinterpret_cast (bytes); } + 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; } #endif @@ -1513,8 +1513,8 @@ public: { } - HeapBlock (const size_t numElements) - : data (reinterpret_cast (::juce_malloc (numElements * sizeof (ElementType)))) + explicit HeapBlock (const size_t numElements) + : data (static_cast (::juce_malloc (numElements * sizeof (ElementType)))) { } @@ -1548,13 +1548,13 @@ public: void malloc (const size_t newNumElements, const size_t elementSize = sizeof (ElementType)) { ::juce_free (data); - data = reinterpret_cast (::juce_malloc (newNumElements * elementSize)); + data = static_cast (::juce_malloc (newNumElements * elementSize)); } void calloc (const size_t newNumElements, const size_t elementSize = sizeof (ElementType)) { ::juce_free (data); - data = reinterpret_cast (::juce_calloc (newNumElements * elementSize)); + data = static_cast (::juce_calloc (newNumElements * elementSize)); } void allocate (const size_t newNumElements, const bool initialiseToZero) @@ -1562,17 +1562,17 @@ public: ::juce_free (data); if (initialiseToZero) - data = reinterpret_cast (::juce_calloc (newNumElements * sizeof (ElementType))); + data = static_cast (::juce_calloc (newNumElements * sizeof (ElementType))); else - data = reinterpret_cast (::juce_malloc (newNumElements * sizeof (ElementType))); + data = static_cast (::juce_malloc (newNumElements * sizeof (ElementType))); } void realloc (const size_t newNumElements, const size_t elementSize = sizeof (ElementType)) { if (data == 0) - data = reinterpret_cast (::juce_malloc (newNumElements * elementSize)); + data = static_cast (::juce_malloc (newNumElements * elementSize)); else - data = reinterpret_cast (::juce_realloc (data, newNumElements * elementSize)); + data = static_cast (::juce_realloc (data, newNumElements * elementSize)); } void free() @@ -4509,7 +4509,7 @@ class JUCE_API XmlElement { public: - XmlElement (const String& tagName) throw(); + explicit XmlElement (const String& tagName) throw(); XmlElement (const XmlElement& other) throw(); @@ -6430,9 +6430,9 @@ class JUCE_API ScopedLock { public: - inline ScopedLock (const CriticalSection& lock) throw() : lock_ (lock) { lock.enter(); } + inline explicit ScopedLock (const CriticalSection& lock) throw() : lock_ (lock) { lock.enter(); } - inline ~ScopedLock() throw() { lock_.exit(); } + inline ~ScopedLock() throw() { lock_.exit(); } private: @@ -6446,9 +6446,9 @@ class ScopedUnlock { public: - inline ScopedUnlock (const CriticalSection& lock) throw() : lock_ (lock) { lock.exit(); } + inline explicit ScopedUnlock (const CriticalSection& lock) throw() : lock_ (lock) { lock.exit(); } - inline ~ScopedUnlock() throw() { lock_.enter(); } + inline ~ScopedUnlock() throw() { lock_.enter(); } private: @@ -6615,7 +6615,7 @@ class JUCE_API ValueTree { public: - ValueTree (const String& type); + explicit ValueTree (const String& type); ValueTree (const ValueTree& other); @@ -7117,7 +7117,7 @@ class JUCE_API Random { public: - Random (int64 seedValue) throw(); + explicit Random (int64 seedValue) throw(); ~Random() throw(); @@ -7518,15 +7518,15 @@ public: MD5& operator= (const MD5& other); - MD5 (const MemoryBlock& data); + explicit MD5 (const MemoryBlock& data); MD5 (const char* data, const size_t numBytes); - MD5 (const String& text); + explicit MD5 (const String& text); MD5 (InputStream& input, int64 numBytesToRead = -1); - MD5 (const File& file); + explicit MD5 (const File& file); ~MD5(); @@ -7580,6 +7580,11 @@ public: int numRandomSeeds = 0); static bool isProbablyPrime (const BigInteger& number, int certainty); + +private: + Primes(); + Primes (const Primes&); + Primes& operator= (const Primes&); }; #endif // __JUCE_PRIMES_JUCEHEADER__ @@ -7599,7 +7604,7 @@ public: RSAKey(); - RSAKey (const String& stringRepresentation); + explicit RSAKey (const String& stringRepresentation); ~RSAKey(); @@ -7679,7 +7684,7 @@ class JUCE_API FileInputStream : public InputStream { public: - FileInputStream (const File& fileToRead); + explicit FileInputStream (const File& fileToRead); ~FileInputStream(); @@ -8641,7 +8646,7 @@ class JUCE_API InterProcessLock { public: - InterProcessLock (const String& name); + explicit InterProcessLock (const String& name); ~InterProcessLock(); @@ -8702,6 +8707,11 @@ public: static void lowerPrivilege(); static bool JUCE_CALLTYPE isRunningUnderDebugger(); + +private: + Process(); + Process (const Process&); + Process& operator= (const Process&); }; #endif // __JUCE_PROCESS_JUCEHEADER__ @@ -8755,7 +8765,7 @@ class JUCE_API Thread { public: - Thread (const String& threadName); + explicit Thread (const String& threadName); virtual ~Thread(); @@ -8883,9 +8893,9 @@ class JUCE_API ScopedReadLock { public: - inline ScopedReadLock (const ReadWriteLock& lock) throw() : lock_ (lock) { lock.enterRead(); } + inline explicit ScopedReadLock (const ReadWriteLock& lock) throw() : lock_ (lock) { lock.enterRead(); } - inline ~ScopedReadLock() throw() { lock_.exitRead(); } + inline ~ScopedReadLock() throw() { lock_.exitRead(); } private: @@ -8910,11 +8920,11 @@ class JUCE_API ScopedTryLock { public: - inline ScopedTryLock (const CriticalSection& lock) throw() : lock_ (lock), lockWasSuccessful (lock.tryEnter()) {} + inline explicit ScopedTryLock (const CriticalSection& lock) throw() : lock_ (lock), lockWasSuccessful (lock.tryEnter()) {} - inline ~ScopedTryLock() throw() { if (lockWasSuccessful) lock_.exit(); } + inline ~ScopedTryLock() throw() { if (lockWasSuccessful) lock_.exit(); } - bool isLocked() const throw() { return lockWasSuccessful; } + bool isLocked() const throw() { return lockWasSuccessful; } private: @@ -8940,9 +8950,9 @@ class JUCE_API ScopedWriteLock { public: - inline ScopedWriteLock (const ReadWriteLock& lock) throw() : lock_ (lock) { lock.enterWrite(); } + inline explicit ScopedWriteLock (const ReadWriteLock& lock) throw() : lock_ (lock) { lock.enterWrite(); } - inline ~ScopedWriteLock() throw() { lock_.exitWrite(); } + inline ~ScopedWriteLock() throw() { lock_.exitWrite(); } private: @@ -8973,7 +8983,7 @@ class JUCE_API ThreadPoolJob { public: - ThreadPoolJob (const String& name); + explicit ThreadPoolJob (const String& name); virtual ~ThreadPoolJob(); @@ -9101,7 +9111,7 @@ class JUCE_API TimeSliceThread : public Thread { public: - TimeSliceThread (const String& threadName); + explicit TimeSliceThread (const String& threadName); ~TimeSliceThread(); @@ -10639,7 +10649,7 @@ public: protected: String name; - Typeface (const String& name) throw(); + explicit Typeface (const String& name) throw(); private: Typeface (const Typeface&); @@ -10652,7 +10662,7 @@ public: CustomTypeface(); - CustomTypeface (InputStream& serialisedTypefaceStream); + explicit CustomTypeface (InputStream& serialisedTypefaceStream); ~CustomTypeface(); @@ -11407,6 +11417,8 @@ public: { } + enum { indexA = 0 }; + private: uint8 a : 8; @@ -11832,7 +11844,7 @@ class JUCE_API Graphics { public: - Graphics (Image& imageToDrawOnto) throw(); + explicit Graphics (Image& imageToDrawOnto) throw(); ~Graphics() throw(); @@ -12176,7 +12188,7 @@ public: int bottomGap, int rightGap) throw(); - BorderSize (int allGaps) throw(); + explicit BorderSize (int allGaps) throw(); ~BorderSize() throw(); @@ -12234,7 +12246,7 @@ public: virtual ~Component(); - Component (const String& componentName); + explicit Component (const String& componentName); const String& getName() const throw() { return componentName_; } @@ -12813,7 +12825,7 @@ namespace StandardApplicationCommandIDs struct JUCE_API ApplicationCommandInfo { - ApplicationCommandInfo (CommandID commandID) throw(); + explicit ApplicationCommandInfo (CommandID commandID) throw(); void setInfo (const String& shortName, const String& description, @@ -14251,7 +14263,7 @@ class JUCE_API AudioThumbnailCache : public TimeSliceThread { public: - AudioThumbnailCache (int maxNumThumbsToStore); + explicit AudioThumbnailCache (int maxNumThumbsToStore); ~AudioThumbnailCache(); @@ -15174,7 +15186,7 @@ public: virtual ~AudioIODeviceType(); protected: - AudioIODeviceType (const String& typeName); + explicit AudioIODeviceType (const String& typeName); private: String typeName; @@ -15468,7 +15480,13 @@ public: private: double timeStamp; uint8* data; - int message, size; + int size; + + union + { + uint8 asBytes[4]; + uint32 asInt32; + } preallocatedData; }; #endif // __JUCE_MIDIMESSAGE_JUCEHEADER__ @@ -15526,7 +15544,7 @@ protected: String name; void* internal; - MidiInput (const String& name); + explicit MidiInput (const String& name); private: MidiInput (const MidiInput&); @@ -15552,7 +15570,7 @@ public: MidiBuffer() throw(); - MidiBuffer (const MidiMessage& message) throw(); + explicit MidiBuffer (const MidiMessage& message) throw(); MidiBuffer (const MidiBuffer& other) throw(); @@ -15621,8 +15639,11 @@ private: MemoryBlock data; int bytesUsed; - uint8* getData() const throw() { return reinterpret_cast (data.getData()); } + uint8* getData() const throw(); uint8* findEventAfter (uint8* d, const int samplePosition) const throw(); + static int getEventTime (const void* d) throw(); + static uint16 getEventDataSize (const void* d) throw(); + static uint16 getEventTotalSize (const void* d) throw(); }; #endif // __JUCE_MIDIBUFFER_JUCEHEADER__ @@ -15765,8 +15786,8 @@ class JUCE_API TooltipWindow : public Component, { public: - TooltipWindow (Component* parentComponent = 0, - int millisecondsBeforeTipAppears = 700); + explicit TooltipWindow (Component* parentComponent = 0, + int millisecondsBeforeTipAppears = 700); ~TooltipWindow(); @@ -15826,7 +15847,7 @@ class JUCE_API Button : public Component, { protected: - Button (const String& buttonName); + explicit Button (const String& buttonName); public: virtual ~Button(); @@ -16105,7 +16126,7 @@ class JUCE_API Viewport : public Component, { public: - Viewport (const String& componentName = String::empty); + explicit Viewport (const String& componentName = String::empty); ~Viewport(); @@ -16401,8 +16422,8 @@ class JUCE_API TextEditor : public Component, { public: - TextEditor (const String& componentName = String::empty, - tchar passwordCharacter = 0); + explicit TextEditor (const String& componentName = String::empty, + tchar passwordCharacter = 0); virtual ~TextEditor(); @@ -16821,7 +16842,7 @@ class JUCE_API ComboBox : public Component, { public: - ComboBox (const String& componentName); + explicit ComboBox (const String& componentName); ~ComboBox(); @@ -17194,6 +17215,11 @@ public: static void deinterleaveSamples (const float* source, float** dest, int numSamples, int numChannels); + +private: + AudioDataConverters(); + AudioDataConverters (const AudioDataConverters&); + AudioDataConverters& operator= (const AudioDataConverters&); }; #endif // __JUCE_AUDIODATACONVERTERS_JUCEHEADER__ @@ -20015,7 +20041,7 @@ class JUCE_API ImageButton : public Button { public: - ImageButton (const String& name); + explicit ImageButton (const String& name); ~ImageButton(); @@ -20979,7 +21005,7 @@ class JUCE_API ProgressBar : public Component, { public: - ProgressBar (double& progress); + explicit ProgressBar (double& progress); ~ProgressBar(); @@ -21058,7 +21084,7 @@ class JUCE_API Slider : public Component, { public: - Slider (const String& componentName); + explicit Slider (const String& componentName); ~Slider(); @@ -23481,7 +23507,7 @@ class JUCE_API KeyPressMappingSet : public KeyListener, { public: - KeyPressMappingSet (ApplicationCommandManager* commandManager) throw(); + explicit KeyPressMappingSet (ApplicationCommandManager* commandManager) throw(); KeyPressMappingSet (const KeyPressMappingSet& other) throw(); @@ -23873,7 +23899,7 @@ class JUCE_API TabbedComponent : public Component { public: - TabbedComponent (const TabbedButtonBar::Orientation orientation); + explicit TabbedComponent (const TabbedButtonBar::Orientation orientation); ~TabbedComponent(); @@ -25349,7 +25375,7 @@ public: { } - SelectedItemSet (const Array & items) + explicit SelectedItemSet (const Array & items) : selectedItems (items) { } @@ -25531,7 +25557,7 @@ class LassoComponent : public Component { public: - LassoComponent (const int outlineThickness_ = 1) + explicit LassoComponent (const int outlineThickness_ = 1) : source (0), outlineThickness (outlineThickness_) { @@ -26960,7 +26986,7 @@ class JUCE_API WebBrowserComponent : public Component { public: - WebBrowserComponent (bool unloadPageWhenBrowserIsHidden = true); + explicit WebBrowserComponent (bool unloadPageWhenBrowserIsHidden = true); ~WebBrowserComponent(); diff --git a/src/application/juce_ApplicationCommandInfo.h b/src/application/juce_ApplicationCommandInfo.h index 7df4f8b4ce..6d38fba376 100644 --- a/src/application/juce_ApplicationCommandInfo.h +++ b/src/application/juce_ApplicationCommandInfo.h @@ -48,7 +48,7 @@ struct JUCE_API ApplicationCommandInfo { //============================================================================== - ApplicationCommandInfo (CommandID commandID) throw(); + explicit ApplicationCommandInfo (CommandID commandID) throw(); //============================================================================== /** Sets a number of the structures values at once. diff --git a/src/audio/audio_file_formats/juce_AudioThumbnailCache.h b/src/audio/audio_file_formats/juce_AudioThumbnailCache.h index cdfed218ef..6df27964ba 100644 --- a/src/audio/audio_file_formats/juce_AudioThumbnailCache.h +++ b/src/audio/audio_file_formats/juce_AudioThumbnailCache.h @@ -49,7 +49,7 @@ public: The maxNumThumbsToStore parameter lets you specify how many previews should be kept in memory at once. */ - AudioThumbnailCache (int maxNumThumbsToStore); + explicit AudioThumbnailCache (int maxNumThumbsToStore); /** Destructor. */ ~AudioThumbnailCache(); diff --git a/src/audio/devices/juce_AudioIODeviceType.h b/src/audio/devices/juce_AudioIODeviceType.h index 0f90f9d404..3cac5d35ee 100644 --- a/src/audio/devices/juce_AudioIODeviceType.h +++ b/src/audio/devices/juce_AudioIODeviceType.h @@ -132,7 +132,7 @@ public: virtual ~AudioIODeviceType(); protected: - AudioIODeviceType (const String& typeName); + explicit AudioIODeviceType (const String& typeName); private: String typeName; diff --git a/src/audio/devices/juce_MidiInput.h b/src/audio/devices/juce_MidiInput.h index ba3d5d9c8e..677d4483ea 100644 --- a/src/audio/devices/juce_MidiInput.h +++ b/src/audio/devices/juce_MidiInput.h @@ -177,7 +177,7 @@ protected: String name; void* internal; - MidiInput (const String& name); + explicit MidiInput (const String& name); private: MidiInput (const MidiInput&); diff --git a/src/audio/dsp/juce_AudioDataConverters.h b/src/audio/dsp/juce_AudioDataConverters.h index fb8558bd5a..68c3cb03ed 100644 --- a/src/audio/dsp/juce_AudioDataConverters.h +++ b/src/audio/dsp/juce_AudioDataConverters.h @@ -87,6 +87,11 @@ public: static void deinterleaveSamples (const float* source, float** dest, int numSamples, int numChannels); + +private: + AudioDataConverters(); + AudioDataConverters (const AudioDataConverters&); + AudioDataConverters& operator= (const AudioDataConverters&); }; diff --git a/src/audio/midi/juce_MidiBuffer.cpp b/src/audio/midi/juce_MidiBuffer.cpp index 134e448e8d..09ecaa4537 100644 --- a/src/audio/midi/juce_MidiBuffer.cpp +++ b/src/audio/midi/juce_MidiBuffer.cpp @@ -66,6 +66,26 @@ MidiBuffer::~MidiBuffer() throw() { } +inline uint8* MidiBuffer::getData() const throw() +{ + return static_cast (data.getData()); +} + +inline int MidiBuffer::getEventTime (const void* const d) throw() +{ + return *static_cast (d); +} + +inline uint16 MidiBuffer::getEventDataSize (const void* const d) throw() +{ + return *reinterpret_cast (static_cast (d) + sizeof (int)); +} + +inline uint16 MidiBuffer::getEventTotalSize (const void* const d) throw() +{ + return getEventDataSize (d) + sizeof (int) + sizeof (uint16); +} + void MidiBuffer::clear() throw() { bytesUsed = 0; @@ -133,23 +153,23 @@ void MidiBuffer::addEvent (const uint8* const newData, if (numBytes > 0) { - int spaceNeeded = bytesUsed + numBytes + 6; + int spaceNeeded = bytesUsed + numBytes + sizeof (int) + sizeof (uint16); data.ensureSize ((spaceNeeded + spaceNeeded / 2 + 8) & ~7); uint8* d = findEventAfter (getData(), sampleNumber); const int bytesToMove = bytesUsed - (int) (d - getData()); if (bytesToMove > 0) - memmove (d + numBytes + 6, d, bytesToMove); + memmove (d + numBytes + sizeof (int) + sizeof (uint16), d, bytesToMove); *reinterpret_cast (d) = sampleNumber; - d += 4; + d += sizeof (int); *reinterpret_cast (d) = (uint16) numBytes; - d += 2; + d += sizeof (uint16); memcpy (d, newData, numBytes); - bytesUsed += numBytes + 6; + bytesUsed += numBytes + sizeof (int) + sizeof (uint16); } } @@ -184,8 +204,7 @@ int MidiBuffer::getNumEvents() const throw() while (d < end) { - d += 4; - d += 2 + *reinterpret_cast (d); + d += getEventTotalSize (d); ++n; } @@ -194,7 +213,7 @@ int MidiBuffer::getNumEvents() const throw() int MidiBuffer::getFirstEventTime() const throw() { - return (bytesUsed > 0) ? *reinterpret_cast (data.getData()) : 0; + return bytesUsed > 0 ? getEventTime (data.getData()) : 0; } int MidiBuffer::getLastEventTime() const throw() @@ -207,10 +226,10 @@ int MidiBuffer::getLastEventTime() const throw() for (;;) { - const uint8* nextOne = d + 6 + *reinterpret_cast (d + 4); + const uint8* const nextOne = d + getEventTotalSize (d); if (nextOne >= endData) - return *reinterpret_cast (d); + return getEventTime (d); d = nextOne; } @@ -220,11 +239,8 @@ uint8* MidiBuffer::findEventAfter (uint8* d, const int samplePosition) const thr { const uint8* const endData = getData() + bytesUsed; - while (d < endData && *reinterpret_cast (d) <= samplePosition) - { - d += 4; - d += 2 + *reinterpret_cast (d); - } + while (d < endData && getEventTime (d) <= samplePosition) + d += getEventTotalSize (d); return d; } @@ -246,11 +262,8 @@ void MidiBuffer::Iterator::setNextSamplePosition (const int samplePosition) thro data = buffer.getData(); const uint8* dataEnd = data + buffer.bytesUsed; - while (data < dataEnd && *reinterpret_cast (data) < samplePosition) - { - data += 4; - data += 2 + *(uint16*) data; - } + while (data < dataEnd && getEventTime (data) < samplePosition) + data += getEventTotalSize (data); } bool MidiBuffer::Iterator::getNextEvent (const uint8* &midiData, int& numBytes, int& samplePosition) throw() @@ -258,10 +271,9 @@ bool MidiBuffer::Iterator::getNextEvent (const uint8* &midiData, int& numBytes, if (data >= buffer.getData() + buffer.bytesUsed) return false; - samplePosition = *reinterpret_cast (data); - data += 4; - numBytes = *reinterpret_cast (data); - data += 2; + samplePosition = getEventTime (data); + numBytes = getEventDataSize (data); + data += sizeof (int) + sizeof (uint16); midiData = data; data += numBytes; @@ -273,10 +285,9 @@ bool MidiBuffer::Iterator::getNextEvent (MidiMessage& result, int& samplePositio if (data >= buffer.getData() + buffer.bytesUsed) return false; - samplePosition = *reinterpret_cast (data); - data += 4; - const int numBytes = *reinterpret_cast (data); - data += 2; + samplePosition = getEventTime (data); + const int numBytes = getEventDataSize (data); + data += sizeof (int) + sizeof (uint16); result = MidiMessage (data, numBytes, samplePosition); data += numBytes; diff --git a/src/audio/midi/juce_MidiBuffer.h b/src/audio/midi/juce_MidiBuffer.h index 098753fd64..88901b44ee 100644 --- a/src/audio/midi/juce_MidiBuffer.h +++ b/src/audio/midi/juce_MidiBuffer.h @@ -47,7 +47,7 @@ public: MidiBuffer() throw(); /** Creates a MidiBuffer containing a single midi message. */ - MidiBuffer (const MidiMessage& message) throw(); + explicit MidiBuffer (const MidiMessage& message) throw(); /** Creates a copy of another MidiBuffer. */ MidiBuffer (const MidiBuffer& other) throw(); @@ -229,8 +229,11 @@ private: MemoryBlock data; int bytesUsed; - uint8* getData() const throw() { return reinterpret_cast (data.getData()); } + uint8* getData() const throw(); uint8* findEventAfter (uint8* d, const int samplePosition) const throw(); + static int getEventTime (const void* d) throw(); + static uint16 getEventDataSize (const void* d) throw(); + static uint16 getEventTotalSize (const void* d) throw(); }; diff --git a/src/audio/midi/juce_MidiMessage.cpp b/src/audio/midi/juce_MidiMessage.cpp index 3590f3c737..417e7180da 100644 --- a/src/audio/midi/juce_MidiMessage.cpp +++ b/src/audio/midi/juce_MidiMessage.cpp @@ -78,26 +78,24 @@ int MidiMessage::getMessageLengthFromFirstByte (const uint8 firstByte) throw() //============================================================================== MidiMessage::MidiMessage (const void* const d, const int dataSize, const double t) : timeStamp (t), - message (0), size (dataSize) { jassert (dataSize > 0); if (dataSize <= 4) - data = (uint8*) &message; + data = static_cast (preallocatedData.asBytes); else - data = (uint8*) juce_malloc (dataSize); + data = static_cast (juce_malloc (dataSize)); memcpy (data, d, dataSize); // check that the length matches the data.. - jassert (size > 3 || *reinterpret_cast (d) >= 0xf0 - || getMessageLengthFromFirstByte (*reinterpret_cast (d)) == size); + jassert (size > 3 || data[0] >= 0xf0 || getMessageLengthFromFirstByte (data[0]) == size); } MidiMessage::MidiMessage (const int byte1, const double t) throw() : timeStamp (t), - data ((uint8*) &message), + data (static_cast (preallocatedData.asBytes)), size (1) { data[0] = (uint8) byte1; @@ -108,7 +106,7 @@ MidiMessage::MidiMessage (const int byte1, const double t) throw() MidiMessage::MidiMessage (const int byte1, const int byte2, const double t) throw() : timeStamp (t), - data ((uint8*) &message), + data (static_cast (preallocatedData.asBytes)), size (2) { data[0] = (uint8) byte1; @@ -120,7 +118,7 @@ MidiMessage::MidiMessage (const int byte1, const int byte2, const double t) thro MidiMessage::MidiMessage (const int byte1, const int byte2, const int byte3, const double t) throw() : timeStamp (t), - data ((uint8*) &message), + data (static_cast (preallocatedData.asBytes)), size (3) { data[0] = (uint8) byte1; @@ -133,40 +131,39 @@ MidiMessage::MidiMessage (const int byte1, const int byte2, const int byte3, con MidiMessage::MidiMessage (const MidiMessage& other) : timeStamp (other.timeStamp), - message (other.message), size (other.size) { - if (other.data != (uint8*) &other.message) + if (other.data != static_cast (other.preallocatedData.asBytes)) { - data = (uint8*) juce_malloc (size); + data = static_cast (juce_malloc (size)); memcpy (data, other.data, size); } else { - data = (uint8*) &message; + data = static_cast (preallocatedData.asBytes); + preallocatedData.asInt32 = other.preallocatedData.asInt32; } } MidiMessage::MidiMessage (const MidiMessage& other, const double newTimeStamp) : timeStamp (newTimeStamp), - message (other.message), size (other.size) { - if (other.data != (uint8*) &other.message) + if (other.data != static_cast (other.preallocatedData.asBytes)) { - data = (uint8*) juce_malloc (size); + data = static_cast (juce_malloc (size)); memcpy (data, other.data, size); } else { - data = (uint8*) &message; + data = static_cast (preallocatedData.asBytes); + preallocatedData.asInt32 = other.preallocatedData.asInt32; } } MidiMessage::MidiMessage (const void* src_, int sz, int& numBytesUsed, const uint8 lastStatusByte, double t) : timeStamp (t), - data ((uint8*) &message), - message (0) + data (static_cast (preallocatedData.asBytes)) { const uint8* src = static_cast (src_); unsigned int byte = (unsigned int) *src; @@ -204,7 +201,7 @@ MidiMessage::MidiMessage (const void* src_, int sz, int& numBytesUsed, const uin size = 1 + (int) (d - src); - data = (uint8*) juce_malloc (size); + data = static_cast (juce_malloc (size)); *data = (uint8) byte; memcpy (data + 1, src, size - 1); } @@ -214,14 +211,15 @@ MidiMessage::MidiMessage (const void* src_, int sz, int& numBytesUsed, const uin const int bytesLeft = readVariableLengthVal (src + 1, n); size = jmin (sz + 1, n + 2 + bytesLeft); - data = (uint8*) juce_malloc (size); + data = static_cast (juce_malloc (size)); *data = (uint8) byte; memcpy (data + 1, src, size - 1); } else { + preallocatedData.asInt32 = 0; size = getMessageLengthFromFirstByte ((uint8) byte); - *data = (uint8) byte; + data[0] = (uint8) byte; if (size > 1) { @@ -236,7 +234,7 @@ MidiMessage::MidiMessage (const void* src_, int sz, int& numBytesUsed, const uin } else { - message = 0; + preallocatedData.asInt32 = 0; size = 0; } } @@ -247,19 +245,19 @@ MidiMessage& MidiMessage::operator= (const MidiMessage& other) { timeStamp = other.timeStamp; size = other.size; - message = other.message; - if (data != (uint8*) &message) + if (data != static_cast (preallocatedData.asBytes)) juce_free (data); - if (other.data != (uint8*) &other.message) + if (other.data != static_cast (other.preallocatedData.asBytes)) { - data = (uint8*) juce_malloc (size); + data = static_cast (juce_malloc (size)); memcpy (data, other.data, size); } else { - data = (uint8*) &message; + data = static_cast (preallocatedData.asBytes); + preallocatedData.asInt32 = other.preallocatedData.asInt32; } } @@ -268,7 +266,7 @@ MidiMessage& MidiMessage::operator= (const MidiMessage& other) MidiMessage::~MidiMessage() { - if (data != (uint8*) &message) + if (data != static_cast (preallocatedData.asBytes)) juce_free (data); } diff --git a/src/audio/midi/juce_MidiMessage.h b/src/audio/midi/juce_MidiMessage.h index c6e2b3752a..38c89ad0a5 100644 --- a/src/audio/midi/juce_MidiMessage.h +++ b/src/audio/midi/juce_MidiMessage.h @@ -896,7 +896,13 @@ public: private: double timeStamp; uint8* data; - int message, size; + int size; + + union + { + uint8 asBytes[4]; + uint32 asInt32; + } preallocatedData; }; diff --git a/src/containers/juce_HeapBlock.h b/src/containers/juce_HeapBlock.h index a0e1800e30..041c7727a5 100644 --- a/src/containers/juce_HeapBlock.h +++ b/src/containers/juce_HeapBlock.h @@ -89,8 +89,8 @@ public: If you want an array of zero values, you can use the calloc() method instead. */ - HeapBlock (const size_t numElements) - : data (reinterpret_cast (::juce_malloc (numElements * sizeof (ElementType)))) + explicit HeapBlock (const size_t numElements) + : data (static_cast (::juce_malloc (numElements * sizeof (ElementType)))) { } @@ -180,7 +180,7 @@ public: void malloc (const size_t newNumElements, const size_t elementSize = sizeof (ElementType)) { ::juce_free (data); - data = reinterpret_cast (::juce_malloc (newNumElements * elementSize)); + data = static_cast (::juce_malloc (newNumElements * elementSize)); } /** Allocates a specified amount of memory and clears it. @@ -189,7 +189,7 @@ public: void calloc (const size_t newNumElements, const size_t elementSize = sizeof (ElementType)) { ::juce_free (data); - data = reinterpret_cast (::juce_calloc (newNumElements * elementSize)); + data = static_cast (::juce_calloc (newNumElements * elementSize)); } /** Allocates a specified amount of memory and optionally clears it. @@ -201,9 +201,9 @@ public: ::juce_free (data); if (initialiseToZero) - data = reinterpret_cast (::juce_calloc (newNumElements * sizeof (ElementType))); + data = static_cast (::juce_calloc (newNumElements * sizeof (ElementType))); else - data = reinterpret_cast (::juce_malloc (newNumElements * sizeof (ElementType))); + data = static_cast (::juce_malloc (newNumElements * sizeof (ElementType))); } /** Re-allocates a specified amount of memory. @@ -214,9 +214,9 @@ public: void realloc (const size_t newNumElements, const size_t elementSize = sizeof (ElementType)) { if (data == 0) - data = reinterpret_cast (::juce_malloc (newNumElements * elementSize)); + data = static_cast (::juce_malloc (newNumElements * elementSize)); else - data = reinterpret_cast (::juce_realloc (data, newNumElements * elementSize)); + data = static_cast (::juce_realloc (data, newNumElements * elementSize)); } /** Frees any currently-allocated data. diff --git a/src/containers/juce_ValueTree.h b/src/containers/juce_ValueTree.h index 63dcf349cd..eeff68e5c1 100644 --- a/src/containers/juce_ValueTree.h +++ b/src/containers/juce_ValueTree.h @@ -77,7 +77,7 @@ public: Like an XmlElement, each ValueTree node has a type, which you can access with getType() and hasType(). */ - ValueTree (const String& type); + explicit ValueTree (const String& type); /** Creates a reference to another ValueTree. */ ValueTree (const ValueTree& other); diff --git a/src/core/juce_ByteOrder.h b/src/core/juce_ByteOrder.h index 81663a6762..196865dad6 100644 --- a/src/core/juce_ByteOrder.h +++ b/src/core/juce_ByteOrder.h @@ -65,16 +65,16 @@ public: //============================================================================== /** Turns 4 bytes into a little-endian integer. */ - static uint32 littleEndianInt (const char* bytes); + static uint32 littleEndianInt (const void* bytes); /** Turns 2 bytes into a little-endian integer. */ - static uint16 littleEndianShort (const char* bytes); + static uint16 littleEndianShort (const void* bytes); /** Turns 4 bytes into a big-endian integer. */ - static uint32 bigEndianInt (const char* bytes); + static uint32 bigEndianInt (const void* bytes); /** Turns 2 bytes into a big-endian integer. */ - static uint16 bigEndianShort (const char* bytes); + static uint16 bigEndianShort (const void* bytes); //============================================================================== /** Converts 3 little-endian bytes into a signed 24-bit value (which is sign-extended to 32 bits). */ @@ -151,10 +151,10 @@ inline uint64 ByteOrder::swap (uint64 value) 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 char* const bytes) { return *reinterpret_cast (bytes); } - inline uint16 ByteOrder::littleEndianShort (const char* const bytes) { return *reinterpret_cast (bytes); } - inline uint32 ByteOrder::bigEndianInt (const char* const bytes) { return swap (*reinterpret_cast (bytes)); } - inline uint16 ByteOrder::bigEndianShort (const char* const bytes) { return swap (*reinterpret_cast (bytes)); } + 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; } #else inline uint16 ByteOrder::swapIfBigEndian (const uint16 v) { return swap (v); } @@ -163,10 +163,10 @@ inline uint64 ByteOrder::swap (uint64 value) 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 char* const bytes) { return swap (*reinterpret_cast (bytes)); } - inline uint16 ByteOrder::littleEndianShort (const char* const bytes) { return swap (*reinterpret_cast (bytes)); } - inline uint32 ByteOrder::bigEndianInt (const char* const bytes) { return *reinterpret_cast (bytes); } - inline uint16 ByteOrder::bigEndianShort (const char* const bytes) { return *reinterpret_cast (bytes); } + 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; } #endif diff --git a/src/core/juce_Random.h b/src/core/juce_Random.h index 4218988a80..052b384668 100644 --- a/src/core/juce_Random.h +++ b/src/core/juce_Random.h @@ -45,7 +45,7 @@ public: new Random (Time::currentTimeMillis()) */ - Random (int64 seedValue) throw(); + explicit Random (int64 seedValue) throw(); /** Destructor. */ ~Random() throw(); diff --git a/src/cryptography/juce_MD5.h b/src/cryptography/juce_MD5.h index bf4424d156..80d70e645e 100644 --- a/src/cryptography/juce_MD5.h +++ b/src/cryptography/juce_MD5.h @@ -55,7 +55,7 @@ public: //============================================================================== /** Creates a checksum for a block of binary data. */ - MD5 (const MemoryBlock& data); + explicit MD5 (const MemoryBlock& data); /** Creates a checksum for a block of binary data. */ MD5 (const char* data, const size_t numBytes); @@ -68,7 +68,7 @@ public: of this method with a checksum created by a different framework, which may have used a different encoding. */ - MD5 (const String& text); + explicit MD5 (const String& text); /** Creates a checksum for the input from a stream. @@ -79,7 +79,7 @@ public: MD5 (InputStream& input, int64 numBytesToRead = -1); /** Creates a checksum for a file. */ - MD5 (const File& file); + explicit MD5 (const File& file); /** Destructor. */ ~MD5(); diff --git a/src/cryptography/juce_Primes.h b/src/cryptography/juce_Primes.h index 5251c225ab..b5f6526963 100644 --- a/src/cryptography/juce_Primes.h +++ b/src/cryptography/juce_Primes.h @@ -64,6 +64,12 @@ public: safe value might be anything over about 20-30. */ static bool isProbablyPrime (const BigInteger& number, int certainty); + + +private: + Primes(); + Primes (const Primes&); + Primes& operator= (const Primes&); }; diff --git a/src/cryptography/juce_RSAKey.h b/src/cryptography/juce_RSAKey.h index d03d6f8a0b..2d1ebe80ff 100644 --- a/src/cryptography/juce_RSAKey.h +++ b/src/cryptography/juce_RSAKey.h @@ -50,7 +50,7 @@ public: This reloads a key from a string created by the toString() method. */ - RSAKey (const String& stringRepresentation); + explicit RSAKey (const String& stringRepresentation); /** Destructor. */ ~RSAKey(); diff --git a/src/gui/components/buttons/juce_Button.h b/src/gui/components/buttons/juce_Button.h index 3875421ea7..5cf275661d 100644 --- a/src/gui/components/buttons/juce_Button.h +++ b/src/gui/components/buttons/juce_Button.h @@ -79,7 +79,7 @@ protected: initially set to this string, but these can be changed later using the setName() and setButtonText() methods) */ - Button (const String& buttonName); + explicit Button (const String& buttonName); public: /** Destructor. */ diff --git a/src/gui/components/buttons/juce_ImageButton.h b/src/gui/components/buttons/juce_ImageButton.h index e7f408e4c0..82ffe4f744 100644 --- a/src/gui/components/buttons/juce_ImageButton.h +++ b/src/gui/components/buttons/juce_ImageButton.h @@ -49,7 +49,7 @@ public: @param name the name to give the component */ - ImageButton (const String& name); + explicit ImageButton (const String& name); /** Destructor. */ ~ImageButton(); diff --git a/src/gui/components/controls/juce_ComboBox.h b/src/gui/components/controls/juce_ComboBox.h index 72d94cc39a..a8a455acc5 100644 --- a/src/gui/components/controls/juce_ComboBox.h +++ b/src/gui/components/controls/juce_ComboBox.h @@ -84,7 +84,7 @@ public: @param componentName the name to set for the component (see Component::setName()) */ - ComboBox (const String& componentName); + explicit ComboBox (const String& componentName); /** Destructor. */ ~ComboBox(); diff --git a/src/gui/components/controls/juce_ProgressBar.h b/src/gui/components/controls/juce_ProgressBar.h index 5bddd72ff7..3be4d1c943 100644 --- a/src/gui/components/controls/juce_ProgressBar.h +++ b/src/gui/components/controls/juce_ProgressBar.h @@ -59,7 +59,7 @@ public: you'd better be careful not to delete this variable while the ProgressBar still exists! */ - ProgressBar (double& progress); + explicit ProgressBar (double& progress); /** Destructor. */ ~ProgressBar(); diff --git a/src/gui/components/controls/juce_Slider.h b/src/gui/components/controls/juce_Slider.h index c01029b7ee..e0268b71de 100644 --- a/src/gui/components/controls/juce_Slider.h +++ b/src/gui/components/controls/juce_Slider.h @@ -68,7 +68,7 @@ public: When created, you'll need to set up the slider's style and range with setSliderStyle(), setRange(), etc. */ - Slider (const String& componentName); + explicit Slider (const String& componentName); /** Destructor. */ ~Slider(); diff --git a/src/gui/components/controls/juce_TextEditor.h b/src/gui/components/controls/juce_TextEditor.h index 45f1d93d0d..9dab1050be 100644 --- a/src/gui/components/controls/juce_TextEditor.h +++ b/src/gui/components/controls/juce_TextEditor.h @@ -89,8 +89,8 @@ public: for a black splodge (not all fonts include this, though), or 0x2022, which is a bullet (probably the best choice for linux). */ - TextEditor (const String& componentName = String::empty, - tchar passwordCharacter = 0); + explicit TextEditor (const String& componentName = String::empty, + tchar passwordCharacter = 0); /** Destructor. */ virtual ~TextEditor(); diff --git a/src/gui/components/juce_Component.h b/src/gui/components/juce_Component.h index 06f4601ffa..c85f12fb52 100644 --- a/src/gui/components/juce_Component.h +++ b/src/gui/components/juce_Component.h @@ -81,7 +81,7 @@ public: @see getName, setName */ - Component (const String& componentName); + explicit Component (const String& componentName); /** Returns the name of this component. diff --git a/src/gui/components/keyboard/juce_KeyPressMappingSet.h b/src/gui/components/keyboard/juce_KeyPressMappingSet.h index 33b72601a0..99390c564d 100644 --- a/src/gui/components/keyboard/juce_KeyPressMappingSet.h +++ b/src/gui/components/keyboard/juce_KeyPressMappingSet.h @@ -107,7 +107,7 @@ public: @see ApplicationCommandManager */ - KeyPressMappingSet (ApplicationCommandManager* commandManager) throw(); + explicit KeyPressMappingSet (ApplicationCommandManager* commandManager) throw(); /** Creates an copy of a KeyPressMappingSet. */ KeyPressMappingSet (const KeyPressMappingSet& other) throw(); diff --git a/src/gui/components/layout/juce_TabbedComponent.h b/src/gui/components/layout/juce_TabbedComponent.h index e380fb62f7..fa9dfefefe 100644 --- a/src/gui/components/layout/juce_TabbedComponent.h +++ b/src/gui/components/layout/juce_TabbedComponent.h @@ -47,7 +47,7 @@ public: Once created, add some tabs with the addTab() method. */ - TabbedComponent (const TabbedButtonBar::Orientation orientation); + explicit TabbedComponent (const TabbedButtonBar::Orientation orientation); /** Destructor. */ ~TabbedComponent(); diff --git a/src/gui/components/layout/juce_Viewport.h b/src/gui/components/layout/juce_Viewport.h index 8fb63e871a..0b34177826 100644 --- a/src/gui/components/layout/juce_Viewport.h +++ b/src/gui/components/layout/juce_Viewport.h @@ -53,7 +53,7 @@ public: The viewport is initially empty - use the setViewedComponent() method to add a child component for it to manage. */ - Viewport (const String& componentName = String::empty); + explicit Viewport (const String& componentName = String::empty); /** Destructor. */ ~Viewport(); diff --git a/src/gui/components/mouse/juce_LassoComponent.h b/src/gui/components/mouse/juce_LassoComponent.h index 70d1af5767..05b59277fe 100644 --- a/src/gui/components/mouse/juce_LassoComponent.h +++ b/src/gui/components/mouse/juce_LassoComponent.h @@ -106,7 +106,7 @@ public: The fill colour is used to fill the lasso'ed rectangle, and the outline colour is used to draw a line around its edge. */ - LassoComponent (const int outlineThickness_ = 1) + explicit LassoComponent (const int outlineThickness_ = 1) : source (0), outlineThickness (outlineThickness_) { diff --git a/src/gui/components/special/juce_WebBrowserComponent.h b/src/gui/components/special/juce_WebBrowserComponent.h index 50e987412b..099ea22518 100644 --- a/src/gui/components/special/juce_WebBrowserComponent.h +++ b/src/gui/components/special/juce_WebBrowserComponent.h @@ -56,7 +56,7 @@ public: the browser using resources in the background when it's not actually being used. */ - WebBrowserComponent (bool unloadPageWhenBrowserIsHidden = true); + explicit WebBrowserComponent (bool unloadPageWhenBrowserIsHidden = true); /** Destructor. */ ~WebBrowserComponent(); diff --git a/src/gui/components/windows/juce_TooltipWindow.h b/src/gui/components/windows/juce_TooltipWindow.h index 5d1c9beb58..897420b9cc 100644 --- a/src/gui/components/windows/juce_TooltipWindow.h +++ b/src/gui/components/windows/juce_TooltipWindow.h @@ -67,8 +67,8 @@ public: @see TooltipClient, LookAndFeel::drawTooltip, LookAndFeel::getTooltipSize */ - TooltipWindow (Component* parentComponent = 0, - int millisecondsBeforeTipAppears = 700); + explicit TooltipWindow (Component* parentComponent = 0, + int millisecondsBeforeTipAppears = 700); /** Destructor. */ ~TooltipWindow(); diff --git a/src/gui/graphics/colour/juce_PixelFormats.h b/src/gui/graphics/colour/juce_PixelFormats.h index 4a88e3a909..1c032bb8ef 100644 --- a/src/gui/graphics/colour/juce_PixelFormats.h +++ b/src/gui/graphics/colour/juce_PixelFormats.h @@ -546,6 +546,10 @@ public: { } + //============================================================================== + /** The indexes of the different components in the byte layout of this type of colour. */ + enum { indexA = 0 }; + private: //============================================================================== uint8 a : 8; diff --git a/src/gui/graphics/contexts/juce_Graphics.h b/src/gui/graphics/contexts/juce_Graphics.h index 780a94343b..ef118860b1 100644 --- a/src/gui/graphics/contexts/juce_Graphics.h +++ b/src/gui/graphics/contexts/juce_Graphics.h @@ -64,7 +64,7 @@ public: Obviously you shouldn't delete the image before this context is deleted. */ - Graphics (Image& imageToDrawOnto) throw(); + explicit Graphics (Image& imageToDrawOnto) throw(); /** Destructor. */ ~Graphics() throw(); diff --git a/src/gui/graphics/contexts/juce_LowLevelGraphicsSoftwareRenderer.cpp b/src/gui/graphics/contexts/juce_LowLevelGraphicsSoftwareRenderer.cpp index 00ed18d0ce..7accc57f69 100644 --- a/src/gui/graphics/contexts/juce_LowLevelGraphicsSoftwareRenderer.cpp +++ b/src/gui/graphics/contexts/juce_LowLevelGraphicsSoftwareRenderer.cpp @@ -586,11 +586,9 @@ public: y = y_; generate (scratchBuffer, x, width); - const uint8* mask = reinterpret_cast (scratchBuffer.getData()); - if (sizeof (SrcPixelType) == sizeof (PixelARGB)) - mask += PixelARGB::indexA; - - et.clipLineToMask (x, y_, mask, sizeof (SrcPixelType), width); + et.clipLineToMask (x, y_, + reinterpret_cast (scratchBuffer.getData()) + SrcPixelType::indexA, + sizeof (SrcPixelType), width); } private: diff --git a/src/gui/graphics/fonts/juce_Typeface.h b/src/gui/graphics/fonts/juce_Typeface.h index 4c3f93eb1d..650e7f6741 100644 --- a/src/gui/graphics/fonts/juce_Typeface.h +++ b/src/gui/graphics/fonts/juce_Typeface.h @@ -112,7 +112,7 @@ public: protected: String name; - Typeface (const String& name) throw(); + explicit Typeface (const String& name) throw(); private: Typeface (const Typeface&); @@ -141,7 +141,7 @@ public: The stream must have been created by writeToStream(). @see writeToStream */ - CustomTypeface (InputStream& serialisedTypefaceStream); + explicit CustomTypeface (InputStream& serialisedTypefaceStream); /** Destructor. */ ~CustomTypeface(); diff --git a/src/gui/graphics/geometry/juce_BorderSize.h b/src/gui/graphics/geometry/juce_BorderSize.h index 9c580a5005..795dc16ca7 100644 --- a/src/gui/graphics/geometry/juce_BorderSize.h +++ b/src/gui/graphics/geometry/juce_BorderSize.h @@ -58,7 +58,7 @@ public: int rightGap) throw(); /** Creates a border with the given gap on all sides. */ - BorderSize (int allGaps) throw(); + explicit BorderSize (int allGaps) throw(); /** Destructor. */ ~BorderSize() throw(); diff --git a/src/io/files/juce_FileInputStream.h b/src/io/files/juce_FileInputStream.h index 0fd7002dfc..23684672e0 100644 --- a/src/io/files/juce_FileInputStream.h +++ b/src/io/files/juce_FileInputStream.h @@ -45,7 +45,7 @@ public: @param fileToRead the file to read from - if the file can't be accessed for some reason, then the stream will just contain no data */ - FileInputStream (const File& fileToRead); + explicit FileInputStream (const File& fileToRead); /** Destructor. */ ~FileInputStream(); diff --git a/src/io/streams/juce_InputStream.cpp b/src/io/streams/juce_InputStream.cpp index 3806623214..cd23230013 100644 --- a/src/io/streams/juce_InputStream.cpp +++ b/src/io/streams/juce_InputStream.cpp @@ -108,35 +108,37 @@ int InputStream::readCompressedInt() int64 InputStream::readInt64() { - char temp[8]; + union { uint8 asBytes[8]; uint64 asInt64; } n; - if (read (temp, 8) == 8) - return (int64) ByteOrder::swapIfBigEndian (*reinterpret_cast (temp)); + if (read (n.asBytes, 8) == 8) + return (int64) ByteOrder::swapIfBigEndian (n.asInt64); return 0; } int64 InputStream::readInt64BigEndian() { - char temp[8]; + union { uint8 asBytes[8]; uint64 asInt64; } n; - if (read (temp, 8) == 8) - return (int64) ByteOrder::swapIfLittleEndian (*reinterpret_cast (temp)); + if (read (n.asBytes, 8) == 8) + return (int64) ByteOrder::swapIfLittleEndian (n.asInt64); return 0; } float InputStream::readFloat() { - union { int asInt; float asFloat; } n; - n.asInt = readInt(); + // the union below relies on these types being the same size... + static_jassert (sizeof (int32) == sizeof (float)); + union { int32 asInt; float asFloat; } n; + n.asInt = (int32) readInt(); return n.asFloat; } float InputStream::readFloatBigEndian() { - union { int asInt; float asFloat; } n; - n.asInt = readIntBigEndian(); + union { int32 asInt; float asFloat; } n; + n.asInt = (int32) readIntBigEndian(); return n.asFloat; } diff --git a/src/native/linux/juce_linux_Audio.cpp b/src/native/linux/juce_linux_Audio.cpp index 18239990e8..ac6aa44039 100644 --- a/src/native/linux/juce_linux_Audio.cpp +++ b/src/native/linux/juce_linux_Audio.cpp @@ -234,7 +234,7 @@ public: if (isInterleaved) { scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false); - float* interleaved = reinterpret_cast (scratch.getData()); + float* interleaved = static_cast (scratch.getData()); AudioDataConverters::interleaveSamples ((const float**) data, interleaved, numSamples, numChannelsRunning); AudioDataConverters::convertFloatToFormat (sampleFormat, interleaved, interleaved, numSamples * numChannelsRunning); @@ -272,7 +272,7 @@ public: if (isInterleaved) { scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false); - float* interleaved = reinterpret_cast (scratch.getData()); + float* interleaved = static_cast (scratch.getData()); snd_pcm_sframes_t num = snd_pcm_readi (handle, (void*) interleaved, numSamples); diff --git a/src/native/linux/juce_linux_Windowing.cpp b/src/native/linux/juce_linux_Windowing.cpp index 52a62c8da8..3463c98642 100644 --- a/src/native/linux/juce_linux_Windowing.cpp +++ b/src/native/linux/juce_linux_Windowing.cpp @@ -1114,15 +1114,15 @@ public: const int width = image.getWidth(); const int height = image.getHeight(); - HeapBlock colour (width * height); + HeapBlock colour (width * height); int index = 0; for (int y = 0; y < height; ++y) for (int x = 0; x < width; ++x) - colour[index++] = image.getPixelAt (x, y).getARGB(); + colour[index++] = static_cast (image.getPixelAt (x, y).getARGB()); XImage* ximage = XCreateImage (display, CopyFromParent, 24, ZPixmap, - 0, reinterpret_cast (colour.getData()), + 0, colour.getData(), width, height, 32, 0); Pixmap pixmap = XCreatePixmap (display, DefaultRootWindow (display), @@ -1142,7 +1142,7 @@ public: const int width = image.getWidth(); const int height = image.getHeight(); const int stride = (width + 7) >> 3; - HeapBlock mask; + HeapBlock mask; mask.calloc (stride * height); const bool msbfirst = (BitmapBitOrder (display) == MSBFirst); @@ -1150,7 +1150,7 @@ public: { for (int x = 0; x < width; ++x) { - const uint8 bit = (uint8) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7))); + const char bit = (char) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7))); const int offset = y * stride + (x >> 3); if (image.getPixelAt (x, y).getAlpha() >= 128) @@ -1159,7 +1159,7 @@ public: } return XCreatePixmapFromBitmapData (display, DefaultRootWindow (display), - reinterpret_cast (mask.getData()), width, height, 1, 0, 1); + mask.getData(), width, height, 1, 0, 1); } void setIcon (const Image& newIcon) @@ -3027,7 +3027,7 @@ void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hot } const int stride = (cursorW + 7) >> 3; - HeapBlock maskPlane, sourcePlane; + HeapBlock maskPlane, sourcePlane; maskPlane.calloc (stride * cursorH); sourcePlane.calloc (stride * cursorH); @@ -3037,7 +3037,7 @@ void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hot { for (int x = cursorW; --x >= 0;) { - const uint8 mask = (uint8) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7))); + const char mask = (char) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7))); const int offset = y * stride + (x >> 3); const Colour c (im.getPixelAt (x, y)); @@ -3050,8 +3050,8 @@ void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hot } } - Pixmap sourcePixmap = XCreatePixmapFromBitmapData (display, root, reinterpret_cast (sourcePlane.getData()), cursorW, cursorH, 0xffff, 0, 1); - Pixmap maskPixmap = XCreatePixmapFromBitmapData (display, root, reinterpret_cast (maskPlane.getData()), cursorW, cursorH, 0xffff, 0, 1); + Pixmap sourcePixmap = XCreatePixmapFromBitmapData (display, root, sourcePlane.getData(), cursorW, cursorH, 0xffff, 0, 1); + Pixmap maskPixmap = XCreatePixmapFromBitmapData (display, root, maskPlane.getData(), cursorW, cursorH, 0xffff, 0, 1); XColor white, black; black.red = black.green = black.blue = 0; diff --git a/src/native/mac/juce_mac_CoreMidi.cpp b/src/native/mac/juce_mac_CoreMidi.cpp index 3e8ec6009c..55b23c87bd 100644 --- a/src/native/mac/juce_mac_CoreMidi.cpp +++ b/src/native/mac/juce_mac_CoreMidi.cpp @@ -161,7 +161,7 @@ static const String getConnectedEndpointName (MIDIEndpointRef endpoint) if (s.isNotEmpty()) { if (result.isNotEmpty()) - result += (", "); + result += ", "; result += s; } diff --git a/src/native/windows/juce_win32_Messaging.cpp b/src/native/windows/juce_win32_Messaging.cpp index 0bfebf2708..4b1b78a564 100644 --- a/src/native/windows/juce_win32_Messaging.cpp +++ b/src/native/windows/juce_win32_Messaging.cpp @@ -213,7 +213,7 @@ void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* call static BOOL CALLBACK BroadcastEnumWindowProc (HWND hwnd, LPARAM lParam) { if (hwnd != juce_messageWindowHandle) - (reinterpret_cast (lParam))->add ((void*) hwnd); + reinterpret_cast (lParam)->add ((void*) hwnd); return TRUE; } diff --git a/src/text/juce_String.cpp b/src/text/juce_String.cpp index bd2aec869a..29c63f9eef 100644 --- a/src/text/juce_String.cpp +++ b/src/text/juce_String.cpp @@ -138,10 +138,10 @@ public: static StringHolder empty; private: - static inline StringHolder* bufferFromText (juce_wchar* const text) throw() + static inline StringHolder* bufferFromText (void* const text) throw() { // (Can't use offsetof() here because of warnings about this not being a POD) - return reinterpret_cast (reinterpret_cast (text) + return reinterpret_cast (static_cast (text) - (reinterpret_cast (reinterpret_cast (1)->text) - 1)); } }; @@ -1364,9 +1364,7 @@ const String String::substring (int start, int end) const return empty; int len = 0; - const juce_wchar* const t = text; - - while (len <= end && t [len] != 0) + while (len <= end && text [len] != 0) ++len; if (end >= len) @@ -1389,8 +1387,8 @@ const String String::substring (const int start) const if (start >= len) return empty; - else - return String (text + start, len - start); + + return String (text + start, len - start); } const String String::dropLastCharacters (const int numberToDrop) const @@ -1409,11 +1407,10 @@ const String String::fromFirstOccurrenceOf (const String& sub, { const int i = ignoreCase ? indexOfIgnoreCase (sub) : indexOf (sub); - if (i < 0) return empty; - else - return substring (includeSubString ? i : i + sub.length()); + + return substring (includeSubString ? i : i + sub.length()); } const String String::fromLastOccurrenceOf (const String& sub, @@ -1422,7 +1419,6 @@ const String String::fromLastOccurrenceOf (const String& sub, { const int i = ignoreCase ? lastIndexOfIgnoreCase (sub) : lastIndexOf (sub); - if (i < 0) return *this; @@ -1435,7 +1431,6 @@ const String String::upToFirstOccurrenceOf (const String& sub, { const int i = ignoreCase ? indexOfIgnoreCase (sub) : indexOf (sub); - if (i < 0) return *this; @@ -1517,8 +1512,8 @@ const String String::trim() const return empty; else if (start > 0 || end < len) return String (text + start, end - start); - else - return *this; + + return *this; } const String String::trimStart() const @@ -1533,8 +1528,8 @@ const String String::trimStart() const if (t == text) return *this; - else - return String (t); + + return String (t); } const String String::trimEnd() const @@ -1552,9 +1547,6 @@ const String String::trimEnd() const const String String::trimCharactersAtStart (const String& charactersToTrim) const { - if (isEmpty()) - return empty; - const juce_wchar* t = text; while (charactersToTrim.containsChar (*t)) @@ -1562,8 +1554,8 @@ const String String::trimCharactersAtStart (const String& charactersToTrim) cons if (t == text) return *this; - else - return String (t); + + return String (t); } const String String::trimCharactersAtEnd (const String& charactersToTrim) const @@ -1624,7 +1616,17 @@ const String String::removeCharacters (const String& charactersToRemove) const const String String::initialSectionContainingOnly (const String& permittedCharacters) const { - return substring (0, CharacterFunctions::getIntialSectionContainingOnly (text, permittedCharacters.text)); + int i = 0; + + for (;;) + { + if (! permittedCharacters.containsChar (text[i])) + break; + + ++i; + } + + return substring (0, i); } const String String::initialSectionNotContaining (const String& charactersToStopAt) const @@ -1940,7 +1942,7 @@ const char* String::toUTF8() const String* const mutableThis = const_cast (this); mutableThis->text = StringHolder::makeUniqueWithSize (mutableThis->text, currentLen + 1 + utf8BytesNeeded / sizeof (juce_wchar)); - char* const otherCopy = (char*) (text + currentLen); + char* const otherCopy = reinterpret_cast (text + currentLen); copyToUTF8 (otherCopy, std::numeric_limits::max()); return otherCopy; @@ -2128,12 +2130,11 @@ const char* String::toCString() const } else { - int len = length(); - + const int len = length(); String* const mutableThis = const_cast (this); mutableThis->text = StringHolder::makeUniqueWithSize (mutableThis->text, (len + 1) * 2); - char* otherCopy = (char*) (text + len + 1); + char* otherCopy = reinterpret_cast (text + len + 1); CharacterFunctions::copy (otherCopy, text, len); otherCopy [len] = 0; return otherCopy; diff --git a/src/text/juce_XmlElement.h b/src/text/juce_XmlElement.h index a801ac50f6..0e92e51b4b 100644 --- a/src/text/juce_XmlElement.h +++ b/src/text/juce_XmlElement.h @@ -145,7 +145,7 @@ class JUCE_API XmlElement public: //============================================================================== /** Creates an XmlElement with this tag name. */ - XmlElement (const String& tagName) throw(); + explicit XmlElement (const String& tagName) throw(); /** Creates a (deep) copy of another element. */ XmlElement (const XmlElement& other) throw(); diff --git a/src/threads/juce_InterProcessLock.h b/src/threads/juce_InterProcessLock.h index 126e127349..202380b74e 100644 --- a/src/threads/juce_InterProcessLock.h +++ b/src/threads/juce_InterProcessLock.h @@ -43,7 +43,7 @@ public: @param name a name that processes will use to identify this lock object */ - InterProcessLock (const String& name); + explicit InterProcessLock (const String& name); /** Destructor. diff --git a/src/threads/juce_Process.h b/src/threads/juce_Process.h index 13d68c402f..ec5009382e 100644 --- a/src/threads/juce_Process.h +++ b/src/threads/juce_Process.h @@ -91,6 +91,12 @@ public: /** Returns true if this process is being hosted by a debugger. */ static bool JUCE_CALLTYPE isRunningUnderDebugger(); + + +private: + Process(); + Process (const Process&); + Process& operator= (const Process&); }; diff --git a/src/threads/juce_ScopedLock.h b/src/threads/juce_ScopedLock.h index d4e1f6af71..38b36238ab 100644 --- a/src/threads/juce_ScopedLock.h +++ b/src/threads/juce_ScopedLock.h @@ -66,7 +66,7 @@ public: otherwise there are no guarantees what will happen! Best just to use it as a local stack object, rather than creating one with the new() operator. */ - inline ScopedLock (const CriticalSection& lock) throw() : lock_ (lock) { lock.enter(); } + inline explicit ScopedLock (const CriticalSection& lock) throw() : lock_ (lock) { lock.enter(); } /** Destructor. @@ -75,7 +75,7 @@ public: Make sure this object is created and deleted by the same thread, otherwise there are no guarantees what will happen! */ - inline ~ScopedLock() throw() { lock_.exit(); } + inline ~ScopedLock() throw() { lock_.exit(); } private: @@ -139,7 +139,7 @@ public: otherwise there are no guarantees what will happen! Best just to use it as a local stack object, rather than creating one with the new() operator. */ - inline ScopedUnlock (const CriticalSection& lock) throw() : lock_ (lock) { lock.exit(); } + inline explicit ScopedUnlock (const CriticalSection& lock) throw() : lock_ (lock) { lock.exit(); } /** Destructor. @@ -148,7 +148,7 @@ public: Make sure this object is created and deleted by the same thread, otherwise there are no guarantees what will happen! */ - inline ~ScopedUnlock() throw() { lock_.enter(); } + inline ~ScopedUnlock() throw() { lock_.enter(); } private: diff --git a/src/threads/juce_ScopedReadLock.h b/src/threads/juce_ScopedReadLock.h index f363b97660..cf9a4f48fb 100644 --- a/src/threads/juce_ScopedReadLock.h +++ b/src/threads/juce_ScopedReadLock.h @@ -66,7 +66,7 @@ public: otherwise there are no guarantees what will happen! Best just to use it as a local stack object, rather than creating one with the new() operator. */ - inline ScopedReadLock (const ReadWriteLock& lock) throw() : lock_ (lock) { lock.enterRead(); } + inline explicit ScopedReadLock (const ReadWriteLock& lock) throw() : lock_ (lock) { lock.enterRead(); } /** Destructor. @@ -75,7 +75,7 @@ public: Make sure this object is created and deleted by the same thread, otherwise there are no guarantees what will happen! */ - inline ~ScopedReadLock() throw() { lock_.exitRead(); } + inline ~ScopedReadLock() throw() { lock_.exitRead(); } private: diff --git a/src/threads/juce_ScopedTryLock.h b/src/threads/juce_ScopedTryLock.h index b55bf759cf..17c3711313 100644 --- a/src/threads/juce_ScopedTryLock.h +++ b/src/threads/juce_ScopedTryLock.h @@ -75,7 +75,7 @@ public: otherwise there are no guarantees what will happen! Best just to use it as a local stack object, rather than creating one with the new() operator. */ - inline ScopedTryLock (const CriticalSection& lock) throw() : lock_ (lock), lockWasSuccessful (lock.tryEnter()) {} + inline explicit ScopedTryLock (const CriticalSection& lock) throw() : lock_ (lock), lockWasSuccessful (lock.tryEnter()) {} /** Destructor. @@ -84,13 +84,13 @@ public: Make sure this object is created and deleted by the same thread, otherwise there are no guarantees what will happen! */ - inline ~ScopedTryLock() throw() { if (lockWasSuccessful) lock_.exit(); } + inline ~ScopedTryLock() throw() { if (lockWasSuccessful) lock_.exit(); } /** Lock state @return True if the CriticalSection is locked. */ - bool isLocked() const throw() { return lockWasSuccessful; } + bool isLocked() const throw() { return lockWasSuccessful; } private: //============================================================================== diff --git a/src/threads/juce_ScopedWriteLock.h b/src/threads/juce_ScopedWriteLock.h index 403d823d3e..977a278864 100644 --- a/src/threads/juce_ScopedWriteLock.h +++ b/src/threads/juce_ScopedWriteLock.h @@ -66,7 +66,7 @@ public: otherwise there are no guarantees what will happen! Best just to use it as a local stack object, rather than creating one with the new() operator. */ - inline ScopedWriteLock (const ReadWriteLock& lock) throw() : lock_ (lock) { lock.enterWrite(); } + inline explicit ScopedWriteLock (const ReadWriteLock& lock) throw() : lock_ (lock) { lock.enterWrite(); } /** Destructor. @@ -75,7 +75,7 @@ public: Make sure this object is created and deleted by the same thread, otherwise there are no guarantees what will happen! */ - inline ~ScopedWriteLock() throw() { lock_.exitWrite(); } + inline ~ScopedWriteLock() throw() { lock_.exitWrite(); } private: diff --git a/src/threads/juce_Thread.h b/src/threads/juce_Thread.h index 57deee04c8..f266fa1aba 100644 --- a/src/threads/juce_Thread.h +++ b/src/threads/juce_Thread.h @@ -55,7 +55,7 @@ public: When first created, the thread is not running. Use the startThread() method to start it. */ - Thread (const String& threadName); + explicit Thread (const String& threadName); /** Destructor. @@ -200,6 +200,8 @@ public: This puts the thread to sleep until either the timeout period expires, or another thread calls the notify() method to wake it up. + A negative time-out value means that the method will wait indefinitely. + @returns true if the event has been signalled, false if the timeout expires. */ bool wait (int timeOutMilliseconds) const; diff --git a/src/threads/juce_ThreadPool.h b/src/threads/juce_ThreadPool.h index 8edb62cadb..a73ae7b46c 100644 --- a/src/threads/juce_ThreadPool.h +++ b/src/threads/juce_ThreadPool.h @@ -57,7 +57,7 @@ public: After creating your job, add it to a thread pool with ThreadPool::addJob(). */ - ThreadPoolJob (const String& name); + explicit ThreadPoolJob (const String& name); /** Destructor. */ virtual ~ThreadPoolJob(); diff --git a/src/threads/juce_TimeSliceThread.h b/src/threads/juce_TimeSliceThread.h index 232a5704d6..ae2a448235 100644 --- a/src/threads/juce_TimeSliceThread.h +++ b/src/threads/juce_TimeSliceThread.h @@ -83,7 +83,7 @@ public: When first created, the thread is not running. Use the startThread() method to start it. */ - TimeSliceThread (const String& threadName); + explicit TimeSliceThread (const String& threadName); /** Destructor. diff --git a/src/utilities/juce_SelectedItemSet.h b/src/utilities/juce_SelectedItemSet.h index 0c9dbb243e..e149a7f6c2 100644 --- a/src/utilities/juce_SelectedItemSet.h +++ b/src/utilities/juce_SelectedItemSet.h @@ -55,7 +55,7 @@ public: } /** Creates a set based on an array of items. */ - SelectedItemSet (const Array & items) + explicit SelectedItemSet (const Array & items) : selectedItems (items) { }