diff --git a/src/Etterna/Actor/Base/Actor.cpp b/src/Etterna/Actor/Base/Actor.cpp index 8d51ee5226..f4ca72a1db 100644 --- a/src/Etterna/Actor/Base/Actor.cpp +++ b/src/Etterna/Actor/Base/Actor.cpp @@ -144,7 +144,7 @@ GetMessageNameFromCommandName(const std::string& sCommandName, Actor::Actor() { - m_pLuaInstance = new LuaClass; + m_pLuaInstance = std::make_unique(); auto* L = LUA->Get(); m_pLuaInstance->PushSelf(L); lua_newtable(L); @@ -176,17 +176,21 @@ Actor::Actor(const Actor& cpy) { /* Don't copy an Actor in the middle of rendering. */ ASSERT(cpy.m_pTempState == nullptr); - m_pTempState = nullptr; -#define CPY(x) x = cpy.x + *this = cpy; +} +Actor& Actor::operator=(const Actor& x) +{ +#define CPY(membername) this->membername = x.membername + CPY(m_pTempState); CPY(m_sName); CPY(m_pParent); CPY(m_FakeParent); - CPY(m_pLuaInstance); + m_pLuaInstance = std::make_unique(*x.m_pLuaInstance); - m_WrapperStates.resize(cpy.m_WrapperStates.size()); + m_WrapperStates.resize(x.m_WrapperStates.size()); for (size_t i = 0; i < m_WrapperStates.size(); ++i) { - auto* const cp = dynamic_cast(cpy.m_WrapperStates[i]); + auto* const cp = dynamic_cast(x.m_WrapperStates[i]); ASSERT_M(cp != nullptr, "Dynamic cast to ActorFrame copy failed at runtime."); m_WrapperStates[i] = new ActorFrame(*cp); @@ -201,15 +205,15 @@ Actor::Actor(const Actor& cpy) CPY(m_size); CPY(m_current); CPY(m_start); - for (auto* m_Tween : cpy.m_Tweens) + for (auto* m_Tween : x.m_Tweens) m_Tweens.push_back(new TweenStateAndInfo(*m_Tween)); CPY(m_fHorizAlign); CPY(m_fVertAlign); #if defined(SSC_FUTURES) // I'm a bit worried about this -aj - for (unsigned i = 0; i < cpy.m_Effects.size(); ++i) - m_Effects.push_back((*cpy.m_Effects[i])); + for (unsigned i = 0; i < x.m_Effects.size(); ++i) + m_Effects.push_back((*x.m_Effects[i])); #else CPY(m_Effect); #endif @@ -247,6 +251,7 @@ Actor::Actor(const Actor& cpy) CPY(m_mapNameToCommands); CPY(m_tween_uses_effect_delta); #undef CPY + return *this; } /* XXX: This calls InitCommand, which must happen after all other diff --git a/src/Etterna/Actor/Base/Actor.h b/src/Etterna/Actor/Base/Actor.h index cb5bce6837..097dabe856 100644 --- a/src/Etterna/Actor/Base/Actor.h +++ b/src/Etterna/Actor/Base/Actor.h @@ -4,7 +4,6 @@ #include "Etterna/Models/Misc/EnumHelper.h" #include "Etterna/Models/Lua/LuaReference.h" #include "RageUtil/Misc/RageTypes.h" -#include "RageUtil/Utils/RageUtil_AutoPtr.h" #include "Etterna/Singletons/MessageManager.h" #include "Tween.h" @@ -84,6 +83,7 @@ class Actor : public MessageSubscriber * @param cpy the new Actor to use in place of this one. */ Actor(const Actor& cpy); ~Actor() override; + Actor& operator=(const Actor& x); [[nodiscard]] virtual auto Copy() const -> Actor*; virtual void InitState(); virtual void LoadFromNode(const XNode* pNode); @@ -808,7 +808,7 @@ class Actor : public MessageSubscriber virtual void SetUpdateRate(float /*unused*/) {} virtual auto GetUpdateRate() -> float { return 1.0F; } - HiddenPtr m_pLuaInstance; + std::unique_ptr m_pLuaInstance; protected: /** @brief the name of the Actor. */ diff --git a/src/Etterna/Actor/Menus/MusicWheel.cpp b/src/Etterna/Actor/Menus/MusicWheel.cpp index 2eb8910f1e..3d53807e04 100644 --- a/src/Etterna/Actor/Menus/MusicWheel.cpp +++ b/src/Etterna/Actor/Menus/MusicWheel.cpp @@ -176,18 +176,6 @@ MusicWheel::MusicWheel() FOREACH_ENUM(SortOrder, so) { m_WheelItemDatasStatus[so] = INVALID; } } -MusicWheel::~MusicWheel() -{ - FOREACH_ENUM(SortOrder, so) - { - auto i = m__UnFilteredWheelItemDatas[so].begin(); - auto iEnd = m__UnFilteredWheelItemDatas[so].end(); - for (; i != iEnd; ++i) { - delete *i; - } - } -} - // this is a trainwreck and i made it worse -mina void MusicWheel::ReloadSongList(bool searching, const std::string& findme) @@ -770,7 +758,7 @@ MusicWheel::FilterBySkillsets(std::vector& inv) void MusicWheel::BuildWheelItemDatas( - std::vector& arrayWheelItemDatas, + std::vector>& arrayWheelItemDatas, SortOrder so, bool searching, const std::string& findme) @@ -782,18 +770,18 @@ MusicWheel::BuildWheelItemDatas( std::vector vsNames; split(MODE_MENU_CHOICE_NAMES, ",", vsNames); for (auto i = 0; i < static_cast(vsNames.size()); ++i) { - MusicWheelItemData wid( + auto wid = std::make_unique( WheelItemDataType_Sort, nullptr, "", SORT_MENU_COLOR, 0); - wid.m_pAction = HiddenPtr(new GameCommand); - wid.m_pAction->m_sName = vsNames[i]; - wid.m_pAction->Load(i, ParseCommands(CHOICE.GetValue(vsNames[i]))); - wid.m_sLabel = WHEEL_TEXT(vsNames[i]); + wid->m_pAction = std::make_unique(); + wid->m_pAction->m_sName = vsNames[i]; + wid->m_pAction->Load(i, ParseCommands(CHOICE.GetValue(vsNames[i]))); + wid->m_sLabel = WHEEL_TEXT(vsNames[i]); - if (!wid.m_pAction->IsPlayable()) { + if (!wid->m_pAction->IsPlayable()) { continue; } - arrayWheelItemDatas.emplace_back(new MusicWheelItemData(wid)); + arrayWheelItemDatas.emplace_back(std::move(wid)); } } else { // Make an array of Song*, then sort them @@ -982,8 +970,7 @@ MusicWheel::BuildWheelItemDatas( : SECTION_COLORS.GetValue(iSectionColorIndex); iSectionColorIndex = (iSectionColorIndex + 1) % NUM_SECTION_COLORS; - arrayWheelItemDatas.emplace_back( - new MusicWheelItemData(WheelItemDataType_Section, + arrayWheelItemDatas.push_back(std::make_unique(WheelItemDataType_Section, nullptr, sThisSection, colorSection, @@ -991,8 +978,7 @@ MusicWheel::BuildWheelItemDatas( sLastSection = sThisSection; } } - arrayWheelItemDatas.emplace_back( - new MusicWheelItemData(WheelItemDataType_Song, + arrayWheelItemDatas.emplace_back(std::make_unique(WheelItemDataType_Song, pSong, sLastSection, SONGMAN->GetSongColor(pSong), @@ -1031,8 +1017,7 @@ MusicWheel::BuildWheelItemDatas( auto colorSection = SONGMAN->GetSongGroupColor(gname); iSectionColorIndex = (iSectionColorIndex + 1) % NUM_SECTION_COLORS; - arrayWheelItemDatas.emplace_back( - new MusicWheelItemData(WheelItemDataType_Section, + arrayWheelItemDatas.emplace_back(std::make_unique(WheelItemDataType_Section, nullptr, gname, colorSection, @@ -1042,8 +1027,7 @@ MusicWheel::BuildWheelItemDatas( // the song is in the arraysongs set defined above -mina for (auto& s : gsongs) { if (hurp.count(s) != 0u) { - arrayWheelItemDatas.emplace_back( - new MusicWheelItemData(WheelItemDataType_Song, + arrayWheelItemDatas.emplace_back(std::make_unique(WheelItemDataType_Song, s, gname, SONGMAN->GetSongColor(s), @@ -1108,7 +1092,7 @@ MusicWheel::readyWheelItemsData(SortOrder so, } void -MusicWheel::FilterWheelItemDatas(std::vector& aUnFilteredDatas, +MusicWheel::FilterWheelItemDatas(std::vector>& aUnFilteredDatas, std::vector& aFilteredData, SortOrder /*so*/) const { @@ -1169,7 +1153,7 @@ MusicWheel::FilterWheelItemDatas(std::vector& aUnFilteredDa if (aiRemove[i]) { continue; } - aFilteredData.emplace_back(aUnFilteredDatas[i]); + aFilteredData.emplace_back(aUnFilteredDatas[i].get()); } // Update the song count in each section header. @@ -1206,10 +1190,11 @@ MusicWheel::FilterWheelItemDatas(std::vector& aUnFilteredDa --filteredSize; } - // If we've filtered all items, insert a dummy. + // If we've filtered all items, insert a static dummy. if (aFilteredData.empty()) { - aFilteredData.emplace_back(new MusicWheelItemData( - WheelItemDataType_Section, nullptr, EMPTY_STRING, EMPTY_COLOR, 0)); + static MusicWheelItemData EmptyDummy( + WheelItemDataType_Section, nullptr, EMPTY_STRING, EMPTY_COLOR, 0); + aFilteredData.emplace_back(&EmptyDummy); } } diff --git a/src/Etterna/Actor/Menus/MusicWheel.h b/src/Etterna/Actor/Menus/MusicWheel.h index a027773d20..bb27e25b00 100644 --- a/src/Etterna/Actor/Menus/MusicWheel.h +++ b/src/Etterna/Actor/Menus/MusicWheel.h @@ -20,7 +20,7 @@ class MusicWheel : public WheelBase public: MusicWheel(); - ~MusicWheel() override; + ~MusicWheel() override = default; void Load(const string& sType) override; void BeginScreen(); @@ -133,14 +133,17 @@ class MusicWheel : public WheelBase NEEDREFILTER, VALID } m_WheelItemDatasStatus[NUM_SortOrder]{}; + // Stores pointers owned by m__UnFilteredWheelItemDatas + // This is fine because whenever m__UnFilteredWheelItemDatas is updated we + // then also update m__WheelItemDatas std::vector m__WheelItemDatas[NUM_SortOrder]; - std::vector m__UnFilteredWheelItemDatas[NUM_SortOrder]; + std::vector> m__UnFilteredWheelItemDatas[NUM_SortOrder]; - void BuildWheelItemDatas(std::vector& arrayWheelItemDatas, + void BuildWheelItemDatas(std::vector>& arrayWheelItemDatas, SortOrder so, bool searching, const std::string& findme); - void FilterWheelItemDatas(std::vector& aUnFilteredDatas, + void FilterWheelItemDatas(std::vector>& aUnFilteredDatas, std::vector& aFilteredData, SortOrder so) const; std::string prevSongTitle; diff --git a/src/Etterna/Actor/Menus/MusicWheelItem.h b/src/Etterna/Actor/Menus/MusicWheelItem.h index 01c3369a78..5fb4875a45 100644 --- a/src/Etterna/Actor/Menus/MusicWheelItem.h +++ b/src/Etterna/Actor/Menus/MusicWheelItem.h @@ -77,7 +77,7 @@ struct MusicWheelItemData : WheelItemBaseData // for TYPE_SORT std::string m_sLabel; - HiddenPtr m_pAction; + std::unique_ptr m_pAction; }; #endif diff --git a/src/Etterna/Models/HighScore/HighScore.cpp b/src/Etterna/Models/HighScore/HighScore.cpp index a3b7ff259d..e6e6c7ece4 100644 --- a/src/Etterna/Models/HighScore/HighScore.cpp +++ b/src/Etterna/Models/HighScore/HighScore.cpp @@ -1008,17 +1008,26 @@ HighScore::HasReplayData() -> bool return DoesFileExist(basicpath); } -REGISTER_CLASS_TRAITS(HighScoreImpl, new HighScoreImpl(*pCopy)) - HighScore::HighScore() { - m_Impl = new HighScoreImpl; + m_Impl = std::make_unique(); +} + +HighScore::HSImplUniquePtr::~HSImplUniquePtr() = default; +HighScore::HSImplUniquePtr::HSImplUniquePtr(std::unique_ptr ptr) :p(std::move(ptr)) {} +HighScore::HSImplUniquePtr::HSImplUniquePtr(): p(std::make_unique()) { } +HighScore::HSImplUniquePtr::HSImplUniquePtr(const HSImplUniquePtr& rhs) { + p = rhs.p ? std::make_unique(*rhs.p) : nullptr; +} +auto HighScore::HSImplUniquePtr::operator=(const HSImplUniquePtr& rhs) -> HSImplUniquePtr& { + p = rhs.p ? std::make_unique(*rhs.p) : nullptr; + return *this; } void HighScore::Unset() { - m_Impl = new HighScoreImpl; + m_Impl = std::make_unique(); } auto @@ -1631,6 +1640,8 @@ HighScore::operator!=(const HighScore& other) const -> bool return !operator==(other); } +auto HighScore::operator=(const HighScore &) -> HighScore& = default; + auto HighScore::CreateEttNode() const -> XNode* { diff --git a/src/Etterna/Models/HighScore/HighScore.h b/src/Etterna/Models/HighScore/HighScore.h index 4fca0e630e..2d24475649 100644 --- a/src/Etterna/Models/HighScore/HighScore.h +++ b/src/Etterna/Models/HighScore/HighScore.h @@ -5,7 +5,6 @@ #include "Etterna/Models/Misc/GameConstantsAndTypes.h" #include "Etterna/Models/Misc/Grade.h" #include "Etterna/Models/HighScore/ReplayConstantsAndTypes.h" -#include "RageUtil/Utils/RageUtil_AutoPtr.h" class XNode; struct RadarValues; @@ -157,6 +156,7 @@ struct HighScore auto operator>=(HighScore const& other) const -> bool; auto operator==(HighScore const& other) const -> bool; auto operator!=(HighScore const& other) const -> bool; + auto HighScore::operator=(const HighScore &) -> HighScore&; [[nodiscard]] auto CreateNode() const -> XNode*; [[nodiscard]] auto CreateEttNode() const -> XNode*; @@ -204,7 +204,21 @@ struct HighScore void PushSelf(lua_State* L); private: - HiddenPtr m_Impl; + struct HSImplUniquePtr { + std::unique_ptr p; + + HSImplUniquePtr(); + ~HSImplUniquePtr(); + HSImplUniquePtr(const HSImplUniquePtr& rhs); + HSImplUniquePtr(std::unique_ptr ptr); + auto operator=(const HSImplUniquePtr& rhs) -> HSImplUniquePtr&; + + HighScoreImpl *operator->() { return &*p; } + HighScoreImpl &operator*() { return *p; } + HighScoreImpl const *operator->() const { return &*p; } + HighScoreImpl const &operator*() const { return *p; } + }; + HSImplUniquePtr m_Impl; }; /** @brief the picture taken of the high score. */ diff --git a/src/Etterna/Models/Lua/LuaBinding.cpp b/src/Etterna/Models/Lua/LuaBinding.cpp index 37b8137b7e..b754feb85a 100644 --- a/src/Etterna/Models/Lua/LuaBinding.cpp +++ b/src/Etterna/Models/Lua/LuaBinding.cpp @@ -297,9 +297,6 @@ LuaBinding::ApplyDerivedType(Lua* L, const std::string& sClassName, void* pSelf) lua_setmetatable(L, iTable); } -#include "RageUtil/Utils/RageUtil_AutoPtr.h" -REGISTER_CLASS_TRAITS(LuaClass, new LuaClass(*pCopy)) - void* LuaBinding::GetPointerFromStack(Lua* L, const std::string& sType, int iArg) { diff --git a/src/Etterna/Models/Lua/LuaReference.cpp b/src/Etterna/Models/Lua/LuaReference.cpp index f2367f330c..d49d7e25a8 100644 --- a/src/Etterna/Models/Lua/LuaReference.cpp +++ b/src/Etterna/Models/Lua/LuaReference.cpp @@ -1,8 +1,6 @@ #include "Etterna/Globals/global.h" #include "LuaReference.h" -REGISTER_CLASS_TRAITS(LuaReference, new LuaReference(*pCopy)) - LuaReference::LuaReference() { m_iReference = LUA_NOREF; diff --git a/src/Etterna/Models/Lua/LuaReference.h b/src/Etterna/Models/Lua/LuaReference.h index 6f067e7f89..c1497e6f46 100644 --- a/src/Etterna/Models/Lua/LuaReference.h +++ b/src/Etterna/Models/Lua/LuaReference.h @@ -2,7 +2,6 @@ #define LUA_REFERENCE_H #include "Etterna/Singletons/LuaManager.h" -#include "RageUtil/Utils/RageUtil_AutoPtr.h" struct lua_State; using Lua = lua_State; diff --git a/src/Etterna/Models/Misc/GameCommand.cpp b/src/Etterna/Models/Misc/GameCommand.cpp index a1e69d6ee2..4d415114d4 100644 --- a/src/Etterna/Models/Misc/GameCommand.cpp +++ b/src/Etterna/Models/Misc/GameCommand.cpp @@ -24,8 +24,6 @@ static LocalizedString COULD_NOT_LAUNCH_BROWSER( "GameCommand", "Could not launch web browser."); -REGISTER_CLASS_TRAITS(GameCommand, new GameCommand(*pCopy)); - void GameCommand::Init() { diff --git a/src/Etterna/Models/NoteData/NoteData.cpp b/src/Etterna/Models/NoteData/NoteData.cpp index b9c5e8dea2..03717f476a 100644 --- a/src/Etterna/Models/NoteData/NoteData.cpp +++ b/src/Etterna/Models/NoteData/NoteData.cpp @@ -2,7 +2,6 @@ #include "Etterna/Singletons/GameState.h" // blame radar calculations. #include "NoteData.h" #include "RageUtil/Utils/RageUtil.h" -#include "RageUtil/Utils/RageUtil_AutoPtr.h" #include "Etterna/FileTypes/XmlFile.h" #include @@ -11,8 +10,6 @@ using std::map; using std::vector; -REGISTER_CLASS_TRAITS(NoteData, new NoteData(*pCopy)) - void NoteData::Init() { diff --git a/src/Etterna/Models/StepsAndStyles/Steps.cpp b/src/Etterna/Models/StepsAndStyles/Steps.cpp index b0ea373b18..33ceb98bb7 100644 --- a/src/Etterna/Models/StepsAndStyles/Steps.cpp +++ b/src/Etterna/Models/StepsAndStyles/Steps.cpp @@ -28,6 +28,7 @@ #include "Core/Services/Locator.hpp" #include "RageUtil/Utils/RageUtil.h" #include "Etterna/Models/Songs/Song.h" +#include "Etterna/Models/StepsAndStyles/Steps.h" #include "Etterna/Singletons/SongManager.h" #include "Etterna/Singletons/FilterManager.h" @@ -54,7 +55,7 @@ LuaXType(DisplayBPM); Steps::Steps(Song* song) : m_StepsType(StepsType_Invalid) , m_pSong(song) - , m_pNoteData(new NoteData) + , m_pNoteData() , m_bNoteDataIsFilled(false) , m_sNoteDataCompressed("") , m_sFilename("") @@ -74,6 +75,7 @@ Steps::Steps(Song* song) } Steps::~Steps() = default; +auto Steps::operator=(const Steps &) -> Steps& = default; void Steps::GetDisplayBpms(DisplayBpms& AddTo) const diff --git a/src/Etterna/Models/StepsAndStyles/Steps.h b/src/Etterna/Models/StepsAndStyles/Steps.h index 2bebc2881e..2d8afcf334 100644 --- a/src/Etterna/Models/StepsAndStyles/Steps.h +++ b/src/Etterna/Models/StepsAndStyles/Steps.h @@ -5,12 +5,11 @@ #include "Etterna/Models/Misc/GameConstantsAndTypes.h" #include "Etterna/Models/Misc/Grade.h" #include "Etterna/Models/Misc/RadarValues.h" -#include "RageUtil/Utils/RageUtil_AutoPtr.h" #include "RageUtil/Utils/RageUtil_CachedObject.h" #include "Etterna/Models/Misc/TimingData.h" +#include "Etterna/Models/NoteData/NoteData.h" class Profile; -class NoteData; struct lua_State; class Song; class Calc; @@ -47,6 +46,8 @@ class Steps /** @brief Destroy the Steps that are no longer needed. */ ~Steps(); + auto Steps::operator=(const Steps &) -> Steps&; + // initializers void CopyFrom(Steps* pSource, StepsType ntTo); void CreateBlank(StepsType ntTo); @@ -271,10 +272,23 @@ class Steps private: std::string ChartKey = ""; + struct UniquePtrNoteData { + std::unique_ptr p; + UniquePtrNoteData(): p(std::make_unique()) { } + UniquePtrNoteData(UniquePtrNoteData& rhs) { + p = rhs.p ? std::make_unique(*rhs.p) : nullptr; + } + UniquePtrNoteData &operator=(UniquePtrNoteData& rhs) { + p = rhs.p ? std::make_unique(*rhs.p) : nullptr; + return *this; + } + NoteData *operator->() { return &*p; } + NoteData &operator*() { return *p; } + }; /* We can have one or both of these; if we have both, they're always * identical. Call Compress() to force us to only have * m_sNoteDataCompressed; otherwise, creation of these is transparent. */ - mutable HiddenPtr m_pNoteData; + mutable UniquePtrNoteData m_pNoteData; mutable bool m_bNoteDataIsFilled; mutable std::string m_sNoteDataCompressed; diff --git a/src/RageUtil/CMakeLists.txt b/src/RageUtil/CMakeLists.txt index 0c3d798f47..cee1842337 100644 --- a/src/RageUtil/CMakeLists.txt +++ b/src/RageUtil/CMakeLists.txt @@ -10,7 +10,6 @@ list(APPEND SMDATA_RAGE_UTILS_SRC list(APPEND SMDATA_RAGE_UTILS_HPP "Utils/RageUtil.h" - "Utils/RageUtil_AutoPtr.h" # TODO: Remove the need for this and replace with c++11 smart pointers "Utils/RageUtil_CachedObject.h" "Utils/RageUtil_CharConversions.h" "Utils/RageUtil_CircularBuffer.h" diff --git a/src/RageUtil/File/RageFileBasic.cpp b/src/RageUtil/File/RageFileBasic.cpp index df023010f7..cd4a3d395e 100644 --- a/src/RageUtil/File/RageFileBasic.cpp +++ b/src/RageUtil/File/RageFileBasic.cpp @@ -1,12 +1,9 @@ #include "Etterna/Globals/global.h" #include "RageFileBasic.h" #include "RageUtil/Utils/RageUtil.h" -#include "RageUtil/Utils/RageUtil_AutoPtr.h" #include -REGISTER_CLASS_TRAITS(RageFileBasic, pCopy->Copy()); - RageFileObj::RageFileObj() { m_pReadBuffer = NULL; diff --git a/src/RageUtil/Sound/RageSoundReader.cpp b/src/RageUtil/Sound/RageSoundReader.cpp index 445f2b133c..a6426dedd0 100644 --- a/src/RageUtil/Sound/RageSoundReader.cpp +++ b/src/RageUtil/Sound/RageSoundReader.cpp @@ -1,9 +1,6 @@ #include "Etterna/Globals/global.h" #include "Core/Services/Locator.hpp" #include "RageSoundReader.h" -#include "RageUtil/Utils/RageUtil_AutoPtr.h" - -REGISTER_CLASS_TRAITS(RageSoundReader, pCopy->Copy()); /* Read(), handling the STREAM_LOOPED and empty return cases. */ int diff --git a/src/RageUtil/Sound/RageSoundReader_FileReader.cpp b/src/RageUtil/Sound/RageSoundReader_FileReader.cpp index b1266dde83..1cd3b2ab94 100644 --- a/src/RageUtil/Sound/RageSoundReader_FileReader.cpp +++ b/src/RageUtil/Sound/RageSoundReader_FileReader.cpp @@ -10,6 +10,12 @@ #include +RageSoundReader_FileReader::RageSoundReader_FileReader(const RageSoundReader_FileReader& rhs): + m_pFile(rhs.m_pFile->Copy()), + m_sError(rhs.m_sError) { +} +RageSoundReader_FileReader::RageSoundReader_FileReader() : m_sError(), m_pFile(nullptr) {} + RageSoundReader_FileReader* RageSoundReader_FileReader::TryOpenFile(RageFileBasic* pFile, std::string& error, @@ -93,27 +99,22 @@ RageSoundReader_FileReader::OpenFile(const std::string& filename, std::string& error, bool* pPrebuffer) { - HiddenPtr pFile; - { - auto* pFileOpen = new RageFile; - if (!pFileOpen->Open(filename)) { - error = pFileOpen->GetError(); - delete pFileOpen; - return nullptr; - } - pFile = pFileOpen; + std::unique_ptr pFileOpen = std::make_unique(); + if (!pFileOpen->Open(filename)) { + error = pFileOpen->GetError(); + return nullptr; } + std::unique_ptr pFile = std::move(pFileOpen); if (pPrebuffer) { if (pFile->GetFileSize() < 1024 * 50) { - auto* pMem = new RageFileObjMem; + auto pMem = std::make_unique(); bool bRet = FileCopy(*pFile, *pMem, error, nullptr); if (!bRet) { - delete pMem; return nullptr; } - pFile = pMem; + pFile = std::move(pMem); pFile->Seek(0); *pPrebuffer = true; } else { diff --git a/src/RageUtil/Sound/RageSoundReader_FileReader.h b/src/RageUtil/Sound/RageSoundReader_FileReader.h index d6ca718d5b..1274bab296 100644 --- a/src/RageUtil/Sound/RageSoundReader_FileReader.h +++ b/src/RageUtil/Sound/RageSoundReader_FileReader.h @@ -3,8 +3,8 @@ #ifndef RAGE_SOUND_READER_FILE_READER_H #define RAGE_SOUND_READER_FILE_READER_H +#include #include "RageSoundReader.h" -#include "RageUtil/Utils/RageUtil_AutoPtr.h" class RageFileBasic; @@ -27,6 +27,8 @@ class RageSoundReader_FileReader : public RageSoundReader OPEN_UNKNOWN_FILE_FORMAT = 1, OPEN_FATAL_ERROR = 2, }; + RageSoundReader_FileReader::RageSoundReader_FileReader(const RageSoundReader_FileReader&); + RageSoundReader_FileReader(); /* Takes ownership of pFile (even on failure). */ virtual OpenResult Open(RageFileBasic* pFile) = 0; @@ -42,7 +44,7 @@ class RageSoundReader_FileReader : public RageSoundReader protected: void SetError(const std::string& sError) const { m_sError = sError; } - HiddenPtr m_pFile; + std::unique_ptr m_pFile; private: static RageSoundReader_FileReader* TryOpenFile(RageFileBasic* pFile, diff --git a/src/RageUtil/Sound/RageSoundReader_Filter.h b/src/RageUtil/Sound/RageSoundReader_Filter.h index e97189f6b1..01c9f3343b 100644 --- a/src/RageUtil/Sound/RageSoundReader_Filter.h +++ b/src/RageUtil/Sound/RageSoundReader_Filter.h @@ -3,8 +3,8 @@ #ifndef RAGE_SOUND_READER_FILTER_H #define RAGE_SOUND_READER_FILTER_H +#include #include "RageSoundReader.h" -#include "RageUtil/Utils/RageUtil_AutoPtr.h" class RageSoundReader_Filter : public RageSoundReader { @@ -13,6 +13,9 @@ class RageSoundReader_Filter : public RageSoundReader : m_pSource(pSource) { } + RageSoundReader_Filter(const RageSoundReader_Filter& rhs) { + m_pSource = std::unique_ptr(rhs.m_pSource->Copy()); + } int GetLength() const override { return m_pSource->GetLength(); } int GetLength_Fast() const override { return m_pSource->GetLength_Fast(); } @@ -45,7 +48,7 @@ class RageSoundReader_Filter : public RageSoundReader std::string GetError() const override { return m_pSource->GetError(); } protected: - HiddenPtr m_pSource; + std::unique_ptr m_pSource; }; #endif diff --git a/src/RageUtil/Sound/RageSoundReader_MP3.cpp b/src/RageUtil/Sound/RageSoundReader_MP3.cpp index 0019d5ea49..70768da4a4 100644 --- a/src/RageUtil/Sound/RageSoundReader_MP3.cpp +++ b/src/RageUtil/Sound/RageSoundReader_MP3.cpp @@ -624,7 +624,7 @@ RageSoundReader_MP3::~RageSoundReader_MP3() RageSoundReader_FileReader::OpenResult RageSoundReader_MP3::Open(RageFileBasic* pFile) { - m_pFile = pFile; + m_pFile = std::unique_ptr(pFile); mad->filesize = m_pFile->GetFileSize(); ASSERT(mad->filesize != -1); @@ -670,7 +670,7 @@ RageSoundReader_MP3::Copy() const { auto ret = new RageSoundReader_MP3; - ret->m_pFile = m_pFile->Copy(); + ret->m_pFile = std::unique_ptr(m_pFile->Copy()); ret->m_pFile->Seek(0); ret->m_bAccurateSync = m_bAccurateSync; ret->mad->filesize = mad->filesize; diff --git a/src/RageUtil/Sound/RageSoundReader_PitchChange.cpp b/src/RageUtil/Sound/RageSoundReader_PitchChange.cpp index d6cf36196c..66f128a839 100644 --- a/src/RageUtil/Sound/RageSoundReader_PitchChange.cpp +++ b/src/RageUtil/Sound/RageSoundReader_PitchChange.cpp @@ -21,7 +21,7 @@ RageSoundReader_PitchChange::RageSoundReader_PitchChange( m_pSpeedChange = new RageSoundReader_SpeedChange(pSource); m_pResample = new RageSoundReader_Resample_Good( m_pSpeedChange, m_pSpeedChange->GetSampleRate()); - m_pSource = m_pResample; + m_pSource = std::unique_ptr(m_pResample); m_fSpeedRatio = 1.0f; m_fPitchRatio = 1.0f; m_fLastSetSpeedRatio = m_fSpeedRatio; diff --git a/src/RageUtil/Sound/RageSoundReader_ThreadedBuffer.cpp b/src/RageUtil/Sound/RageSoundReader_ThreadedBuffer.cpp index a8fd9d8d0d..43919d9363 100644 --- a/src/RageUtil/Sound/RageSoundReader_ThreadedBuffer.cpp +++ b/src/RageUtil/Sound/RageSoundReader_ThreadedBuffer.cpp @@ -60,7 +60,7 @@ RageSoundReader_ThreadedBuffer::RageSoundReader_ThreadedBuffer( { bool bWasEnabled = cpy.DisableBuffering(); - m_pSource = cpy.m_pSource->Copy(); + m_pSource = std::unique_ptr(cpy.m_pSource->Copy()); m_iSampleRate = cpy.m_iSampleRate; m_iChannels = cpy.m_iChannels; m_DataBuffer = cpy.m_DataBuffer; diff --git a/src/RageUtil/Sound/RageSoundReader_Vorbisfile.cpp b/src/RageUtil/Sound/RageSoundReader_Vorbisfile.cpp index 0739aaf6a5..f09f3bd821 100644 --- a/src/RageUtil/Sound/RageSoundReader_Vorbisfile.cpp +++ b/src/RageUtil/Sound/RageSoundReader_Vorbisfile.cpp @@ -106,7 +106,7 @@ ov_ssprintf(int err, const char* fmt, ...) RageSoundReader_FileReader::OpenResult RageSoundReader_Vorbisfile::Open(RageFileBasic* pFile) { - m_pFile = pFile; + m_pFile = std::unique_ptr(pFile); vf = new OggVorbis_File; memset(vf, 0, sizeof(*vf)); diff --git a/src/RageUtil/Sound/RageSoundReader_WAV.cpp b/src/RageUtil/Sound/RageSoundReader_WAV.cpp index 6fca09b678..4e53ee2be4 100644 --- a/src/RageUtil/Sound/RageSoundReader_WAV.cpp +++ b/src/RageUtil/Sound/RageSoundReader_WAV.cpp @@ -490,7 +490,7 @@ ReadString(RageFileBasic& f, int iSize, std::string& sError) RageSoundReader_FileReader::OpenResult RageSoundReader_WAV::Open(RageFileBasic* pFile) { - m_pFile = pFile; + m_pFile = std::unique_ptr(pFile); std::string sError; diff --git a/src/RageUtil/Utils/RageUtil_AutoPtr.h b/src/RageUtil/Utils/RageUtil_AutoPtr.h deleted file mode 100644 index 66df8385f2..0000000000 --- a/src/RageUtil/Utils/RageUtil_AutoPtr.h +++ /dev/null @@ -1,116 +0,0 @@ -/* AutoPtrCopyOnWrite - Simple smart pointer template. */ - -#ifndef RAGE_UTIL_AUTO_PTR_H -#define RAGE_UTIL_AUTO_PTR_H - - -/* - * This smart pointer template is used to safely hide implementations from - * headers, to reduce dependencies. This is the same as declaring a pointer - * to a class, and allocating/deallocating it in the implementation: only - * the implementation needs to include that class. This makes copying - * and deletion automatic, so you don't need to include a copy ctor or - * remember to delete it. - * - * There's one subtlety: in order to copy or delete an object, we need its - * definition. This is intended to avoid pulling in the definition. So, - * we use a traits class to hide it. Use REGISTER_CLASS_TRAITS for each - * class used with this template. - * - * Concepts from http://www.gotw.ca/gotw/062.htm. - */ -template -struct HiddenPtrTraits -{ - static auto Copy(const T* pCopy) -> T*; - static void Delete(T* p); -}; -#define REGISTER_CLASS_TRAITS(T, CopyExpr) \ - template<> \ - T* HiddenPtrTraits::Copy(const T* pCopy) \ - { \ - return CopyExpr; \ - } \ - template<> \ - void HiddenPtrTraits::Delete(T* p) \ - { \ - delete p; \ - } - -template -class HiddenPtr -{ - public: - auto operator*() const -> const T& { return *m_pPtr; } - auto operator->() const -> const T* { return m_pPtr; } - auto operator*() -> T& { return *m_pPtr; } - auto operator->() -> T* { return m_pPtr; } - - explicit HiddenPtr(T* p = NULL) - : m_pPtr(p) - { - } - - HiddenPtr(const HiddenPtr& cpy) - : m_pPtr(nullptr) - { - if (cpy.m_pPtr != nullptr) { - m_pPtr = HiddenPtrTraits::Copy(cpy.m_pPtr); - } - } - -#if 0 // broken VC6 - template - HiddenPtr( const HiddenPtr &cpy ) - { - if( cpy.m_pPtr == NULL ) - m_pPtr = NULL; - else - m_pPtr = HiddenPtrTraits::Copy( cpy.m_pPtr ); - } -#endif - - ~HiddenPtr() { HiddenPtrTraits::Delete(m_pPtr); } - void Swap(HiddenPtr& rhs) { std::swap(m_pPtr, rhs.m_pPtr); } - - auto operator=(T* p) -> HiddenPtr& - { - HiddenPtr t(p); - Swap(t); - return *this; - } - - auto operator=(const HiddenPtr& cpy) -> HiddenPtr& - { - HiddenPtr t(cpy); - Swap(t); - return *this; - } - -#if 0 // broken VC6 - template - HiddenPtr &operator=( const HiddenPtr &cpy ) - { - HiddenPtr t( cpy ); - Swap( t ); - return *this; - } -#endif - - private: - T* m_pPtr; - -#if 0 // broken VC6 - template - friend class HiddenPtr; -#endif -}; - -template -inline void -swap(HiddenPtr& a, HiddenPtr& b) -{ - a.Swap(b); -} - -#endif