diff --git a/ApplicationCode/Application/RiaApplication.cpp b/ApplicationCode/Application/RiaApplication.cpp index 8a3fbfb496..8b1cf734c4 100644 --- a/ApplicationCode/Application/RiaApplication.cpp +++ b/ApplicationCode/Application/RiaApplication.cpp @@ -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(); 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(); } 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(); } oilField->summaryCaseMainCollection()->loadAllSummaryCaseData(); if ( !oilField->observedDataCollection() ) { - oilField->observedDataCollection = new RimObservedDataCollection(); + oilField->observedDataCollection = std::make_unique(); } for ( RimObservedSummaryData* observedData : oilField->observedDataCollection()->allObservedSummaryData() ) { @@ -720,7 +716,7 @@ bool RiaApplication::loadProject( const QString& projectFileName ) //-------------------------------------------------------------------------------------------------- bool RiaApplication::saveProject( gsl::not_null errorMessage ) { - CAF_ASSERT( m_project.notNull() ); + CAF_ASSERT( m_project ); if ( !isProjectSavedToDisc() ) { @@ -738,7 +734,7 @@ bool RiaApplication::saveProject( gsl::not_null errorMessage ) //-------------------------------------------------------------------------------------------------- bool RiaApplication::saveProjectAs( const QString& fileName, gsl::not_null 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(); } + gsl::not_null 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(); 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 RiaApplication::addWellPathsToModel( QList if ( oilField->wellPathCollection == nullptr ) { // printf("Create well path collection.\n"); - oilField->wellPathCollection = new RimWellPathCollection(); + oilField->wellPathCollection = std::make_unique(); m_project->updateConnectedEditors(); } @@ -940,7 +936,7 @@ void RiaApplication::addWellPathFormationsToModel( QList wellPathFormat if ( oilField->wellPathCollection == nullptr ) { - oilField->wellPathCollection = new RimWellPathCollection(); + oilField->wellPathCollection = std::make_unique(); m_project->updateConnectedEditors(); } @@ -964,9 +960,9 @@ std::vector RiaApplication::addWellLogsToModel( const QListactiveOilField(); if ( oilField == nullptr ) return {}; - if ( oilField->wellPathCollection == nullptr ) + if ( !oilField->wellPathCollection ) { - oilField->wellPathCollection = new RimWellPathCollection(); + oilField->wellPathCollection = std::make_unique(); 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( 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( 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(); + caf::PdmSettings::readFieldsFromApplicationStore( m_preferences.get() ); m_preferences->initAfterReadRecursively(); applyPreferences(); // Start with a project - m_project = new RimProject; + m_project = std::make_unique(); 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(); } diff --git a/ApplicationCode/Application/RiaApplication.h b/ApplicationCode/Application/RiaApplication.h index d90a3e2193..aa45053efe 100644 --- a/ApplicationCode/Application/RiaApplication.h +++ b/ApplicationCode/Application/RiaApplication.h @@ -30,8 +30,8 @@ #include "cvfFont.h" #include "cvfObject.h" -#include #include +#include #include #include #include @@ -241,21 +241,21 @@ protected: cvf::ref m_defaultWellLabelFont; caf::PdmPointer m_activeReservoirView; - caf::PdmPointer m_project; + std::unique_ptr m_project; - RiaSocketServer* m_socketServer; - caf::UiProcess* m_workerProcess; + QPointer m_socketServer; + std::unique_ptr m_workerProcess; #ifdef ENABLE_GRPC std::unique_ptr m_grpcServer; #endif // Execute for all settings - std::list m_scriptCaseIds; - int m_currentScriptCaseId; - QString m_currentProgram; - QStringList m_currentArguments; - RiaPreferences* m_preferences; + std::list m_scriptCaseIds; + int m_currentScriptCaseId; + QString m_currentProgram; + QStringList m_currentArguments; + std::unique_ptr m_preferences; std::map m_fileDialogDefaultDirectories; QString m_startupDefaultDirectory; diff --git a/ApplicationCode/Application/RiaConsoleApplication.cpp b/ApplicationCode/Application/RiaConsoleApplication.cpp index ac4fa75ddc..37ca8d3c6e 100644 --- a/ApplicationCode/Application/RiaConsoleApplication.cpp +++ b/ApplicationCode/Application/RiaConsoleApplication.cpp @@ -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() ); RiaLogging::loggerInstance()->setLevel( int( RILogLevel::RI_LL_DEBUG ) ); m_socketServer = new RiaSocketServer( this ); diff --git a/ApplicationCode/Application/RiaGuiApplication.cpp b/ApplicationCode/Application/RiaGuiApplication.cpp index 52dc5682b7..397bd64a0b 100644 --- a/ApplicationCode/Application/RiaGuiApplication.cpp +++ b/ApplicationCode/Application/RiaGuiApplication.cpp @@ -189,7 +189,7 @@ RiaGuiApplication::RiaGuiApplication( int& argc, char** argv ) { setWindowIcon( QIcon( ":/AppLogo48x48.png" ) ); - m_recentFileActionProvider = std::unique_ptr( new RiuRecentFileActionProvider ); + m_recentFileActionProvider = std::make_unique(); 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(); 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(); 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(); 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(); 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(); } //-------------------------------------------------------------------------------------------------- @@ -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( portNumber ); m_grpcServer->runInThread(); } #endif diff --git a/ApplicationCode/Application/Tools/RiaLogging.cpp b/ApplicationCode/Application/Tools/RiaLogging.cpp index 25413e3084..c4196fbebb 100644 --- a/ApplicationCode/Application/Tools/RiaLogging.cpp +++ b/ApplicationCode/Application/Tools/RiaLogging.cpp @@ -169,37 +169,22 @@ void RiaDefaultConsoleLogger::writeToConsole( const std::string& str ) // //================================================================================================== -RiaLogger* RiaLogging::sm_logger = new RiaDefaultConsoleLogger; +std::unique_ptr RiaLogging::sm_logger = std::make_unique(); //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- RiaLogger* RiaLogging::loggerInstance() { - return sm_logger; + return sm_logger.get(); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RiaLogging::setLoggerInstance( RiaLogger* loggerInstance ) +void RiaLogging::setLoggerInstance( std::unique_ptr loggerInstance ) { - // Only delete if we're currently using our own default impl - if ( dynamic_cast( sm_logger ) ) - { - delete sm_logger; - } - - sm_logger = loggerInstance; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RiaLogging::deleteLoggerInstance() -{ - delete sm_logger; - sm_logger = nullptr; + sm_logger = std::move( loggerInstance ); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/Application/Tools/RiaLogging.h b/ApplicationCode/Application/Tools/RiaLogging.h index e1ef358075..bd94605bfa 100644 --- a/ApplicationCode/Application/Tools/RiaLogging.h +++ b/ApplicationCode/Application/Tools/RiaLogging.h @@ -18,6 +18,7 @@ #pragma once +#include #include 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 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 sm_logger; }; //================================================================================================== diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmChildArrayField.h b/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmChildArrayField.h index ed16a14306..999d252d9b 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmChildArrayField.h +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmChildArrayField.h @@ -6,6 +6,8 @@ #include "cafPdmFieldHandle.h" #include "cafPdmPointer.h" +#include + namespace caf { template @@ -47,7 +49,8 @@ public: template class PdmChildArrayField : public PdmChildArrayFieldHandle { - typedef DataType* DataTypePtr; + typedef DataType* DataTypePtr; + typedef std::unique_ptr DataTypeUniquePtr; public: PdmChildArrayField() {} @@ -63,6 +66,7 @@ public: void clear() override; void deleteAllChildObjects() override; void insertAt( int indexAfter, PdmObjectHandle* obj ) override; + void insertAt( int indexAfter, std::unique_ptr obj ); PdmObjectHandle* at( size_t index ) override; void setValue( const std::vector& objects ); @@ -72,9 +76,12 @@ public: DataType* operator[]( size_t index ) const; - void push_back( DataType* pointer ); - void set( size_t index, DataType* pointer ); - void insert( size_t indexAfter, DataType* pointer ); + void push_back( DataTypePtr pointer ); + void push_back( DataTypeUniquePtr pointer ); + void set( size_t index, DataTypePtr pointer ); + void set( size_t index, DataTypeUniquePtr pointer ); + void insert( size_t indexAfter, DataTypePtr pointer ); + void insert( size_t indexAfter, DataTypeUniquePtr pointer ); void insert( size_t indexAfter, const std::vector>& objects ); size_t count( const DataType* pointer ) const; diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmChildArrayField.inl b/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmChildArrayField.inl index 392e6d59fb..ac570f54d1 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmChildArrayField.inl +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmChildArrayField.inl @@ -35,7 +35,16 @@ void PdmChildArrayField::push_back( DataType* pointer ) CAF_ASSERT( isInitializedByInitFieldMacro() ); m_pointers.push_back( pointer ); - if ( pointer ) pointer->setAsParentField( this ); + if ( m_pointers.back() ) m_pointers.back()->setAsParentField( this ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +template +void PdmChildArrayField::push_back( DataTypeUniquePtr pointer ) +{ + this->push_back( pointer.release() ); } //-------------------------------------------------------------------------------------------------- @@ -49,7 +58,17 @@ void PdmChildArrayField::set( size_t index, DataType* pointer ) if ( m_pointers[index] ) m_pointers[index]->removeAsParentField( this ); m_pointers[index] = pointer; - if ( m_pointers[index] ) pointer->setAsParentField( this ); + if ( m_pointers[index] ) m_pointers[index]->setAsParentField( this ); +} + +//-------------------------------------------------------------------------------------------------- +/// Set the value at position index to pointer, overwriting any pointer already present at that +/// position without deleting the object pointed to. +//-------------------------------------------------------------------------------------------------- +template +void PdmChildArrayField::set( size_t index, DataTypeUniquePtr pointer ) +{ + this->set( index, pointer.release() ); } //-------------------------------------------------------------------------------------------------- @@ -63,7 +82,17 @@ void PdmChildArrayField::insert( size_t index, DataType* pointer ) m_pointers.insert( m_pointers.begin() + index, pointer ); - if ( pointer ) pointer->setAsParentField( this ); + if ( m_pointers[index] ) m_pointers[index]->setAsParentField( this ); +} + +//-------------------------------------------------------------------------------------------------- +/// Insert pointer at position index, pushing the value previously at that position and all +/// the preceding values backwards +//-------------------------------------------------------------------------------------------------- +template +void PdmChildArrayField::insert( size_t index, DataTypeUniquePtr pointer ) +{ + this->insert( index, pointer.release() ); } //-------------------------------------------------------------------------------------------------- @@ -285,6 +314,15 @@ void PdmChildArrayField::insertAt( int indexAfter, PdmObjectHandle* o obj->setAsParentField( this ); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +template +void PdmChildArrayField::insertAt( int indexAfter, std::unique_ptr obj ) +{ + this->insertAt( indexAfter, obj.release() ); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmChildField.h b/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmChildField.h index c903aa0c7a..622af931fa 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmChildField.h +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmChildField.h @@ -5,6 +5,8 @@ #include "cafAssert.h" #include "cafPdmPointer.h" +#include + namespace caf { template @@ -37,21 +39,24 @@ public: template class PdmChildField : public PdmChildFieldHandle { - typedef DataType* DataTypePtr; + typedef DataType* DataTypePtr; + typedef std::unique_ptr DataTypeUniquePtr; public: PdmChildField() {} explicit PdmChildField( const DataTypePtr& fieldValue ); + explicit PdmChildField( DataTypeUniquePtr fieldValue ); virtual ~PdmChildField(); // Assignment PdmChildField& operator=( const DataTypePtr& fieldValue ); - + PdmChildField& operator=( DataTypeUniquePtr fieldValue ); // Basic access DataType* value() const { return m_fieldValue; } void setValue( const DataTypePtr& fieldValue ); + void setValue( DataTypeUniquePtr fieldValue ); // Access operators diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmChildField.inl b/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmChildField.inl index 11f386e224..c111c92712 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmChildField.inl +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmChildField.inl @@ -59,6 +59,17 @@ caf::PdmChildField::PdmChildField( const DataTypePtr& fieldValue ) if ( m_fieldValue != nullptr ) m_fieldValue->setAsParentField( this ); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +template +caf::PdmChildField::PdmChildField( DataTypeUniquePtr fieldValue ) +{ + if ( m_fieldValue ) m_fieldValue->removeAsParentField( this ); + m_fieldValue = fieldValue.release(); + if ( m_fieldValue != nullptr ) m_fieldValue->setAsParentField( this ); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -82,6 +93,15 @@ caf::PdmChildField& PdmChildField::operator=( const DataTy return *this; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +template +caf::PdmChildField& PdmChildField::operator=( DataTypeUniquePtr fieldValue ) +{ + return this->operator=( fieldValue.release() ); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -93,4 +113,13 @@ void caf::PdmChildField::setValue( const DataTypePtr& fieldValue ) if ( m_fieldValue != nullptr ) m_fieldValue->setAsParentField( this ); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +template +void caf::PdmChildField::setValue( DataTypeUniquePtr fieldValue ) +{ + return this->setValue( fieldValue.release() ); +} + } // End of namespace caf