Use unique_ptr for data loaders.

This commit is contained in:
Kristian Bendiksen 2024-08-14 11:02:39 +02:00
parent 76a1d43b0e
commit 6e3e0ad538
3 changed files with 14 additions and 16 deletions

View File

@ -1755,15 +1755,15 @@ void RiaApplication::initializeDataLoadController()
const QString wellPathGeometryKeyword = "WELL_PATH_GEOMETRY"; const QString wellPathGeometryKeyword = "WELL_PATH_GEOMETRY";
dataLoadController->registerDataLoader( RimFileWellPath::classKeywordStatic(), dataLoadController->registerDataLoader( RimFileWellPath::classKeywordStatic(),
wellPathGeometryKeyword, wellPathGeometryKeyword,
std::make_shared<RimFileWellPathDataLoader>() ); std::make_unique<RimFileWellPathDataLoader>() );
dataLoadController->registerDataLoader( RimOsduWellPath::classKeywordStatic(), dataLoadController->registerDataLoader( RimOsduWellPath::classKeywordStatic(),
wellPathGeometryKeyword, wellPathGeometryKeyword,
std::make_shared<RimOsduWellPathDataLoader>() ); std::make_unique<RimOsduWellPathDataLoader>() );
dataLoadController->registerDataLoader( RimModeledWellPath::classKeywordStatic(), dataLoadController->registerDataLoader( RimModeledWellPath::classKeywordStatic(),
wellPathGeometryKeyword, wellPathGeometryKeyword,
std::make_shared<RimModeledWellPathDataLoader>() ); std::make_unique<RimModeledWellPathDataLoader>() );
const QString wellLogKeyword = "WELL_LOG"; const QString wellLogKeyword = "WELL_LOG";
dataLoadController->registerDataLoader( RimWellLogFile::classKeywordStatic(), wellLogKeyword, std::make_shared<RimWellLogFileDataLoader>() ); dataLoadController->registerDataLoader( RimWellLogFile::classKeywordStatic(), wellLogKeyword, std::make_unique<RimWellLogFileDataLoader>() );
dataLoadController->registerDataLoader( RimOsduWellLog::classKeywordStatic(), wellLogKeyword, std::make_shared<RimOsduWellLogDataLoader>() ); dataLoadController->registerDataLoader( RimOsduWellLog::classKeywordStatic(), wellLogKeyword, std::make_unique<RimOsduWellLogDataLoader>() );
} }

View File

@ -68,12 +68,12 @@ DataLoadController* DataLoadController::instance()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void DataLoadController::registerDataLoader( const QString& objectType, void DataLoadController::registerDataLoader( const QString& objectType,
const QString& dataType, const QString& dataType,
std::shared_ptr<DataLoader> dataLoader ) std::unique_ptr<DataLoader> dataLoader )
{ {
std::pair<QString, QString> key = { objectType, dataType };
m_dataLoaders[key] = dataLoader;
dataLoader->taskDone.connect( this, &DataLoadController::onTaskFinished ); dataLoader->taskDone.connect( this, &DataLoadController::onTaskFinished );
std::pair<QString, QString> key = { objectType, dataType };
m_dataLoaders[key] = std::move( dataLoader );
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -85,21 +85,19 @@ void DataLoadController::loadData( caf::PdmObject& object, const QString& dataTy
auto it = m_dataLoaders.find( key ); auto it = m_dataLoaders.find( key );
if ( it != m_dataLoaders.end() ) if ( it != m_dataLoaders.end() )
{ {
std::shared_ptr<caf::DataLoader> dataLoader = it->second;
QMutexLocker locker( &m_mutex ); QMutexLocker locker( &m_mutex );
m_pendingTasksByType[dataType]++; m_pendingTasksByType[dataType]++;
locker.unlock(); locker.unlock();
if ( dataLoader->isRunnable() ) if ( it->second->isRunnable() )
{ {
DataLoadTask* task = new DataLoadTask( *this, *dataLoader.get(), object, dataType, m_taskId++, progressInfo ); DataLoadTask* task = new DataLoadTask( *this, *it->second.get(), object, dataType, m_taskId++, progressInfo );
task->setAutoDelete( true ); task->setAutoDelete( true );
QThreadPool::globalInstance()->start( task ); QThreadPool::globalInstance()->start( task );
} }
else else
{ {
dataLoader->loadData( object, dataType, m_taskId++, progressInfo ); it->second->loadData( object, dataType, m_taskId++, progressInfo );
} }
} }
} }

View File

@ -64,7 +64,7 @@ public:
DataLoadController( const DataLoadController& ) = delete; DataLoadController( const DataLoadController& ) = delete;
DataLoadController& operator=( const DataLoadController& ) = delete; DataLoadController& operator=( const DataLoadController& ) = delete;
void registerDataLoader( const QString& objectType, const QString& dataType, std::shared_ptr<DataLoader> dataLoader ); void registerDataLoader( const QString& objectType, const QString& dataType, std::unique_ptr<DataLoader> dataLoader );
void loadData( caf::PdmObject& object, const QString& dateType, ProgressInfo& progressInfo ); void loadData( caf::PdmObject& object, const QString& dateType, ProgressInfo& progressInfo );
@ -75,7 +75,7 @@ public:
private: private:
DataLoadController(); DataLoadController();
std::map<std::pair<QString, QString>, std::shared_ptr<caf::DataLoader>> m_dataLoaders; std::map<std::pair<QString, QString>, std::unique_ptr<caf::DataLoader>> m_dataLoaders;
std::map<QString, int> m_pendingTasksByType; std::map<QString, int> m_pendingTasksByType;
int m_taskId; int m_taskId;