- atempt to cleanup use fo auto_ptr

This commit is contained in:
SoftCoder 2016-01-18 13:20:49 -08:00
parent d82aaa22ad
commit 86a59859b9
16 changed files with 76 additions and 50 deletions

View File

@ -25,14 +25,12 @@
#include "game_constants.h"
#include <wx/stdpaths.h>
#include <platform_util.h>
//#include "interpolation.h"
#include "common_scoped_ptr.h"
#ifndef WIN32
#include <errno.h>
#endif
//#include <wx/filename.h>
#ifndef WIN32
#define stricmp strcasecmp
#define strnicmp strncasecmp
@ -452,7 +450,7 @@ MainWindow::MainWindow( std::pair<string,vector<string> > 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<wchar_t> wstr(Ansi2WideString(appPath.c_str()));
unique_ptr<wchar_t> 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<wchar_t> wstr(Ansi2WideString(file.c_str()));
unique_ptr<wchar_t> 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<wchar_t> wstr(Ansi2WideString(file.c_str()));
unique_ptr<wchar_t> 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<wchar_t> wstr(Ansi2WideString(file.c_str()));
unique_ptr<wchar_t> 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<wchar_t> wstr(Ansi2WideString(file.c_str()));
unique_ptr<wchar_t> 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<wchar_t> wstr(Ansi2WideString(autoScreenShotParams[i].c_str()));
unique_ptr<wchar_t> 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<wchar_t> wstr(Ansi2WideString(unitToLoad.first.c_str()));
unique_ptr<wchar_t> 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<wchar_t> wstr(Ansi2WideString(value.c_str()));
unique_ptr<wchar_t> 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<wchar_t> wstr(Ansi2WideString(modelPath.c_str()));
unique_ptr<wchar_t> 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<wchar_t> wstr(Ansi2WideString(particlePath.c_str()));
unique_ptr<wchar_t> 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<wchar_t> wstr(Ansi2WideString(projectileParticlePath.c_str()));
unique_ptr<wchar_t> 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<wchar_t> wstr(Ansi2WideString(splashParticlePath.c_str()));
unique_ptr<wchar_t> 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<wchar_t> wstr(Ansi2WideString(modelPath.c_str()));
unique_ptr<wchar_t> 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<wchar_t> wstr(Ansi2WideString(appPath.c_str()));
unique_ptr<wchar_t> wstr(Ansi2WideString(appPath.c_str()));
appPath = utf8_encode(wstr.get());
#else
string appPath(wxFNCONV(exe_path));

View File

@ -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<google_breakpad::ExceptionHandler> errorHandlerPtr;
unique_ptr<google_breakpad::ExceptionHandler> errorHandlerPtr;
#endif
class NavtiveLanguageNameListCacheGenerator : public SimpleTaskCallbackInterface {
@ -5554,8 +5555,8 @@ int glestMain(int argc, char** argv) {
preCacheThread->start();
}
std::auto_ptr<NavtiveLanguageNameListCacheGenerator> lngCacheGen;
std::auto_ptr<SimpleTaskThread> languageCacheGen;
unique_ptr<NavtiveLanguageNameListCacheGenerator> lngCacheGen;
unique_ptr<SimpleTaskThread> languageCacheGen;
bool startNativeLanguageNamesPrecacheThread = config.getBool("PreCacheNativeLanguageNamesThread","true");
if(startNativeLanguageNamesPrecacheThread == true &&

View File

@ -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> techTree;
unique_ptr<TechTree> techTree;
GameSettings originalGamesettings;
bool validOriginalGameSettings;

View File

@ -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> techTree;
unique_ptr<TechTree> techTree;
string gameUUID;

View File

@ -22,6 +22,7 @@
#include <algorithm>
#include <cassert>
#include <stdexcept>
#include "common_scoped_ptr.h"
#include "leak_dumper.h"
@ -34,7 +35,7 @@ namespace Glest{ namespace Game{
bool NetworkMessage::useOldProtocol = true;
auto_ptr<Mutex> NetworkMessage::mutexMessageStats(new Mutex(CODE_AT_LINE));
unique_ptr<Mutex> NetworkMessage::mutexMessageStats(new Mutex(CODE_AT_LINE));
Chrono NetworkMessage::statsTimer;
Chrono NetworkMessage::lastSend;
Chrono NetworkMessage::lastRecv;

View File

@ -17,7 +17,7 @@
#include "network_types.h"
#include "byte_order.h"
#include <map>
#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<Mutex> mutexMessageStats;
static unique_ptr<Mutex> mutexMessageStats;
static Chrono statsTimer;
static Chrono lastSend;
static Chrono lastRecv;

View File

@ -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<string> &pathTechList) {
bool techFound = false;
std::auto_ptr<TechTree> techTree(new TechTree(pathTechList));
unique_ptr<TechTree> techTree(new TechTree(pathTechList));
string path = techTree->findPath(techName);
if(path != "") {
techFound = true;

View File

@ -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<CommandType> UnitType::ctHarvestEmergencyReturnCommandType(new HarvestEmergencyReturnCommandType());
unique_ptr<CommandType> UnitType::ctHarvestEmergencyReturnCommandType(new HarvestEmergencyReturnCommandType());
// ===============================
// class Level
// ===============================

View File

@ -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<CommandType> ctHarvestEmergencyReturnCommandType;
static unique_ptr<CommandType> ctHarvestEmergencyReturnCommandType;
public:
//creation and loading

View File

@ -21,6 +21,7 @@
#ifndef WIN32
#include <errno.h>
#endif
#include "common_scoped_ptr.h"
#include <memory>
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<wchar_t> wstr(Ansi2WideString(currentFile.c_str()));
unique_ptr<wchar_t> 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<wchar_t> wstr(Ansi2WideString(currentFile.c_str()));
unique_ptr<wchar_t> 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<wchar_t> wstr(Ansi2WideString(fileparam.c_str()));
unique_ptr<wchar_t> 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<wchar_t> wstr(Ansi2WideString(appPath.c_str()));
unique_ptr<wchar_t> wstr(Ansi2WideString(appPath.c_str()));
appPath = utf8_encode(wstr.get());
#else
appPath = wxFNCONV(exe_path);

View File

@ -663,20 +663,12 @@ void Program::loadMap(const string &path) {
redoStack.clear();
std::string encodedPath = path;
//#ifdef WIN32
// std::auto_ptr<wchar_t> 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<wchar_t> wstr(Ansi2WideString(path.c_str()));
// encodedPath = utf8_encode(wstr.get());
//#endif
map->saveToFile(encodedPath);
}

View File

@ -20,6 +20,7 @@
#include "texture.h"
#include "model_header.h"
#include <memory>
#include "common_scoped_ptr.h"
#include "byte_order.h"
#include "leak_dumper.h"
@ -314,7 +315,7 @@ private:
static vector<vector<unsigned char> > nextColorIDReuseList;
static auto_ptr<PixelBufferWrapper> pbo;
static unique_ptr<PixelBufferWrapper> pbo;
void assign_color();

View File

@ -0,0 +1,27 @@
// ==============================================================
// This file is part of Glest Shared Library (www.glest.org)
//
// Copyright (C) 2005 Matthias Braun <matze@braunis.de>
//
// 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 <memory>
// =====================================================
// class Thread
// =====================================================
using namespace std;
#if !defined(HAVE_CXX11) && !defined(__GXX_EXPERIMENTAL_CXX0X__)
#define unique_ptr auto_ptr
#endif
#endif

View File

@ -19,6 +19,7 @@
#include <SDL_mutex.h>
#include <string>
#include <memory>
#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<Mutex> mutexthreadAccessor;
//std::unique_ptr<Mutex> mutexthreadAccessor;
Mutex *mutexthreadAccessor;
ThreadState currentState;
bool threadObjectValid();
@ -128,7 +129,7 @@ private:
Shared::PlatformCommon::Chrono *chronoPerf;
bool isStaticMutexListMutex;
static auto_ptr<Mutex> mutexMutexList;
static unique_ptr<Mutex> mutexMutexList;
static vector<Mutex *> mutexList;
public:

View File

@ -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<PixelBufferWrapper> BaseColorPickEntity::pbo;
unique_ptr<PixelBufferWrapper> BaseColorPickEntity::pbo;
map<string,bool> BaseColorPickEntity::usedColorIDList;
bool BaseColorPickEntity::trackColorUse = true;
@ -2128,7 +2128,7 @@ vector<int> 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<Pixmap2D> cachedPixels;
static unique_ptr<Pixmap2D> cachedPixels;
if(rendererModels.empty() == false) {
if(PixelBufferWrapper::getIsPBOEnable() == true) {

View File

@ -18,7 +18,6 @@
#include "platform_common.h"
#include "base_thread.h"
#include "time.h"
#include <memory>
using namespace std;
@ -28,15 +27,15 @@ bool Thread::enableVerboseMode = false;
Mutex Thread::mutexthreadList;
vector<Thread *> Thread::threadList;
auto_ptr<Mutex> Mutex::mutexMutexList(new Mutex(CODE_AT_LINE));
unique_ptr<Mutex> Mutex::mutexMutexList(new Mutex(CODE_AT_LINE));
vector<Mutex *> Mutex::mutexList;
class ThreadGarbageCollector;
class Mutex;
class MutexSafeWrapper;
static auto_ptr<ThreadGarbageCollector> cleanupThread;
static auto_ptr<Mutex> cleanupThreadMutex(new Mutex(CODE_AT_LINE));
static unique_ptr<ThreadGarbageCollector> cleanupThread;
static unique_ptr<Mutex> 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<Chrono> chronoLockPerf;
// std::unique_ptr<Chrono> chronoLockPerf;
// if(debugMutexLock == true) {
// chronoLockPerf.reset(new Chrono());
// chronoLockPerf->start();