Skip to content

Commit

Permalink
ADD: CLI handling of parameters to AverageAligner #42
Browse files Browse the repository at this point in the history
CLEANUP: Simplify addition of new ARender parsers
  • Loading branch information
spillerrec committed Oct 30, 2015
1 parent 3bfc9d3 commit 2c6c649
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 17 deletions.
29 changes: 25 additions & 4 deletions interface/cli/AlignParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,33 @@

#include <QString>

using namespace std;
using namespace Overmix;

static void convert( QString str, AImageAligner::AlignMethod& func ){
func = getEnum<AImageAligner::AlignMethod>( str,
{ { "both", AImageAligner::ALIGN_BOTH }
, { "ver", AImageAligner::ALIGN_VER }
, { "hor", AImageAligner::ALIGN_HOR }
} );
}


void Overmix::alignerParser( QString parameters, AContainer& container ){
//TODO: parse parameters
AverageAligner aligner( container, AImageAligner::ALIGN_BOTH );
aligner.addImages();
aligner.align();
unique_ptr<AImageAligner> aligner;

Splitter split( parameters, ':' );
if( split.left == "average" ){
AImageAligner::AlignMethod method;
double scale;
convert( split.right, method, scale );
//TODO: parse parameters
aligner = make_unique<AverageAligner>( container, method, scale );
}
else
throw std::invalid_argument( fromQString( "No aligner found with the name: '" + split.left + "'" ) );


aligner->addImages();
aligner->align();
}
33 changes: 33 additions & 0 deletions interface/cli/Parsers.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
This file is part of Overmix.
Overmix is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Overmix is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Overmix. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef PARSERS_HPP
#define PARSERS_HPP

class QString;

namespace Overmix{

class ImageEx;
class AContainer;

ImageEx renderParser( QString parameters, const AContainer& container );
void alignerParser( QString parameters, AContainer& container );

}

#endif
27 changes: 25 additions & 2 deletions interface/cli/Parsing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@
#include <QString>

#include <stdexcept>
#include <memory>

namespace Overmix{


struct Splitter{
QString left;
QString right;
template<typename T>

template<typename T>
Splitter( QString str, T split ){
auto pos = str.indexOf( split );
left = str.left( pos );
Expand Down Expand Up @@ -104,6 +105,28 @@ void convert( QString str, Point<T>& val ){
convert( split.right, val.y );
}


template<typename Tuple, std::size_t... I>
Tuple callConvert( QString str, Tuple tuple, std::index_sequence<I...> ){
convert( str, std::get<I>(tuple)... );
return tuple;
}

template<typename... Args>
std::tuple<Args...> convertTuple( QString str )
{ return callConvert( str, std::tuple<Args...>(), std::index_sequence_for<Args...>{} ); }


template<typename Output, typename Tuple, std::size_t... I>
std::unique_ptr<Output> uniqueFromTuple( Tuple& tuple, std::index_sequence<I...> )
{ return std::make_unique<Output>( std::get<I>(tuple)... ); }

template<typename Output, typename... Args>
std::unique_ptr<Output> convertUnique( QString parameters ){
auto args = convertTuple<Args...>( parameters );
return uniqueFromTuple<Output>( args, std::index_sequence_for<Args...>{} );
}

}

#endif
15 changes: 4 additions & 11 deletions interface/cli/RenderParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,10 @@ static void convert( QString str, Statistics& func ){

ImageEx Overmix::renderParser( QString parameters, const AContainer& container ){
Splitter split( parameters, ':' );
if( split.left == "average" ){
bool upscale_chroma;
bool for_merging;
convert( split.right, upscale_chroma, for_merging );
return AverageRender( upscale_chroma, for_merging ).render( container );
}
else if( split.left == "statistics" ){
Statistics stats;
convert( split.right, stats );
return StatisticsRender(stats).render( container );
}
if( split.left == "average" )
return convertUnique<AverageRender, bool, bool>( split.right )->render( container );
else if( split.left == "statistics" )
return convertUnique<StatisticsRender, Statistics>( split.right )->render( container );

throw std::invalid_argument( fromQString( "No render found with the name: '" + split.left + "'" ) );
}

0 comments on commit 2c6c649

Please sign in to comment.