diff --git a/modules/juce_audio_devices/native/juce_win32_ASIO.cpp b/modules/juce_audio_devices/native/juce_win32_ASIO.cpp index a9c7ccd8d0..b110de6fc4 100644 --- a/modules/juce_audio_devices/native/juce_win32_ASIO.cpp +++ b/modules/juce_audio_devices/native/juce_win32_ASIO.cpp @@ -508,11 +508,10 @@ public: if (err == ASE_OK) { buffersCreated = true; - tempBuffer.calloc (totalBuffers * currentBlockSizeSamples + 32); int n = 0; - Array types; + Array types; currentBitDepth = 16; for (int i = 0; i < (int) totalNumInputChans; ++i) diff --git a/modules/juce_audio_processors/format_types/juce_LADSPAPluginFormat.cpp b/modules/juce_audio_processors/format_types/juce_LADSPAPluginFormat.cpp index dfbc7bc9ae..ce71f45f8b 100644 --- a/modules/juce_audio_processors/format_types/juce_LADSPAPluginFormat.cpp +++ b/modules/juce_audio_processors/format_types/juce_LADSPAPluginFormat.cpp @@ -60,9 +60,9 @@ public: typedef ReferenceCountedObjectPtr Ptr; - static Array & getActiveModules() + static Array& getActiveModules() { - static Array activeModules; + static Array activeModules; return activeModules; } @@ -571,7 +571,7 @@ private: LADSPAPluginFormat::LADSPAPluginFormat() {} LADSPAPluginFormat::~LADSPAPluginFormat() {} -void LADSPAPluginFormat::findAllTypesForFile (OwnedArray & results, +void LADSPAPluginFormat::findAllTypesForFile (OwnedArray& results, const String& fileOrIdentifier) { if (! fileMightContainThisPluginType (fileOrIdentifier)) diff --git a/modules/juce_audio_processors/processors/juce_GenericAudioProcessorEditor.cpp b/modules/juce_audio_processors/processors/juce_GenericAudioProcessorEditor.cpp index 08f160932c..c4cc16100f 100644 --- a/modules/juce_audio_processors/processors/juce_GenericAudioProcessorEditor.cpp +++ b/modules/juce_audio_processors/processors/juce_GenericAudioProcessorEditor.cpp @@ -36,7 +36,6 @@ public: : PropertyComponent (name), owner (p), index (paramIndex), - paramHasChanged (false), slider (p, paramIndex) { startTimer (100); @@ -87,9 +86,9 @@ private: public: ParamSlider (AudioProcessor& p, int paramIndex) : owner (p), index (paramIndex) { - const int steps = owner.getParameterNumSteps (index); - const AudioProcessorParameter::Category category = p.getParameterCategory (index); - const bool isLevelMeter = (((category & 0xffff0000) >> 16) == 2); + auto steps = owner.getParameterNumSteps (index); + auto category = p.getParameterCategory (index); + bool isLevelMeter = (((category & 0xffff0000) >> 16) == 2); if (steps > 1 && steps < 0x7fffffff) setRange (0.0, 1.0, 1.0 / (steps - 1.0)); @@ -104,7 +103,7 @@ private: void valueChanged() override { - const float newVal = (float) getValue(); + auto newVal = static_cast (getValue()); if (owner.getParameter (index) != newVal) { @@ -138,7 +137,7 @@ private: AudioProcessor& owner; const int index; - bool volatile paramHasChanged; + bool volatile paramHasChanged = false; ParamSlider slider; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProcessorParameterPropertyComp) @@ -154,18 +153,19 @@ GenericAudioProcessorEditor::GenericAudioProcessorEditor (AudioProcessor* const addAndMakeVisible (panel); - Array params; + Array params; - const int numParams = p->getNumParameters(); + auto numParams = p->getNumParameters(); int totalHeight = 0; for (int i = 0; i < numParams; ++i) { - String name (p->getParameterName (i)); + auto name = p->getParameterName (i); + if (name.trim().isEmpty()) name = "Unnamed"; - ProcessorParameterPropertyComp* const pc = new ProcessorParameterPropertyComp (name, *p, i); + auto* pc = new ProcessorParameterPropertyComp (name, *p, i); params.add (pc); totalHeight += pc->getPreferredHeight(); } diff --git a/modules/juce_audio_processors/scanning/juce_KnownPluginList.h b/modules/juce_audio_processors/scanning/juce_KnownPluginList.h index 17ce28fb31..3bfa606b5f 100644 --- a/modules/juce_audio_processors/scanning/juce_KnownPluginList.h +++ b/modules/juce_audio_processors/scanning/juce_KnownPluginList.h @@ -95,7 +95,7 @@ public: */ bool scanAndAddFile (const String& possiblePluginFileOrIdentifier, bool dontRescanIfAlreadyInList, - OwnedArray & typesFound, + OwnedArray& typesFound, AudioPluginFormat& formatToUse); /** Tells a custom scanner that a scan has finished, and it can release any resources. */ @@ -112,7 +112,7 @@ public: */ void scanAndAddDragAndDroppedFiles (AudioPluginFormatManager& formatManager, const StringArray& filenames, - OwnedArray & typesFound); + OwnedArray& typesFound); //============================================================================== /** Returns the list of blacklisted files. */ @@ -194,7 +194,7 @@ public: @returns true if the plugin loaded, false if it crashed */ virtual bool findPluginTypesFor (AudioPluginFormat& format, - OwnedArray & result, + OwnedArray& result, const String& fileOrIdentifier) = 0; /** Called when a scan has finished, to allow clean-up of resources. */ diff --git a/modules/juce_core/containers/juce_ElementComparator.h b/modules/juce_core/containers/juce_ElementComparator.h index aa30b194a5..91fc5026f9 100644 --- a/modules/juce_core/containers/juce_ElementComparator.h +++ b/modules/juce_core/containers/juce_ElementComparator.h @@ -165,7 +165,7 @@ static int findInsertIndexInSortedArray (ElementComparator& comparator, This will work for primitive types and objects that implement operator<(). Example: @code - Array myArray; + Array myArray; DefaultElementComparator sorter; myArray.sort (sorter); @endcode diff --git a/modules/juce_core/files/juce_File.cpp b/modules/juce_core/files/juce_File.cpp index ef96be662c..e35a8883b2 100644 --- a/modules/juce_core/files/juce_File.cpp +++ b/modules/juce_core/files/juce_File.cpp @@ -79,12 +79,12 @@ static String removeEllipsis (const String& path) #endif { StringArray toks; - toks.addTokens (path, File::separatorString, StringRef()); + toks.addTokens (path, File::separatorString, {}); bool anythingChanged = false; for (int i = 1; i < toks.size(); ++i) { - const String& t = toks[i]; + auto& t = toks[i]; if (t == ".." && toks[i - 1] != "..") { @@ -118,7 +118,7 @@ String File::parseAbsolutePath (const String& p) #if JUCE_WINDOWS // Windows.. - String path (removeEllipsis (p.replaceCharacter ('/', '\\'))); + auto path = removeEllipsis (p.replaceCharacter ('/', '\\')); if (path.startsWithChar (separator)) { @@ -157,7 +157,7 @@ String File::parseAbsolutePath (const String& p) // If that's why you've ended up here, use File::getChildFile() to build your paths instead. jassert ((! p.containsChar ('\\')) || (p.indexOfChar ('/') >= 0 && p.indexOfChar ('/') < p.indexOfChar ('\\'))); - String path (removeEllipsis (p)); + auto path = removeEllipsis (p); if (path.startsWithChar ('~')) { @@ -170,9 +170,9 @@ String File::parseAbsolutePath (const String& p) else { // expand a name of type "~dave/abc" - const String userName (path.substring (1).upToFirstOccurrenceOf ("/", false, false)); + auto userName = path.substring (1).upToFirstOccurrenceOf ("/", false, false); - if (struct passwd* const pw = getpwnam (userName.toUTF8())) + if (auto* pw = getpwnam (userName.toUTF8())) path = addTrailingSeparator (pw->pw_dir) + path.fromFirstOccurrenceOf ("/", false, false); } } @@ -248,11 +248,11 @@ bool File::setReadOnly (const bool shouldBeReadOnly, if (applyRecursively && isDirectory()) { - Array subFiles; + Array subFiles; findChildFiles (subFiles, File::findFilesAndDirectories, false); - for (int i = subFiles.size(); --i >= 0;) - worked = subFiles.getReference(i).setReadOnly (shouldBeReadOnly, true) && worked; + for (auto& f : subFiles) + worked = f.setReadOnly (shouldBeReadOnly, true) && worked; } return setFileReadOnlyInternal (shouldBeReadOnly) && worked; @@ -272,8 +272,8 @@ bool File::deleteRecursively() const Array subFiles; findChildFiles (subFiles, File::findFilesAndDirectories, false); - for (int i = subFiles.size(); --i >= 0;) - worked = subFiles.getReference(i).deleteRecursively() && worked; + for (auto& f : subFiles) + worked = f.deleteRecursively() && worked; } return deleteFile() && worked; @@ -324,15 +324,15 @@ bool File::copyDirectoryTo (const File& newDirectory) const Array subFiles; findChildFiles (subFiles, File::findFiles, false); - for (int i = 0; i < subFiles.size(); ++i) - if (! subFiles.getReference(i).copyFileTo (newDirectory.getChildFile (subFiles.getReference(i).getFileName()))) + for (auto& f : subFiles) + if (! f.copyFileTo (newDirectory.getChildFile (f.getFileName()))) return false; subFiles.clear(); findChildFiles (subFiles, File::findDirectories, false); - for (int i = 0; i < subFiles.size(); ++i) - if (! subFiles.getReference(i).copyDirectoryTo (newDirectory.getChildFile (subFiles.getReference(i).getFileName()))) + for (auto& f : subFiles) + if (! f.copyDirectoryTo (newDirectory.getChildFile (f.getFileName()))) return false; return true; @@ -344,7 +344,7 @@ bool File::copyDirectoryTo (const File& newDirectory) const //============================================================================== String File::getPathUpToLastSlash() const { - const int lastSlash = fullPath.lastIndexOfChar (separator); + auto lastSlash = fullPath.lastIndexOfChar (separator); if (lastSlash > 0) return fullPath.substring (0, lastSlash); @@ -357,9 +357,7 @@ String File::getPathUpToLastSlash() const File File::getParentDirectory() const { - File f; - f.fullPath = getPathUpToLastSlash(); - return f; + return createFileWithoutCheckingPath (getPathUpToLastSlash()); } //============================================================================== @@ -370,8 +368,8 @@ String File::getFileName() const String File::getFileNameWithoutExtension() const { - const int lastSlash = fullPath.lastIndexOfChar (separator) + 1; - const int lastDot = fullPath.lastIndexOfChar ('.'); + auto lastSlash = fullPath.lastIndexOfChar (separator) + 1; + auto lastDot = fullPath.lastIndexOfChar ('.'); if (lastDot > lastSlash) return fullPath.substring (lastSlash, lastDot); @@ -384,7 +382,7 @@ bool File::isAChildOf (const File& potentialParent) const if (potentialParent.fullPath.isEmpty()) return false; - const String ourPath (getPathUpToLastSlash()); + auto ourPath = getPathUpToLastSlash(); if (compareFilenames (potentialParent.fullPath, ourPath) == 0) return true; @@ -401,7 +399,7 @@ int64 File::hashCode64() const { return fullPath.hashCode64(); } //============================================================================== bool File::isAbsolutePath (StringRef path) { - const juce_wchar firstChar = *(path.text); + auto firstChar = *(path.text); return firstChar == separator #if JUCE_WINDOWS @@ -413,7 +411,7 @@ bool File::isAbsolutePath (StringRef path) File File::getChildFile (StringRef relativePath) const { - String::CharPointerType r = relativePath.text; + auto r = relativePath.text; if (isAbsolutePath (r)) return File (String (r)); @@ -423,20 +421,21 @@ File File::getChildFile (StringRef relativePath) const return getChildFile (String (r).replaceCharacter ('/', '\\')); #endif - String path (fullPath); + auto path = fullPath; while (*r == '.') { - String::CharPointerType lastPos = r; - const juce_wchar secondChar = *++r; + auto lastPos = r; + auto secondChar = *++r; if (secondChar == '.') // remove "../" { - const juce_wchar thirdChar = *++r; + auto thirdChar = *++r; if (thirdChar == separator || thirdChar == 0) { - const int lastSlash = path.lastIndexOfChar (separator); + auto lastSlash = path.lastIndexOfChar (separator); + if (lastSlash >= 0) path = path.substring (0, lastSlash); @@ -492,12 +491,12 @@ Result File::create() const if (exists()) return Result::ok(); - const File parentDir (getParentDirectory()); + auto parentDir = getParentDirectory(); if (parentDir == *this) return Result::fail ("Cannot create parent directory"); - Result r (parentDir.createDirectory()); + auto r = parentDir.createDirectory(); if (r.wasOk()) { @@ -513,12 +512,12 @@ Result File::createDirectory() const if (isDirectory()) return Result::ok(); - const File parentDir (getParentDirectory()); + auto parentDir = getParentDirectory(); if (parentDir == *this) return Result::fail ("Cannot create parent directory"); - Result r (parentDir.createDirectory()); + auto r = parentDir.createDirectory(); if (r.wasOk()) r = createDirectoryInternal (fullPath.trimCharactersAtEnd (separatorString)); @@ -601,20 +600,20 @@ File File::getNonexistentChildFile (const String& suggestedPrefix, const String& suffix, bool putNumbersInBrackets) const { - File f (getChildFile (suggestedPrefix + suffix)); + auto f = getChildFile (suggestedPrefix + suffix); if (f.exists()) { int number = 1; - String prefix (suggestedPrefix); + auto prefix = suggestedPrefix; // remove any bracketed numbers that may already be on the end.. if (prefix.trim().endsWithChar (')')) { putNumbersInBrackets = true; - const int openBracks = prefix.lastIndexOfChar ('('); - const int closeBracks = prefix.lastIndexOfChar (')'); + auto openBracks = prefix.lastIndexOfChar ('('); + auto closeBracks = prefix.lastIndexOfChar (')'); if (openBracks > 0 && closeBracks > openBracks @@ -627,7 +626,7 @@ File File::getNonexistentChildFile (const String& suggestedPrefix, do { - String newName (prefix); + auto newName = prefix; if (putNumbersInBrackets) { @@ -662,7 +661,7 @@ File File::getNonexistentSibling (const bool putNumbersInBrackets) const //============================================================================== String File::getFileExtension() const { - const int indexOfDot = fullPath.lastIndexOfChar ('.'); + auto indexOfDot = fullPath.lastIndexOfChar ('.'); if (indexOfDot > fullPath.lastIndexOfChar (separator)) return fullPath.substring (indexOfDot); @@ -675,7 +674,7 @@ bool File::hasFileExtension (StringRef possibleSuffix) const if (possibleSuffix.isEmpty()) return fullPath.lastIndexOfChar ('.') <= fullPath.lastIndexOfChar (separator); - const int semicolon = possibleSuffix.text.indexOf ((juce_wchar) ';'); + auto semicolon = possibleSuffix.text.indexOf ((juce_wchar) ';'); if (semicolon >= 0) return hasFileExtension (String (possibleSuffix.text).substring (0, semicolon).trimEnd()) @@ -686,10 +685,10 @@ bool File::hasFileExtension (StringRef possibleSuffix) const if (possibleSuffix.text[0] == '.') return true; - const int dotPos = fullPath.length() - possibleSuffix.length() - 1; + auto dotPos = fullPath.length() - possibleSuffix.length() - 1; if (dotPos >= 0) - return fullPath [dotPos] == '.'; + return fullPath[dotPos] == '.'; } return false; @@ -700,11 +699,12 @@ File File::withFileExtension (StringRef newExtension) const if (fullPath.isEmpty()) return {}; - String filePart (getFileName()); + auto filePart = getFileName(); + + auto lastDot = filePart.lastIndexOfChar ('.'); - const int i = filePart.lastIndexOfChar ('.'); - if (i >= 0) - filePart = filePart.substring (0, i); + if (lastDot >= 0) + filePart = filePart.substring (0, lastDot); if (newExtension.isNotEmpty() && newExtension.text[0] != '.') filePart << '.'; @@ -729,7 +729,7 @@ FileInputStream* File::createInputStream() const return nullptr; } -FileOutputStream* File::createOutputStream (const size_t bufferSize) const +FileOutputStream* File::createOutputStream (size_t bufferSize) const { ScopedPointer out (new FileOutputStream (*this, bufferSize)); @@ -798,8 +798,8 @@ bool File::hasIdenticalContentTo (const File& other) const for (;;) { - const int num1 = in1.read (buffer1, bufferSize); - const int num2 = in2.read (buffer2, bufferSize); + auto num1 = in1.read (buffer1, bufferSize); + auto num2 = in2.read (buffer2, bufferSize); if (num1 != num2) break; @@ -819,7 +819,7 @@ bool File::hasIdenticalContentTo (const File& other) const //============================================================================== String File::createLegalPathName (const String& original) { - String s (original); + auto s = original; String start; if (s.isNotEmpty() && s[1] == ':') @@ -834,14 +834,14 @@ String File::createLegalPathName (const String& original) String File::createLegalFileName (const String& original) { - String s (original.removeCharacters ("\"#@,;:<>*^|?\\/")); + auto s = original.removeCharacters ("\"#@,;:<>*^|?\\/"); const int maxLength = 128; // only the length of the filename, not the whole path - const int len = s.length(); + auto len = s.length(); if (len > maxLength) { - const int lastDot = s.lastIndexOfChar ('.'); + auto lastDot = s.lastIndexOfChar ('.'); if (lastDot > jmax (0, len - 12)) { @@ -931,9 +931,9 @@ String File::getRelativePathFrom (const File& dir) const return thisPathAfterCommon; #if JUCE_WINDOWS - String s (String::repeatedString ("..\\", numUpDirectoriesNeeded)); + auto s = String::repeatedString ("..\\", numUpDirectoriesNeeded); #else - String s (String::repeatedString ("../", numUpDirectoriesNeeded)); + auto s = String::repeatedString ("../", numUpDirectoriesNeeded); #endif s.appendCharPointer (thisPathAfterCommon); return s; @@ -989,13 +989,13 @@ bool File::createSymbolicLink (const File& linkFileToCreate, bool overwriteExist //============================================================================== MemoryMappedFile::MemoryMappedFile (const File& file, MemoryMappedFile::AccessMode mode, bool exclusive) - : address (nullptr), range (0, file.getSize()), fileHandle (0) + : range (0, file.getSize()) { openInternal (file, mode, exclusive); } MemoryMappedFile::MemoryMappedFile (const File& file, const Range& fileRange, AccessMode mode, bool exclusive) - : address (nullptr), range (fileRange.getIntersectionWith (Range (0, file.getSize()))), fileHandle (0) + : range (fileRange.getIntersectionWith (Range (0, file.getSize()))) { openInternal (file, mode, exclusive); } diff --git a/modules/juce_core/files/juce_MemoryMappedFile.h b/modules/juce_core/files/juce_MemoryMappedFile.h index 1afc083122..1edba373e4 100644 --- a/modules/juce_core/files/juce_MemoryMappedFile.h +++ b/modules/juce_core/files/juce_MemoryMappedFile.h @@ -96,13 +96,13 @@ public: private: //============================================================================== - void* address; + void* address = nullptr; Range range; #if JUCE_WINDOWS - void* fileHandle; + void* fileHandle = nullptr; #else - int fileHandle; + int fileHandle = 0; #endif void openInternal (const File&, AccessMode, bool); diff --git a/modules/juce_core/javascript/juce_JSON.cpp b/modules/juce_core/javascript/juce_JSON.cpp index 494da5a83d..eb939ad7f4 100644 --- a/modules/juce_core/javascript/juce_JSON.cpp +++ b/modules/juce_core/javascript/juce_JSON.cpp @@ -45,7 +45,7 @@ struct JSONParser for (;;) { - juce_wchar c = t.getAndAdvance(); + auto c = t.getAndAdvance(); if (c == quoteChar) break; @@ -74,7 +74,8 @@ struct JSONParser for (int i = 4; --i >= 0;) { - const int digitValue = CharacterFunctions::getHexDigitValue (t.getAndAdvance()); + auto digitValue = CharacterFunctions::getHexDigitValue (t.getAndAdvance()); + if (digitValue < 0) return createFail ("Syntax error in unicode escape sequence"); @@ -99,7 +100,7 @@ struct JSONParser static Result parseAny (String::CharPointerType& t, var& result) { t = t.findEndOfWhitespace(); - String::CharPointerType t2 (t); + auto t2 = t; switch (t2.getAndAdvance()) { @@ -167,16 +168,16 @@ private: static Result parseNumber (String::CharPointerType& t, var& result, const bool isNegative) { - String::CharPointerType oldT (t); + auto oldT = t; int64 intValue = t.getAndAdvance() - '0'; jassert (intValue >= 0 && intValue < 10); for (;;) { - String::CharPointerType previousChar (t); - const juce_wchar c = t.getAndAdvance(); - const int digit = ((int) c) - '0'; + auto previousChar = t; + auto c = t.getAndAdvance(); + auto digit = ((int) c) - '0'; if (isPositiveAndBelow (digit, 10)) { @@ -187,7 +188,7 @@ private: if (c == 'e' || c == 'E' || c == '.') { t = oldT; - const double asDouble = CharacterFunctions::readDoubleValue (t); + auto asDouble = CharacterFunctions::readDoubleValue (t); result = isNegative ? -asDouble : asDouble; return Result::ok(); } @@ -202,7 +203,7 @@ private: return createFail ("Syntax error in number", &oldT); } - const int64 correctedValue = isNegative ? -intValue : intValue; + auto correctedValue = isNegative ? -intValue : intValue; if ((intValue >> 31) != 0) result = correctedValue; @@ -214,16 +215,16 @@ private: static Result parseObject (String::CharPointerType& t, var& result) { - DynamicObject* const resultObject = new DynamicObject(); + auto resultObject = new DynamicObject(); result = resultObject; - NamedValueSet& resultProperties = resultObject->getProperties(); + auto& resultProperties = resultObject->getProperties(); for (;;) { t = t.findEndOfWhitespace(); - String::CharPointerType oldT (t); - const juce_wchar c = t.getAndAdvance(); + auto oldT = t; + auto c = t.getAndAdvance(); if (c == '}') break; @@ -234,7 +235,7 @@ private: if (c == '"') { var propertyNameVar; - Result r (parseString ('"', t, propertyNameVar)); + auto r = parseString ('"', t, propertyNameVar); if (r.failed()) return r; @@ -246,14 +247,15 @@ private: t = t.findEndOfWhitespace(); oldT = t; - const juce_wchar c2 = t.getAndAdvance(); + auto c2 = t.getAndAdvance(); + if (c2 != ':') return createFail ("Expected ':', but found", &oldT); resultProperties.set (propertyName, var()); var* propertyValue = resultProperties.getVarPointer (propertyName); - Result r2 (parseAny (t, *propertyValue)); + auto r2 = parseAny (t, *propertyValue); if (r2.failed()) return r2; @@ -261,7 +263,7 @@ private: t = t.findEndOfWhitespace(); oldT = t; - const juce_wchar nextChar = t.getAndAdvance(); + auto nextChar = t.getAndAdvance(); if (nextChar == ',') continue; @@ -280,14 +282,14 @@ private: static Result parseArray (String::CharPointerType& t, var& result) { result = var (Array()); - Array* const destArray = result.getArray(); + auto* destArray = result.getArray(); for (;;) { t = t.findEndOfWhitespace(); - String::CharPointerType oldT (t); - const juce_wchar c = t.getAndAdvance(); + auto oldT = t; + auto c = t.getAndAdvance(); if (c == ']') break; @@ -297,7 +299,7 @@ private: t = oldT; destArray->add (var()); - Result r (parseAny (t, destArray->getReference (destArray->size() - 1))); + auto r = parseAny (t, destArray->getReference (destArray->size() - 1)); if (r.failed()) return r; @@ -305,7 +307,7 @@ private: t = t.findEndOfWhitespace(); oldT = t; - const juce_wchar nextChar = t.getAndAdvance(); + auto nextChar = t.getAndAdvance(); if (nextChar == ',') continue; @@ -324,8 +326,7 @@ private: struct JSONFormatter { static void write (OutputStream& out, const var& v, - const int indentLevel, const bool allOnOneLine, - int maximumDecimalPlaces) + int indentLevel, bool allOnOneLine, int maximumDecimalPlaces) { if (v.isString()) { @@ -355,7 +356,7 @@ struct JSONFormatter } else if (v.isObject()) { - if (DynamicObject* object = v.getDynamicObject()) + if (auto* object = v.getDynamicObject()) object->writeAsJSON (out, indentLevel, allOnOneLine, maximumDecimalPlaces); else jassertfalse; // Only DynamicObjects can be converted to JSON! @@ -378,7 +379,7 @@ struct JSONFormatter { for (;;) { - const juce_wchar c (t.getAndAdvance()); + auto c = t.getAndAdvance(); switch (c) { @@ -426,12 +427,11 @@ struct JSONFormatter } static void writeArray (OutputStream& out, const Array& array, - const int indentLevel, const bool allOnOneLine, - int maximumDecimalPlaces) + int indentLevel, bool allOnOneLine, int maximumDecimalPlaces) { out << '['; - if (array.size() > 0) + if (! array.isEmpty()) { if (! allOnOneLine) out << newLine; @@ -521,7 +521,7 @@ String JSON::escapeString (StringRef s) Result JSON::parseQuotedString (String::CharPointerType& t, var& result) { - const juce_wchar quote = t.getAndAdvance(); + auto quote = t.getAndAdvance(); if (quote == '"' || quote == '\'') return JSONParser::parseString (quote, t, result); diff --git a/modules/juce_core/streams/juce_MemoryOutputStream.cpp b/modules/juce_core/streams/juce_MemoryOutputStream.cpp index 1b27e05dec..d84cf6b31e 100644 --- a/modules/juce_core/streams/juce_MemoryOutputStream.cpp +++ b/modules/juce_core/streams/juce_MemoryOutputStream.cpp @@ -24,24 +24,21 @@ namespace juce { MemoryOutputStream::MemoryOutputStream (const size_t initialSize) - : blockToUse (&internalBlock), externalData (nullptr), - position (0), size (0), availableSize (0) + : blockToUse (&internalBlock) { internalBlock.setSize (initialSize, false); } MemoryOutputStream::MemoryOutputStream (MemoryBlock& memoryBlockToWriteTo, const bool appendToExistingBlockContent) - : blockToUse (&memoryBlockToWriteTo), externalData (nullptr), - position (0), size (0), availableSize (0) + : blockToUse (&memoryBlockToWriteTo) { if (appendToExistingBlockContent) position = size = memoryBlockToWriteTo.getSize(); } MemoryOutputStream::MemoryOutputStream (void* destBuffer, size_t destBufferSize) - : blockToUse (nullptr), externalData (destBuffer), - position (0), size (0), availableSize (destBufferSize) + : externalData (destBuffer), availableSize (destBufferSize) { jassert (externalData != nullptr); // This must be a valid pointer. } @@ -77,7 +74,7 @@ void MemoryOutputStream::reset() noexcept char* MemoryOutputStream::prepareToWrite (size_t numBytes) { jassert ((ssize_t) numBytes >= 0); - size_t storageNeeded = position + numBytes; + auto storageNeeded = position + numBytes; char* data; @@ -96,7 +93,7 @@ char* MemoryOutputStream::prepareToWrite (size_t numBytes) data = static_cast (externalData); } - char* const writePointer = data + position; + auto* writePointer = data + position; position += numBytes; size = jmax (size, position); return writePointer; @@ -109,7 +106,7 @@ bool MemoryOutputStream::write (const void* const buffer, size_t howMany) if (howMany == 0) return true; - if (char* dest = prepareToWrite (howMany)) + if (auto* dest = prepareToWrite (howMany)) { memcpy (dest, buffer, howMany); return true; @@ -123,7 +120,7 @@ bool MemoryOutputStream::writeRepeatedByte (uint8 byte, size_t howMany) if (howMany == 0) return true; - if (char* dest = prepareToWrite (howMany)) + if (auto* dest = prepareToWrite (howMany)) { memset (dest, byte, howMany); return true; @@ -134,7 +131,7 @@ bool MemoryOutputStream::writeRepeatedByte (uint8 byte, size_t howMany) bool MemoryOutputStream::appendUTF8Char (juce_wchar c) { - if (char* dest = prepareToWrite (CharPointer_UTF8::getBytesRequiredFor (c))) + if (auto* dest = prepareToWrite (CharPointer_UTF8::getBytesRequiredFor (c))) { CharPointer_UTF8 (dest).write (c); return true; @@ -191,7 +188,7 @@ int64 MemoryOutputStream::writeFromInputStream (InputStream& source, int64 maxNu String MemoryOutputStream::toUTF8() const { - const char* const d = static_cast (getData()); + auto* d = static_cast (getData()); return String (CharPointer_UTF8 (d), CharPointer_UTF8 (d + getDataSize())); } @@ -202,7 +199,7 @@ String MemoryOutputStream::toString() const OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const MemoryOutputStream& streamToRead) { - const size_t dataSize = streamToRead.getDataSize(); + auto dataSize = streamToRead.getDataSize(); if (dataSize > 0) stream.write (streamToRead.getData(), dataSize); diff --git a/modules/juce_core/streams/juce_MemoryOutputStream.h b/modules/juce_core/streams/juce_MemoryOutputStream.h index 6f89c940ce..56d4620b08 100644 --- a/modules/juce_core/streams/juce_MemoryOutputStream.h +++ b/modules/juce_core/streams/juce_MemoryOutputStream.h @@ -114,10 +114,10 @@ public: private: //============================================================================== - MemoryBlock* const blockToUse; + MemoryBlock* const blockToUse = nullptr; MemoryBlock internalBlock; - void* externalData; - size_t position, size, availableSize; + void* externalData = nullptr; + size_t position = 0, size = 0, availableSize = 0; void trimExternalBlockSize(); char* prepareToWrite (size_t); diff --git a/modules/juce_core/text/juce_StringArray.cpp b/modules/juce_core/text/juce_StringArray.cpp index a22b31c7b0..5e737edc5e 100644 --- a/modules/juce_core/text/juce_StringArray.cpp +++ b/modules/juce_core/text/juce_StringArray.cpp @@ -33,7 +33,7 @@ StringArray::StringArray (const StringArray& other) } StringArray::StringArray (StringArray&& other) noexcept - : strings (static_cast&&> (other.strings)) + : strings (static_cast&&> (other.strings)) { } @@ -174,8 +174,8 @@ void StringArray::addArray (const StringArray& otherArray, int startIndex, int n void StringArray::mergeArray (const StringArray& otherArray, const bool ignoreCase) { - for (int i = 0; i < otherArray.size(); ++i) - addIfNotAlreadyThere (otherArray[i], ignoreCase); + for (auto& s : otherArray) + addIfNotAlreadyThere (s, ignoreCase); } void StringArray::set (const int index, const String& newString) @@ -193,7 +193,7 @@ int StringArray::indexOf (StringRef stringToLookFor, const bool ignoreCase, int if (i < 0) i = 0; - const int numElements = size(); + auto numElements = size(); if (ignoreCase) { @@ -217,7 +217,7 @@ void StringArray::move (const int currentIndex, const int newIndex) noexcept } //============================================================================== -void StringArray::remove (const int index) +void StringArray::remove (int index) { strings.remove (index); } @@ -262,11 +262,8 @@ void StringArray::removeEmptyStrings (const bool removeWhitespaceStrings) void StringArray::trim() { - for (int i = size(); --i >= 0;) - { - String& s = strings.getReference(i); + for (auto& s : strings) s = s.trim(); - } } //============================================================================== @@ -308,8 +305,8 @@ void StringArray::sortNatural() //============================================================================== String StringArray::joinIntoString (StringRef separator, int start, int numberToJoin) const { - const int last = (numberToJoin < 0) ? size() - : jmin (size(), start + numberToJoin); + auto last = (numberToJoin < 0) ? size() + : jmin (size(), start + numberToJoin); if (start < 0) start = 0; @@ -320,8 +317,8 @@ String StringArray::joinIntoString (StringRef separator, int start, int numberTo if (start == last - 1) return strings.getReference (start); - const size_t separatorBytes = separator.text.sizeInBytes() - sizeof (String::CharPointerType::CharType); - size_t bytesNeeded = separatorBytes * (size_t) (last - start - 1); + auto separatorBytes = separator.text.sizeInBytes() - sizeof (String::CharPointerType::CharType); + auto bytesNeeded = separatorBytes * (size_t) (last - start - 1); for (int i = start; i < last; ++i) bytesNeeded += strings.getReference(i).getCharPointer().sizeInBytes() - sizeof (String::CharPointerType::CharType); @@ -333,7 +330,7 @@ String StringArray::joinIntoString (StringRef separator, int start, int numberTo while (start < last) { - const String& s = strings.getReference (start); + auto& s = strings.getReference (start); if (! s.isEmpty()) dest.writeAll (s.getCharPointer()); @@ -358,11 +355,11 @@ int StringArray::addTokens (StringRef text, StringRef breakCharacters, StringRef if (text.isNotEmpty()) { - for (String::CharPointerType t (text.text);;) + for (auto t = text.text;;) { - String::CharPointerType tokenEnd (CharacterFunctions::findEndOfToken (t, - breakCharacters.text, - quoteCharacters.text)); + auto tokenEnd = CharacterFunctions::findEndOfToken (t, + breakCharacters.text, + quoteCharacters.text); strings.add (String (t, tokenEnd)); ++num; @@ -379,14 +376,14 @@ int StringArray::addTokens (StringRef text, StringRef breakCharacters, StringRef int StringArray::addLines (StringRef sourceText) { int numLines = 0; - String::CharPointerType text (sourceText.text); + auto text = sourceText.text; bool finished = text.isEmpty(); while (! finished) { - for (String::CharPointerType startOfLine (text);;) + for (auto startOfLine = text;;) { - const String::CharPointerType endOfLine (text); + auto endOfLine = text; switch (text.getAndAdvance()) { @@ -433,7 +430,7 @@ void StringArray::removeDuplicates (const bool ignoreCase) { for (int i = 0; i < size() - 1; ++i) { - const String s (strings.getReference(i)); + auto s = strings.getReference(i); for (int nextIndex = i + 1;;) { @@ -452,24 +449,20 @@ void StringArray::appendNumbersToDuplicates (const bool ignoreCase, CharPointer_UTF8 preNumberString, CharPointer_UTF8 postNumberString) { - CharPointer_UTF8 defaultPre (" ("), defaultPost (")"); - if (preNumberString.getAddress() == nullptr) - preNumberString = defaultPre; + preNumberString = CharPointer_UTF8 (" ("); if (postNumberString.getAddress() == nullptr) - postNumberString = defaultPost; + postNumberString = CharPointer_UTF8 (")"); for (int i = 0; i < size() - 1; ++i) { - String& s = strings.getReference(i); - - int nextIndex = indexOf (s, ignoreCase, i + 1); + auto& s = strings.getReference(i); + auto nextIndex = indexOf (s, ignoreCase, i + 1); if (nextIndex >= 0) { - const String original (s); - + auto original = s; int number = 0; if (appendNumberToFirstInstance) diff --git a/modules/juce_core/threads/juce_TimeSliceThread.h b/modules/juce_core/threads/juce_TimeSliceThread.h index 53648b69c5..8f4cacd62a 100644 --- a/modules/juce_core/threads/juce_TimeSliceThread.h +++ b/modules/juce_core/threads/juce_TimeSliceThread.h @@ -135,7 +135,7 @@ public: //============================================================================== private: CriticalSection callbackLock, listLock; - Array clients; + Array clients; TimeSliceClient* clientBeingCalled = nullptr; TimeSliceClient* getNextClient (int index) const; diff --git a/modules/juce_core/unit_tests/juce_UnitTest.cpp b/modules/juce_core/unit_tests/juce_UnitTest.cpp index 9e9150ee63..c35a86a53f 100644 --- a/modules/juce_core/unit_tests/juce_UnitTest.cpp +++ b/modules/juce_core/unit_tests/juce_UnitTest.cpp @@ -24,7 +24,7 @@ namespace juce { UnitTest::UnitTest (const String& nm, const String& ctg) - : name (nm), category (ctg), runner (nullptr) + : name (nm), category (ctg) { getAllTests().add (this); } @@ -114,16 +114,8 @@ Random UnitTest::getRandom() const } //============================================================================== -UnitTestRunner::UnitTestRunner() - : currentTest (nullptr), - assertOnFailure (true), - logPasses (false) -{ -} - -UnitTestRunner::~UnitTestRunner() -{ -} +UnitTestRunner::UnitTestRunner() {} +UnitTestRunner::~UnitTestRunner() {} void UnitTestRunner::setAssertOnFailure (bool shouldAssert) noexcept { @@ -160,17 +152,17 @@ void UnitTestRunner::runTests (const Array& tests, int64 randomSeed) randomForTest = Random (randomSeed); logMessage ("Random seed: 0x" + String::toHexString (randomSeed)); - for (int i = 0; i < tests.size(); ++i) + for (auto* t : tests) { if (shouldAbortTests()) break; #if JUCE_EXCEPTIONS_DISABLED - tests.getUnchecked(i)->performTest (this); + t->performTest (this); #else try { - tests.getUnchecked(i)->performTest (this); + t->performTest (this); } catch (...) { @@ -207,7 +199,7 @@ void UnitTestRunner::beginNewTest (UnitTest* const test, const String& subCatego endTest(); currentTest = test; - TestResult* const r = new TestResult(); + auto* r = new TestResult(); results.add (r); r->unitTestName = test->getName(); r->subcategoryName = subCategory; @@ -222,10 +214,8 @@ void UnitTestRunner::beginNewTest (UnitTest* const test, const String& subCatego void UnitTestRunner::endTest() { - if (results.size() > 0) + if (auto* r = results.getLast()) { - TestResult* const r = results.getLast(); - if (r->failures > 0) { String m ("FAILED!! "); @@ -248,7 +238,7 @@ void UnitTestRunner::addPass() { const ScopedLock sl (results.getLock()); - TestResult* const r = results.getLast(); + auto* r = results.getLast(); jassert (r != nullptr); // You need to call UnitTest::beginTest() before performing any tests! r->passes++; @@ -269,7 +259,7 @@ void UnitTestRunner::addFail (const String& failureMessage) { const ScopedLock sl (results.getLock()); - TestResult* const r = results.getLast(); + auto* r = results.getLast(); jassert (r != nullptr); // You need to call UnitTest::beginTest() before performing any tests! r->failures++; diff --git a/modules/juce_core/unit_tests/juce_UnitTest.h b/modules/juce_core/unit_tests/juce_UnitTest.h index 9a9580b836..048f53a58e 100644 --- a/modules/juce_core/unit_tests/juce_UnitTest.h +++ b/modules/juce_core/unit_tests/juce_UnitTest.h @@ -298,9 +298,8 @@ private: } //============================================================================== - const String name; - const String category; - UnitTestRunner* runner; + const String name, category; + UnitTestRunner* runner = nullptr; JUCE_DECLARE_NON_COPYABLE (UnitTest) }; @@ -418,10 +417,10 @@ private: //============================================================================== friend class UnitTest; - UnitTest* currentTest; + UnitTest* currentTest = nullptr; String currentSubCategory; - OwnedArray results; - bool assertOnFailure, logPasses; + OwnedArray results; + bool assertOnFailure = true, logPasses = false; Random randomForTest; void beginNewTest (UnitTest* test, const String& subCategory); diff --git a/modules/juce_dsp/processors/juce_ProcessContext.h b/modules/juce_dsp/processors/juce_ProcessContext.h index 3016ccdccb..c8e6c6945a 100644 --- a/modules/juce_dsp/processors/juce_ProcessContext.h +++ b/modules/juce_dsp/processors/juce_ProcessContext.h @@ -51,7 +51,7 @@ struct ProcessSpec which is typically shared among several procoessors. This is useful to for multi-mono filters which share the same state among several mono processors. */ -struct ProcessorState : ReferenceCountedObject +struct ProcessorState : public ReferenceCountedObject { /** The ProcessorState structure is ref-counted, so this is a handy type that can be used as a pointer to one. diff --git a/modules/juce_graphics/contexts/juce_LowLevelGraphicsPostScriptRenderer.h b/modules/juce_graphics/contexts/juce_LowLevelGraphicsPostScriptRenderer.h index 889702bca3..569c557c8d 100644 --- a/modules/juce_graphics/contexts/juce_LowLevelGraphicsPostScriptRenderer.h +++ b/modules/juce_graphics/contexts/juce_LowLevelGraphicsPostScriptRenderer.h @@ -94,18 +94,16 @@ protected: struct SavedState { SavedState(); + SavedState& operator= (const SavedState&) = delete; ~SavedState(); RectangleList clip; int xOffset, yOffset; FillType fillType; Font font; - - private: - SavedState& operator= (const SavedState&); }; - OwnedArray stateStack; + OwnedArray stateStack; void writeClip(); void writeColour (Colour colour); diff --git a/modules/juce_graphics/fonts/juce_CustomTypeface.cpp b/modules/juce_graphics/fonts/juce_CustomTypeface.cpp index 5897a3753c..e8b05254ef 100644 --- a/modules/juce_graphics/fonts/juce_CustomTypeface.cpp +++ b/modules/juce_graphics/fonts/juce_CustomTypeface.cpp @@ -30,7 +30,7 @@ namespace juce class CustomTypeface::GlyphInfo { public: - GlyphInfo (const juce_wchar c, const Path& p, const float w) noexcept + GlyphInfo (juce_wchar c, const Path& p, float w) noexcept : character (c), path (p), width (w) { } @@ -41,21 +41,17 @@ public: float kerningAmount; }; - void addKerningPair (const juce_wchar subsequentCharacter, - const float extraKerningAmount) noexcept + void addKerningPair (juce_wchar subsequentCharacter, float extraKerningAmount) noexcept { - KerningPair kp; - kp.character2 = subsequentCharacter; - kp.kerningAmount = extraKerningAmount; - kerningPairs.add (kp); + kerningPairs.add ({ subsequentCharacter, extraKerningAmount }); } - float getHorizontalSpacing (const juce_wchar subsequentCharacter) const noexcept + float getHorizontalSpacing (juce_wchar subsequentCharacter) const noexcept { if (subsequentCharacter != 0) - for (int i = kerningPairs.size(); --i >= 0;) - if (kerningPairs.getReference(i).character2 == subsequentCharacter) - return width + kerningPairs.getReference(i).kerningAmount; + for (auto& kp : kerningPairs) + if (kp.character2 == subsequentCharacter) + return width + kp.kerningAmount; return width; } @@ -63,7 +59,7 @@ public: const juce_wchar character; const Path path; float width; - Array kerningPairs; + Array kerningPairs; private: JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (GlyphInfo) @@ -74,11 +70,11 @@ namespace CustomTypefaceHelpers { static juce_wchar readChar (InputStream& in) { - uint32 n = (uint32) (uint16) in.readShort(); + auto n = (uint32) (uint16) in.readShort(); if (n >= 0xd800 && n <= 0xdfff) { - const uint32 nextWord = (uint32) (uint16) in.readShort(); + auto nextWord = (uint32) (uint16) in.readShort(); jassert (nextWord >= 0xdc00); // illegal unicode character! n = 0x10000 + (((n - 0xd800) << 10) | (nextWord - 0xdc00)); @@ -126,24 +122,24 @@ CustomTypeface::CustomTypeface (InputStream& serialisedTypefaceStream) ascent = in.readFloat(); defaultCharacter = CustomTypefaceHelpers::readChar (in); - int numChars = in.readInt(); + auto numChars = in.readInt(); for (int i = 0; i < numChars; ++i) { - const juce_wchar c = CustomTypefaceHelpers::readChar (in); - const float width = in.readFloat(); + auto c = CustomTypefaceHelpers::readChar (in); + auto width = in.readFloat(); Path p; p.loadPathFromStream (in); addGlyph (c, p, width); } - const int numKerningPairs = in.readInt(); + auto numKerningPairs = in.readInt(); for (int i = 0; i < numKerningPairs; ++i) { - const juce_wchar char1 = CustomTypefaceHelpers::readChar (in); - const juce_wchar char2 = CustomTypefaceHelpers::readChar (in); + auto char1 = CustomTypefaceHelpers::readChar (in); + auto char2 = CustomTypefaceHelpers::readChar (in); addKerningPair (char1, char2, in.readFloat()); } @@ -163,8 +159,8 @@ void CustomTypeface::clear() glyphs.clear(); } -void CustomTypeface::setCharacteristics (const String& newName, const float newAscent, const bool isBold, - const bool isItalic, const juce_wchar newDefaultCharacter) noexcept +void CustomTypeface::setCharacteristics (const String& newName, float newAscent, bool isBold, + bool isItalic, juce_wchar newDefaultCharacter) noexcept { name = newName; defaultCharacter = newDefaultCharacter; @@ -172,8 +168,8 @@ void CustomTypeface::setCharacteristics (const String& newName, const float newA style = FontStyleHelpers::getStyleName (isBold, isItalic); } -void CustomTypeface::setCharacteristics (const String& newName, const String& newStyle, const float newAscent, - const juce_wchar newDefaultCharacter) noexcept +void CustomTypeface::setCharacteristics (const String& newName, const String& newStyle, + float newAscent, juce_wchar newDefaultCharacter) noexcept { name = newName; style = newStyle; @@ -181,7 +177,7 @@ void CustomTypeface::setCharacteristics (const String& newName, const String& ne ascent = newAscent; } -void CustomTypeface::addGlyph (const juce_wchar character, const Path& path, const float width) noexcept +void CustomTypeface::addGlyph (juce_wchar character, const Path& path, float width) noexcept { // Check that you're not trying to add the same character twice.. jassert (findGlyph (character, false) == nullptr); @@ -192,7 +188,7 @@ void CustomTypeface::addGlyph (const juce_wchar character, const Path& path, con glyphs.add (new GlyphInfo (character, path, width)); } -void CustomTypeface::addKerningPair (const juce_wchar char1, const juce_wchar char2, const float extraAmount) noexcept +void CustomTypeface::addKerningPair (juce_wchar char1, juce_wchar char2, float extraAmount) noexcept { if (extraAmount != 0.0f) { @@ -203,17 +199,14 @@ void CustomTypeface::addKerningPair (const juce_wchar char1, const juce_wchar ch } } -CustomTypeface::GlyphInfo* CustomTypeface::findGlyph (const juce_wchar character, const bool loadIfNeeded) noexcept +CustomTypeface::GlyphInfo* CustomTypeface::findGlyph (juce_wchar character, bool loadIfNeeded) noexcept { if (isPositiveAndBelow ((int) character, numElementsInArray (lookupTable)) && lookupTable [character] > 0) return glyphs [(int) lookupTable [(int) character]]; - for (int i = 0; i < glyphs.size(); ++i) - { - GlyphInfo* const g = glyphs.getUnchecked(i); + for (auto* g : glyphs) if (g->character == character) return g; - } if (loadIfNeeded && loadGlyphIfPossible (character)) return findGlyph (character, false); @@ -221,7 +214,7 @@ CustomTypeface::GlyphInfo* CustomTypeface::findGlyph (const juce_wchar character return nullptr; } -bool CustomTypeface::loadGlyphIfPossible (const juce_wchar /*characterNeeded*/) +bool CustomTypeface::loadGlyphIfPossible (juce_wchar) { return false; } @@ -232,17 +225,17 @@ void CustomTypeface::addGlyphsFromOtherTypeface (Typeface& typefaceToCopy, juce_ for (int i = 0; i < numCharacters; ++i) { - const juce_wchar c = (juce_wchar) (characterStartIndex + static_cast (i)); + auto c = (juce_wchar) (characterStartIndex + static_cast (i)); - Array glyphIndexes; - Array offsets; + Array glyphIndexes; + Array offsets; typefaceToCopy.getGlyphPositions (String::charToString (c), glyphIndexes, offsets); const int glyphIndex = glyphIndexes.getFirst(); if (glyphIndex >= 0 && glyphIndexes.size() > 0) { - const float glyphWidth = offsets[1]; + auto glyphWidth = offsets[1]; Path p; typefaceToCopy.getOutlineForGlyph (glyphIndex, p); @@ -251,7 +244,7 @@ void CustomTypeface::addGlyphsFromOtherTypeface (Typeface& typefaceToCopy, juce_ for (int j = glyphs.size() - 1; --j >= 0;) { - const juce_wchar char2 = glyphs.getUnchecked (j)->character; + auto char2 = glyphs.getUnchecked (j)->character; glyphIndexes.clearQuick(); offsets.clearQuick(); typefaceToCopy.getGlyphPositions (String::charToString (c) + String::charToString (char2), glyphIndexes, offsets); @@ -276,9 +269,8 @@ bool CustomTypeface::writeToStream (OutputStream& outputStream) int numKerningPairs = 0; - for (int i = 0; i < glyphs.size(); ++i) + for (auto* g : glyphs) { - const GlyphInfo* const g = glyphs.getUnchecked (i); CustomTypefaceHelpers::writeChar (out, g->character); out.writeFloat (g->width); g->path.writePathToStream (out); @@ -288,13 +280,10 @@ bool CustomTypeface::writeToStream (OutputStream& outputStream) out.writeInt (numKerningPairs); - for (int i = 0; i < glyphs.size(); ++i) + for (auto* g : glyphs) { - const GlyphInfo* const g = glyphs.getUnchecked (i); - - for (int j = 0; j < g->kerningPairs.size(); ++j) + for (auto& p : g->kerningPairs) { - const GlyphInfo::KerningPair& p = g->kerningPairs.getReference (j); CustomTypefaceHelpers::writeChar (out, g->character); CustomTypefaceHelpers::writeChar (out, p.character2); out.writeFloat (p.kerningAmount); @@ -313,51 +302,50 @@ float CustomTypeface::getStringWidth (const String& text) { float x = 0; - for (String::CharPointerType t (text.getCharPointer()); ! t.isEmpty();) + for (auto t = text.getCharPointer(); ! t.isEmpty();) { - const juce_wchar c = t.getAndAdvance(); + auto c = t.getAndAdvance(); - if (const GlyphInfo* const glyph = findGlyph (c, true)) + if (auto* glyph = findGlyph (c, true)) { x += glyph->getHorizontalSpacing (*t); } else { - const Typeface::Ptr fallbackTypeface (Typeface::getFallbackTypeface()); - - if (fallbackTypeface != nullptr && fallbackTypeface != this) - x += fallbackTypeface->getStringWidth (String::charToString (c)); + if (auto fallbackTypeface = Typeface::getFallbackTypeface()) + if (fallbackTypeface != this) + x += fallbackTypeface->getStringWidth (String::charToString (c)); } } return x; } -void CustomTypeface::getGlyphPositions (const String& text, Array & resultGlyphs, Array& xOffsets) +void CustomTypeface::getGlyphPositions (const String& text, Array& resultGlyphs, Array& xOffsets) { xOffsets.add (0); float x = 0; - for (String::CharPointerType t (text.getCharPointer()); ! t.isEmpty();) + for (auto t = text.getCharPointer(); ! t.isEmpty();) { float width = 0.0f; int glyphChar = 0; - const juce_wchar c = t.getAndAdvance(); + auto c = t.getAndAdvance(); - if (const GlyphInfo* const glyph = findGlyph (c, true)) + if (auto* glyph = findGlyph (c, true)) { width = glyph->getHorizontalSpacing (*t); glyphChar = (int) glyph->character; } else { - const Typeface::Ptr fallbackTypeface (getFallbackTypeface()); + auto fallbackTypeface = getFallbackTypeface(); if (fallbackTypeface != nullptr && fallbackTypeface != this) { - Array subGlyphs; - Array subOffsets; + Array subGlyphs; + Array subOffsets; fallbackTypeface->getGlyphPositions (String::charToString (c), subGlyphs, subOffsets); if (subGlyphs.size() > 0) @@ -376,23 +364,22 @@ void CustomTypeface::getGlyphPositions (const String& text, Array & resultG bool CustomTypeface::getOutlineForGlyph (int glyphNumber, Path& path) { - if (const GlyphInfo* const glyph = findGlyph ((juce_wchar) glyphNumber, true)) + if (auto* glyph = findGlyph ((juce_wchar) glyphNumber, true)) { path = glyph->path; return true; } - const Typeface::Ptr fallbackTypeface (getFallbackTypeface()); - - if (fallbackTypeface != nullptr && fallbackTypeface != this) - return fallbackTypeface->getOutlineForGlyph (glyphNumber, path); + if (auto fallbackTypeface = getFallbackTypeface()) + if (fallbackTypeface != this) + return fallbackTypeface->getOutlineForGlyph (glyphNumber, path); return false; } EdgeTable* CustomTypeface::getEdgeTableForGlyph (int glyphNumber, const AffineTransform& transform, float fontHeight) { - if (const GlyphInfo* const glyph = findGlyph ((juce_wchar) glyphNumber, true)) + if (auto* glyph = findGlyph ((juce_wchar) glyphNumber, true)) { if (! glyph->path.isEmpty()) return new EdgeTable (glyph->path.getBoundsTransformed (transform) @@ -401,10 +388,9 @@ EdgeTable* CustomTypeface::getEdgeTableForGlyph (int glyphNumber, const AffineTr } else { - const Typeface::Ptr fallbackTypeface (getFallbackTypeface()); - - if (fallbackTypeface != nullptr && fallbackTypeface != this) - return fallbackTypeface->getEdgeTableForGlyph (glyphNumber, transform, fontHeight); + if (auto fallbackTypeface = getFallbackTypeface()) + if (fallbackTypeface != this) + return fallbackTypeface->getEdgeTableForGlyph (glyphNumber, transform, fontHeight); } return nullptr; diff --git a/modules/juce_graphics/fonts/juce_CustomTypeface.h b/modules/juce_graphics/fonts/juce_CustomTypeface.h index 36dda6d5cd..306e009c5c 100644 --- a/modules/juce_graphics/fonts/juce_CustomTypeface.h +++ b/modules/juce_graphics/fonts/juce_CustomTypeface.h @@ -132,7 +132,7 @@ public: float getDescent() const override; float getHeightToPointsFactor() const override; float getStringWidth (const String&) override; - void getGlyphPositions (const String&, Array & glyphs, Array& xOffsets) override; + void getGlyphPositions (const String&, Array& glyphs, Array& xOffsets) override; bool getOutlineForGlyph (int glyphNumber, Path&) override; EdgeTable* getEdgeTableForGlyph (int glyphNumber, const AffineTransform&, float fontHeight) override; diff --git a/modules/juce_graphics/fonts/juce_Font.cpp b/modules/juce_graphics/fonts/juce_Font.cpp index 40e7f1bdea..5b1b85aaca 100644 --- a/modules/juce_graphics/fonts/juce_Font.cpp +++ b/modules/juce_graphics/fonts/juce_Font.cpp @@ -139,14 +139,14 @@ public: private: struct CachedFace { - CachedFace() noexcept : lastUsageCount (0) {} + CachedFace() noexcept {} // Although it seems a bit wacky to store the name here, it's because it may be a // placeholder rather than a real one, e.g. "" vs the actual typeface name. // Since the typeface itself doesn't know that it may have this alias, the name under // which it was fetched needs to be stored separately. String typefaceName, typefaceStyle; - size_t lastUsageCount; + size_t lastUsageCount = 0; Typeface::Ptr typeface; }; diff --git a/modules/juce_graphics/fonts/juce_Font.h b/modules/juce_graphics/fonts/juce_Font.h index cacea2d219..54440a349e 100644 --- a/modules/juce_graphics/fonts/juce_Font.h +++ b/modules/juce_graphics/fonts/juce_Font.h @@ -392,7 +392,7 @@ public: An extra x offset is added at the end of the run, to indicate where the right hand edge of the last character is. */ - void getGlyphPositions (const String& text, Array & glyphs, Array & xOffsets) const; + void getGlyphPositions (const String& text, Array& glyphs, Array& xOffsets) const; //============================================================================== /** Returns the typeface used by this font. diff --git a/modules/juce_graphics/fonts/juce_Typeface.h b/modules/juce_graphics/fonts/juce_Typeface.h index 82a2eb8f6d..c9e7e38eb7 100644 --- a/modules/juce_graphics/fonts/juce_Typeface.h +++ b/modules/juce_graphics/fonts/juce_Typeface.h @@ -110,7 +110,7 @@ public: The distances returned are based on the font having an normalised height of 1.0. You should never need to call this directly! Use Font::getGlyphPositions() instead! */ - virtual void getGlyphPositions (const String& text, Array & glyphs, Array& xOffsets) = 0; + virtual void getGlyphPositions (const String& text, Array& glyphs, Array& xOffsets) = 0; /** Returns the outline for a glyph. The path returned will be normalised to a font height of 1.0. diff --git a/modules/juce_gui_basics/keyboard/juce_TextInputTarget.h b/modules/juce_gui_basics/keyboard/juce_TextInputTarget.h index 9d198be134..44b28c261e 100644 --- a/modules/juce_gui_basics/keyboard/juce_TextInputTarget.h +++ b/modules/juce_gui_basics/keyboard/juce_TextInputTarget.h @@ -62,7 +62,7 @@ public: /** Sets a number of temporarily underlined sections. This is needed by MS Windows input method UI. */ - virtual void setTemporaryUnderlining (const Array >& underlinedRegions) = 0; + virtual void setTemporaryUnderlining (const Array>& underlinedRegions) = 0; /** Returns a specified sub-section of the text. */ virtual String getTextInRange (const Range& range) const = 0; diff --git a/modules/juce_gui_basics/layout/juce_ComponentMovementWatcher.cpp b/modules/juce_gui_basics/layout/juce_ComponentMovementWatcher.cpp index 6e5cfe94e3..448891b794 100644 --- a/modules/juce_gui_basics/layout/juce_ComponentMovementWatcher.cpp +++ b/modules/juce_gui_basics/layout/juce_ComponentMovementWatcher.cpp @@ -29,14 +29,11 @@ namespace juce ComponentMovementWatcher::ComponentMovementWatcher (Component* const comp) : component (comp), - lastPeerID (0), - reentrant (false), wasShowing (comp->isShowing()) { jassert (component != nullptr); // can't use this with a null pointer.. component->addComponentListener (this); - registerWithParentComps(); } @@ -55,8 +52,8 @@ void ComponentMovementWatcher::componentParentHierarchyChanged (Component&) { const ScopedValueSetter setter (reentrant, true); - ComponentPeer* const peer = component->getPeer(); - const uint32 peerID = peer != nullptr ? peer->getUniqueID() : 0; + auto* peer = component->getPeer(); + auto peerID = peer != nullptr ? peer->getUniqueID() : 0; if (peerID != lastPeerID) { @@ -85,7 +82,7 @@ void ComponentMovementWatcher::componentMovedOrResized (Component&, bool wasMove if (wasMoved) { Point newPos; - Component* const top = component->getTopLevelComponent(); + auto* top = component->getTopLevelComponent(); if (top != component) newPos = top->getLocalPoint (component, Point()); @@ -128,7 +125,7 @@ void ComponentMovementWatcher::componentVisibilityChanged (Component&) void ComponentMovementWatcher::registerWithParentComps() { - for (Component* p = component->getParentComponent(); p != nullptr; p = p->getParentComponent()) + for (auto* p = component->getParentComponent(); p != nullptr; p = p->getParentComponent()) { p->addComponentListener (this); registeredParentComps.add (p); @@ -137,8 +134,8 @@ void ComponentMovementWatcher::registerWithParentComps() void ComponentMovementWatcher::unregister() { - for (int i = registeredParentComps.size(); --i >= 0;) - registeredParentComps.getUnchecked(i)->removeComponentListener (this); + for (auto* c : registeredParentComps) + c->removeComponentListener (this); registeredParentComps.clear(); } diff --git a/modules/juce_gui_basics/layout/juce_ComponentMovementWatcher.h b/modules/juce_gui_basics/layout/juce_ComponentMovementWatcher.h index 583ae4e32f..c425ab36e5 100644 --- a/modules/juce_gui_basics/layout/juce_ComponentMovementWatcher.h +++ b/modules/juce_gui_basics/layout/juce_ComponentMovementWatcher.h @@ -81,9 +81,9 @@ public: private: //============================================================================== WeakReference component; - uint32 lastPeerID; - Array registeredParentComps; - bool reentrant, wasShowing; + uint32 lastPeerID = 0; + Array registeredParentComps; + bool reentrant = false, wasShowing; Rectangle lastBounds; void unregister(); diff --git a/modules/juce_gui_basics/layout/juce_MultiDocumentPanel.cpp b/modules/juce_gui_basics/layout/juce_MultiDocumentPanel.cpp index 94d0c88a91..210fafd4b8 100644 --- a/modules/juce_gui_basics/layout/juce_MultiDocumentPanel.cpp +++ b/modules/juce_gui_basics/layout/juce_MultiDocumentPanel.cpp @@ -40,7 +40,7 @@ MultiDocumentPanelWindow::~MultiDocumentPanelWindow() //============================================================================== void MultiDocumentPanelWindow::maximiseButtonPressed() { - if (MultiDocumentPanel* const owner = getOwner()) + if (auto* owner = getOwner()) owner->setLayoutMode (MultiDocumentPanel::MaximisedWindowsWithTabs); else jassertfalse; // these windows are only designed to be used inside a MultiDocumentPanel! @@ -48,7 +48,7 @@ void MultiDocumentPanelWindow::maximiseButtonPressed() void MultiDocumentPanelWindow::closeButtonPressed() { - if (MultiDocumentPanel* const owner = getOwner()) + if (auto* owner = getOwner()) owner->closeDocument (getContentComponent(), true); else jassertfalse; // these windows are only designed to be used inside a MultiDocumentPanel! @@ -68,7 +68,7 @@ void MultiDocumentPanelWindow::broughtToFront() void MultiDocumentPanelWindow::updateOrder() { - if (MultiDocumentPanel* const owner = getOwner()) + if (auto* owner = getOwner()) owner->updateOrder(); } @@ -77,19 +77,14 @@ MultiDocumentPanel* MultiDocumentPanelWindow::getOwner() const noexcept return findParentComponentOfClass(); } - //============================================================================== -class MultiDocumentPanel::TabbedComponentInternal : public TabbedComponent +struct MultiDocumentPanel::TabbedComponentInternal : public TabbedComponent { -public: - TabbedComponentInternal() - : TabbedComponent (TabbedButtonBar::TabsAtTop) - { - } + TabbedComponentInternal() : TabbedComponent (TabbedButtonBar::TabsAtTop) {} - void currentTabChanged (int, const String&) + void currentTabChanged (int, const String&) override { - if (MultiDocumentPanel* const owner = findParentComponentOfClass()) + if (auto* owner = findParentComponentOfClass()) owner->updateOrder(); } }; @@ -97,10 +92,6 @@ public: //============================================================================== MultiDocumentPanel::MultiDocumentPanel() - : mode (MaximisedWindowsWithTabs), - backgroundColour (Colours::lightblue), - maximumNumDocuments (0), - numDocsBeforeTabsUsed (0) { setOpaque (true); } @@ -121,7 +112,7 @@ namespace MultiDocHelpers bool MultiDocumentPanel::closeAllDocuments (const bool checkItsOkToCloseFirst) { - while (components.size() > 0) + while (! components.isEmpty()) if (! closeDocument (components.getLast(), checkItsOkToCloseFirst)) return false; @@ -135,13 +126,13 @@ MultiDocumentPanelWindow* MultiDocumentPanel::createNewDocumentWindow() void MultiDocumentPanel::addWindow (Component* component) { - MultiDocumentPanelWindow* const dw = createNewDocumentWindow(); + auto* dw = createNewDocumentWindow(); dw->setResizable (true, false); dw->setContentNonOwned (component, true); dw->setName (component->getName()); - const var bkg (component->getProperties() ["mdiDocumentBkg_"]); + auto bkg = component->getProperties() ["mdiDocumentBkg_"]; dw->setBackgroundColour (bkg.isVoid() ? backgroundColour : Colour ((uint32) static_cast (bkg))); int x = 4; @@ -152,7 +143,7 @@ void MultiDocumentPanel::addWindow (Component* component) dw->setTopLeftPosition (x, x); - const var pos (component->getProperties() ["mdiDocumentPos_"]); + auto pos = component->getProperties() ["mdiDocumentPos_"]; if (pos.toString().isNotEmpty()) dw->restoreWindowStateFromString (pos.toString()); @@ -203,10 +194,10 @@ bool MultiDocumentPanel::addDocument (Component* const component, { addAndMakeVisible (tabComponent = new TabbedComponentInternal()); - Array temp (components); + auto temp = components; - for (int i = 0; i < temp.size(); ++i) - tabComponent->addTab (temp[i]->getName(), docColour, temp[i], false); + for (auto& c : temp) + tabComponent->addTab (c->getName(), docColour, c, false); resized(); } @@ -302,7 +293,7 @@ bool MultiDocumentPanel::closeDocument (Component* component, resized(); // This ensures that the active tab is painted properly when a tab is closed! - if (Component* activeComponent = getActiveDocument()) + if (auto* activeComponent = getActiveDocument()) setActiveDocument (activeComponent); activeDocumentChanged(); @@ -414,17 +405,13 @@ void MultiDocumentPanel::setLayoutMode (const LayoutMode newLayoutMode) resized(); - const Array tempComps (components); + auto tempComps = components; components.clear(); - for (int i = 0; i < tempComps.size(); ++i) - { - Component* const c = tempComps.getUnchecked(i); - + for (auto* c : tempComps) addDocument (c, Colour ((uint32) static_cast (c->getProperties().getWithDefault ("mdiDocumentBkg_", (int) Colours::white.getARGB()))), MultiDocHelpers::shouldDeleteComp (c)); - } } } diff --git a/modules/juce_gui_basics/layout/juce_MultiDocumentPanel.h b/modules/juce_gui_basics/layout/juce_MultiDocumentPanel.h index a19c37c14f..3635711f0a 100644 --- a/modules/juce_gui_basics/layout/juce_MultiDocumentPanel.h +++ b/modules/juce_gui_basics/layout/juce_MultiDocumentPanel.h @@ -285,15 +285,14 @@ public: private: //============================================================================== - LayoutMode mode; - Array components; + LayoutMode mode = MaximisedWindowsWithTabs; + Array components; ScopedPointer tabComponent; - Colour backgroundColour; - int maximumNumDocuments, numDocsBeforeTabsUsed; + Colour backgroundColour { Colours::lightblue }; + int maximumNumDocuments = 0, numDocsBeforeTabsUsed = 0; - class TabbedComponentInternal; + struct TabbedComponentInternal; friend class MultiDocumentPanelWindow; - friend class TabbedComponentInternal; Component* getContainerComp (Component*) const; void updateOrder(); diff --git a/modules/juce_gui_basics/layout/juce_StretchableLayoutManager.cpp b/modules/juce_gui_basics/layout/juce_StretchableLayoutManager.cpp index 75a52fa4f8..fee36cae3b 100644 --- a/modules/juce_gui_basics/layout/juce_StretchableLayoutManager.cpp +++ b/modules/juce_gui_basics/layout/juce_StretchableLayoutManager.cpp @@ -27,14 +27,8 @@ namespace juce { -StretchableLayoutManager::StretchableLayoutManager() - : totalSize (0) -{ -} - -StretchableLayoutManager::~StretchableLayoutManager() -{ -} +StretchableLayoutManager::StretchableLayoutManager() {} +StretchableLayoutManager::~StretchableLayoutManager() {} //============================================================================== void StretchableLayoutManager::clearAllItems() @@ -48,7 +42,7 @@ void StretchableLayoutManager::setItemLayout (const int itemIndex, const double maximumSize, const double preferredSize) { - ItemLayoutProperties* layout = getInfoFor (itemIndex); + auto* layout = getInfoFor (itemIndex); if (layout == nullptr) { @@ -74,7 +68,7 @@ bool StretchableLayoutManager::getItemLayout (const int itemIndex, double& maximumSize, double& preferredSize) const { - if (const ItemLayoutProperties* const layout = getInfoFor (itemIndex)) + if (auto* layout = getInfoFor (itemIndex)) { minimumSize = layout->minSize; maximumSize = layout->maxSize; @@ -98,7 +92,7 @@ int StretchableLayoutManager::getItemCurrentPosition (const int itemIndex) const int pos = 0; for (int i = 0; i < itemIndex; ++i) - if (const ItemLayoutProperties* const layout = getInfoFor (i)) + if (auto* layout = getInfoFor (i)) pos += layout->currentSize; return pos; @@ -106,7 +100,7 @@ int StretchableLayoutManager::getItemCurrentPosition (const int itemIndex) const int StretchableLayoutManager::getItemCurrentAbsoluteSize (const int itemIndex) const { - if (const ItemLayoutProperties* const layout = getInfoFor (itemIndex)) + if (auto* layout = getInfoFor (itemIndex)) return layout->currentSize; return 0; @@ -114,7 +108,7 @@ int StretchableLayoutManager::getItemCurrentAbsoluteSize (const int itemIndex) c double StretchableLayoutManager::getItemCurrentRelativeSize (const int itemIndex) const { - if (const ItemLayoutProperties* const layout = getInfoFor (itemIndex)) + if (auto* layout = getInfoFor (itemIndex)) return -layout->currentSize / (double) totalSize; return 0; @@ -125,18 +119,18 @@ void StretchableLayoutManager::setItemPosition (const int itemIndex, { for (int i = items.size(); --i >= 0;) { - const ItemLayoutProperties* const layout = items.getUnchecked(i); + auto* layout = items.getUnchecked(i); if (layout->itemIndex == itemIndex) { - int realTotalSize = jmax (totalSize, getMinimumSizeOfItems (0, items.size())); - const int minSizeAfterThisComp = getMinimumSizeOfItems (i, items.size()); - const int maxSizeAfterThisComp = getMaximumSizeOfItems (i + 1, items.size()); + auto realTotalSize = jmax (totalSize, getMinimumSizeOfItems (0, items.size())); + auto minSizeAfterThisComp = getMinimumSizeOfItems (i, items.size()); + auto maxSizeAfterThisComp = getMaximumSizeOfItems (i + 1, items.size()); newPosition = jmax (newPosition, totalSize - maxSizeAfterThisComp - layout->currentSize); newPosition = jmin (newPosition, realTotalSize - minSizeAfterThisComp); - int endPos = fitComponentsIntoSpace (0, i, newPosition, 0); + auto endPos = fitComponentsIntoSpace (0, i, newPosition, 0); endPos += layout->currentSize; @@ -159,9 +153,9 @@ void StretchableLayoutManager::layOutComponents (Component** const components, for (int i = 0; i < numComponents; ++i) { - if (const ItemLayoutProperties* const layout = getInfoFor (i)) + if (auto* layout = getInfoFor (i)) { - if (Component* const c = components[i]) + if (auto* c = components[i]) { if (i == numComponents - 1) { @@ -209,9 +203,9 @@ void StretchableLayoutManager::layOutComponents (Component** const components, //============================================================================== StretchableLayoutManager::ItemLayoutProperties* StretchableLayoutManager::getInfoFor (const int itemIndex) const { - for (int i = items.size(); --i >= 0;) - if (items.getUnchecked(i)->itemIndex == itemIndex) - return items.getUnchecked(i); + for (auto* i : items) + if (i->itemIndex == itemIndex) + return i; return nullptr; } @@ -227,7 +221,7 @@ int StretchableLayoutManager::fitComponentsIntoSpace (const int startIndex, for (int i = startIndex; i < endIndex; ++i) { - ItemLayoutProperties* const layout = items.getUnchecked (i); + auto* layout = items.getUnchecked (i); layout->currentSize = sizeToRealSize (layout->minSize, totalSize); @@ -249,14 +243,14 @@ int StretchableLayoutManager::fitComponentsIntoSpace (const int startIndex, // first figure out how many comps want a slice of the extra space.. for (int i = startIndex; i < endIndex; ++i) { - ItemLayoutProperties* const layout = items.getUnchecked (i); + auto* layout = items.getUnchecked (i); - double sizeWanted = sizeToRealSize (layout->preferredSize, totalSize); + auto sizeWanted = sizeToRealSize (layout->preferredSize, totalSize); - const int bestSize = jlimit (layout->currentSize, - jmax (layout->currentSize, - sizeToRealSize (layout->maxSize, totalSize)), - roundToInt (sizeWanted * availableSpace / totalIdealSize)); + auto bestSize = jlimit (layout->currentSize, + jmax (layout->currentSize, + sizeToRealSize (layout->maxSize, totalSize)), + roundToInt (sizeWanted * availableSpace / totalIdealSize)); if (bestSize > layout->currentSize) ++numWantingMoreSpace; @@ -265,20 +259,20 @@ int StretchableLayoutManager::fitComponentsIntoSpace (const int startIndex, // ..share out the extra space.. for (int i = startIndex; i < endIndex; ++i) { - ItemLayoutProperties* const layout = items.getUnchecked (i); + auto* layout = items.getUnchecked (i); - double sizeWanted = sizeToRealSize (layout->preferredSize, totalSize); + auto sizeWanted = sizeToRealSize (layout->preferredSize, totalSize); - int bestSize = jlimit (layout->currentSize, - jmax (layout->currentSize, sizeToRealSize (layout->maxSize, totalSize)), - roundToInt (sizeWanted * availableSpace / totalIdealSize)); + auto bestSize = jlimit (layout->currentSize, + jmax (layout->currentSize, sizeToRealSize (layout->maxSize, totalSize)), + roundToInt (sizeWanted * availableSpace / totalIdealSize)); - const int extraWanted = bestSize - layout->currentSize; + auto extraWanted = bestSize - layout->currentSize; if (extraWanted > 0) { - const int extraAllowed = jmin (extraWanted, - extraSpace / jmax (1, numWantingMoreSpace)); + auto extraAllowed = jmin (extraWanted, + extraSpace / jmax (1, numWantingMoreSpace)); if (extraAllowed > 0) { @@ -298,7 +292,7 @@ int StretchableLayoutManager::fitComponentsIntoSpace (const int startIndex, // ..and calculate the end position for (int i = startIndex; i < endIndex; ++i) { - ItemLayoutProperties* const layout = items.getUnchecked(i); + auto* layout = items.getUnchecked(i); startPos += layout->currentSize; } @@ -330,7 +324,7 @@ void StretchableLayoutManager::updatePrefSizesToMatchCurrentPositions() { for (int i = 0; i < items.size(); ++i) { - ItemLayoutProperties* const layout = items.getUnchecked (i); + auto* layout = items.getUnchecked (i); layout->preferredSize = (layout->preferredSize < 0) ? getItemCurrentRelativeSize (i) diff --git a/modules/juce_gui_basics/layout/juce_StretchableLayoutManager.h b/modules/juce_gui_basics/layout/juce_StretchableLayoutManager.h index e6b72ed40f..4a5468a378 100644 --- a/modules/juce_gui_basics/layout/juce_StretchableLayoutManager.h +++ b/modules/juce_gui_basics/layout/juce_StretchableLayoutManager.h @@ -242,8 +242,8 @@ private: double minSize, maxSize, preferredSize; }; - OwnedArray items; - int totalSize; + OwnedArray items; + int totalSize = 0; //============================================================================== static int sizeToRealSize (double size, int totalSpace); diff --git a/modules/juce_gui_basics/layout/juce_TabbedButtonBar.cpp b/modules/juce_gui_basics/layout/juce_TabbedButtonBar.cpp index 0031a1882d..7bcf2a33ad 100644 --- a/modules/juce_gui_basics/layout/juce_TabbedButtonBar.cpp +++ b/modules/juce_gui_basics/layout/juce_TabbedButtonBar.cpp @@ -27,8 +27,8 @@ namespace juce { -TabBarButton::TabBarButton (const String& name, TabbedButtonBar& owner_) - : Button (name), owner (owner_), overlapPixels (0), extraCompPlacement (afterText) +TabBarButton::TabBarButton (const String& name, TabbedButtonBar& bar) + : Button (name), owner (bar) { setWantsKeyboardFocus (false); } @@ -54,7 +54,7 @@ void TabBarButton::clicked (const ModifierKeys& mods) bool TabBarButton::hitTest (int mx, int my) { - const Rectangle area (getActiveArea()); + auto area = getActiveArea(); if (owner.isVertical()) { @@ -83,11 +83,11 @@ int TabBarButton::getBestTabLength (const int depth) void TabBarButton::calcAreas (Rectangle& extraComp, Rectangle& textArea) const { - LookAndFeel& lf = getLookAndFeel(); + auto& lf = getLookAndFeel(); textArea = getActiveArea(); - const int depth = owner.isVertical() ? textArea.getWidth() : textArea.getHeight(); - const int overlap = lf.getTabButtonOverlap (depth); + auto depth = owner.isVertical() ? textArea.getWidth() : textArea.getHeight(); + auto overlap = lf.getTabButtonOverlap (depth); if (overlap > 0) { @@ -101,7 +101,7 @@ void TabBarButton::calcAreas (Rectangle& extraComp, Rectangle& textAre { extraComp = lf.getTabButtonExtraComponentBounds (*this, textArea, *extraComponent); - const TabbedButtonBar::Orientation orientation = owner.getOrientation(); + auto orientation = owner.getOrientation(); if (orientation == TabbedButtonBar::TabsAtLeft || orientation == TabbedButtonBar::TabsAtRight) { @@ -129,9 +129,9 @@ Rectangle TabBarButton::getTextArea() const Rectangle TabBarButton::getActiveArea() const { - Rectangle r (getLocalBounds()); - const int spaceAroundImage = getLookAndFeel().getTabButtonSpaceAroundImage(); - const TabbedButtonBar::Orientation orientation = owner.getOrientation(); + auto r = getLocalBounds(); + auto spaceAroundImage = getLookAndFeel().getTabButtonSpaceAroundImage(); + auto orientation = owner.getOrientation(); if (orientation != TabbedButtonBar::TabsAtLeft) r.removeFromRight (spaceAroundImage); if (orientation != TabbedButtonBar::TabsAtRight) r.removeFromLeft (spaceAroundImage); @@ -203,10 +203,8 @@ private: //============================================================================== -TabbedButtonBar::TabbedButtonBar (const Orientation orientation_) - : orientation (orientation_), - minimumScale (0.7), - currentTabIndex (-1) +TabbedButtonBar::TabbedButtonBar (Orientation orientationToUse) + : orientation (orientationToUse) { setInterceptsMouseClicks (false, true); addAndMakeVisible (behindFrontTab = new BehindFrontTabComp (*this)); @@ -260,9 +258,9 @@ void TabbedButtonBar::addTab (const String& tabName, if (! isPositiveAndBelow (insertIndex, tabs.size())) insertIndex = tabs.size(); - TabInfo* const currentTab = tabs [currentTabIndex]; + auto* currentTab = tabs[currentTabIndex]; - TabInfo* newTab = new TabInfo(); + auto* newTab = new TabInfo(); newTab->name = tabName; newTab->colour = tabBackgroundColour; newTab->button = createTabButton (tabName, insertIndex); @@ -279,9 +277,9 @@ void TabbedButtonBar::addTab (const String& tabName, } } -void TabbedButtonBar::setTabName (const int tabIndex, const String& newName) +void TabbedButtonBar::setTabName (int tabIndex, const String& newName) { - if (TabInfo* const tab = tabs [tabIndex]) + if (auto* tab = tabs[tabIndex]) { if (tab->name != newName) { @@ -296,7 +294,7 @@ void TabbedButtonBar::removeTab (const int indexToRemove, const bool animate) { if (isPositiveAndBelow (indexToRemove, tabs.size())) { - int oldSelectedIndex = currentTabIndex; + auto oldSelectedIndex = currentTabIndex; if (indexToRemove == currentTabIndex) oldSelectedIndex = -1; @@ -312,7 +310,7 @@ void TabbedButtonBar::removeTab (const int indexToRemove, const bool animate) void TabbedButtonBar::moveTab (const int currentIndex, const int newIndex, const bool animate) { - TabInfo* const currentTab = tabs [currentTabIndex]; + auto* currentTab = tabs[currentTabIndex]; tabs.move (currentIndex, newIndex); currentTabIndex = tabs.indexOf (currentTab); updateTabPositions (animate); @@ -325,21 +323,23 @@ int TabbedButtonBar::getNumTabs() const String TabbedButtonBar::getCurrentTabName() const { - TabInfo* tab = tabs [currentTabIndex]; - return tab == nullptr ? String() : tab->name; + if (auto* tab = tabs [currentTabIndex]) + return tab->name; + + return {}; } StringArray TabbedButtonBar::getTabNames() const { StringArray names; - for (int i = 0; i < tabs.size(); ++i) - names.add (tabs.getUnchecked(i)->name); + for (auto* t : tabs) + names.add (t->name); return names; } -void TabbedButtonBar::setCurrentTabIndex (int newIndex, const bool sendChangeMessage_) +void TabbedButtonBar::setCurrentTabIndex (int newIndex, bool shouldSendChangeMessage) { if (currentTabIndex != newIndex) { @@ -349,14 +349,11 @@ void TabbedButtonBar::setCurrentTabIndex (int newIndex, const bool sendChangeMes currentTabIndex = newIndex; for (int i = 0; i < tabs.size(); ++i) - { - TabBarButton* tb = tabs.getUnchecked(i)->button; - tb->setToggleState (i == newIndex, dontSendNotification); - } + tabs.getUnchecked(i)->button->setToggleState (i == newIndex, dontSendNotification); resized(); - if (sendChangeMessage_) + if (shouldSendChangeMessage) sendChangeMessage(); currentTabChanged (newIndex, getCurrentTabName()); @@ -365,7 +362,7 @@ void TabbedButtonBar::setCurrentTabIndex (int newIndex, const bool sendChangeMes TabBarButton* TabbedButtonBar::getTabButton (const int index) const { - if (TabInfo* tab = tabs[index]) + if (auto* tab = tabs[index]) return static_cast (tab->button); return nullptr; @@ -383,11 +380,12 @@ int TabbedButtonBar::indexOfTabButton (const TabBarButton* button) const Rectangle TabbedButtonBar::getTargetBounds (TabBarButton* button) const { if (button == nullptr || indexOfTabButton (button) == -1) - return Rectangle(); + return {}; - ComponentAnimator& animator = Desktop::getInstance().getAnimator(); + auto& animator = Desktop::getInstance().getAnimator(); - return animator.isAnimating (button) ? animator.getComponentDestination (button) : button->getBounds(); + return animator.isAnimating (button) ? animator.getComponentDestination (button) + : button->getBounds(); } void TabbedButtonBar::lookAndFeelChanged() @@ -409,22 +407,22 @@ void TabbedButtonBar::resized() //============================================================================== void TabbedButtonBar::updateTabPositions (bool animate) { - LookAndFeel& lf = getLookAndFeel(); + auto& lf = getLookAndFeel(); - int depth = getWidth(); - int length = getHeight(); + auto depth = getWidth(); + auto length = getHeight(); if (! isVertical()) std::swap (depth, length); - const int overlap = lf.getTabButtonOverlap (depth) + lf.getTabButtonSpaceAroundImage() * 2; + auto overlap = lf.getTabButtonOverlap (depth) + lf.getTabButtonSpaceAroundImage() * 2; - int totalLength = jmax (0, overlap); - int numVisibleButtons = tabs.size(); + auto totalLength = jmax (0, overlap); + auto numVisibleButtons = tabs.size(); for (int i = 0; i < tabs.size(); ++i) { - TabBarButton* const tb = tabs.getUnchecked(i)->button; + auto* tb = tabs.getUnchecked(i)->button.get(); totalLength += tb->getBestTabLength (depth) - overlap; tb->overlapPixels = jmax (0, overlap / 2); @@ -448,7 +446,7 @@ void TabbedButtonBar::updateTabPositions (bool animate) extraTabsButton->setTriggeredOnMouseDown (true); } - const int buttonSize = jmin (proportionOfWidth (0.7f), proportionOfHeight (0.7f)); + auto buttonSize = jmin (proportionOfWidth (0.7f), proportionOfHeight (0.7f)); extraTabsButton->setSize (buttonSize, buttonSize); if (isVertical()) @@ -466,8 +464,8 @@ void TabbedButtonBar::updateTabPositions (bool animate) for (int i = 0; i < tabs.size(); ++i) { - TabBarButton* const tb = tabs.getUnchecked(i)->button; - const int newLength = totalLength + tb->getBestTabLength (depth); + auto* tb = tabs.getUnchecked(i)->button.get(); + auto newLength = totalLength + tb->getBestTabLength (depth); if (i > 0 && newLength * minimumScale > tabsButtonPos) { @@ -489,18 +487,18 @@ void TabbedButtonBar::updateTabPositions (bool animate) int pos = 0; TabBarButton* frontTab = nullptr; - ComponentAnimator& animator = Desktop::getInstance().getAnimator(); + auto& animator = Desktop::getInstance().getAnimator(); for (int i = 0; i < tabs.size(); ++i) { - if (TabBarButton* const tb = getTabButton (i)) + if (auto* tb = getTabButton (i)) { - const int bestLength = roundToInt (scale * tb->getBestTabLength (depth)); + auto bestLength = roundToInt (scale * tb->getBestTabLength (depth)); if (i < numVisibleButtons) { - const Rectangle newBounds (isVertical() ? Rectangle (0, pos, getWidth(), bestLength) - : Rectangle (pos, 0, bestLength, getHeight())); + auto newBounds = isVertical() ? Rectangle (0, pos, getWidth(), bestLength) + : Rectangle (pos, 0, bestLength, getHeight()); if (animate) { @@ -538,17 +536,17 @@ void TabbedButtonBar::updateTabPositions (bool animate) } //============================================================================== -Colour TabbedButtonBar::getTabBackgroundColour (const int tabIndex) +Colour TabbedButtonBar::getTabBackgroundColour (int tabIndex) { - if (TabInfo* tab = tabs [tabIndex]) + if (auto* tab = tabs[tabIndex]) return tab->colour; return Colours::transparentBlack; } -void TabbedButtonBar::setTabBackgroundColour (const int tabIndex, Colour newColour) +void TabbedButtonBar::setTabBackgroundColour (int tabIndex, Colour newColour) { - if (TabInfo* const tab = tabs [tabIndex]) + if (auto* tab = tabs [tabIndex]) { if (tab->colour != newColour) { @@ -570,7 +568,7 @@ void TabbedButtonBar::showExtraItemsMenu() for (int i = 0; i < tabs.size(); ++i) { - const TabInfo* const tab = tabs.getUnchecked(i); + auto* tab = tabs.getUnchecked(i); if (! tab->button->isVisible()) m.addItem (i + 1, tab->name, true, i == currentTabIndex); @@ -581,12 +579,7 @@ void TabbedButtonBar::showExtraItemsMenu() } //============================================================================== -void TabbedButtonBar::currentTabChanged (const int, const String&) -{ -} - -void TabbedButtonBar::popupMenuClickOnTab (const int, const String&) -{ -} +void TabbedButtonBar::currentTabChanged (int, const String&) {} +void TabbedButtonBar::popupMenuClickOnTab (int, const String&) {} } // namespace juce diff --git a/modules/juce_gui_basics/layout/juce_TabbedButtonBar.h b/modules/juce_gui_basics/layout/juce_TabbedButtonBar.h index a788408c93..54ad0a0596 100644 --- a/modules/juce_gui_basics/layout/juce_TabbedButtonBar.h +++ b/modules/juce_gui_basics/layout/juce_TabbedButtonBar.h @@ -120,10 +120,10 @@ public: protected: friend class TabbedButtonBar; TabbedButtonBar& owner; - int overlapPixels; + int overlapPixels = 0; ScopedPointer extraComponent; - ExtraComponentPlacement extraCompPlacement; + ExtraComponentPlacement extraCompPlacement = afterText; private: void calcAreas (Rectangle&, Rectangle&) const; @@ -341,8 +341,6 @@ protected: virtual TabBarButton* createTabButton (const String& tabName, int tabIndex); private: - Orientation orientation; - struct TabInfo { ScopedPointer button; @@ -350,10 +348,11 @@ private: Colour colour; }; - OwnedArray tabs; + OwnedArray tabs; - double minimumScale; - int currentTabIndex; + Orientation orientation; + double minimumScale = 0.7; + int currentTabIndex = -1; class BehindFrontTabComp; friend class BehindFrontTabComp; diff --git a/modules/juce_gui_basics/layout/juce_TabbedComponent.cpp b/modules/juce_gui_basics/layout/juce_TabbedComponent.cpp index d6349e32f1..21f45ff98a 100644 --- a/modules/juce_gui_basics/layout/juce_TabbedComponent.cpp +++ b/modules/juce_gui_basics/layout/juce_TabbedComponent.cpp @@ -54,12 +54,10 @@ namespace TabbedComponentHelpers } //============================================================================== -class TabbedComponent::ButtonBar : public TabbedButtonBar +struct TabbedComponent::ButtonBar : public TabbedButtonBar { -public: - ButtonBar (TabbedComponent& owner_, const TabbedButtonBar::Orientation orientation_) - : TabbedButtonBar (orientation_), - owner (owner_) + ButtonBar (TabbedComponent& tabComp, TabbedButtonBar::Orientation o) + : TabbedButtonBar (o), owner (tabComp) { } @@ -83,7 +81,6 @@ public: return owner.createTabButton (tabName, tabIndex); } -private: TabbedComponent& owner; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ButtonBar) @@ -92,9 +89,6 @@ private: //============================================================================== TabbedComponent::TabbedComponent (const TabbedButtonBar::Orientation orientation) - : tabDepth (30), - outlineThickness (1), - edgeIndent (0) { addAndMakeVisible (tabs = new ButtonBar (*this, orientation)); } @@ -246,7 +240,7 @@ void TabbedComponent::paint (Graphics& g) { g.fillAll (findColour (backgroundColourId)); - Rectangle content (getLocalBounds()); + auto content = getLocalBounds(); BorderSize outline (outlineThickness); TabbedComponentHelpers::getTabArea (content, outline, getOrientation(), tabDepth); @@ -265,7 +259,7 @@ void TabbedComponent::paint (Graphics& g) void TabbedComponent::resized() { - Rectangle content (getLocalBounds()); + auto content = getLocalBounds(); BorderSize outline (outlineThickness); tabs->setBounds (TabbedComponentHelpers::getTabArea (content, outline, getOrientation(), tabDepth)); @@ -285,7 +279,7 @@ void TabbedComponent::lookAndFeelChanged() void TabbedComponent::changeCallback (const int newCurrentTabIndex, const String& newTabName) { - Component* const newPanelComp = getTabContentComponent (getCurrentTabIndex()); + auto* newPanelComp = getTabContentComponent (getCurrentTabIndex()); if (newPanelComp != panelComponent) { @@ -311,11 +305,10 @@ void TabbedComponent::changeCallback (const int newCurrentTabIndex, const String } resized(); - currentTabChanged (newCurrentTabIndex, newTabName); } -void TabbedComponent::currentTabChanged (const int, const String&) {} -void TabbedComponent::popupMenuClickOnTab (const int, const String&) {} +void TabbedComponent::currentTabChanged (int, const String&) {} +void TabbedComponent::popupMenuClickOnTab (int, const String&) {} } // namespace juce diff --git a/modules/juce_gui_basics/layout/juce_TabbedComponent.h b/modules/juce_gui_basics/layout/juce_TabbedComponent.h index f62846e656..6ba317440b 100644 --- a/modules/juce_gui_basics/layout/juce_TabbedComponent.h +++ b/modules/juce_gui_basics/layout/juce_TabbedComponent.h @@ -211,12 +211,11 @@ protected: private: //============================================================================== - Array > contentComponents; + Array> contentComponents; WeakReference panelComponent; - int tabDepth, outlineThickness, edgeIndent; + int tabDepth = 30, outlineThickness = 1, edgeIndent = 0; - class ButtonBar; - friend class ButtonBar; + struct ButtonBar; void changeCallback (int newCurrentTabIndex, const String& newTabName); JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TabbedComponent) diff --git a/modules/juce_gui_basics/mouse/juce_LassoComponent.h b/modules/juce_gui_basics/mouse/juce_LassoComponent.h index f2c278b118..2b0bda4dd3 100644 --- a/modules/juce_gui_basics/mouse/juce_LassoComponent.h +++ b/modules/juce_gui_basics/mouse/juce_LassoComponent.h @@ -52,7 +52,7 @@ public: component. (i.e. they are the same as the size and position of the lasso component itself). */ - virtual void findLassoItemsInArea (Array & itemsFound, + virtual void findLassoItemsInArea (Array& itemsFound, const Rectangle& area) = 0; /** Returns the SelectedItemSet that the lasso should update. @@ -99,9 +99,7 @@ class LassoComponent : public Component public: //============================================================================== /** Creates a Lasso component. */ - LassoComponent() : source (nullptr) - { - } + LassoComponent() {} //============================================================================== /** Call this in your mouseDown event, to initialise a drag. @@ -158,7 +156,7 @@ public: } else if (e.mods.isCommandDown() || e.mods.isAltDown()) { - Array originalMinusNew (originalSelection); + auto originalMinusNew = originalSelection; originalMinusNew.removeValuesIn (itemsInLasso); itemsInLasso.removeValuesIn (originalSelection); @@ -214,7 +212,7 @@ public: private: //============================================================================== Array originalSelection; - LassoSource* source; + LassoSource* source = nullptr; Point dragStartPos; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LassoComponent) diff --git a/modules/juce_gui_basics/native/juce_mac_Windowing.mm b/modules/juce_gui_basics/native/juce_mac_Windowing.mm index 47b9490544..166cb8ab26 100644 --- a/modules/juce_gui_basics/native/juce_mac_Windowing.mm +++ b/modules/juce_gui_basics/native/juce_mac_Windowing.mm @@ -79,7 +79,7 @@ private: void handleAsyncUpdate() override { - const int result = getResult(); + auto result = getResult(); if (callback != nullptr) callback->modalStateFinished (result); @@ -171,7 +171,7 @@ NSView* getNSViewForDragEvent (Component* sourceComp) sourceComp = draggingSource->getComponentUnderMouse(); if (sourceComp != nullptr) - return (NSView*) sourceComp->getWindowHandle(); + return (NSView*) sourceComp->getWindowHandle(); jassertfalse; // This method must be called in response to a component's mouseDown or mouseDrag event! return nil; @@ -247,18 +247,14 @@ bool DragAndDropContainer::performExternalDragDropOfText (const String& text, Co return false; } -class NSDraggingSourceHelper : public ObjCClass > +struct NSDraggingSourceHelper : public ObjCClass> { -public: - NSDraggingSourceHelper() - : ObjCClass > ("JUCENSDraggingSourceHelper_") + NSDraggingSourceHelper() : ObjCClass> ("JUCENSDraggingSourceHelper_") { addMethod (@selector (draggingSession:sourceOperationMaskForDraggingContext:), sourceOperationMaskForDraggingContext, "c@:@@"); - registerClass(); } -private: static NSDragOperation sourceOperationMaskForDraggingContext (id, SEL, NSDraggingSession*, NSDraggingContext) { return NSDragOperationCopy; @@ -280,6 +276,7 @@ bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& fi if (auto* event = [[view window] currentEvent]) { auto* dragItems = [[[NSMutableArray alloc] init] autorelease]; + for (auto& filename : files) { auto* nsFilename = juceStringToNS (filename); @@ -299,12 +296,9 @@ bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& fi auto* helper = [draggingSourceHelper.createInstance() autorelease]; - if (! [view beginDraggingSessionWithItems: dragItems - event: event - source: helper]) - return false; - - return true; + return [view beginDraggingSessionWithItems: dragItems + event: event + source: helper]; } } } @@ -430,9 +424,8 @@ bool Desktop::isScreenSaverEnabled() } //============================================================================== -class DisplaySettingsChangeCallback : private DeletedAtShutdown +struct DisplaySettingsChangeCallback : private DeletedAtShutdown { -public: DisplaySettingsChangeCallback() { CGDisplayRegisterReconfigurationCallback (displayReconfigurationCallBack, 0); @@ -451,7 +444,6 @@ public: juce_DeclareSingleton_SingleThreaded_Minimal (DisplaySettingsChangeCallback) -private: JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DisplaySettingsChangeCallback) }; @@ -577,7 +569,7 @@ Image createSnapshotOfNativeWindow (void* nativeWindowHandle) return createNSWindowSnapshot ([(NSView*) windowOrView window]); } - return Image(); + return {}; } //============================================================================== @@ -600,12 +592,9 @@ String SystemClipboard::getTextFromClipboard() void Process::setDockIconVisible (bool isVisible) { ProcessSerialNumber psn { 0, kCurrentProcess }; - ProcessApplicationTransformState state = isVisible - ? kProcessTransformToForegroundApplication - : kProcessTransformToUIElementApplication; - - OSStatus err = TransformProcessType (&psn, state); + OSStatus err = TransformProcessType (&psn, isVisible ? kProcessTransformToForegroundApplication + : kProcessTransformToUIElementApplication); jassert (err == 0); ignoreUnused (err); } diff --git a/modules/juce_gui_basics/positioning/juce_RelativePointPath.h b/modules/juce_gui_basics/positioning/juce_RelativePointPath.h index 6e648a5fe1..d0c719dbe3 100644 --- a/modules/juce_gui_basics/positioning/juce_RelativePointPath.h +++ b/modules/juce_gui_basics/positioning/juce_RelativePointPath.h @@ -174,7 +174,7 @@ public: void addElement (ElementBase* newElement); //============================================================================== - OwnedArray elements; + OwnedArray elements; bool usesNonZeroWinding; private: diff --git a/modules/juce_gui_basics/widgets/juce_ToolbarItemPalette.cpp b/modules/juce_gui_basics/widgets/juce_ToolbarItemPalette.cpp index 474e4742a8..7ea946f47d 100644 --- a/modules/juce_gui_basics/widgets/juce_ToolbarItemPalette.cpp +++ b/modules/juce_gui_basics/widgets/juce_ToolbarItemPalette.cpp @@ -30,14 +30,14 @@ namespace juce ToolbarItemPalette::ToolbarItemPalette (ToolbarItemFactory& tbf, Toolbar& bar) : factory (tbf), toolbar (bar) { - Component* const itemHolder = new Component(); + auto* itemHolder = new Component(); viewport.setViewedComponent (itemHolder); Array allIds; factory.getAllToolbarItemIds (allIds); - for (int i = 0; i < allIds.size(); ++i) - addComponent (allIds.getUnchecked (i), -1); + for (auto& i : allIds) + addComponent (i, -1); addAndMakeVisible (viewport); } @@ -49,7 +49,7 @@ ToolbarItemPalette::~ToolbarItemPalette() //============================================================================== void ToolbarItemPalette::addComponent (const int itemId, const int index) { - if (ToolbarItemComponent* const tc = Toolbar::createItem (factory, itemId)) + if (auto* tc = Toolbar::createItem (factory, itemId)) { items.insert (index, tc); viewport.getViewedComponent()->addAndMakeVisible (tc, index); @@ -63,7 +63,7 @@ void ToolbarItemPalette::addComponent (const int itemId, const int index) void ToolbarItemPalette::replaceComponent (ToolbarItemComponent& comp) { - const int index = items.indexOf (&comp); + auto index = items.indexOf (&comp); jassert (index >= 0); items.removeObject (&comp, false); @@ -75,19 +75,17 @@ void ToolbarItemPalette::resized() { viewport.setBoundsInset (BorderSize (1)); - Component* const itemHolder = viewport.getViewedComponent(); + auto* itemHolder = viewport.getViewedComponent(); const int indent = 8; const int preferredWidth = viewport.getWidth() - viewport.getScrollBarThickness() - indent; const int height = toolbar.getThickness(); - int x = indent; - int y = indent; + auto x = indent; + auto y = indent; int maxX = 0; - for (int i = 0; i < items.size(); ++i) + for (auto* tc : items) { - ToolbarItemComponent* const tc = items.getUnchecked(i); - tc->setStyle (toolbar.getStyle()); int preferredSize = 1, minSize = 1, maxSize = 1; diff --git a/modules/juce_gui_basics/widgets/juce_ToolbarItemPalette.h b/modules/juce_gui_basics/widgets/juce_ToolbarItemPalette.h index a281baa258..bbfccf1fbe 100644 --- a/modules/juce_gui_basics/widgets/juce_ToolbarItemPalette.h +++ b/modules/juce_gui_basics/widgets/juce_ToolbarItemPalette.h @@ -64,7 +64,7 @@ private: ToolbarItemFactory& factory; Toolbar& toolbar; Viewport viewport; - OwnedArray items; + OwnedArray items; friend class Toolbar; void replaceComponent (ToolbarItemComponent&); diff --git a/modules/juce_gui_extra/code_editor/juce_CodeDocument.cpp b/modules/juce_gui_extra/code_editor/juce_CodeDocument.cpp index 713b933cf2..58f316c673 100644 --- a/modules/juce_gui_extra/code_editor/juce_CodeDocument.cpp +++ b/modules/juce_gui_extra/code_editor/juce_CodeDocument.cpp @@ -44,20 +44,20 @@ public: static void createLines (Array& newLines, StringRef text) { - String::CharPointerType t (text.text); + auto t = text.text; int charNumInFile = 0; bool finished = false; while (! (finished || t.isEmpty())) { - String::CharPointerType startOfLine (t); - int startOfLineInFile = charNumInFile; + auto startOfLine = t; + auto startOfLineInFile = charNumInFile; int lineLength = 0; int numNewLineChars = 0; for (;;) { - const juce_wchar c = t.getAndAdvance(); + auto c = t.getAndAdvance(); if (c == 0) { @@ -107,9 +107,9 @@ public: lineLength = 0; lineLengthWithoutNewLines = 0; - for (String::CharPointerType t (line.getCharPointer());;) + for (auto t = line.getCharPointer();;) { - const juce_wchar c = t.getAndAdvance(); + auto c = t.getAndAdvance(); if (c == 0) break; @@ -126,32 +126,10 @@ public: }; //============================================================================== -CodeDocument::Iterator::Iterator (const CodeDocument& doc) noexcept - : document (&doc), - charPointer (nullptr), - line (0), - position (0) +CodeDocument::Iterator::Iterator (const CodeDocument& doc) noexcept : document (&doc) { } -CodeDocument::Iterator::Iterator (const CodeDocument::Iterator& other) noexcept - : document (other.document), - charPointer (other.charPointer), - line (other.line), - position (other.position) -{ -} - -CodeDocument::Iterator& CodeDocument::Iterator::operator= (const CodeDocument::Iterator& other) noexcept -{ - document = other.document; - charPointer = other.charPointer; - line = other.line; - position = other.position; - - return *this; -} - CodeDocument::Iterator::~Iterator() noexcept { } @@ -162,13 +140,13 @@ juce_wchar CodeDocument::Iterator::nextChar() noexcept { if (charPointer.getAddress() == nullptr) { - if (const CodeDocumentLine* const l = document->lines[line]) + if (auto* l = document->lines[line]) charPointer = l->line.getCharPointer(); else return 0; } - if (const juce_wchar result = charPointer.getAndAdvance()) + if (auto result = charPointer.getAndAdvance()) { if (charPointer.isEmpty()) { @@ -194,12 +172,10 @@ void CodeDocument::Iterator::skipToEndOfLine() noexcept { if (charPointer.getAddress() == nullptr) { - const CodeDocumentLine* const l = document->lines[line]; - - if (l == nullptr) + if (auto* l = document->lines[line]) + charPointer = l->line.getCharPointer(); + else return; - - charPointer = l->line.getCharPointer(); } position += (int) charPointer.length(); @@ -211,16 +187,16 @@ juce_wchar CodeDocument::Iterator::peekNextChar() const noexcept { if (charPointer.getAddress() == nullptr) { - if (const CodeDocumentLine* const l = document->lines[line]) + if (auto* l = document->lines[line]) charPointer = l->line.getCharPointer(); else return 0; } - if (const juce_wchar c = *charPointer) + if (auto c = *charPointer) return c; - if (const CodeDocumentLine* const l = document->lines [line + 1]) + if (auto* l = document->lines [line + 1]) return l->line[0]; return 0; @@ -239,30 +215,26 @@ bool CodeDocument::Iterator::isEOF() const noexcept //============================================================================== CodeDocument::Position::Position() noexcept - : owner (nullptr), characterPos (0), line (0), - indexInLine (0), positionMaintained (false) { } CodeDocument::Position::Position (const CodeDocument& ownerDocument, const int lineNum, const int index) noexcept : owner (const_cast (&ownerDocument)), - characterPos (0), line (lineNum), - indexInLine (index), positionMaintained (false) + line (lineNum), indexInLine (index) { setLineAndIndex (lineNum, index); } -CodeDocument::Position::Position (const CodeDocument& ownerDocument, const int characterPos_) noexcept - : owner (const_cast (&ownerDocument)), - positionMaintained (false) +CodeDocument::Position::Position (const CodeDocument& ownerDocument, int pos) noexcept + : owner (const_cast (&ownerDocument)) { - setPosition (characterPos_); + setPosition (pos); } CodeDocument::Position::Position (const Position& other) noexcept : owner (other.owner), characterPos (other.characterPos), line (other.line), - indexInLine (other.indexInLine), positionMaintained (false) + indexInLine (other.indexInLine) { jassert (*this == other); } @@ -324,7 +296,7 @@ void CodeDocument::Position::setLineAndIndex (const int newLineNum, const int ne { line = owner->lines.size() - 1; - const CodeDocumentLine& l = *owner->lines.getUnchecked (line); + auto& l = *owner->lines.getUnchecked (line); indexInLine = l.lineLengthWithoutNewLines; characterPos = l.lineStartInFile + indexInLine; } @@ -332,7 +304,7 @@ void CodeDocument::Position::setLineAndIndex (const int newLineNum, const int ne { line = jmax (0, newLineNum); - const CodeDocumentLine& l = *owner->lines.getUnchecked (line); + auto& l = *owner->lines.getUnchecked (line); if (l.lineLengthWithoutNewLines > 0) indexInLine = jlimit (0, l.lineLengthWithoutNewLines, newIndexInLine); @@ -355,7 +327,7 @@ void CodeDocument::Position::setPosition (const int newPosition) if (newPosition > 0) { int lineStart = 0; - int lineEnd = owner->lines.size(); + auto lineEnd = owner->lines.size(); for (;;) { @@ -363,8 +335,8 @@ void CodeDocument::Position::setPosition (const int newPosition) { for (int i = lineStart; i < lineEnd; ++i) { - const CodeDocumentLine& l = *owner->lines.getUnchecked (i); - const int index = newPosition - l.lineStartInFile; + auto& l = *owner->lines.getUnchecked (i); + auto index = newPosition - l.lineStartInFile; if (index >= 0 && (index < l.lineLength || i == lineEnd - 1)) { @@ -378,7 +350,7 @@ void CodeDocument::Position::setPosition (const int newPosition) } else { - const int midIndex = (lineStart + lineEnd + 1) / 2; + auto midIndex = (lineStart + lineEnd + 1) / 2; if (newPosition >= owner->lines.getUnchecked (midIndex)->lineStartInFile) lineStart = midIndex; @@ -400,7 +372,7 @@ void CodeDocument::Position::moveBy (int characterDelta) // If moving right, make sure we don't get stuck between the \r and \n characters.. if (line < owner->lines.size()) { - const CodeDocumentLine& l = *owner->lines.getUnchecked (line); + auto& l = *owner->lines.getUnchecked (line); if (indexInLine + characterDelta < l.lineLength && indexInLine + characterDelta >= l.lineLengthWithoutNewLines + 1) @@ -465,12 +437,7 @@ void CodeDocument::Position::setPositionMaintained (const bool isMaintained) } //============================================================================== -CodeDocument::CodeDocument() - : undoManager (std::numeric_limits::max(), 10000), - currentActionIndex (0), - indexOfSavedState (-1), - maximumLineLength (-1), - newLineChars ("\r\n") +CodeDocument::CodeDocument() : undoManager (std::numeric_limits::max(), 10000) { } @@ -489,12 +456,12 @@ String CodeDocument::getTextBetween (const Position& start, const Position& end) if (end.getPosition() <= start.getPosition()) return {}; - const int startLine = start.getLineNumber(); - const int endLine = end.getLineNumber(); + auto startLine = start.getLineNumber(); + auto endLine = end.getLineNumber(); if (startLine == endLine) { - if (CodeDocumentLine* const line = lines [startLine]) + if (auto* line = lines [startLine]) return line->line.substring (start.getIndexInLine(), end.getIndexInLine()); return {}; @@ -503,16 +470,16 @@ String CodeDocument::getTextBetween (const Position& start, const Position& end) MemoryOutputStream mo; mo.preallocate ((size_t) (end.getPosition() - start.getPosition() + 4)); - const int maxLine = jmin (lines.size() - 1, endLine); + auto maxLine = jmin (lines.size() - 1, endLine); for (int i = jmax (0, startLine); i <= maxLine; ++i) { - const CodeDocumentLine& line = *lines.getUnchecked(i); - int len = line.lineLength; + auto& line = *lines.getUnchecked(i); + auto len = line.lineLength; if (i == startLine) { - const int index = start.getIndexInLine(); + auto index = start.getIndexInLine(); mo << line.line.substring (index, len); } else if (i == endLine) @@ -539,7 +506,7 @@ int CodeDocument::getNumCharacters() const noexcept String CodeDocument::getLine (const int lineIndex) const noexcept { - if (auto* line = lines [lineIndex]) + if (auto* line = lines[lineIndex]) return line->line; return {}; @@ -551,8 +518,8 @@ int CodeDocument::getMaximumLineLength() noexcept { maximumLineLength = 0; - for (int i = lines.size(); --i >= 0;) - maximumLineLength = jmax (maximumLineLength, lines.getUnchecked(i)->lineLength); + for (auto* l : lines) + maximumLineLength = jmax (maximumLineLength, l->lineLength); } return maximumLineLength; @@ -591,10 +558,8 @@ void CodeDocument::applyChanges (const String& newContent) TextDiff diff (getAllContent(), corrected); - for (int i = 0; i < diff.changes.size(); ++i) + for (auto& c : diff.changes) { - const TextDiff::Change& c = diff.changes.getReference(i); - if (c.isDeletion()) remove (c.start, c.start + c.length, true); else @@ -619,9 +584,9 @@ bool CodeDocument::loadFromStream (InputStream& stream) bool CodeDocument::writeToStream (OutputStream& stream) { - for (int i = 0; i < lines.size(); ++i) + for (auto* l : lines) { - String temp (lines.getUnchecked(i)->line); // use a copy to avoid bloating the memory footprint of the stored string. + auto temp = l->line; // use a copy to avoid bloating the memory footprint of the stored string. const char* utf8 = temp.toUTF8(); if (! stream.write (utf8, strlen (utf8))) @@ -669,23 +634,15 @@ bool CodeDocument::hasChangedSinceSavePoint() const noexcept } //============================================================================== -namespace CodeDocumentHelpers +static inline int getCharacterType (juce_wchar character) noexcept { - static int getCharacterType (const juce_wchar character) noexcept - { - return (CharacterFunctions::isLetterOrDigit (character) || character == '_') - ? 2 : (CharacterFunctions::isWhitespace (character) ? 0 : 1); - } - - static bool isTokenCharacter (const juce_wchar c) noexcept - { - return CharacterFunctions::isLetterOrDigit (c) || c == '.' || c == '_'; - } + return (CharacterFunctions::isLetterOrDigit (character) || character == '_') + ? 2 : (CharacterFunctions::isWhitespace (character) ? 0 : 1); } CodeDocument::Position CodeDocument::findWordBreakAfter (const Position& position) const noexcept { - Position p (position); + auto p = position; const int maxDistance = 256; int i = 0; @@ -700,9 +657,9 @@ CodeDocument::Position CodeDocument::findWordBreakAfter (const Position& positio if (i == 0) { - const int type = CodeDocumentHelpers::getCharacterType (p.getCharacter()); + auto type = getCharacterType (p.getCharacter()); - while (i < maxDistance && type == CodeDocumentHelpers::getCharacterType (p.getCharacter())) + while (i < maxDistance && type == getCharacterType (p.getCharacter())) { ++i; p.moveBy (1); @@ -723,14 +680,14 @@ CodeDocument::Position CodeDocument::findWordBreakAfter (const Position& positio CodeDocument::Position CodeDocument::findWordBreakBefore (const Position& position) const noexcept { - Position p (position); + auto p = position; const int maxDistance = 256; int i = 0; bool stoppedAtLineStart = false; while (i < maxDistance) { - const juce_wchar c = p.movedBy (-1).getCharacter(); + auto c = p.movedBy (-1).getCharacter(); if (c == '\r' || c == '\n') { @@ -749,9 +706,9 @@ CodeDocument::Position CodeDocument::findWordBreakBefore (const Position& positi if (i < maxDistance && ! stoppedAtLineStart) { - const int type = CodeDocumentHelpers::getCharacterType (p.movedBy (-1).getCharacter()); + auto type = getCharacterType (p.movedBy (-1).getCharacter()); - while (i < maxDistance && type == CodeDocumentHelpers::getCharacterType (p.movedBy (-1).getCharacter())) + while (i < maxDistance && type == getCharacterType (p.movedBy (-1).getCharacter())) { p.moveBy (-1); ++i; @@ -763,13 +720,15 @@ CodeDocument::Position CodeDocument::findWordBreakBefore (const Position& positi void CodeDocument::findTokenContaining (const Position& pos, Position& start, Position& end) const noexcept { + auto isTokenCharacter = [] (juce_wchar c) { return CharacterFunctions::isLetterOrDigit (c) || c == '.' || c == '_'; }; + end = pos; - while (CodeDocumentHelpers::isTokenCharacter (end.getCharacter())) + while (isTokenCharacter (end.getCharacter())) end.moveBy (1); start = end; while (start.getIndexInLine() > 0 - && CodeDocumentHelpers::isTokenCharacter (start.movedBy (-1).getCharacter())) + && isTokenCharacter (start.movedBy (-1).getCharacter())) start.moveBy (-1); } @@ -800,14 +759,13 @@ void CodeDocument::checkLastLineStatus() } //============================================================================== -void CodeDocument::addListener (CodeDocument::Listener* const l) noexcept { listeners.add (l); } -void CodeDocument::removeListener (CodeDocument::Listener* const l) noexcept { listeners.remove (l); } +void CodeDocument::addListener (CodeDocument::Listener* l) noexcept { listeners.add (l); } +void CodeDocument::removeListener (CodeDocument::Listener* l) noexcept { listeners.remove (l); } //============================================================================== -class CodeDocumentInsertAction : public UndoableAction +struct CodeDocument::InsertAction : public UndoableAction { -public: - CodeDocumentInsertAction (CodeDocument& doc, const String& t, const int pos) noexcept + InsertAction (CodeDocument& doc, const String& t, const int pos) noexcept : owner (doc), text (t), insertPos (pos) { } @@ -828,12 +786,11 @@ public: int getSizeInUnits() override { return text.length() + 32; } -private: CodeDocument& owner; const String text; const int insertPos; - JUCE_DECLARE_NON_COPYABLE (CodeDocumentInsertAction) + JUCE_DECLARE_NON_COPYABLE (InsertAction) }; void CodeDocument::insert (const String& text, const int insertPos, const bool undoable) @@ -842,19 +799,19 @@ void CodeDocument::insert (const String& text, const int insertPos, const bool u { if (undoable) { - undoManager.perform (new CodeDocumentInsertAction (*this, text, insertPos)); + undoManager.perform (new InsertAction (*this, text, insertPos)); } else { Position pos (*this, insertPos); - const int firstAffectedLine = pos.getLineNumber(); + auto firstAffectedLine = pos.getLineNumber(); - CodeDocumentLine* const firstLine = lines [firstAffectedLine]; - String textInsideOriginalLine (text); + auto* firstLine = lines[firstAffectedLine]; + auto textInsideOriginalLine = text; if (firstLine != nullptr) { - const int index = pos.getIndexInLine(); + auto index = pos.getIndexInLine(); textInsideOriginalLine = firstLine->line.substring (0, index) + textInsideOriginalLine + firstLine->line.substring (index); @@ -865,7 +822,7 @@ void CodeDocument::insert (const String& text, const int insertPos, const bool u CodeDocumentLine::createLines (newLines, textInsideOriginalLine); jassert (newLines.size() > 0); - CodeDocumentLine* const newFirstLine = newLines.getUnchecked (0); + auto* newFirstLine = newLines.getUnchecked (0); newFirstLine->lineStartInFile = firstLine != nullptr ? firstLine->lineStartInFile : 0; lines.set (firstAffectedLine, newFirstLine); @@ -873,23 +830,20 @@ void CodeDocument::insert (const String& text, const int insertPos, const bool u lines.insertArray (firstAffectedLine + 1, newLines.getRawDataPointer() + 1, newLines.size() - 1); int lineStart = newFirstLine->lineStartInFile; + for (int i = firstAffectedLine; i < lines.size(); ++i) { - CodeDocumentLine& l = *lines.getUnchecked (i); + auto& l = *lines.getUnchecked (i); l.lineStartInFile = lineStart; lineStart += l.lineLength; } checkLastLineStatus(); + auto newTextLength = text.length(); - const int newTextLength = text.length(); - for (int i = 0; i < positionsToMaintain.size(); ++i) - { - CodeDocument::Position& p = *positionsToMaintain.getUnchecked(i); - - if (p.getPosition() >= insertPos) - p.setPosition (p.getPosition() + newTextLength); - } + for (auto* p : positionsToMaintain) + if (p->getPosition() >= insertPos) + p->setPosition (p->getPosition() + newTextLength); listeners.call (&CodeDocument::Listener::codeDocumentTextInserted, text, insertPos); } @@ -897,10 +851,9 @@ void CodeDocument::insert (const String& text, const int insertPos, const bool u } //============================================================================== -class CodeDocumentDeleteAction : public UndoableAction +struct CodeDocument::DeleteAction : public UndoableAction { -public: - CodeDocumentDeleteAction (CodeDocument& doc, const int start, const int end) noexcept + DeleteAction (CodeDocument& doc, int start, int end) noexcept : owner (doc), startPos (start), endPos (end), removedText (doc.getTextBetween (CodeDocument::Position (doc, start), CodeDocument::Position (doc, end))) @@ -923,12 +876,11 @@ public: int getSizeInUnits() override { return (endPos - startPos) + 32; } -private: CodeDocument& owner; const int startPos, endPos; const String removedText; - JUCE_DECLARE_NON_COPYABLE (CodeDocumentDeleteAction) + JUCE_DECLARE_NON_COPYABLE (DeleteAction) }; void CodeDocument::remove (const int startPos, const int endPos, const bool undoable) @@ -938,7 +890,7 @@ void CodeDocument::remove (const int startPos, const int endPos, const bool undo if (undoable) { - undoManager.perform (new CodeDocumentDeleteAction (*this, startPos, endPos)); + undoManager.perform (new DeleteAction (*this, startPos, endPos)); } else { @@ -946,9 +898,9 @@ void CodeDocument::remove (const int startPos, const int endPos, const bool undo Position endPosition (*this, endPos); maximumLineLength = -1; - const int firstAffectedLine = startPosition.getLineNumber(); - const int endLine = endPosition.getLineNumber(); - CodeDocumentLine& firstLine = *lines.getUnchecked (firstAffectedLine); + auto firstAffectedLine = startPosition.getLineNumber(); + auto endLine = endPosition.getLineNumber(); + auto& firstLine = *lines.getUnchecked (firstAffectedLine); if (firstAffectedLine == endLine) { @@ -958,7 +910,7 @@ void CodeDocument::remove (const int startPos, const int endPos, const bool undo } else { - CodeDocumentLine& lastLine = *lines.getUnchecked (endLine); + auto& lastLine = *lines.getUnchecked (endLine); firstLine.line = firstLine.line.substring (0, startPosition.getIndexInLine()) + lastLine.line.substring (endPosition.getIndexInLine()); @@ -970,24 +922,21 @@ void CodeDocument::remove (const int startPos, const int endPos, const bool undo for (int i = firstAffectedLine + 1; i < lines.size(); ++i) { - CodeDocumentLine& l = *lines.getUnchecked (i); - const CodeDocumentLine& previousLine = *lines.getUnchecked (i - 1); + auto& l = *lines.getUnchecked (i); + auto& previousLine = *lines.getUnchecked (i - 1); l.lineStartInFile = previousLine.lineStartInFile + previousLine.lineLength; } checkLastLineStatus(); + auto totalChars = getNumCharacters(); - const int totalChars = getNumCharacters(); - - for (int i = 0; i < positionsToMaintain.size(); ++i) + for (auto* p : positionsToMaintain) { - CodeDocument::Position& p = *positionsToMaintain.getUnchecked(i); - - if (p.getPosition() > startPosition.getPosition()) - p.setPosition (jmax (startPos, p.getPosition() + startPos - endPos)); + if (p->getPosition() > startPosition.getPosition()) + p->setPosition (jmax (startPos, p->getPosition() + startPos - endPos)); - if (p.getPosition() > totalChars) - p.setPosition (totalChars); + if (p->getPosition() > totalChars) + p->setPosition (totalChars); } listeners.call (&CodeDocument::Listener::codeDocumentTextDeleted, startPos, endPos); diff --git a/modules/juce_gui_extra/code_editor/juce_CodeDocument.h b/modules/juce_gui_extra/code_editor/juce_CodeDocument.h index 7c18a00f63..04b3c94c17 100644 --- a/modules/juce_gui_extra/code_editor/juce_CodeDocument.h +++ b/modules/juce_gui_extra/code_editor/juce_CodeDocument.h @@ -179,9 +179,9 @@ public: String getLineText() const; private: - CodeDocument* owner; - int characterPos, line, indexInLine; - bool positionMaintained; + CodeDocument* owner = nullptr; + int characterPos = 0, line = 0, indexInLine = 0; + bool positionMaintained = false; }; //============================================================================== @@ -357,8 +357,8 @@ public: { public: Iterator (const CodeDocument& document) noexcept; - Iterator (const Iterator&) noexcept; - Iterator& operator= (const Iterator&) noexcept; + Iterator (const Iterator&) noexcept = default; + Iterator& operator= (const Iterator&) noexcept = default; ~Iterator() noexcept; /** Reads the next character and returns it. @@ -389,24 +389,24 @@ public: private: const CodeDocument* document; - mutable String::CharPointerType charPointer; - int line, position; + mutable String::CharPointerType charPointer { nullptr }; + int line = 0, position = 0; }; private: //============================================================================== - friend class CodeDocumentInsertAction; - friend class CodeDocumentDeleteAction; + struct InsertAction; + struct DeleteAction; friend class Iterator; friend class Position; - OwnedArray lines; - Array positionsToMaintain; + OwnedArray lines; + Array positionsToMaintain; UndoManager undoManager; - int currentActionIndex, indexOfSavedState; - int maximumLineLength; - ListenerList listeners; - String newLineChars; + int currentActionIndex = 0, indexOfSavedState = -1; + int maximumLineLength = -1; + ListenerList listeners; + String newLineChars { "\r\n" }; void insert (const String& text, int insertPos, bool undoable); void remove (int startPos, int endPos, bool undoable);