From 86a59859b9ce2d15f4aee1b5d734a362a8372297 Mon Sep 17 00:00:00 2001 From: SoftCoder Date: Mon, 18 Jan 2016 13:20:49 -0800 Subject: [PATCH] - atempt to cleanup use fo auto_ptr --- source/g3d_viewer/main.cpp | 32 +++++++++---------- source/glest_game/main/main.cpp | 7 ++-- .../menu/menu_state_connected_game.h | 3 +- .../glest_game/menu/menu_state_custom_game.h | 3 +- source/glest_game/network/network_message.cpp | 3 +- source/glest_game/network/network_message.h | 4 +-- source/glest_game/types/tech_tree.cpp | 3 +- source/glest_game/types/unit_type.cpp | 3 +- source/glest_game/types/unit_type.h | 3 +- source/glest_map_editor/main.cpp | 9 +++--- source/glest_map_editor/program.cpp | 8 ----- source/shared_lib/include/graphics/model.h | 3 +- .../platform/common/common_scoped_ptr.h | 27 ++++++++++++++++ .../shared_lib/include/platform/sdl/thread.h | 5 +-- source/shared_lib/sources/graphics/model.cpp | 4 +-- .../sources/platform/sdl/thread.cpp | 9 +++--- 16 files changed, 76 insertions(+), 50 deletions(-) create mode 100644 source/shared_lib/include/platform/common/common_scoped_ptr.h diff --git a/source/g3d_viewer/main.cpp b/source/g3d_viewer/main.cpp index dd53fcc2..c4a56499 100644 --- a/source/g3d_viewer/main.cpp +++ b/source/g3d_viewer/main.cpp @@ -25,14 +25,12 @@ #include "game_constants.h" #include #include -//#include "interpolation.h" +#include "common_scoped_ptr.h" #ifndef WIN32 #include #endif -//#include - #ifndef WIN32 #define stricmp strcasecmp #define strnicmp strncasecmp @@ -452,7 +450,7 @@ MainWindow::MainWindow( std::pair > unitToLoad, DWORD dwDisposition; RegCreateKeyEx(HKEY_CURRENT_USER,subKey.c_str(),0, NULL, 0, KEY_ALL_ACCESS, NULL, &keyHandle, &dwDisposition); //Set the value. - std::auto_ptr wstr(Ansi2WideString(appPath.c_str())); + unique_ptr wstr(Ansi2WideString(appPath.c_str())); wstring launchApp = wstring(wstr.get()) + L" \"%1\""; DWORD len = (DWORD)launchApp.length() + 1; @@ -851,7 +849,7 @@ void MainWindow::onMenuFileLoad(wxCommandEvent &event){ const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(fileDialog->GetPath()); file = tmp_buf; - std::auto_ptr wstr(Ansi2WideString(file.c_str())); + unique_ptr wstr(Ansi2WideString(file.c_str())); file = utf8_encode(wstr.get()); #else file = (const char*)wxFNCONV(fileDialog->GetPath().c_str()); @@ -886,7 +884,7 @@ void MainWindow::onMenuFileLoadParticleXML(wxCommandEvent &event){ #ifdef WIN32 const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(fileDialog->GetPath()); file = tmp_buf; - std::auto_ptr wstr(Ansi2WideString(file.c_str())); + unique_ptr wstr(Ansi2WideString(file.c_str())); file = utf8_encode(wstr.get()); #else file = (const char*)wxFNCONV(fileDialog->GetPath().c_str()); @@ -920,7 +918,7 @@ void MainWindow::onMenuFileLoadProjectileParticleXML(wxCommandEvent &event){ #ifdef WIN32 const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(fileDialog->GetPath()); file = tmp_buf; - std::auto_ptr wstr(Ansi2WideString(file.c_str())); + unique_ptr wstr(Ansi2WideString(file.c_str())); file = utf8_encode(wstr.get()); #else file = (const char*)wxFNCONV(fileDialog->GetPath().c_str()); @@ -955,7 +953,7 @@ void MainWindow::onMenuFileLoadSplashParticleXML(wxCommandEvent &event){ const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(fileDialog->GetPath()); file = tmp_buf; - std::auto_ptr wstr(Ansi2WideString(file.c_str())); + unique_ptr wstr(Ansi2WideString(file.c_str())); file = utf8_encode(wstr.get()); #else file = (const char*)wxFNCONV(fileDialog->GetPath().c_str()); @@ -2160,7 +2158,7 @@ bool App::OnInit() { for(unsigned int i = 0; i < autoScreenShotParams.size(); ++i) { #ifdef WIN32 - std::auto_ptr wstr(Ansi2WideString(autoScreenShotParams[i].c_str())); + unique_ptr wstr(Ansi2WideString(autoScreenShotParams[i].c_str())); autoScreenShotParams[i] = utf8_encode(wstr.get()); #endif @@ -2205,14 +2203,14 @@ bool App::OnInit() { if(delimitedList.size() >= 2) { unitToLoad.first = delimitedList[0]; #ifdef WIN32 - std::auto_ptr wstr(Ansi2WideString(unitToLoad.first.c_str())); + unique_ptr wstr(Ansi2WideString(unitToLoad.first.c_str())); unitToLoad.first = utf8_encode(wstr.get()); #endif for(unsigned int i = 1; i < delimitedList.size(); ++i) { string value = delimitedList[i]; #ifdef WIN32 - std::auto_ptr wstr(Ansi2WideString(value.c_str())); + unique_ptr wstr(Ansi2WideString(value.c_str())); value = utf8_encode(wstr.get()); #endif @@ -2251,7 +2249,7 @@ bool App::OnInit() { string customPathValue = paramPartTokens[1]; modelPath = customPathValue; #ifdef WIN32 - std::auto_ptr wstr(Ansi2WideString(modelPath.c_str())); + unique_ptr wstr(Ansi2WideString(modelPath.c_str())); modelPath = utf8_encode(wstr.get()); #endif @@ -2281,7 +2279,7 @@ bool App::OnInit() { string customPathValue = paramPartTokens[1]; particlePath = customPathValue; #ifdef WIN32 - std::auto_ptr wstr(Ansi2WideString(particlePath.c_str())); + unique_ptr wstr(Ansi2WideString(particlePath.c_str())); particlePath = utf8_encode(wstr.get()); #endif } @@ -2309,7 +2307,7 @@ bool App::OnInit() { string customPathValue = paramPartTokens[1]; projectileParticlePath = customPathValue; #ifdef WIN32 - std::auto_ptr wstr(Ansi2WideString(projectileParticlePath.c_str())); + unique_ptr wstr(Ansi2WideString(projectileParticlePath.c_str())); projectileParticlePath = utf8_encode(wstr.get()); #endif } @@ -2337,7 +2335,7 @@ bool App::OnInit() { string customPathValue = paramPartTokens[1]; splashParticlePath = customPathValue; #ifdef WIN32 - std::auto_ptr wstr(Ansi2WideString(splashParticlePath.c_str())); + unique_ptr wstr(Ansi2WideString(splashParticlePath.c_str())); splashParticlePath = utf8_encode(wstr.get()); #endif } @@ -2496,7 +2494,7 @@ bool App::OnInit() { #ifdef WIN32 const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(wxFNCONV(argv[1])); modelPath = tmp_buf; - std::auto_ptr wstr(Ansi2WideString(modelPath.c_str())); + unique_ptr wstr(Ansi2WideString(modelPath.c_str())); modelPath = utf8_encode(wstr.get()); #else modelPath = wxFNCONV(argv[1]); @@ -2526,7 +2524,7 @@ bool App::OnInit() { const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(wxFNCONV(exe_path)); string appPath = tmp_buf; - std::auto_ptr wstr(Ansi2WideString(appPath.c_str())); + unique_ptr wstr(Ansi2WideString(appPath.c_str())); appPath = utf8_encode(wstr.get()); #else string appPath(wxFNCONV(exe_path)); diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index d95391d1..a2f16f90 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -55,6 +55,7 @@ #include "auto_test.h" #include "lua_script.h" #include "interpolation.h" +#include "common_scoped_ptr.h" // To handle signal catching #if defined(__GNUC__) && !defined(__MINGW32__) && !defined(__FreeBSD__) && !defined(BSD) @@ -128,7 +129,7 @@ static string runtimeErrorMsg = ""; #endif #ifdef HAVE_GOOGLE_BREAKPAD -std::auto_ptr errorHandlerPtr; +unique_ptr errorHandlerPtr; #endif class NavtiveLanguageNameListCacheGenerator : public SimpleTaskCallbackInterface { @@ -5554,8 +5555,8 @@ int glestMain(int argc, char** argv) { preCacheThread->start(); } - std::auto_ptr lngCacheGen; - std::auto_ptr languageCacheGen; + unique_ptr lngCacheGen; + unique_ptr languageCacheGen; bool startNativeLanguageNamesPrecacheThread = config.getBool("PreCacheNativeLanguageNamesThread","true"); if(startNativeLanguageNamesPrecacheThread == true && diff --git a/source/glest_game/menu/menu_state_connected_game.h b/source/glest_game/menu/menu_state_connected_game.h index a26f76e2..137d741d 100644 --- a/source/glest_game/menu/menu_state_connected_game.h +++ b/source/glest_game/menu/menu_state_connected_game.h @@ -21,6 +21,7 @@ #include "chat_manager.h" #include "map_preview.h" #include "miniftpclient.h" +#include "common_scoped_ptr.h" #include "leak_dumper.h" namespace Shared { namespace Graphics { @@ -242,7 +243,7 @@ private: bool launchingNewGame; bool isfirstSwitchingMapMessage; - std::auto_ptr techTree; + unique_ptr techTree; GameSettings originalGamesettings; bool validOriginalGameSettings; diff --git a/source/glest_game/menu/menu_state_custom_game.h b/source/glest_game/menu/menu_state_custom_game.h index bcc1ff2e..2668f552 100644 --- a/source/glest_game/menu/menu_state_custom_game.h +++ b/source/glest_game/menu/menu_state_custom_game.h @@ -16,6 +16,7 @@ #include "chat_manager.h" #include "simple_threads.h" #include "map_preview.h" +#include "common_scoped_ptr.h" #include "leak_dumper.h" using namespace Shared::Map; @@ -218,7 +219,7 @@ private: bool masterserverModeMinimalResources; int lastMasterServerSettingsUpdateCount; - std::auto_ptr techTree; + unique_ptr techTree; string gameUUID; diff --git a/source/glest_game/network/network_message.cpp b/source/glest_game/network/network_message.cpp index 8868548c..1637cf1b 100644 --- a/source/glest_game/network/network_message.cpp +++ b/source/glest_game/network/network_message.cpp @@ -22,6 +22,7 @@ #include #include #include +#include "common_scoped_ptr.h" #include "leak_dumper.h" @@ -34,7 +35,7 @@ namespace Glest{ namespace Game{ bool NetworkMessage::useOldProtocol = true; -auto_ptr NetworkMessage::mutexMessageStats(new Mutex(CODE_AT_LINE)); +unique_ptr NetworkMessage::mutexMessageStats(new Mutex(CODE_AT_LINE)); Chrono NetworkMessage::statsTimer; Chrono NetworkMessage::lastSend; Chrono NetworkMessage::lastRecv; diff --git a/source/glest_game/network/network_message.h b/source/glest_game/network/network_message.h index 6fd97c9a..e06976a8 100644 --- a/source/glest_game/network/network_message.h +++ b/source/glest_game/network/network_message.h @@ -17,7 +17,7 @@ #include "network_types.h" #include "byte_order.h" #include - +#include "common_scoped_ptr.h" #include "leak_dumper.h" using Shared::Platform::Socket; @@ -98,7 +98,7 @@ enum NetworkMessageStatisticType { class NetworkMessage { private: - static auto_ptr mutexMessageStats; + static unique_ptr mutexMessageStats; static Chrono statsTimer; static Chrono lastSend; static Chrono lastRecv; diff --git a/source/glest_game/types/tech_tree.cpp b/source/glest_game/types/tech_tree.cpp index cbd97a32..25a4f8c3 100644 --- a/source/glest_game/types/tech_tree.cpp +++ b/source/glest_game/types/tech_tree.cpp @@ -21,6 +21,7 @@ #include "platform_util.h" #include "game_util.h" #include "window.h" +#include "common_scoped_ptr.h" #include "leak_dumper.h" using namespace Shared::Util; @@ -176,7 +177,7 @@ Checksum TechTree::loadTech(const string &techName, bool TechTree::exists(const string &techName, const vector &pathTechList) { bool techFound = false; - std::auto_ptr techTree(new TechTree(pathTechList)); + unique_ptr techTree(new TechTree(pathTechList)); string path = techTree->findPath(techName); if(path != "") { techFound = true; diff --git a/source/glest_game/types/unit_type.cpp b/source/glest_game/types/unit_type.cpp index 9191eead..3a4ad222 100644 --- a/source/glest_game/types/unit_type.cpp +++ b/source/glest_game/types/unit_type.cpp @@ -28,6 +28,7 @@ #include "game_util.h" #include "unit_particle_type.h" #include "faction.h" +#include "common_scoped_ptr.h" #include "leak_dumper.h" using namespace Shared::Xml; @@ -36,7 +37,7 @@ using namespace Shared::Util; namespace Glest{ namespace Game{ -auto_ptr UnitType::ctHarvestEmergencyReturnCommandType(new HarvestEmergencyReturnCommandType()); +unique_ptr UnitType::ctHarvestEmergencyReturnCommandType(new HarvestEmergencyReturnCommandType()); // =============================== // class Level // =============================== diff --git a/source/glest_game/types/unit_type.h b/source/glest_game/types/unit_type.h index 564ed14b..e594ab18 100644 --- a/source/glest_game/types/unit_type.h +++ b/source/glest_game/types/unit_type.h @@ -24,6 +24,7 @@ #include "checksum.h" #include "game_constants.h" #include "platform_common.h" +#include "common_scoped_ptr.h" #include "leak_dumper.h" namespace Glest{ namespace Game{ @@ -233,7 +234,7 @@ private: UnitCountsInVictoryConditions countInVictoryConditions; - static auto_ptr ctHarvestEmergencyReturnCommandType; + static unique_ptr ctHarvestEmergencyReturnCommandType; public: //creation and loading diff --git a/source/glest_map_editor/main.cpp b/source/glest_map_editor/main.cpp index a046ebc0..9b31ffdf 100644 --- a/source/glest_map_editor/main.cpp +++ b/source/glest_map_editor/main.cpp @@ -21,6 +21,7 @@ #ifndef WIN32 #include #endif +#include "common_scoped_ptr.h" #include using namespace Shared::Util; @@ -689,7 +690,7 @@ void MainWindow::onMenuFileLoad(wxCommandEvent &event) { const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(wxFNCONV(fileDialog->GetPath())); currentFile = tmp_buf; - std::auto_ptr wstr(Ansi2WideString(currentFile.c_str())); + unique_ptr wstr(Ansi2WideString(currentFile.c_str())); currentFile = utf8_encode(wstr.get()); #else //currentFile = fileDialog->GetPath().ToAscii(); @@ -765,7 +766,7 @@ void MainWindow::onMenuFileSaveAs(wxCommandEvent &event) { const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(wxFNCONV(fd.GetPath())); currentFile = tmp_buf; - std::auto_ptr wstr(Ansi2WideString(currentFile.c_str())); + unique_ptr wstr(Ansi2WideString(currentFile.c_str())); currentFile = utf8_encode(wstr.get()); #else //currentFile = fd.GetPath().ToAscii(); @@ -1638,7 +1639,7 @@ bool App::OnInit() { fileparam = tmp_buf; #ifdef WIN32 - std::auto_ptr wstr(Ansi2WideString(fileparam.c_str())); + unique_ptr wstr(Ansi2WideString(fileparam.c_str())); fileparam = utf8_encode(wstr.get()); #endif @@ -1663,7 +1664,7 @@ bool App::OnInit() { const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(wxFNCONV(exe_path)); appPath = tmp_buf; - std::auto_ptr wstr(Ansi2WideString(appPath.c_str())); + unique_ptr wstr(Ansi2WideString(appPath.c_str())); appPath = utf8_encode(wstr.get()); #else appPath = wxFNCONV(exe_path); diff --git a/source/glest_map_editor/program.cpp b/source/glest_map_editor/program.cpp index aba2ec0a..8f08936b 100644 --- a/source/glest_map_editor/program.cpp +++ b/source/glest_map_editor/program.cpp @@ -663,20 +663,12 @@ void Program::loadMap(const string &path) { redoStack.clear(); std::string encodedPath = path; -//#ifdef WIN32 -// std::auto_ptr wstr(Ansi2WideString(path.c_str())); -// encodedPath = utf8_encode(wstr.get()); -//#endif map->loadFromFile(encodedPath); } void Program::saveMap(const string &path) { if(map) { std::string encodedPath = path; -//#ifdef WIN32 -// std::auto_ptr wstr(Ansi2WideString(path.c_str())); -// encodedPath = utf8_encode(wstr.get()); -//#endif map->saveToFile(encodedPath); } diff --git a/source/shared_lib/include/graphics/model.h b/source/shared_lib/include/graphics/model.h index d01e3dff..dc8bc480 100644 --- a/source/shared_lib/include/graphics/model.h +++ b/source/shared_lib/include/graphics/model.h @@ -20,6 +20,7 @@ #include "texture.h" #include "model_header.h" #include +#include "common_scoped_ptr.h" #include "byte_order.h" #include "leak_dumper.h" @@ -314,7 +315,7 @@ private: static vector > nextColorIDReuseList; - static auto_ptr pbo; + static unique_ptr pbo; void assign_color(); diff --git a/source/shared_lib/include/platform/common/common_scoped_ptr.h b/source/shared_lib/include/platform/common/common_scoped_ptr.h new file mode 100644 index 00000000..235ffeec --- /dev/null +++ b/source/shared_lib/include/platform/common/common_scoped_ptr.h @@ -0,0 +1,27 @@ +// ============================================================== +// This file is part of Glest Shared Library (www.glest.org) +// +// Copyright (C) 2005 Matthias Braun +// +// You can redistribute this code and/or modify it under +// the terms of the GNU General Public License as published +// by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version +// ============================================================== + +#ifndef _COMMON_SCOPED_PTR_H_ +#define _COMMON_SCOPED_PTR_H_ + +#include + + +// ===================================================== +// class Thread +// ===================================================== +using namespace std; + +#if !defined(HAVE_CXX11) && !defined(__GXX_EXPERIMENTAL_CXX0X__) + #define unique_ptr auto_ptr +#endif + +#endif diff --git a/source/shared_lib/include/platform/sdl/thread.h b/source/shared_lib/include/platform/sdl/thread.h index 7d0660c3..6f53c532 100644 --- a/source/shared_lib/include/platform/sdl/thread.h +++ b/source/shared_lib/include/platform/sdl/thread.h @@ -19,6 +19,7 @@ #include #include #include +#include "common_scoped_ptr.h" #include "data_types.h" #ifdef DEBUG_PERFORMANCE_MUTEXES @@ -69,7 +70,7 @@ public: private: SDL_Thread* thread; - //std::auto_ptr mutexthreadAccessor; + //std::unique_ptr mutexthreadAccessor; Mutex *mutexthreadAccessor; ThreadState currentState; bool threadObjectValid(); @@ -128,7 +129,7 @@ private: Shared::PlatformCommon::Chrono *chronoPerf; bool isStaticMutexListMutex; - static auto_ptr mutexMutexList; + static unique_ptr mutexMutexList; static vector mutexList; public: diff --git a/source/shared_lib/sources/graphics/model.cpp b/source/shared_lib/sources/graphics/model.cpp index 34741460..9e5d5717 100644 --- a/source/shared_lib/sources/graphics/model.cpp +++ b/source/shared_lib/sources/graphics/model.cpp @@ -1896,7 +1896,7 @@ const unsigned int BaseColorPickEntity::k = 43067; unsigned int BaseColorPickEntity::nextColorRGB = BaseColorPickEntity::k; unsigned char BaseColorPickEntity::nextColorID[COLOR_COMPONENTS] = { 1, 1, 1, 0 }; -auto_ptr BaseColorPickEntity::pbo; +unique_ptr BaseColorPickEntity::pbo; map BaseColorPickEntity::usedColorIDList; bool BaseColorPickEntity::trackColorUse = true; @@ -2128,7 +2128,7 @@ vector BaseColorPickEntity::getPickedList(int x,int y,int w,int h, pickedModels.reserve(rendererModels.size()); //printf("In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); - static auto_ptr cachedPixels; + static unique_ptr cachedPixels; if(rendererModels.empty() == false) { if(PixelBufferWrapper::getIsPBOEnable() == true) { diff --git a/source/shared_lib/sources/platform/sdl/thread.cpp b/source/shared_lib/sources/platform/sdl/thread.cpp index e8920e2b..e1caf260 100644 --- a/source/shared_lib/sources/platform/sdl/thread.cpp +++ b/source/shared_lib/sources/platform/sdl/thread.cpp @@ -18,7 +18,6 @@ #include "platform_common.h" #include "base_thread.h" #include "time.h" -#include using namespace std; @@ -28,15 +27,15 @@ bool Thread::enableVerboseMode = false; Mutex Thread::mutexthreadList; vector Thread::threadList; -auto_ptr Mutex::mutexMutexList(new Mutex(CODE_AT_LINE)); +unique_ptr Mutex::mutexMutexList(new Mutex(CODE_AT_LINE)); vector Mutex::mutexList; class ThreadGarbageCollector; class Mutex; class MutexSafeWrapper; -static auto_ptr cleanupThread; -static auto_ptr cleanupThreadMutex(new Mutex(CODE_AT_LINE)); +static unique_ptr cleanupThread; +static unique_ptr cleanupThreadMutex(new Mutex(CODE_AT_LINE)); class ThreadGarbageCollector : public BaseThread { @@ -547,7 +546,7 @@ inline void Mutex::p() { // snprintf(szBuf,8095,"In [%s::%s Line: %d] mutex == NULL refCount = %d owner [%s] deleteownerId [%s] stack: %s",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,refCount,ownerId.c_str(),deleteownerId.c_str(),stack.c_str()); // throw megaglest_runtime_error(szBuf); // } -// std::auto_ptr chronoLockPerf; +// std::unique_ptr chronoLockPerf; // if(debugMutexLock == true) { // chronoLockPerf.reset(new Chrono()); // chronoLockPerf->start();