diff options
| author | shuffle2 <godisgovernment@gmail.com> | 2014-05-11 01:46:09 -0700 |
|---|---|---|
| committer | shuffle2 <godisgovernment@gmail.com> | 2014-05-11 01:46:09 -0700 |
| commit | 36720e6822a8049c34ff1bfe4ea24e47f85847ca (patch) | |
| tree | 44b9b13f3322c0a46b6b23cf53a350f56b10798e /Source/Core | |
| parent | 541ff4cc7cab32d7a0dde05758a6383351f33b44 (diff) | |
| parent | fd94ce5210c9d2299965eee434cde550383681c9 (diff) | |
Merge pull request #351 from Tilka/make_unique
Add a std::make_unique implementation (Common/StdMakeUnique.h)
Diffstat (limited to 'Source/Core')
| -rw-r--r-- | Source/Core/Common/Common.vcxproj | 1 | ||||
| -rw-r--r-- | Source/Core/Common/Common.vcxproj.filters | 1 | ||||
| -rw-r--r-- | Source/Core/Common/StdMakeUnique.h | 82 | ||||
| -rw-r--r-- | Source/Core/Core/Boot/Boot_WiiWAD.cpp | 5 | ||||
| -rw-r--r-- | Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_es.cpp | 5 | ||||
| -rw-r--r-- | Source/Core/Core/PowerPC/Jit64IL/JitIL.cpp | 3 | ||||
| -rw-r--r-- | Source/Core/Core/PowerPC/JitILCommon/IR.cpp | 3 | ||||
| -rw-r--r-- | Source/Core/DolphinWX/GameListCtrl.cpp | 12 |
8 files changed, 100 insertions, 12 deletions
diff --git a/Source/Core/Common/Common.vcxproj b/Source/Core/Common/Common.vcxproj index a7cc5df100..00bcb07c80 100644 --- a/Source/Core/Common/Common.vcxproj +++ b/Source/Core/Common/Common.vcxproj @@ -82,6 +82,7 @@ <ClInclude Include="SettingsHandler.h" /> <ClInclude Include="stdafx.h" /> <ClInclude Include="StdConditionVariable.h" /> + <ClInclude Include="StdMakeUnique.h" /> <ClInclude Include="StdMutex.h" /> <ClInclude Include="StdThread.h" /> <ClInclude Include="StringUtil.h" /> diff --git a/Source/Core/Common/Common.vcxproj.filters b/Source/Core/Common/Common.vcxproj.filters index 2fbca73212..b571231c46 100644 --- a/Source/Core/Common/Common.vcxproj.filters +++ b/Source/Core/Common/Common.vcxproj.filters @@ -42,6 +42,7 @@ <ClInclude Include="SDCardUtil.h" /> <ClInclude Include="SettingsHandler.h" /> <ClInclude Include="StdConditionVariable.h" /> + <ClInclude Include="StdMakeUnique.h" /> <ClInclude Include="StdMutex.h" /> <ClInclude Include="StdThread.h" /> <ClInclude Include="StringUtil.h" /> diff --git a/Source/Core/Common/StdMakeUnique.h b/Source/Core/Common/StdMakeUnique.h new file mode 100644 index 0000000000..16fd507f7f --- /dev/null +++ b/Source/Core/Common/StdMakeUnique.h @@ -0,0 +1,82 @@ +// Copyright 2013 Dolphin Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#pragma once + +// VS 2013 defines __cplusplus as 199711L but has std::make_unique. +#if __cplusplus > 201103L || _MSC_VER >= 1800 +#include <memory> +#else + +// Implementation of C++14 std::make_unique, which is not supported by all the +// compilers we care about yet. +// +// NOTE: This code is based on the libc++ implementation of std::make_unique. +// +// Copyright (c) 2009-2014 by the libc++ contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. + +#include <cstddef> +#include <memory> +#include <type_traits> + +namespace std +{ + +struct unspecified {}; + +template<class T> +struct unique_if +{ + typedef std::unique_ptr<T> unique_single; +}; + +template<class T> +struct unique_if<T[]> +{ + typedef std::unique_ptr<T[]> unique_array_unknown_bound; +}; + +template<class T, size_t N> +struct unique_if<T[N]> +{ + typedef void unique_array_known_bound; +}; + +template<class T, class... Args> +inline typename unique_if<T>::unique_single make_unique(Args&&... args) +{ + return std::unique_ptr<T>(new T(std::forward<Args>(args)...)); +} + +template<class T> +inline typename unique_if<T>::unique_array_unknown_bound make_unique(size_t n) +{ + typedef typename std::remove_extent<T>::type U; + return std::unique_ptr<T>(new U[n]()); +} + +template<class T, class... Args> +typename unique_if<T>::unique_array_known_bound make_unique(Args&&...) = delete; + +} // namespace std + +#endif // __cplusplus diff --git a/Source/Core/Core/Boot/Boot_WiiWAD.cpp b/Source/Core/Core/Boot/Boot_WiiWAD.cpp index 03fa4a2548..e1a132a033 100644 --- a/Source/Core/Core/Boot/Boot_WiiWAD.cpp +++ b/Source/Core/Core/Boot/Boot_WiiWAD.cpp @@ -8,6 +8,7 @@ #include "Common/CommonPaths.h" #include "Common/FileUtil.h" #include "Common/NandPaths.h" +#include "Common/StdMakeUnique.h" #include "Core/ConfigManager.h" #include "Core/PatchEngine.h" @@ -98,11 +99,11 @@ bool CBoot::Boot_WiiWAD(const std::string& _pFilename) std::unique_ptr<CDolLoader> pDolLoader; if (pContent->m_pData) { - pDolLoader.reset(new CDolLoader(pContent->m_pData, pContent->m_Size)); + pDolLoader = std::make_unique<CDolLoader>(pContent->m_pData, pContent->m_Size); } else { - pDolLoader.reset(new CDolLoader(pContent->m_Filename)); + pDolLoader = std::make_unique<CDolLoader>(pContent->m_Filename); } pDolLoader->Load(); PC = pDolLoader->GetEntryPoint() | 0x80000000; diff --git a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_es.cpp b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_es.cpp index 96dc66f03d..c5fd2871eb 100644 --- a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_es.cpp +++ b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_es.cpp @@ -42,6 +42,7 @@ #include "Common/CommonPaths.h" #include "Common/FileUtil.h" #include "Common/NandPaths.h" +#include "Common/StdMakeUnique.h" #include "Common/StringUtil.h" #include "Core/ConfigManager.h" @@ -918,11 +919,11 @@ bool CWII_IPC_HLE_Device_es::IOCtlV(u32 _CommandAddress) std::unique_ptr<CDolLoader> pDolLoader; if (pContent->m_pData) { - pDolLoader.reset(new CDolLoader(pContent->m_pData, pContent->m_Size)); + pDolLoader = std::make_unique<CDolLoader>(pContent->m_pData, pContent->m_Size); } else { - pDolLoader.reset(new CDolLoader(pContent->m_Filename)); + pDolLoader = std::make_unique<CDolLoader>(pContent->m_Filename); } pDolLoader->Load(); // TODO: Check why sysmenu does not load the DOL correctly PC = pDolLoader->GetEntryPoint() | 0x80000000; diff --git a/Source/Core/Core/PowerPC/Jit64IL/JitIL.cpp b/Source/Core/Core/PowerPC/Jit64IL/JitIL.cpp index b686cbc514..89c7f7d022 100644 --- a/Source/Core/Core/PowerPC/Jit64IL/JitIL.cpp +++ b/Source/Core/Core/PowerPC/Jit64IL/JitIL.cpp @@ -8,6 +8,7 @@ #include <memory> #include "Common/Common.h" +#include "Common/StdMakeUnique.h" #include "Core/PatchEngine.h" #include "Core/HLE/HLE.h" #include "Core/PowerPC/Profiler.h" @@ -223,7 +224,7 @@ namespace JitILProfiler std::unique_ptr<JitILProfilerFinalizer> finalizer; static void Init() { - finalizer = std::unique_ptr<JitILProfilerFinalizer>(new JitILProfilerFinalizer); + finalizer = std::make_unique<JitILProfilerFinalizer>(); } static void Shutdown() { diff --git a/Source/Core/Core/PowerPC/JitILCommon/IR.cpp b/Source/Core/Core/PowerPC/JitILCommon/IR.cpp index 90f3118cab..3684e4e514 100644 --- a/Source/Core/Core/PowerPC/JitILCommon/IR.cpp +++ b/Source/Core/Core/PowerPC/JitILCommon/IR.cpp @@ -125,6 +125,7 @@ TODO (in no particular order): #include <memory> #include <set> +#include "Common/StdMakeUnique.h" #include "Core/Core.h" #include "Core/CoreTiming.h" #include "Core/HW/GPFifo.h" @@ -1280,7 +1281,7 @@ void IRBuilder::WriteToFile(u64 codeHash) { _assert_(sizeof(opcodeNames) / sizeof(opcodeNames[0]) == Int3 + 1); if (!writer.get()) { - writer = std::unique_ptr<Writer>(new Writer); + writer = std::make_unique<Writer>(); } FILE* const file = writer->file.GetHandle(); diff --git a/Source/Core/DolphinWX/GameListCtrl.cpp b/Source/Core/DolphinWX/GameListCtrl.cpp index a193e19447..5bfec7d936 100644 --- a/Source/Core/DolphinWX/GameListCtrl.cpp +++ b/Source/Core/DolphinWX/GameListCtrl.cpp @@ -44,6 +44,7 @@ #include "Common/FileSearch.h" #include "Common/FileUtil.h" #include "Common/MathUtil.h" +#include "Common/StdMakeUnique.h" #include "Common/StringUtil.h" #include "Common/SysConf.h" #include "Core/ConfigManager.h" @@ -555,14 +556,13 @@ void CGameListCtrl::ScanForISOs() if (dialog.WasCancelled()) break; - std::unique_ptr<GameListItem> iso_file(new GameListItem(rFilenames[i])); - const GameListItem& ISOFile = *iso_file; + auto iso_file = std::make_unique<GameListItem>(rFilenames[i]); - if (ISOFile.IsValid()) + if (iso_file->IsValid()) { bool list = true; - switch (ISOFile.GetPlatform()) + switch(iso_file->GetPlatform()) { case GameListItem::WII_DISC: if (!SConfig::GetInstance().m_ListWii) @@ -578,7 +578,7 @@ void CGameListCtrl::ScanForISOs() break; } - switch (ISOFile.GetCountry()) + switch(iso_file->GetCountry()) { case DiscIO::IVolume::COUNTRY_TAIWAN: if (!SConfig::GetInstance().m_ListTaiwan) @@ -621,7 +621,7 @@ void CGameListCtrl::ScanForISOs() for (const auto& drive : drives) { - std::unique_ptr<GameListItem> gli(new GameListItem(drive)); + auto gli = std::make_unique<GameListItem>(drive); if (gli->IsValid()) m_ISOFiles.push_back(gli.release()); |
