mirror of
https://github.com/OPM/ResInsight.git
synced 2026-08-03 01:59:40 -05:00
Removal of new/delete from RiaApplication
This commit is contained in:
@@ -178,9 +178,6 @@ RiaApplication::RiaApplication()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaApplication::~RiaApplication()
|
||||
{
|
||||
delete m_preferences;
|
||||
delete m_project;
|
||||
|
||||
RiaFontCache::clear();
|
||||
}
|
||||
|
||||
@@ -323,7 +320,7 @@ int RiaApplication::currentScriptCaseId() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimProject* RiaApplication::project()
|
||||
{
|
||||
return m_project;
|
||||
return m_project.get();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -373,7 +370,7 @@ bool RiaApplication::openFile( const QString& fileName )
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaApplication::isProjectSavedToDisc() const
|
||||
{
|
||||
if ( m_project.isNull() ) return false;
|
||||
if ( !m_project ) return false;
|
||||
|
||||
return caf::Utils::fileExists( m_project->fileName() );
|
||||
}
|
||||
@@ -455,7 +452,7 @@ bool RiaApplication::loadProject( const QString& projectFileName,
|
||||
// Apply any modifications to the loaded project before we go ahead and load actual data
|
||||
if ( projectModifier )
|
||||
{
|
||||
projectModifier->applyModificationsToProject( m_project );
|
||||
projectModifier->applyModificationsToProject( m_project.get() );
|
||||
}
|
||||
|
||||
// Propagate possible new location of project
|
||||
@@ -474,8 +471,7 @@ bool RiaApplication::loadProject( const QString& projectFileName,
|
||||
onProjectOpeningError( errMsg );
|
||||
|
||||
// Delete all object possibly generated by readFile()
|
||||
delete m_project;
|
||||
m_project = new RimProject;
|
||||
m_project = std::make_unique<RimProject>();
|
||||
|
||||
onProjectOpened();
|
||||
|
||||
@@ -522,7 +518,7 @@ bool RiaApplication::loadProject( const QString& projectFileName,
|
||||
if ( oilField == nullptr ) continue;
|
||||
if ( oilField->wellPathCollection == nullptr )
|
||||
{
|
||||
oilField->wellPathCollection = new RimWellPathCollection();
|
||||
oilField->wellPathCollection = std::make_unique<RimWellPathCollection>();
|
||||
}
|
||||
|
||||
oilField->wellPathCollection->loadDataAndUpdate();
|
||||
@@ -541,13 +537,13 @@ bool RiaApplication::loadProject( const QString& projectFileName,
|
||||
// Temporary
|
||||
if ( !oilField->summaryCaseMainCollection() )
|
||||
{
|
||||
oilField->summaryCaseMainCollection = new RimSummaryCaseMainCollection();
|
||||
oilField->summaryCaseMainCollection = std::make_unique<RimSummaryCaseMainCollection>();
|
||||
}
|
||||
oilField->summaryCaseMainCollection()->loadAllSummaryCaseData();
|
||||
|
||||
if ( !oilField->observedDataCollection() )
|
||||
{
|
||||
oilField->observedDataCollection = new RimObservedDataCollection();
|
||||
oilField->observedDataCollection = std::make_unique<RimObservedDataCollection>();
|
||||
}
|
||||
for ( RimObservedSummaryData* observedData : oilField->observedDataCollection()->allObservedSummaryData() )
|
||||
{
|
||||
@@ -720,7 +716,7 @@ bool RiaApplication::loadProject( const QString& projectFileName )
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaApplication::saveProject( gsl::not_null<QString*> errorMessage )
|
||||
{
|
||||
CAF_ASSERT( m_project.notNull() );
|
||||
CAF_ASSERT( m_project );
|
||||
|
||||
if ( !isProjectSavedToDisc() )
|
||||
{
|
||||
@@ -738,7 +734,7 @@ bool RiaApplication::saveProject( gsl::not_null<QString*> errorMessage )
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaApplication::saveProjectAs( const QString& fileName, gsl::not_null<QString*> errorMessage )
|
||||
{
|
||||
CAF_ASSERT( m_project.notNull() );
|
||||
CAF_ASSERT( m_project );
|
||||
// Make sure we always store path with forward slash to avoid issues when opening the project file on Linux
|
||||
m_project->fileName = RiaFilePathTools::toInternalSeparator( fileName );
|
||||
|
||||
@@ -850,15 +846,16 @@ bool RiaApplication::openOdbCaseFromFile( const QString& fileName, bool applyTim
|
||||
QFileInfo gridFileName( fileName );
|
||||
QString caseName = gridFileName.completeBaseName();
|
||||
|
||||
RimGeoMechModels* geoMechModelCollection = m_project->activeOilField() ? m_project->activeOilField()->geoMechModels()
|
||||
: nullptr;
|
||||
if ( !m_project->activeOilField() ) return false;
|
||||
|
||||
// Create the geoMech model container if it is not there already
|
||||
if ( geoMechModelCollection == nullptr )
|
||||
if ( !m_project->activeOilField()->geoMechModels )
|
||||
{
|
||||
geoMechModelCollection = new RimGeoMechModels();
|
||||
m_project->activeOilField()->geoMechModels = geoMechModelCollection;
|
||||
m_project->activeOilField()->geoMechModels = std::make_unique<RimGeoMechModels>();
|
||||
}
|
||||
|
||||
gsl::not_null<RimGeoMechModels*> geoMechModelCollection = m_project->activeOilField()->geoMechModels();
|
||||
|
||||
// Check if the file is already open, the odb reader does not support opening the same file twice very well
|
||||
for ( auto gmcase : geoMechModelCollection->cases() )
|
||||
{
|
||||
@@ -869,11 +866,11 @@ bool RiaApplication::openOdbCaseFromFile( const QString& fileName, bool applyTim
|
||||
}
|
||||
}
|
||||
|
||||
RimGeoMechCase* geoMechCase = new RimGeoMechCase();
|
||||
auto geoMechCase = std::make_unique<RimGeoMechCase>();
|
||||
geoMechCase->setGridFileName( fileName );
|
||||
geoMechCase->caseUserDescription = caseName;
|
||||
geoMechCase->setApplyTimeFilter( applyTimeStepFilter );
|
||||
m_project->assignCaseIdToCase( geoMechCase );
|
||||
m_project->assignCaseIdToCase( geoMechCase.get() );
|
||||
|
||||
RimGeoMechView* riv = geoMechCase->createAndAddReservoirView();
|
||||
caf::ProgressInfo progress( 11, "Loading Case" );
|
||||
@@ -883,10 +880,9 @@ bool RiaApplication::openOdbCaseFromFile( const QString& fileName, bool applyTim
|
||||
|
||||
if ( !riv->geoMechCase() )
|
||||
{
|
||||
delete geoMechCase;
|
||||
return false;
|
||||
}
|
||||
geoMechModelCollection->addCase( geoMechCase );
|
||||
geoMechModelCollection->addCase( geoMechCase.release() );
|
||||
|
||||
progress.incrementProgress();
|
||||
progress.setProgressDescription( "Loading results information" );
|
||||
@@ -912,7 +908,7 @@ std::vector<RimWellPath*> RiaApplication::addWellPathsToModel( QList<QString>
|
||||
if ( oilField->wellPathCollection == nullptr )
|
||||
{
|
||||
// printf("Create well path collection.\n");
|
||||
oilField->wellPathCollection = new RimWellPathCollection();
|
||||
oilField->wellPathCollection = std::make_unique<RimWellPathCollection>();
|
||||
|
||||
m_project->updateConnectedEditors();
|
||||
}
|
||||
@@ -940,7 +936,7 @@ void RiaApplication::addWellPathFormationsToModel( QList<QString> wellPathFormat
|
||||
|
||||
if ( oilField->wellPathCollection == nullptr )
|
||||
{
|
||||
oilField->wellPathCollection = new RimWellPathCollection();
|
||||
oilField->wellPathCollection = std::make_unique<RimWellPathCollection>();
|
||||
|
||||
m_project->updateConnectedEditors();
|
||||
}
|
||||
@@ -964,9 +960,9 @@ std::vector<RimWellLogFile*> RiaApplication::addWellLogsToModel( const QList<QSt
|
||||
RimOilField* oilField = m_project->activeOilField();
|
||||
if ( oilField == nullptr ) return {};
|
||||
|
||||
if ( oilField->wellPathCollection == nullptr )
|
||||
if ( !oilField->wellPathCollection )
|
||||
{
|
||||
oilField->wellPathCollection = new RimWellPathCollection();
|
||||
oilField->wellPathCollection = std::make_unique<RimWellPathCollection>();
|
||||
|
||||
m_project->updateConnectedEditors();
|
||||
}
|
||||
@@ -1125,15 +1121,15 @@ bool RiaApplication::launchProcess( const QString& program,
|
||||
}
|
||||
|
||||
m_runningWorkerProcess = true;
|
||||
m_workerProcess = new caf::UiProcess( QCoreApplication::instance() );
|
||||
m_workerProcess = std::make_unique<caf::UiProcess>( QCoreApplication::instance() );
|
||||
|
||||
m_workerProcess->setProcessEnvironment( processEnvironment );
|
||||
|
||||
QCoreApplication::instance()->connect( m_workerProcess,
|
||||
QCoreApplication::instance()->connect( m_workerProcess.get(),
|
||||
SIGNAL( finished( int, QProcess::ExitStatus ) ),
|
||||
SLOT( slotWorkerProcessFinished( int, QProcess::ExitStatus ) ) );
|
||||
|
||||
startMonitoringWorkProgress( m_workerProcess );
|
||||
startMonitoringWorkProgress( m_workerProcess.get() );
|
||||
|
||||
m_workerProcess->start( program, arguments );
|
||||
|
||||
@@ -1211,7 +1207,7 @@ void RiaApplication::waitForProcess() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaPreferences* RiaApplication::preferences()
|
||||
{
|
||||
return m_preferences;
|
||||
return m_preferences.get();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -1531,7 +1527,7 @@ bool RiaApplication::initializeGrpcServer( const cvf::ProgramOptions& progOpt )
|
||||
{
|
||||
portNumber = RiaGrpcServer::findAvailablePortNumber( defaultPortNumber );
|
||||
}
|
||||
m_grpcServer.reset( new RiaGrpcServer( portNumber ) );
|
||||
m_grpcServer = std::make_unique<RiaGrpcServer>( portNumber );
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
@@ -1543,13 +1539,13 @@ bool RiaApplication::initializeGrpcServer( const cvf::ProgramOptions& progOpt )
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaApplication::initialize()
|
||||
{
|
||||
m_preferences = new RiaPreferences;
|
||||
caf::PdmSettings::readFieldsFromApplicationStore( m_preferences );
|
||||
m_preferences = std::make_unique<RiaPreferences>();
|
||||
caf::PdmSettings::readFieldsFromApplicationStore( m_preferences.get() );
|
||||
m_preferences->initAfterReadRecursively();
|
||||
applyPreferences();
|
||||
|
||||
// Start with a project
|
||||
m_project = new RimProject;
|
||||
m_project = std::make_unique<RimProject>();
|
||||
m_project->setScriptDirectories( m_preferences->scriptDirectories() );
|
||||
m_project->setPlotTemplateFolders( m_preferences->plotTemplateFolders() );
|
||||
}
|
||||
@@ -1767,17 +1763,8 @@ void RiaApplication::loadAndUpdatePlotData()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaApplication::resetProject()
|
||||
{
|
||||
if ( m_project.notNull() )
|
||||
{
|
||||
delete m_project.p();
|
||||
m_project = nullptr;
|
||||
}
|
||||
|
||||
if ( m_preferences )
|
||||
{
|
||||
delete m_preferences;
|
||||
m_preferences = nullptr;
|
||||
}
|
||||
m_project.reset();
|
||||
m_preferences.reset();
|
||||
|
||||
initialize();
|
||||
}
|
||||
|
||||
@@ -30,8 +30,8 @@
|
||||
#include "cvfFont.h"
|
||||
#include "cvfObject.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QMutex>
|
||||
#include <QPointer>
|
||||
#include <QProcess>
|
||||
#include <QProcessEnvironment>
|
||||
#include <QString>
|
||||
@@ -241,21 +241,21 @@ protected:
|
||||
cvf::ref<cvf::Font> m_defaultWellLabelFont;
|
||||
|
||||
caf::PdmPointer<Rim3dView> m_activeReservoirView;
|
||||
caf::PdmPointer<RimProject> m_project;
|
||||
std::unique_ptr<RimProject> m_project;
|
||||
|
||||
RiaSocketServer* m_socketServer;
|
||||
caf::UiProcess* m_workerProcess;
|
||||
QPointer<RiaSocketServer> m_socketServer;
|
||||
std::unique_ptr<caf::UiProcess> m_workerProcess;
|
||||
|
||||
#ifdef ENABLE_GRPC
|
||||
std::unique_ptr<RiaGrpcServer> m_grpcServer;
|
||||
#endif
|
||||
|
||||
// Execute for all settings
|
||||
std::list<int> m_scriptCaseIds;
|
||||
int m_currentScriptCaseId;
|
||||
QString m_currentProgram;
|
||||
QStringList m_currentArguments;
|
||||
RiaPreferences* m_preferences;
|
||||
std::list<int> m_scriptCaseIds;
|
||||
int m_currentScriptCaseId;
|
||||
QString m_currentProgram;
|
||||
QStringList m_currentArguments;
|
||||
std::unique_ptr<RiaPreferences> m_preferences;
|
||||
|
||||
std::map<QString, QString> m_fileDialogDefaultDirectories;
|
||||
QString m_startupDefaultDirectory;
|
||||
|
||||
@@ -59,7 +59,6 @@ RiaConsoleApplication::RiaConsoleApplication( int& argc, char** argv )
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaConsoleApplication::~RiaConsoleApplication()
|
||||
{
|
||||
RiaLogging::deleteLoggerInstance();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -103,7 +102,7 @@ void RiaConsoleApplication::initialize()
|
||||
|
||||
RiaApplication::initialize();
|
||||
|
||||
RiaLogging::setLoggerInstance( new RiaStdOutLogger );
|
||||
RiaLogging::setLoggerInstance( std::make_unique<RiaStdOutLogger>() );
|
||||
RiaLogging::loggerInstance()->setLevel( int( RILogLevel::RI_LL_DEBUG ) );
|
||||
|
||||
m_socketServer = new RiaSocketServer( this );
|
||||
|
||||
@@ -189,7 +189,7 @@ RiaGuiApplication::RiaGuiApplication( int& argc, char** argv )
|
||||
{
|
||||
setWindowIcon( QIcon( ":/AppLogo48x48.png" ) );
|
||||
|
||||
m_recentFileActionProvider = std::unique_ptr<RiuRecentFileActionProvider>( new RiuRecentFileActionProvider );
|
||||
m_recentFileActionProvider = std::make_unique<RiuRecentFileActionProvider>();
|
||||
|
||||
connect( this, SIGNAL( aboutToQuit() ), this, SLOT( onProgramExit() ) );
|
||||
}
|
||||
@@ -201,8 +201,6 @@ RiaGuiApplication::~RiaGuiApplication()
|
||||
{
|
||||
deleteMainPlotWindow();
|
||||
deleteMainWindow();
|
||||
|
||||
RiaLogging::deleteLoggerInstance();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -210,7 +208,7 @@ RiaGuiApplication::~RiaGuiApplication()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaGuiApplication::saveProject()
|
||||
{
|
||||
CVF_ASSERT( m_project.notNull() );
|
||||
CVF_ASSERT( m_project );
|
||||
|
||||
QString fileName;
|
||||
if ( !isProjectSavedToDisc() )
|
||||
@@ -429,10 +427,10 @@ void RiaGuiApplication::initialize()
|
||||
RiuGuiTheme::updateGuiTheme( m_preferences->guiTheme() );
|
||||
|
||||
{
|
||||
auto logger = new RiuMessagePanelLogger;
|
||||
auto logger = std::make_unique<RiuMessagePanelLogger>();
|
||||
logger->addMessagePanel( m_mainWindow->messagePanel() );
|
||||
logger->addMessagePanel( m_mainPlotWindow->messagePanel() );
|
||||
RiaLogging::setLoggerInstance( logger );
|
||||
RiaLogging::setLoggerInstance( std::move( logger ) );
|
||||
RiaLogging::loggerInstance()->setLevel( int( RILogLevel::RI_LL_DEBUG ) );
|
||||
}
|
||||
m_socketServer = new RiaSocketServer( this );
|
||||
@@ -498,10 +496,10 @@ RiaApplication::ApplicationStatus RiaGuiApplication::handleArguments( gsl::not_n
|
||||
// Use a logger writing to stdout instead of message panel
|
||||
// This is useful when executing regression tests on a build server, and this is the reason for creating the
|
||||
// logger when parsing the command line options
|
||||
auto stdLogger = new RiaStdOutLogger;
|
||||
auto stdLogger = std::make_unique<RiaStdOutLogger>();
|
||||
stdLogger->setLevel( int( RILogLevel::RI_LL_DEBUG ) );
|
||||
|
||||
RiaLogging::setLoggerInstance( stdLogger );
|
||||
RiaLogging::setLoggerInstance( std::move( stdLogger ) );
|
||||
|
||||
RiaRegressionTestRunner::instance()->executeRegressionTests( regressionTestPath, QStringList() );
|
||||
return ApplicationStatus::EXIT_COMPLETED;
|
||||
@@ -627,7 +625,7 @@ RiaApplication::ApplicationStatus RiaGuiApplication::handleArguments( gsl::not_n
|
||||
|
||||
if ( cvf::Option o = progOpt->option( "replaceSourceCases" ) )
|
||||
{
|
||||
if ( projectModifier.isNull() ) projectModifier = new RiaProjectModifier;
|
||||
if ( projectModifier.isNull() ) projectModifier = cvf::make_ref<RiaProjectModifier>();
|
||||
|
||||
if ( o.valueCount() == 1 )
|
||||
{
|
||||
@@ -658,7 +656,7 @@ RiaApplication::ApplicationStatus RiaGuiApplication::handleArguments( gsl::not_n
|
||||
|
||||
if ( cvf::Option o = progOpt->option( "replacePropertiesFolder" ) )
|
||||
{
|
||||
if ( projectModifier.isNull() ) projectModifier = new RiaProjectModifier;
|
||||
if ( projectModifier.isNull() ) projectModifier = cvf::make_ref<RiaProjectModifier>();
|
||||
|
||||
if ( o.valueCount() == 1 )
|
||||
{
|
||||
@@ -1266,7 +1264,7 @@ void RiaGuiApplication::onFileSuccessfullyLoaded( const QString& fileName, RiaDe
|
||||
void RiaGuiApplication::onProjectBeingOpened()
|
||||
{
|
||||
// When importing a project, do not maximize the first MDI window to be created
|
||||
m_maximizeWindowGuard.reset( new RiuMdiMaximizeWindowGuard );
|
||||
m_maximizeWindowGuard = std::make_unique<RiuMdiMaximizeWindowGuard>();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -1614,7 +1612,7 @@ void RiaGuiApplication::updateGrpcServer()
|
||||
else if ( !isGrpcRunning && shouldItBeRunning )
|
||||
{
|
||||
int portNumber = RiaGrpcServer::findAvailablePortNumber( m_preferences->defaultGrpcPortNumber() );
|
||||
m_grpcServer.reset( new RiaGrpcServer( portNumber ) );
|
||||
m_grpcServer = std::make_unique<RiaGrpcServer>( portNumber );
|
||||
m_grpcServer->runInThread();
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -169,37 +169,22 @@ void RiaDefaultConsoleLogger::writeToConsole( const std::string& str )
|
||||
//
|
||||
//==================================================================================================
|
||||
|
||||
RiaLogger* RiaLogging::sm_logger = new RiaDefaultConsoleLogger;
|
||||
std::unique_ptr<RiaLogger> RiaLogging::sm_logger = std::make_unique<RiaDefaultConsoleLogger>();
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaLogger* RiaLogging::loggerInstance()
|
||||
{
|
||||
return sm_logger;
|
||||
return sm_logger.get();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaLogging::setLoggerInstance( RiaLogger* loggerInstance )
|
||||
void RiaLogging::setLoggerInstance( std::unique_ptr<RiaLogger> loggerInstance )
|
||||
{
|
||||
// Only delete if we're currently using our own default impl
|
||||
if ( dynamic_cast<RiaDefaultConsoleLogger*>( sm_logger ) )
|
||||
{
|
||||
delete sm_logger;
|
||||
}
|
||||
|
||||
sm_logger = loggerInstance;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaLogging::deleteLoggerInstance()
|
||||
{
|
||||
delete sm_logger;
|
||||
sm_logger = nullptr;
|
||||
sm_logger = std::move( loggerInstance );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
class QString;
|
||||
@@ -59,8 +60,7 @@ class RiaLogging
|
||||
{
|
||||
public:
|
||||
static RiaLogger* loggerInstance();
|
||||
static void setLoggerInstance( RiaLogger* loggerInstance );
|
||||
static void deleteLoggerInstance();
|
||||
static void setLoggerInstance( std::unique_ptr<RiaLogger> loggerInstance );
|
||||
|
||||
static void error( const QString& message );
|
||||
static void warning( const QString& message );
|
||||
@@ -70,7 +70,7 @@ public:
|
||||
static void errorInMessageBox( QWidget* parent, const QString& title, const QString& text );
|
||||
|
||||
private:
|
||||
static RiaLogger* sm_logger;
|
||||
static std::unique_ptr<RiaLogger> sm_logger;
|
||||
};
|
||||
|
||||
//==================================================================================================
|
||||
|
||||
Reference in New Issue
Block a user