From 468801fcb3c6c6603e311d867dce424f8e67730a Mon Sep 17 00:00:00 2001 From: Olivier Langella <Olivier.Langella@moulon.inra.fr> Date: Fri, 17 Mar 2017 11:19:30 +0100 Subject: [PATCH] map identifications data sources --- .../identificationdatasource.cpp | 30 ++++++++++++++----- .../identificationdatasource.h | 9 ++++-- .../identificationxtandemfile.cpp | 5 ++-- .../identificationxtandemfile.h | 6 ++-- 4 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/core/identification_sources/identificationdatasource.cpp b/src/core/identification_sources/identificationdatasource.cpp index afb025013..b8dcb46ba 100644 --- a/src/core/identification_sources/identificationdatasource.cpp +++ b/src/core/identification_sources/identificationdatasource.cpp @@ -21,11 +21,21 @@ * Olivier Langella <Olivier.Langella@moulon.inra.fr> - initial API and implementation ******************************************************************************/ #include "identificationdatasource.h" +#include "identificationxtandemfile.h" +#include <pappsomspp/pappsoexception.h> #include <QFileInfo> -IdentificationDataSource::IdentificationDataSource(pappso::MsRunIdSp & ms_run_sp) + +IdentificationDataSource::MapIdentificationDataSources IdentificationDataSource::_map_identification_data_sources = [] { - _ms_run_sp = ms_run_sp; + MapIdentificationDataSources ret; + + return ret; +}(); + +IdentificationDataSource::IdentificationDataSource(const QString resource_name) +{ + _resource_name = resource_name; } IdentificationDataSource::IdentificationDataSource(const IdentificationDataSource& other) @@ -46,20 +56,23 @@ bool IdentificationDataSource::operator==(const IdentificationDataSource& other) IdentificationDataSource * IdentificationDataSource::getInstance(const QString & location) { - std::map< QString, IdentificationDataSource* >::iterator it = _map_identification_data_sources.find(location); - if (it != _map_identification_data_sources.end()) { + std::map< QString, IdentificationDataSource* >::iterator it = IdentificationDataSource::_map_identification_data_sources.find(location); + if (it != IdentificationDataSource::_map_identification_data_sources.end()) { return it->second; } else { QFileInfo location_file(location); QString ext = location_file.suffix(); - QString sample_name = location_file.baseName(); + //QString sample_name = location_file.baseName(); if (ext.toLower() == "xml") { //X!Tandem result file - MsRunIdSp msrunid_sp = - + IdentificationXtandemFile * p_xtfile = new IdentificationXtandemFile(location_file); + _map_identification_data_sources.insert(std::pair< QString, IdentificationDataSource* >(location, p_xtfile)); + _map_identification_data_sources.insert(std::pair< QString, IdentificationDataSource* >(location_file.absoluteFilePath(), p_xtfile)); + return p_xtfile; } } + throw pappso::PappsoException(QObject::tr("Identification resource %1 not recognized").arg(location)); } const QString & IdentificationDataSource::getResourceName () const { @@ -67,6 +80,9 @@ const QString & IdentificationDataSource::getResourceName () const { } +void IdentificationDataSource::setMsRunSp (pappso::MsRunIdSp ms_run_sp) { + _ms_run_sp = ms_run_sp; +} pappso::MsRunIdSp IdentificationDataSource::getMsRunSp () const { return (_ms_run_sp); } diff --git a/src/core/identification_sources/identificationdatasource.h b/src/core/identification_sources/identificationdatasource.h index 928430919..cc007b31d 100644 --- a/src/core/identification_sources/identificationdatasource.h +++ b/src/core/identification_sources/identificationdatasource.h @@ -31,21 +31,24 @@ class IdentificationDataSource { public: + + using MapIdentificationDataSources = std::map<QString, IdentificationDataSource *>; static IdentificationDataSource * getInstance(const QString & location); - IdentificationDataSource(pappso::MsRunIdSp & ms_run_sp); + IdentificationDataSource(const QString resource_name); IdentificationDataSource(const IdentificationDataSource& other); ~IdentificationDataSource(); bool operator==(const IdentificationDataSource& other) const; const QString & getResourceName () const; + void setMsRunSp (pappso::MsRunIdSp ms_run_sp); pappso::MsRunIdSp getMsRunSp () const; protected : QString _resource_name; private : - static std::map<QString, IdentificationDataSource *> _map_identification_data_sources; - static std::map<QString, pappso::MsRunIdSp> _map_msrunidsp; + static MapIdentificationDataSources _map_identification_data_sources; + //static std::map<QString, pappso::MsRunIdSp> _map_msrunidsp; pappso::MsRunIdSp _ms_run_sp = nullptr; }; diff --git a/src/core/identification_sources/identificationxtandemfile.cpp b/src/core/identification_sources/identificationxtandemfile.cpp index 9e4aa1dad..27cb17c35 100644 --- a/src/core/identification_sources/identificationxtandemfile.cpp +++ b/src/core/identification_sources/identificationxtandemfile.cpp @@ -22,13 +22,12 @@ ******************************************************************************/ #include "identificationxtandemfile.h" -IdentificationXtandemFile::IdentificationXtandemFile(pappso::MsRunIdSp & ms_run_sp, const QFileInfo & xtandem_file) : IdentificationDataSource(ms_run_sp), _xtandem_file(xtandem_file) +IdentificationXtandemFile::IdentificationXtandemFile(const QFileInfo & xtandem_file) : IdentificationDataSource(xtandem_file.absoluteFilePath()), _xtandem_file(xtandem_file) { - _resource_name = _xtandem_file.absoluteFilePath(); } IdentificationXtandemFile::IdentificationXtandemFile(const IdentificationXtandemFile& other) : IdentificationDataSource(other),_xtandem_file (other._xtandem_file) -{ +{ } IdentificationXtandemFile::~IdentificationXtandemFile() diff --git a/src/core/identification_sources/identificationxtandemfile.h b/src/core/identification_sources/identificationxtandemfile.h index 1b5383114..d2f364837 100644 --- a/src/core/identification_sources/identificationxtandemfile.h +++ b/src/core/identification_sources/identificationxtandemfile.h @@ -29,13 +29,13 @@ class IdentificationXtandemFile: public IdentificationDataSource { public: - IdentificationXtandemFile(pappso::MsRunIdSp & ms_run_sp, const QFileInfo & xtandem_file); + IdentificationXtandemFile(const QFileInfo & xtandem_file); IdentificationXtandemFile(const IdentificationXtandemFile& other); ~IdentificationXtandemFile(); bool operator==(const IdentificationXtandemFile& other) const; - + private: - const QFileInfo _xtandem_file; + const QFileInfo _xtandem_file; }; #endif // IDENTIFICATIONXTANDEMFILE_H -- GitLab