From: <man...@us...> - 2013-11-13 19:38:10
|
Revision: 3210 http://sourceforge.net/p/modplug/code/3210 Author: manxorist Date: 2013-11-13 19:38:03 +0000 (Wed, 13 Nov 2013) Log Message: ----------- [Ref] Remove mpt::PathString::NativeRef() and replace the only usage site with an explicit copy from AsNative() (scope life-time of .c_str() is neede in FileDialog::Show()). [Fix] Do not return string values by const reference in getter functions. This could silently cause temporary objects to be created by accident later on if the type of the return expression is changed to a type implicitely convertible to the return type by some other (potentially not directly related) refactoring. All users have been reviewed if they actually depended on the reference semantics (and none of them did). Modified Paths: -------------- trunk/OpenMPT/common/mptPathString.h trunk/OpenMPT/mptrack/FileDialog.cpp trunk/OpenMPT/mptrack/FileDialog.h trunk/OpenMPT/soundlib/tuning.h trunk/OpenMPT/soundlib/tuningbase.h trunk/OpenMPT/soundlib/tuningcollection.h Modified: trunk/OpenMPT/common/mptPathString.h =================================================================== --- trunk/OpenMPT/common/mptPathString.h 2013-11-13 19:23:27 UTC (rev 3209) +++ trunk/OpenMPT/common/mptPathString.h 2013-11-13 19:38:03 UTC (rev 3210) @@ -73,10 +73,6 @@ return a.AsNative() != b.AsNative(); } bool empty() const { return path.empty(); } - const RawPathString &NativeRef() const - { - return path; - } #if defined(WIN32) static int CompareNoCase(const PathString & a, const PathString & b) Modified: trunk/OpenMPT/mptrack/FileDialog.cpp =================================================================== --- trunk/OpenMPT/mptrack/FileDialog.cpp 2013-11-13 19:23:27 UTC (rev 3209) +++ trunk/OpenMPT/mptrack/FileDialog.cpp 2013-11-13 19:38:03 UTC (rev 3210) @@ -31,6 +31,8 @@ filenameBuffer.insert(filenameBuffer.begin(), defaultFilename.begin(), defaultFilename.end()); filenameBuffer.push_back(0); + const std::wstring workingDirectoryNative = workingDirectory.AsNative(); + // First, set up the dialog... OPENFILENAMEW ofn; MemsetZero(ofn); @@ -45,7 +47,7 @@ ofn.nMaxFile = filenameBuffer.size(); ofn.lpstrFileTitle = NULL; ofn.nMaxFileTitle = 0; - ofn.lpstrInitialDir = workingDirectory.empty() ? NULL : workingDirectory.NativeRef().c_str(); + ofn.lpstrInitialDir = workingDirectory.empty() ? NULL : workingDirectoryNative.c_str(); ofn.lpstrTitle = NULL; ofn.Flags = OFN_EXPLORER | OFN_HIDEREADONLY | OFN_ENABLESIZING | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | (multiSelect ? OFN_ALLOWMULTISELECT : 0) | (load ? 0 : (OFN_OVERWRITEPROMPT | OFN_NOREADONLYRETURN)); ofn.nFileOffset = 0; Modified: trunk/OpenMPT/mptrack/FileDialog.h =================================================================== --- trunk/OpenMPT/mptrack/FileDialog.h 2013-11-13 19:23:27 UTC (rev 3209) +++ trunk/OpenMPT/mptrack/FileDialog.h 2013-11-13 19:38:03 UTC (rev 3210) @@ -55,13 +55,22 @@ bool Show(); // Get some selected file. Mostly useful when only one selected file is possible anyway. - const mpt::PathString &GetFirstFile() const { return filenames.front(); } - // Gets all selected files. + mpt::PathString GetFirstFile() const + { + if(!filenames.empty()) + { + return filenames.front(); + } else + { + return mpt::PathString(); + } + } + // Gets a reference to all selected filenames. const PathList &GetFilenames() const { return filenames; } // Gets directory in which the selected files are placed. - const mpt::PathString &GetWorkingDirectory() const { return workingDirectory; } + mpt::PathString GetWorkingDirectory() const { return workingDirectory; } // Gets the extension of the first selected file, without dot. - const mpt::PathString &GetExtension() const { return extension; } + mpt::PathString GetExtension() const { return extension; } protected: static UINT_PTR CALLBACK OFNHookProc(HWND hdlg, UINT uiMsg, WPARAM wParam, LPARAM lParam); @@ -100,7 +109,7 @@ bool Show(); // Gets selected directory. - const mpt::PathString &GetDirectory() const { return workingDirectory; } + mpt::PathString GetDirectory() const { return workingDirectory; } protected: static int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData); Modified: trunk/OpenMPT/soundlib/tuning.h =================================================================== --- trunk/OpenMPT/soundlib/tuning.h 2013-11-13 19:23:27 UTC (rev 3209) +++ trunk/OpenMPT/soundlib/tuning.h 2013-11-13 19:38:03 UTC (rev 3210) @@ -131,7 +131,7 @@ //For example GetRefNote(-1) is to return note :'groupsize-1'. NOTEINDEXTYPE GetRefNote(NOTEINDEXTYPE note) const; - virtual const std::string& GetDerivedClassID() const {return s_DerivedclassID;} + virtual std::string GetDerivedClassID() const {return s_DerivedclassID;} private: //PRIVATE METHODS: Modified: trunk/OpenMPT/soundlib/tuningbase.h =================================================================== --- trunk/OpenMPT/soundlib/tuningbase.h 2013-11-13 19:23:27 UTC (rev 3209) +++ trunk/OpenMPT/soundlib/tuningbase.h 2013-11-13 19:38:03 UTC (rev 3210) @@ -226,7 +226,7 @@ TUNINGTYPE GetType() const {return m_TuningType;} //This is appended to baseclassID in serialization with which objects are identified when loading. - virtual const std::string& GetDerivedClassID() const = 0; + virtual std::string GetDerivedClassID() const = 0; //Return true if data loading failed, false otherwise. virtual bool ProProcessUnserializationdata() = 0; Modified: trunk/OpenMPT/soundlib/tuningcollection.h =================================================================== --- trunk/OpenMPT/soundlib/tuningcollection.h 2013-11-13 19:23:27 UTC (rev 3209) +++ trunk/OpenMPT/soundlib/tuningcollection.h 2013-11-13 19:38:03 UTC (rev 3210) @@ -92,10 +92,10 @@ size_t GetNumTunings() const {return m_Tunings.size();} - const std::string& GetName() const {return m_Name;} + std::string GetName() const {return m_Name;} void SetSavefilePath(const mpt::PathString &psz) {m_SavefilePath = psz;} - const mpt::PathString& GetSaveFilePath() const {return m_SavefilePath;} + mpt::PathString GetSaveFilePath() const {return m_SavefilePath;} std::string GetVersionString() const {return Stringify(static_cast<int>(s_SerializationVersion));} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |