diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 40bac86..09af52a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -48,7 +48,6 @@ jobs: with: repository: 'pixlra/calyp-testdata' path: ${{github.workspace}}/tests_data - lfs: true - name: Configure CMake # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. diff --git a/app/dialog/ConfigureFormatDialog.h b/app/dialog/ConfigureFormatDialog.h index 7f515fa..bf3c4a4 100644 --- a/app/dialog/ConfigureFormatDialog.h +++ b/app/dialog/ConfigureFormatDialog.h @@ -38,7 +38,7 @@ class QSpinBox; class QString; class QWidget; -typedef QVector CalypStandardResolutionVector; +using CalypStandardResolutionVector = QVector; QDataStream& operator<<( QDataStream& out, const CalypStandardResolutionVector& array ); QDataStream& operator>>( QDataStream& in, CalypStandardResolutionVector& array ); diff --git a/app/dialog/ModulesHandleOptDialog.cpp b/app/dialog/ModulesHandleOptDialog.cpp index be79e92..8c8ab37 100644 --- a/app/dialog/ModulesHandleOptDialog.cpp +++ b/app/dialog/ModulesHandleOptDialog.cpp @@ -36,18 +36,17 @@ class QLineEdit; -class OpionConfiguration : public QWidget +class OptionConfiguration : public QWidget { public: - OpionConfiguration( OptionBase* option ) + OptionConfiguration( CalypOptions::OptionBase* option ) + : m_cName{ option->opt_string } { - m_pcChecked = NULL; - m_cName = option->opt_string; - m_pcDescription = new QLabel; + auto* pcDescription = new QLabel; QString desc = QString::fromStdString( option->opt_desc ); - m_pcDescription->setText( desc ); + pcDescription->setText( desc ); QHBoxLayout* layout = new QHBoxLayout; - layout->addWidget( m_pcDescription, 0, Qt::AlignLeft ); + layout->addWidget( pcDescription, 0, Qt::AlignLeft ); if( !option->isBinary() ) { m_pcValue = new QLineEdit; @@ -64,7 +63,7 @@ public: layout->setContentsMargins( 1, 1, 1, 1 ); setLayout( layout ); } - const QString getValue() const + auto getValue() const -> QString { if( m_pcChecked ) { @@ -72,12 +71,11 @@ public: } return m_pcValue->text(); } - const std::string& getName() { return m_cName; } + auto getName() const -> std::string { return m_cName; } private: - QLineEdit* m_pcValue; - QCheckBox* m_pcChecked; - QLabel* m_pcDescription; + QLineEdit* m_pcValue{ nullptr }; + QCheckBox* m_pcChecked{ nullptr }; std::string m_cName; }; @@ -87,13 +85,12 @@ ModulesHandleOptDialog::ModulesHandleOptDialog( QWidget* parent, CalypAppModuleI resize( 400, 10 ); setWindowTitle( "Select module parameters" ); - const CalypOptions::OptionsList& moduleOptions = m_pcCurrModuleIf->m_pcModule->m_cModuleOptions.getOptionList(); + auto& moduleOptions = m_pcCurrModuleIf->m_pcModule->m_cModuleOptions.getOptionList(); QVBoxLayout* optionsLayout = new QVBoxLayout; - OpionConfiguration* pcOption; - for( CalypOptions::OptionsList::const_iterator it = moduleOptions.begin(); it != moduleOptions.end(); ++it ) + for( auto& option : moduleOptions ) { - pcOption = new OpionConfiguration( ( *it )->opt ); + auto pcOption = new OptionConfiguration( option->base_opt.get() ); m_apcOptionList.append( pcOption ); optionsLayout->addWidget( pcOption ); } @@ -125,13 +122,13 @@ int ModulesHandleOptDialog::runConfiguration() std::string optionString; QString valueString( "" ); - for( int i = 0; i < m_apcOptionList.size(); i++ ) + for( const auto& option : m_apcOptionList ) { - valueString = m_apcOptionList.at( i )->getValue(); + valueString = option->getValue(); if( !valueString.isEmpty() ) { optionString.append( "--" ); - optionString.append( m_apcOptionList.at( i )->getName() ); + optionString.append( option->getName() ); if( !( valueString == "true" ) ) { optionString.append( "=" ); diff --git a/app/dialog/ModulesHandleOptDialog.h b/app/dialog/ModulesHandleOptDialog.h index 3dde134..a1b25a0 100644 --- a/app/dialog/ModulesHandleOptDialog.h +++ b/app/dialog/ModulesHandleOptDialog.h @@ -32,7 +32,7 @@ #include "CommonDefs.h" #include "config.h" -class OpionConfiguration; +class OptionConfiguration; /** * @@ -47,7 +47,7 @@ public: private: CalypAppModuleIf* m_pcCurrModuleIf; - QVector m_apcOptionList; + QVector m_apcOptionList; }; #endif // __MODULEHANDLEOPTDIALOG_H__ diff --git a/lib/CalypOptions.cpp b/lib/CalypOptions.cpp index bec3f2a..e820653 100644 --- a/lib/CalypOptions.cpp +++ b/lib/CalypOptions.cpp @@ -40,6 +40,7 @@ #include #include +#include #include #include "config.h" @@ -52,32 +53,33 @@ struct ParseFailure : public std::exception std::string arg; std::string val; ParseFailure( std::string arg0, std::string val0 ) throw() - : arg( arg0 ), val( val0 ) {} + : arg{ std::move( arg0 ) }, val{ std::move( val0 ) } {} + ParseFailure( ParseFailure&& other ) noexcept = delete; + ParseFailure& operator=( ParseFailure&& other ) noexcept = delete; + ParseFailure( const ParseFailure& other ) = delete; + ParseFailure& operator=( const ParseFailure& other ) = delete; ~ParseFailure() throw() {} - const char* what() const throw() { return "Option Parse Failure"; } + const char* what() const throw() override { return "Option Parse Failure"; } }; /** Type specific option storage */ -class boolOption : public OptionBase +class boolOption : public CalypOptions::OptionBase { public: boolOption( const std::string& name, const std::string& desc ) - : OptionBase( name, desc, "(1-0)" ) { is_binary = true; } - void parse( const std::string& arg ) { arg_count++; } + : CalypOptions::OptionBase( name, desc, "(1-0)" ) { is_binary = true; } + void parse( const std::string& arg ) override { arg_count++; } }; /** Type specific option storage */ template -class StandardOption : public OptionBase +class StandardOption : public CalypOptions::OptionBase { public: StandardOption( const std::string& name, T& storage, const std::string& desc, const std::string& def ) - : OptionBase( name, desc, def ), opt_storage( storage ) - { - is_binary = false; - } + : CalypOptions::OptionBase( name, desc, def ), opt_storage( storage ) {} - void parse( const std::string& arg ); + void parse( const std::string& arg ) override; T& opt_storage; std::vector opt_storage_array; }; @@ -105,7 +107,7 @@ inline void StandardOption::parse( const std::string& arg ) template <> inline void StandardOption>::parse( const std::string& arg ) { - unsigned int aux_opt_storage; + unsigned int aux_opt_storage{ 0 }; std::istringstream arg_ss( arg, std::istringstream::in ); arg_ss.exceptions( std::ios::failbit ); try @@ -123,7 +125,7 @@ inline void StandardOption>::parse( const std::string& template <> inline void StandardOption>::parse( const std::string& arg ) { - int aux_opt_storage; + int aux_opt_storage{ 0 }; std::istringstream arg_ss( arg, std::istringstream::in ); arg_ss.exceptions( std::ios::failbit ); try @@ -155,26 +157,26 @@ inline void StandardOption>::parse( const std::string& } /** Option class for argument handling using a user provided function */ -struct FunctionOption : public OptionBase +struct FunctionOption : public CalypOptions::OptionBase { -public: - typedef void( Func )( CalypOptions&, const std::string& ); + using OptFunc = std::function; - FunctionOption( const std::string& name, CalypOptions& parent_, Func* func_, const std::string& desc, const std::string& def ) - : OptionBase( name, desc, def ), parent( parent_ ), func( func_ ) +public: + FunctionOption( const std::string& name, CalypOptions& parent, OptFunc func, const std::string& desc, const std::string& def ) + : CalypOptions::OptionBase( name, desc, def ), m_parent( parent ), m_func( func ) { is_binary = false; } - void parse( const std::string& arg ) + void parse( const std::string& arg ) override { - func( parent, arg ); + m_func( m_parent, arg ); arg_count++; } private: - CalypOptions& parent; - void ( *func )( CalypOptions&, const std::string& ); + CalypOptions& m_parent; + OptFunc m_func; }; /* Helper method to initiate adding options to Options */ @@ -187,7 +189,7 @@ private: */ CalypOptions& CalypOptions::operator()( const std::string& name, const std::string& desc ) { - addOption( new boolOption( name, desc ) ); + addOption( std::make_unique( name, desc ) ); return *this; } @@ -199,14 +201,14 @@ CalypOptions& CalypOptions::operator()( const std::string& name, const std::stri template CalypOptions& CalypOptions::operator()( const std::string& name, T& storage, const std::string& desc ) { - addOption( new StandardOption( name, storage, desc, std::string( "" ) ) ); + addOption( std::make_unique>( name, storage, desc, std::string( "" ) ) ); return *this; } template CalypOptions& CalypOptions::operator()( const std::string& name, T& storage, const std::string& desc, const std::string& defaults ) { - addOption( new StandardOption( name, storage, desc ) ); + addOption( std::make_unique>( name, storage, desc ) ); return *this; } @@ -223,53 +225,35 @@ template CalypOptions& CalypOptions::operator()( const std::string& name, std::v template CalypOptions& CalypOptions::operator()( const std::string& name, std::vector& storage, const std::string& desc ); -CalypOptions::Option::Option() - : opt( 0 ) {} - -CalypOptions::Option::~Option() +CalypOptions::CalypOptions( std::string name ) + : m_cOptionGroupName{ std::move( name ) } { - if( opt ) - delete opt; } -CalypOptions::CalypOptions( const std::string& name ) -{ - m_cOptionGroupName = name; - m_bAllowUnkonw = true; -} - -CalypOptions::~CalypOptions() -{ - for( CalypOptions::OptionsList::iterator it = opt_list.begin(); it != opt_list.end(); it++ ) - { - delete *it; - } -} - -OptionBase* CalypOptions::operator[]( const std::string& optName ) +CalypOptions::OptionBase* CalypOptions::operator[]( const std::string& optName ) { return getOption( optName ); } -OptionBase* CalypOptions::getOption( const std::string& optName ) +CalypOptions::OptionBase* CalypOptions::getOption( const std::string& optName ) { - CalypOptions::OptionMap::iterator opt_it; + std::map>::iterator opt_it; opt_it = opt_short_map.find( optName ); if( opt_it != opt_short_map.end() ) { - OptionsList opt_list = ( *opt_it ).second; - for( CalypOptions::OptionsList::iterator it = opt_list.begin(); it != opt_list.end(); ++it ) + auto opt_list = ( *opt_it ).second; + for( auto& option : opt_list ) { - return ( *it )->opt; + return option->base_opt.get(); } } opt_it = opt_long_map.find( optName ); if( opt_it != opt_long_map.end() ) { - OptionsList opt_list = ( *opt_it ).second; - for( CalypOptions::OptionsList::iterator it = opt_list.begin(); it != opt_list.end(); ++it ) + auto opt_list = ( *opt_it ).second; + for( auto& option : opt_list ) { - return ( *it )->opt; + return option->base_opt.get(); } } return NULL; @@ -281,26 +265,16 @@ bool CalypOptions::hasOpt( const std::string& optName ) return opt ? opt->count() > 0 ? true : false : false; } -void CalypOptions::addDefaultOptions() -{ - addOptions() /**/ - ( "help", "produce help message" ) /**/ - ( "version", "show version and exit" ) /**/ - ( "pel_fmts", "list pixel formats" ) /**/ - ( "quality_metrics", "list supported quality metrics" ) /**/ - ( "module_list", "list supported modules" ) /**/ - ( "module_list_full", "detailed list supported modules" ); -} - CalypOptions& CalypOptions::addOptions() { return *this; } -void CalypOptions::addOption( OptionBase* opt ) +void CalypOptions::addOption( std::unique_ptr opt ) { - Option* names = new Option(); - names->opt = opt; + auto names = std::make_unique