From 44cd80969dce755d519ec3924e19df4a8b373721 Mon Sep 17 00:00:00 2001 From: jules Date: Tue, 28 Mar 2017 12:31:51 +0100 Subject: [PATCH] A few C++11 modernisations and comment corrections --- examples/Demo/Source/Demos/MDIDemo.cpp | 2 +- .../Projucer/Source/Application/jucer_CommandLine.cpp | 6 ++---- .../Projucer/Source/Application/jucer_MainWindow.cpp | 10 +++++----- .../Source/Application/jucer_OpenDocumentManager.h | 2 +- .../Source/Code Editor/jucer_SourceCodeEditor.h | 4 ++-- .../ComponentEditor/components/jucer_ViewportHandler.h | 4 ++-- .../Source/ComponentEditor/ui/jucer_TestComponent.cpp | 2 +- .../Source/LiveBuildEngine/projucer_ClassDatabase.h | 2 +- .../Source/LiveBuildEngine/projucer_CompileEngineDLL.h | 2 +- .../Project Saving/jucer_ProjectExport_Android.h | 2 +- extras/Projucer/Source/Project/jucer_Module.cpp | 10 +++++----- extras/Projucer/Source/Project/jucer_Project.cpp | 4 ++-- .../Projucer/Source/Project/jucer_ProjectTree_File.h | 2 +- .../Projucer/Source/Utility/jucer_JucerTreeViewBase.h | 2 +- extras/Projucer/Source/Wizards/jucer_NewFileWizard.cpp | 2 +- .../Source/Wizards/jucer_TemplateThumbnailsComponent.h | 2 +- modules/juce_core/files/juce_File.cpp | 2 +- modules/juce_core/native/juce_android_Files.cpp | 2 +- modules/juce_core/native/juce_linux_Files.cpp | 6 +++--- modules/juce_core/native/juce_mac_Files.mm | 2 +- modules/juce_core/native/juce_win32_Files.cpp | 4 ++-- .../app_properties/juce_PropertiesFile.cpp | 2 +- .../filebrowser/juce_DirectoryContentsList.cpp | 6 +++--- .../filebrowser/juce_FileTreeComponent.cpp | 4 ++-- modules/juce_gui_basics/widgets/juce_ListBox.h | 2 +- 25 files changed, 43 insertions(+), 45 deletions(-) diff --git a/examples/Demo/Source/Demos/MDIDemo.cpp b/examples/Demo/Source/Demos/MDIDemo.cpp index d065064511..80211274ce 100644 --- a/examples/Demo/Source/Demos/MDIDemo.cpp +++ b/examples/Demo/Source/Demos/MDIDemo.cpp @@ -86,7 +86,7 @@ public: File getLastDocumentOpened() override { // not interested in this for now - return File(); + return {}; } void setLastDocumentOpened (const File& /*file*/) override diff --git a/extras/Projucer/Source/Application/jucer_CommandLine.cpp b/extras/Projucer/Source/Application/jucer_CommandLine.cpp index 014cfdf541..de96db2220 100644 --- a/extras/Projucer/Source/Application/jucer_CommandLine.cpp +++ b/extras/Projucer/Source/Application/jucer_CommandLine.cpp @@ -456,14 +456,12 @@ namespace { File result; - for (int i = 0; i < allFiles.size(); ++i) + for (auto& f : allFiles) { - const File& f = allFiles.getReference(i); - if (f.getFileName().equalsIgnoreCase (name) && f != sourceFile) { if (result.exists()) - return File(); // multiple possible results, so don't change it! + return {}; // multiple possible results, so don't change it! result = f; } diff --git a/extras/Projucer/Source/Application/jucer_MainWindow.cpp b/extras/Projucer/Source/Application/jucer_MainWindow.cpp index 7ac45ec647..6fd20369b4 100644 --- a/extras/Projucer/Source/Application/jucer_MainWindow.cpp +++ b/extras/Projucer/Source/Application/jucer_MainWindow.cpp @@ -597,11 +597,11 @@ Project* MainWindowList::getFrontmostProject() File findDefaultModulesFolder (bool mustContainJuceCoreModule) { - const MainWindowList& windows = ProjucerApplication::getApp().mainWindowList; + auto& windows = ProjucerApplication::getApp().mainWindowList; for (int i = windows.windows.size(); --i >= 0;) { - if (Project* p = windows.windows.getUnchecked (i)->getProject()) + if (auto* p = windows.windows.getUnchecked (i)->getProject()) { const File f (EnabledModuleList::findDefaultModulesFolder (*p)); @@ -613,11 +613,11 @@ File findDefaultModulesFolder (bool mustContainJuceCoreModule) if (mustContainJuceCoreModule) return findDefaultModulesFolder (false); - File f (File::getSpecialLocation (File::currentApplicationFile)); + auto f = File::getSpecialLocation (File::currentApplicationFile); for (;;) { - File parent (f.getParentDirectory()); + auto parent = f.getParentDirectory(); if (parent == f || ! parent.isDirectory()) break; @@ -628,5 +628,5 @@ File findDefaultModulesFolder (bool mustContainJuceCoreModule) f = parent; } - return File(); + return {}; } diff --git a/extras/Projucer/Source/Application/jucer_OpenDocumentManager.h b/extras/Projucer/Source/Application/jucer_OpenDocumentManager.h index b873e663ca..2f4ff1d214 100644 --- a/extras/Projucer/Source/Application/jucer_OpenDocumentManager.h +++ b/extras/Projucer/Source/Application/jucer_OpenDocumentManager.h @@ -61,7 +61,7 @@ public: virtual void fileHasBeenRenamed (const File& newFile) = 0; virtual String getState() const = 0; virtual void restoreState (const String& state) = 0; - virtual File getCounterpartFile() const { return File(); } + virtual File getCounterpartFile() const { return {}; } }; //============================================================================== diff --git a/extras/Projucer/Source/Code Editor/jucer_SourceCodeEditor.h b/extras/Projucer/Source/Code Editor/jucer_SourceCodeEditor.h index 8aa7952660..1a7a8b5603 100644 --- a/extras/Projucer/Source/Code Editor/jucer_SourceCodeEditor.h +++ b/extras/Projucer/Source/Code Editor/jucer_SourceCodeEditor.h @@ -64,7 +64,7 @@ public: return findCounterpart (file, extensions); } - return File(); + return {}; } static File findCounterpart (const File& file, const char** extensions) @@ -77,7 +77,7 @@ public: return f; } - return File(); + return {}; } void reloadFromFile() override; diff --git a/extras/Projucer/Source/ComponentEditor/components/jucer_ViewportHandler.h b/extras/Projucer/Source/ComponentEditor/components/jucer_ViewportHandler.h index 4afacc9585..3683ad1c3a 100644 --- a/extras/Projucer/Source/ComponentEditor/components/jucer_ViewportHandler.h +++ b/extras/Projucer/Source/ComponentEditor/components/jucer_ViewportHandler.h @@ -502,10 +502,10 @@ private: File getFile() const { - const String filename (getViewportJucerComponentFile (component)); + auto filename = getViewportJucerComponentFile (component); if (filename.isEmpty()) - return File(); + return {}; return document.getCppFile().getSiblingFile (filename); } diff --git a/extras/Projucer/Source/ComponentEditor/ui/jucer_TestComponent.cpp b/extras/Projucer/Source/ComponentEditor/ui/jucer_TestComponent.cpp index 48672b415c..514d268c13 100644 --- a/extras/Projucer/Source/ComponentEditor/ui/jucer_TestComponent.cpp +++ b/extras/Projucer/Source/ComponentEditor/ui/jucer_TestComponent.cpp @@ -69,7 +69,7 @@ static StringArray recursiveFiles; File TestComponent::findFile() const { if (filename.isEmpty()) - return File(); + return {}; if (ownerDocument != nullptr) return ownerDocument->getCppFile().getSiblingFile (filename); diff --git a/extras/Projucer/Source/LiveBuildEngine/projucer_ClassDatabase.h b/extras/Projucer/Source/LiveBuildEngine/projucer_ClassDatabase.h index f68d4391be..d5c8934776 100644 --- a/extras/Projucer/Source/LiveBuildEngine/projucer_ClassDatabase.h +++ b/extras/Projucer/Source/LiveBuildEngine/projucer_ClassDatabase.h @@ -346,7 +346,7 @@ struct ClassDatabase if (m.definition.isValid() && File (m.definition.file).exists()) return m.definition.file; - return File(); + return {}; } Array getAllSourceFiles() const diff --git a/extras/Projucer/Source/LiveBuildEngine/projucer_CompileEngineDLL.h b/extras/Projucer/Source/LiveBuildEngine/projucer_CompileEngineDLL.h index 262b359b57..3361545d7a 100644 --- a/extras/Projucer/Source/LiveBuildEngine/projucer_CompileEngineDLL.h +++ b/extras/Projucer/Source/LiveBuildEngine/projucer_CompileEngineDLL.h @@ -127,7 +127,7 @@ private: if (tryFindDLLFileInAppConfigFolder(dllFile)) return dllFile; - return File(); + return {}; } #if JUCE_MAC diff --git a/extras/Projucer/Source/Project Saving/jucer_ProjectExport_Android.h b/extras/Projucer/Source/Project Saving/jucer_ProjectExport_Android.h index ca3666c909..4d5ab792ad 100644 --- a/extras/Projucer/Source/Project Saving/jucer_ProjectExport_Android.h +++ b/extras/Projucer/Source/Project Saving/jucer_ProjectExport_Android.h @@ -284,7 +284,7 @@ public: return defaultInstallation; #endif - return File(); + return {}; } protected: diff --git a/extras/Projucer/Source/Project/jucer_Module.cpp b/extras/Projucer/Source/Project/jucer_Module.cpp index dee2d89096..f24ddeb6c0 100644 --- a/extras/Projucer/Source/Project/jucer_Module.cpp +++ b/extras/Projucer/Source/Project/jucer_Module.cpp @@ -96,21 +96,21 @@ File ModuleDescription::getHeader() const { const char* extensions[] = { ".h", ".hpp", ".hxx" }; - for (int i = 0; i < numElementsInArray (extensions); ++i) + for (auto e : extensions) { - File header (moduleFolder.getChildFile (moduleFolder.getFileName() + extensions[i])); + File header (moduleFolder.getChildFile (moduleFolder.getFileName() + e)); if (header.existsAsFile()) return header; } } - return File(); + return {}; } StringArray ModuleDescription::getDependencies() const { - StringArray deps = StringArray::fromTokens (moduleInfo ["dependencies"].toString(), " \t;,", "\"'"); + auto deps = StringArray::fromTokens (moduleInfo ["dependencies"].toString(), " \t;,", "\"'"); deps.trim(); deps.removeEmptyStrings(); return deps; @@ -635,7 +635,7 @@ File EnabledModuleList::findLocalModuleFolder (const String& moduleID, bool useE } } - return File(); + return {}; } File EnabledModuleList::getModuleFolder (const String& moduleID) diff --git a/extras/Projucer/Source/Project/jucer_Project.cpp b/extras/Projucer/Source/Project/jucer_Project.cpp index 191a699735..b017f85f2d 100644 --- a/extras/Projucer/Source/Project/jucer_Project.cpp +++ b/extras/Projucer/Source/Project/jucer_Project.cpp @@ -400,7 +400,7 @@ bool Project::hasProjectBeenModified() File Project::resolveFilename (String filename) const { if (filename.isEmpty()) - return File(); + return {}; filename = replacePreprocessorDefs (getPreprocessorDefs(), filename); @@ -863,7 +863,7 @@ File Project::Item::getFile() const if (isFile()) return project.resolveFilename (state [Ids::file].toString()); - return File(); + return {}; } void Project::Item::setFile (const File& file) diff --git a/extras/Projucer/Source/Project/jucer_ProjectTree_File.h b/extras/Projucer/Source/Project/jucer_ProjectTree_File.h index 31bd3adc6c..7a1fba819f 100644 --- a/extras/Projucer/Source/Project/jucer_ProjectTree_File.h +++ b/extras/Projucer/Source/Project/jucer_ProjectTree_File.h @@ -43,7 +43,7 @@ public: if (f.hasFileExtension (sourceFileExtensions)) return f.withFileExtension (".h"); if (f.hasFileExtension (headerFileExtensions)) return f.withFileExtension (".cpp"); - return File(); + return {}; } void setName (const String& newName) override diff --git a/extras/Projucer/Source/Utility/jucer_JucerTreeViewBase.h b/extras/Projucer/Source/Utility/jucer_JucerTreeViewBase.h index a87514765e..ed8d33a07c 100644 --- a/extras/Projucer/Source/Utility/jucer_JucerTreeViewBase.h +++ b/extras/Projucer/Source/Utility/jucer_JucerTreeViewBase.h @@ -57,7 +57,7 @@ public: virtual void paintIcon (Graphics& g, Rectangle area) { getIcon().draw (g, area.reduced (2).toFloat(), isIconCrossedOut()); } virtual void paintContent (Graphics& g, const Rectangle& area); virtual int getMillisecsAllowedForDragGesture() { return 120; }; - virtual File getDraggableFile() const { return File(); } + virtual File getDraggableFile() const { return {}; } void refreshSubItems(); virtual void deleteItem(); diff --git a/extras/Projucer/Source/Wizards/jucer_NewFileWizard.cpp b/extras/Projucer/Source/Wizards/jucer_NewFileWizard.cpp index b00791115d..13a1e855a1 100644 --- a/extras/Projucer/Source/Wizards/jucer_NewFileWizard.cpp +++ b/extras/Projucer/Source/Wizards/jucer_NewFileWizard.cpp @@ -225,7 +225,7 @@ File NewFileWizard::Type::askUserToChooseNewFile (const String& suggestedFilenam if (fc.browseForFileToSave (true)) return fc.getResult(); - return File(); + return {}; } //============================================================================== diff --git a/extras/Projucer/Source/Wizards/jucer_TemplateThumbnailsComponent.h b/extras/Projucer/Source/Wizards/jucer_TemplateThumbnailsComponent.h index b4bab3da4b..d22b9979aa 100644 --- a/extras/Projucer/Source/Wizards/jucer_TemplateThumbnailsComponent.h +++ b/extras/Projucer/Source/Wizards/jucer_TemplateThumbnailsComponent.h @@ -253,7 +253,7 @@ public: appFolder = appFolder.getParentDirectory(); } - return File(); + return {}; } private: diff --git a/modules/juce_core/files/juce_File.cpp b/modules/juce_core/files/juce_File.cpp index a1db679cb6..b5826c7cdb 100644 --- a/modules/juce_core/files/juce_File.cpp +++ b/modules/juce_core/files/juce_File.cpp @@ -698,7 +698,7 @@ bool File::hasFileExtension (StringRef possibleSuffix) const File File::withFileExtension (StringRef newExtension) const { if (fullPath.isEmpty()) - return File(); + return {}; String filePart (getFileName()); diff --git a/modules/juce_core/native/juce_android_Files.cpp b/modules/juce_core/native/juce_android_Files.cpp index cdf8219bf2..333c82ad5d 100644 --- a/modules/juce_core/native/juce_android_Files.cpp +++ b/modules/juce_core/native/juce_android_Files.cpp @@ -86,7 +86,7 @@ File File::getSpecialLocation (const SpecialLocationType type) break; } - return File(); + return {}; } bool File::moveToTrash() const diff --git a/modules/juce_core/native/juce_linux_Files.cpp b/modules/juce_core/native/juce_linux_Files.cpp index 1767798578..d3bc7ba6c3 100644 --- a/modules/juce_core/native/juce_linux_Files.cpp +++ b/modules/juce_core/native/juce_linux_Files.cpp @@ -114,10 +114,10 @@ File File::getSpecialLocation (const SpecialLocationType type) if (const char* homeDir = getenv ("HOME")) return File (CharPointer_UTF8 (homeDir)); - if (struct passwd* const pw = getpwuid (getuid())) + if (auto* pw = getpwuid (getuid())) return File (CharPointer_UTF8 (pw->pw_dir)); - return File(); + return {}; } case userDocumentsDirectory: return resolveXDGFolder ("XDG_DOCUMENTS_DIR", "~/Documents"); @@ -161,7 +161,7 @@ File File::getSpecialLocation (const SpecialLocationType type) break; } - return File(); + return {}; } //============================================================================== diff --git a/modules/juce_core/native/juce_mac_Files.mm b/modules/juce_core/native/juce_mac_Files.mm index 2b8f77b7e4..a2897d13a9 100644 --- a/modules/juce_core/native/juce_mac_Files.mm +++ b/modules/juce_core/native/juce_mac_Files.mm @@ -259,7 +259,7 @@ File File::getSpecialLocation (const SpecialLocationType type) return File (resultPath.convertToPrecomposedUnicode()); } - return File(); + return {}; } //============================================================================== diff --git a/modules/juce_core/native/juce_win32_Files.cpp b/modules/juce_core/native/juce_win32_Files.cpp index ed3ab2e8bc..5a3a2d0284 100644 --- a/modules/juce_core/native/juce_win32_Files.cpp +++ b/modules/juce_core/native/juce_win32_Files.cpp @@ -96,7 +96,7 @@ namespace WindowsFileHelpers if (SHGetSpecialFolderPath (0, path, type, FALSE)) return File (String (path)); - return File(); + return {}; } File getModuleFileName (HINSTANCE moduleHandle) @@ -599,7 +599,7 @@ File JUCE_CALLTYPE File::getSpecialLocation (const SpecialLocationType type) default: jassertfalse; // unknown type? - return File(); + return {}; } return WindowsFileHelpers::getSpecialFolderPath (csidlType); diff --git a/modules/juce_data_structures/app_properties/juce_PropertiesFile.cpp b/modules/juce_data_structures/app_properties/juce_PropertiesFile.cpp index 10a43dbca7..4b2228a105 100644 --- a/modules/juce_data_structures/app_properties/juce_PropertiesFile.cpp +++ b/modules/juce_data_structures/app_properties/juce_PropertiesFile.cpp @@ -92,7 +92,7 @@ File PropertiesFile::Options::getDefaultFile() const : File::userApplicationDataDirectory)); if (dir == File()) - return File(); + return {}; dir = dir.getChildFile (folderName.isNotEmpty() ? folderName : applicationName); diff --git a/modules/juce_gui_basics/filebrowser/juce_DirectoryContentsList.cpp b/modules/juce_gui_basics/filebrowser/juce_DirectoryContentsList.cpp index 79d810fdb2..e2cf3b8015 100644 --- a/modules/juce_gui_basics/filebrowser/juce_DirectoryContentsList.cpp +++ b/modules/juce_gui_basics/filebrowser/juce_DirectoryContentsList.cpp @@ -119,7 +119,7 @@ bool DirectoryContentsList::getFileInfo (const int index, FileInfo& result) cons { const ScopedLock sl (fileListLock); - if (const FileInfo* const info = files [index]) + if (auto* info = files [index]) { result = *info; return true; @@ -132,10 +132,10 @@ File DirectoryContentsList::getFile (const int index) const { const ScopedLock sl (fileListLock); - if (const FileInfo* const info = files [index]) + if (auto* info = files [index]) return root.getChildFile (info->filename); - return File(); + return {}; } bool DirectoryContentsList::contains (const File& targetFile) const diff --git a/modules/juce_gui_basics/filebrowser/juce_FileTreeComponent.cpp b/modules/juce_gui_basics/filebrowser/juce_FileTreeComponent.cpp index 6565ba4619..f04e893819 100644 --- a/modules/juce_gui_basics/filebrowser/juce_FileTreeComponent.cpp +++ b/modules/juce_gui_basics/filebrowser/juce_FileTreeComponent.cpp @@ -282,10 +282,10 @@ void FileTreeComponent::refresh() //============================================================================== File FileTreeComponent::getSelectedFile (const int index) const { - if (const FileListTreeItem* const item = dynamic_cast (getSelectedItem (index))) + if (auto* item = dynamic_cast (getSelectedItem (index))) return item->file; - return File(); + return {}; } void FileTreeComponent::deselectAllFiles() diff --git a/modules/juce_gui_basics/widgets/juce_ListBox.h b/modules/juce_gui_basics/widgets/juce_ListBox.h index af0f901d07..2bec6938bd 100644 --- a/modules/juce_gui_basics/widgets/juce_ListBox.h +++ b/modules/juce_gui_basics/widgets/juce_ListBox.h @@ -59,7 +59,7 @@ public: and handle mouse clicks with listBoxItemClicked(). This method will be called whenever a custom component might need to be updated - e.g. - when the table is changed, or TableListBox::updateContent() is called. + when the list is changed, or ListBox::updateContent() is called. If you don't need a custom component for the specified row, then return nullptr. (Bear in mind that even if you're not creating a new component, you may still need to