Merge branch 'develParseOpt' into devel
This commit is contained in:
commit
1804a78523
21 files changed
+582
-696
No files matched your search
+1
-1
@@ -15,7 +15,7 @@ set(PlaYUVer_Lib_SRCS
|
||||
StreamHandlerPortableMap.cpp
|
||||
# Command Parser
|
||||
PlaYUVerOptions.cpp
|
||||
PlaYUVerCmdParser.cpp
|
||||
# PlaYUVerCmdParser.cpp
|
||||
)
|
||||
|
||||
IF( USE_FFMPEG )
|
||||
|
||||
@@ -1,140 +0,0 @@
|
||||
/* This file is a part of plaYUVer project
|
||||
* Copyright (C) 2014-2016 by Luis Lucas (luisfrlucas@gmail.com)
|
||||
* Joao Carreira (jfmcarreira@gmail.com)
|
||||
*
|
||||
* This program 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 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file PlaYUVerCmdParser.cpp
|
||||
* \brief Command parser
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <iostream>
|
||||
#include <exception>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "PlaYUVerCmdParser.h"
|
||||
#include "PlaYUVerFrame.h"
|
||||
|
||||
|
||||
PlaYUVerCmdParser::PlaYUVerCmdParser()
|
||||
{
|
||||
Opts().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" );
|
||||
}
|
||||
|
||||
PlaYUVerCmdParser::~PlaYUVerCmdParser()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Options& PlaYUVerCmdParser::Opts()
|
||||
{
|
||||
return m_cParserOptions;
|
||||
}
|
||||
|
||||
std::list<const Char*>& PlaYUVerCmdParser::getNoArgs()
|
||||
{
|
||||
return m_aUnhandledArgs;
|
||||
}
|
||||
|
||||
Bool PlaYUVerCmdParser::parse()
|
||||
{
|
||||
try
|
||||
{
|
||||
// m_cParserOptions.setDefaults();
|
||||
m_aUnhandledArgs = m_cParserOptions.scanArgv( m_iArgc, ( const Char** )m_ppArgv );
|
||||
|
||||
if( checkListingOpts() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch( std::exception& e )
|
||||
{
|
||||
std::cerr << "error: "
|
||||
<< e.what()
|
||||
<< "\n";
|
||||
return false;
|
||||
}
|
||||
catch( ... )
|
||||
{
|
||||
std::cerr << "Exception of unknown type!\n";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Bool PlaYUVerCmdParser::parse( Options& opts, Int argc, Char *argv[] )
|
||||
{
|
||||
try
|
||||
{
|
||||
// m_cParserOptions.setDefaults();
|
||||
m_aUnhandledArgs = opts.scanArgv( argc, ( const Char** )argv );
|
||||
|
||||
}
|
||||
catch( std::exception& e )
|
||||
{
|
||||
std::cerr << "error: "
|
||||
<< e.what()
|
||||
<< "\n";
|
||||
return false;
|
||||
}
|
||||
catch( ... )
|
||||
{
|
||||
std::cerr << "Exception of unknown type!\n";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Bool PlaYUVerCmdParser::checkListingOpts()
|
||||
{
|
||||
Bool bRet = false;
|
||||
|
||||
if( m_cParserOptions["version"]->count() )
|
||||
{
|
||||
std::cout << "PlaYUVer version "
|
||||
<< PLAYUVER_VERSION_STRING
|
||||
<< "\n";
|
||||
bRet |= true;
|
||||
}
|
||||
if( m_cParserOptions["pel_fmts"]->count() )
|
||||
{
|
||||
printf( "PlaYUVer supported pixel formats: \n" );
|
||||
for( UInt i = 0; i < PlaYUVerFrame::supportedPixelFormatListNames().size(); i++ )
|
||||
{
|
||||
printf( " %s\n", PlaYUVerFrame::supportedPixelFormatListNames()[i].c_str() );
|
||||
}
|
||||
bRet |= true;
|
||||
}
|
||||
if( Opts()["quality_metrics"]->count() )
|
||||
{
|
||||
printf( "PlaYUVer supported quality metrics: \n" );
|
||||
for( UInt i = 0; i < PlaYUVerFrame::supportedQualityMetricsList().size(); i++ )
|
||||
{
|
||||
printf( " %s\n", PlaYUVerFrame::supportedQualityMetricsList()[i].c_str() );
|
||||
}
|
||||
bRet |= true;
|
||||
}
|
||||
return bRet;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
/* This file is a part of plaYUVer project
|
||||
* Copyright (C) 2014-2016 by Luis Lucas (luisfrlucas@gmail.com)
|
||||
* Joao Carreira (jfmcarreira@gmail.com)
|
||||
*
|
||||
* This program 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 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file PlaYUVerCmdParser.h
|
||||
* \brief Command parser
|
||||
*/
|
||||
|
||||
#include "PlaYUVerDefs.h"
|
||||
#include "PlaYUVerOptions.h"
|
||||
|
||||
#ifndef __PLAYUVERCMDPARSER_H__
|
||||
#define __PLAYUVERCMDPARSER_H__
|
||||
|
||||
class PlaYUVerCmdParser
|
||||
{
|
||||
public:
|
||||
PlaYUVerCmdParser();
|
||||
~PlaYUVerCmdParser();
|
||||
|
||||
Void config( Int argc, Char *argv[] )
|
||||
{
|
||||
m_iArgc = argc;
|
||||
m_ppArgv = argv;
|
||||
}
|
||||
Bool parse();
|
||||
Bool parse( Options& opts, Int argc, Char *argv[] );
|
||||
std::list<const Char*>& getNoArgs();
|
||||
Options& Opts();
|
||||
private:
|
||||
Int m_iArgc;
|
||||
Char** m_ppArgv;
|
||||
Options m_cParserOptions;
|
||||
std::list<const Char*> m_aUnhandledArgs;
|
||||
|
||||
Bool checkListingOpts();
|
||||
Void listModules();
|
||||
};
|
||||
|
||||
#endif // __PLAYUVERCMDPARSER_H__
|
||||
@@ -134,6 +134,22 @@ inline String uppercase( const String& in )
|
||||
return out;
|
||||
}
|
||||
|
||||
struct PlaYUVerFailure: public std::exception
|
||||
{
|
||||
String m_class_name;
|
||||
String m_error_msg;
|
||||
PlaYUVerFailure( String error_msg ) throw() :
|
||||
m_error_msg( error_msg ) { }
|
||||
PlaYUVerFailure( String class_name, String error_msg ) throw() :
|
||||
m_class_name( class_name ),
|
||||
m_error_msg( error_msg ) { }
|
||||
~PlaYUVerFailure() throw() { }
|
||||
const Char* what() const throw()
|
||||
{
|
||||
String* msg = new String( "[" + m_class_name + "] " + m_error_msg );
|
||||
return msg->c_str();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif // __PLAYUVERDEFS_H__
|
||||
+10
-10
@@ -216,13 +216,13 @@ Void PlaYUVerFramePrivate::init( UInt width, UInt height, Int pel_format, Int bi
|
||||
m_iEndianness = endianness;
|
||||
if( m_uiBitsPel > 8 && m_iEndianness == -1 )
|
||||
{
|
||||
throw "Invalid endianness type for Bits per Pixel greater than 8";
|
||||
throw PlaYUVerFailure( "PlaYUVerFrame", "Invalid endianness type for Bits per Pixel greater than 8" );
|
||||
}
|
||||
m_uiHalfPelValue = 1 << ( m_uiBitsPel - 1 );
|
||||
|
||||
if( m_uiWidth == 0 || m_uiHeight == 0 || m_iPixelFormat == -1 || bitsPixel > 16 )
|
||||
{
|
||||
throw "Cannot create a PlYUVerFrame of this type";
|
||||
throw PlaYUVerFailure( "PlaYUVerFrame", "Cannot create a PlYUVerFrame of this type" );
|
||||
}
|
||||
|
||||
m_pcPelFormat = &( g_PlaYUVerPixFmtDescriptorsList[pel_format] );
|
||||
@@ -1090,14 +1090,14 @@ Void PlaYUVerFrame::fromCvMat( cv::Mat* pcCvFrame )
|
||||
{
|
||||
switch( pcCvFrame->channels() )
|
||||
{
|
||||
case 1:
|
||||
d->m_iPixelFormat = findPixelFormat( "GRAY" );
|
||||
break;
|
||||
case 3:
|
||||
d->m_iPixelFormat = findPixelFormat( "BGR24" );
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
case 1:
|
||||
d->m_iPixelFormat = findPixelFormat( "GRAY" );
|
||||
break;
|
||||
case 3:
|
||||
d->m_iPixelFormat = findPixelFormat( "BGR24" );
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
d->init( pcCvFrame->cols, pcCvFrame->rows, d->m_iPixelFormat, 8, -1 );
|
||||
|
||||
@@ -101,7 +101,7 @@ public:
|
||||
enum Module_NumberOfFrames m_uiNumberOfFrames;
|
||||
UInt m_uiModuleRequirements;
|
||||
|
||||
Options m_cModuleOptions;
|
||||
PlaYUVerOptions m_cModuleOptions;
|
||||
|
||||
PlaYUVerModuleIf()
|
||||
{
|
||||
|
||||
+375
-54
@@ -36,46 +36,245 @@
|
||||
* \brief Input args handler
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "PlaYUVerOptions.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <cstdarg>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <algorithm>
|
||||
#include "PlaYUVerOptions.h"
|
||||
|
||||
#include "lib/PlaYUVerModuleIf.h"
|
||||
#include "modules/PlaYUVerModuleFactory.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
struct ParseFailure: public std::exception
|
||||
{
|
||||
String arg;
|
||||
String val;
|
||||
ParseFailure( String arg0, String val0 ) throw() :
|
||||
arg( arg0 ),
|
||||
val( val0 ) { }
|
||||
~ParseFailure() throw() { }
|
||||
const Char* what() const throw()
|
||||
{
|
||||
return "Option Parse Failure";
|
||||
}
|
||||
};
|
||||
|
||||
Options::Options( const String& name )
|
||||
|
||||
/** Type specific option storage */
|
||||
class BoolOption: public OptionBase
|
||||
{
|
||||
public:
|
||||
BoolOption( const String& name, const String& desc ) :
|
||||
OptionBase( name, desc )
|
||||
{
|
||||
is_binary = true;
|
||||
}
|
||||
|
||||
void parse( const String& arg )
|
||||
{
|
||||
arg_count++;
|
||||
}
|
||||
};
|
||||
|
||||
/** Type specific option storage */
|
||||
template<typename T>
|
||||
class StandardOption: public OptionBase
|
||||
{
|
||||
public:
|
||||
StandardOption( const String& name, T& storage, const String& desc ) :
|
||||
OptionBase( name, desc ),
|
||||
opt_storage( storage )
|
||||
{
|
||||
is_binary = false;
|
||||
}
|
||||
|
||||
void parse( const String& arg );
|
||||
T& opt_storage;
|
||||
std::vector<T> opt_storage_array;
|
||||
};
|
||||
|
||||
/* Generic parsing */
|
||||
template<typename T>
|
||||
inline void StandardOption<T>::parse( const String& arg )
|
||||
{
|
||||
if( !is_binary )
|
||||
{
|
||||
std::istringstream arg_ss( arg, std::istringstream::in );
|
||||
arg_ss.exceptions( std::ios::failbit );
|
||||
try
|
||||
{
|
||||
arg_ss >> opt_storage;
|
||||
}
|
||||
catch( ... )
|
||||
{
|
||||
throw ParseFailure( opt_string, arg );
|
||||
}
|
||||
}
|
||||
arg_count++;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline void StandardOption< std::vector<UInt> >::parse( const String& arg )
|
||||
{
|
||||
UInt aux_opt_storage;
|
||||
std::istringstream arg_ss( arg, std::istringstream::in );
|
||||
arg_ss.exceptions( std::ios::failbit );
|
||||
try
|
||||
{
|
||||
arg_ss >> aux_opt_storage;
|
||||
opt_storage.push_back( aux_opt_storage );
|
||||
}
|
||||
catch( ... )
|
||||
{
|
||||
throw ParseFailure( opt_string, arg );
|
||||
}
|
||||
arg_count++;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline void StandardOption< std::vector<Int> >::parse( const String& arg )
|
||||
{
|
||||
Int aux_opt_storage;
|
||||
std::istringstream arg_ss( arg, std::istringstream::in );
|
||||
arg_ss.exceptions( std::ios::failbit );
|
||||
try
|
||||
{
|
||||
arg_ss >> aux_opt_storage;
|
||||
opt_storage.push_back( aux_opt_storage );
|
||||
}
|
||||
catch( ... )
|
||||
{
|
||||
throw ParseFailure( opt_string, arg );
|
||||
}
|
||||
arg_count++;
|
||||
}
|
||||
|
||||
/* string parsing is specialized */
|
||||
template<>
|
||||
inline void StandardOption<String>::parse( const String& arg )
|
||||
{
|
||||
opt_storage = arg;
|
||||
arg_count++;
|
||||
}
|
||||
|
||||
/* string vector parsing is specialized */
|
||||
template<>
|
||||
inline void StandardOption<std::vector<String> >::parse( const String& arg )
|
||||
{
|
||||
opt_storage.push_back( arg );
|
||||
arg_count++;
|
||||
}
|
||||
|
||||
/** Option class for argument handling using a user provided function */
|
||||
struct FunctionOption: public OptionBase
|
||||
{
|
||||
public:
|
||||
typedef Void( Func )( PlaYUVerOptions&, const String& );
|
||||
|
||||
FunctionOption( const String& name, PlaYUVerOptions& parent_, Func *func_, const String& desc ) :
|
||||
OptionBase( name, desc ),
|
||||
parent( parent_ ),
|
||||
func( func_ )
|
||||
{
|
||||
is_binary = false;
|
||||
}
|
||||
|
||||
void parse( const String& arg )
|
||||
{
|
||||
func( parent, arg );
|
||||
arg_count++;
|
||||
}
|
||||
|
||||
private:
|
||||
PlaYUVerOptions& parent;
|
||||
void ( *func )( PlaYUVerOptions&, const String& );
|
||||
};
|
||||
|
||||
/* Helper method to initiate adding options to Options */
|
||||
|
||||
/**
|
||||
* Add option described by name to the parent Options list,
|
||||
* with storage for the option's value
|
||||
* with default_val as the default value
|
||||
* with desc as an optional help description
|
||||
*/
|
||||
PlaYUVerOptions& PlaYUVerOptions::operator()( const String& name, const String& desc )
|
||||
{
|
||||
addOption( new BoolOption( name, desc ) );
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add option described by name to the parent Options list,
|
||||
* with storage for the option's value
|
||||
* with desc as an optional help description
|
||||
*/
|
||||
template<typename T>
|
||||
PlaYUVerOptions& PlaYUVerOptions::operator()( const String& name, T& storage, const String& desc )
|
||||
{
|
||||
addOption( new StandardOption<T>( name, storage, desc ) );
|
||||
return *this;
|
||||
}
|
||||
|
||||
template PlaYUVerOptions& PlaYUVerOptions::operator()( const String& name, Bool& storage, const String& desc );
|
||||
template PlaYUVerOptions& PlaYUVerOptions::operator()( const String& name, UInt& storage, const String& desc );
|
||||
template PlaYUVerOptions& PlaYUVerOptions::operator()( const String& name, Int& storage, const String& desc );
|
||||
template PlaYUVerOptions& PlaYUVerOptions::operator()( const String& name, Int64& storage, const String& desc );
|
||||
template PlaYUVerOptions& PlaYUVerOptions::operator()( const String& name, String& storage, const String& desc );
|
||||
template PlaYUVerOptions& PlaYUVerOptions::operator()( const String& name, std::vector<UInt>& storage, const String& desc );
|
||||
template PlaYUVerOptions& PlaYUVerOptions::operator()( const String& name, std::vector<Int>& storage, const String& desc );
|
||||
template PlaYUVerOptions& PlaYUVerOptions::operator()( const String& name, std::vector<String>& storage, const String& desc );
|
||||
|
||||
/**
|
||||
* Add option described by name to the parent Options list,
|
||||
* with desc as an optional help description
|
||||
* instead of storing the value somewhere, a function of type
|
||||
* FunctionOption::Func is called. It is upto this function to correctly
|
||||
* handle evaluating the option's value.
|
||||
*/
|
||||
// PlaYUVerOptions& PlaYUVerOptions::operator()( const String& name, FunctionOption::Func *func, const String& desc )
|
||||
// {
|
||||
// addOption( new FunctionOption( name, parent, func, desc ) );
|
||||
// return *this;
|
||||
// }
|
||||
|
||||
PlaYUVerOptions::PlaYUVerOptions( const String& name )
|
||||
{
|
||||
m_cOptionGroupName = name;
|
||||
m_bAllowUnkonw = true;
|
||||
}
|
||||
|
||||
Options::~Options()
|
||||
PlaYUVerOptions::~PlaYUVerOptions()
|
||||
{
|
||||
for( Options::OptionsList::iterator it = opt_list.begin(); it != opt_list.end(); it++ )
|
||||
for( PlaYUVerOptions::OptionsList::iterator it = opt_list.begin(); it != opt_list.end(); it++ )
|
||||
{
|
||||
delete *it;
|
||||
}
|
||||
}
|
||||
|
||||
OptionBase* Options::operator[]( const String& optName )
|
||||
OptionBase* PlaYUVerOptions::operator[]( const String& optName )
|
||||
{
|
||||
return getOption( optName );
|
||||
}
|
||||
|
||||
OptionBase* Options::getOption( const String& optName )
|
||||
OptionBase* PlaYUVerOptions::getOption( const String& optName )
|
||||
{
|
||||
Options::OptionMap::iterator opt_it;
|
||||
PlaYUVerOptions::OptionMap::iterator opt_it;
|
||||
opt_it = opt_short_map.find( optName );
|
||||
if( opt_it != opt_short_map.end() )
|
||||
{
|
||||
OptionsList opt_list = ( *opt_it ).second;
|
||||
for( Options::OptionsList::iterator it = opt_list.begin(); it != opt_list.end(); ++it )
|
||||
for( PlaYUVerOptions::OptionsList::iterator it = opt_list.begin(); it != opt_list.end(); ++it )
|
||||
{
|
||||
return ( *it )->opt;
|
||||
}
|
||||
@@ -84,7 +283,7 @@ OptionBase* Options::getOption( const String& optName )
|
||||
if( opt_it != opt_long_map.end() )
|
||||
{
|
||||
OptionsList opt_list = ( *opt_it ).second;
|
||||
for( Options::OptionsList::iterator it = opt_list.begin(); it != opt_list.end(); ++it )
|
||||
for( PlaYUVerOptions::OptionsList::iterator it = opt_list.begin(); it != opt_list.end(); ++it )
|
||||
{
|
||||
return ( *it )->opt;
|
||||
}
|
||||
@@ -92,12 +291,30 @@ OptionBase* Options::getOption( const String& optName )
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Bool Options::hasOpt( const String& optName )
|
||||
Bool PlaYUVerOptions::hasOpt( const String& optName )
|
||||
{
|
||||
return getOption( optName )->count() > 0 ? true : false;
|
||||
OptionBase* opt = getOption( optName );
|
||||
return opt ? opt->count() > 0 ? true : false : false;
|
||||
}
|
||||
|
||||
void Options::addOption( OptionBase *opt )
|
||||
Void PlaYUVerOptions::addDefaultOptions()
|
||||
{
|
||||
addOptions()/**/
|
||||
( "help,h", "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" );
|
||||
}
|
||||
|
||||
|
||||
PlaYUVerOptions& PlaYUVerOptions::addOptions()
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
void PlaYUVerOptions::addOption( OptionBase *opt )
|
||||
{
|
||||
Option* names = new Option();
|
||||
names->opt = opt;
|
||||
@@ -129,36 +346,22 @@ void Options::addOption( OptionBase *opt )
|
||||
opt_list.push_back( names );
|
||||
}
|
||||
|
||||
/* Helper method to initiate adding options to Options */
|
||||
OptionSpecific Options::addOptions()
|
||||
{
|
||||
return OptionSpecific( *this );
|
||||
}
|
||||
|
||||
/* for all options in opts, set their storage to their specified
|
||||
* default value */
|
||||
Void Options::setDefaults()
|
||||
{
|
||||
// for( Options::OptionsList::iterator it = opt_list.begin(); it != opt_list.end(); it++ )
|
||||
// {
|
||||
// ( *it )->opt->setDefault();
|
||||
// }
|
||||
}
|
||||
|
||||
static void setOptions( Options::OptionsList& opt_list, const string& value )
|
||||
static void setOptions( PlaYUVerOptions::OptionsList& opt_list, const string& value )
|
||||
{
|
||||
/* multiple options may be registered for the same name:
|
||||
* allow each to parse value */
|
||||
for( Options::OptionsList::iterator it = opt_list.begin(); it != opt_list.end(); ++it )
|
||||
for( PlaYUVerOptions::OptionsList::iterator it = opt_list.begin(); it != opt_list.end(); ++it )
|
||||
{
|
||||
( *it )->opt->parse( value );
|
||||
}
|
||||
}
|
||||
|
||||
Bool Options::storePair( Bool allow_long, Bool allow_short, const string& name, const string& value )
|
||||
Bool PlaYUVerOptions::storePair( Bool allow_long, Bool allow_short, const string& name, const string& value )
|
||||
{
|
||||
bool found = false;
|
||||
Options::OptionMap::iterator opt_it;
|
||||
PlaYUVerOptions::OptionMap::iterator opt_it;
|
||||
if( allow_long )
|
||||
{
|
||||
opt_it = opt_long_map.find( name );
|
||||
@@ -197,7 +400,7 @@ Bool Options::storePair( Bool allow_long, Bool allow_short, const string& name,
|
||||
return true;
|
||||
}
|
||||
|
||||
Bool Options::storePair( const string& name, const string& value )
|
||||
Bool PlaYUVerOptions::storePair( const string& name, const string& value )
|
||||
{
|
||||
return storePair( true, true, name, value );
|
||||
}
|
||||
@@ -205,7 +408,7 @@ Bool Options::storePair( const string& name, const string& value )
|
||||
/**
|
||||
* returns number of extra arguments consumed
|
||||
*/
|
||||
UInt Options::parseLONG( unsigned argc, const char* argv[] )
|
||||
UInt PlaYUVerOptions::parseLONG( UInt argc, Char* argv[] )
|
||||
{
|
||||
/* gnu style long options can take the forms:
|
||||
* --option=arg
|
||||
@@ -216,7 +419,7 @@ UInt Options::parseLONG( unsigned argc, const char* argv[] )
|
||||
size_t arg_opt_sep = arg.find_first_of( '=' );
|
||||
string option = arg.substr( arg_opt_start, arg_opt_sep - arg_opt_start );
|
||||
|
||||
unsigned extra_argc_consumed = 0;
|
||||
UInt extra_argc_consumed = 0;
|
||||
if( arg_opt_sep == string::npos )
|
||||
{
|
||||
/* no argument found => argument in argv[1] (maybe) */
|
||||
@@ -225,8 +428,8 @@ UInt Options::parseLONG( unsigned argc, const char* argv[] )
|
||||
/* commented out, to return to true GNU style processing
|
||||
* where longopts have to include an =, otherwise they are
|
||||
* booleans */
|
||||
if (argc == 1)
|
||||
return 0; /* run out of argv for argument */
|
||||
if( argc == 1 )
|
||||
return 0; /* run out of argv for argument */
|
||||
extra_argc_consumed = 1;
|
||||
#endif
|
||||
if( !storePair( true, false, option, "1" ) )
|
||||
@@ -246,7 +449,7 @@ UInt Options::parseLONG( unsigned argc, const char* argv[] )
|
||||
/**
|
||||
* returns number of extra arguments consumed
|
||||
*/
|
||||
UInt Options::parseLONG( string arg )
|
||||
UInt PlaYUVerOptions::parseLONG( string arg )
|
||||
{
|
||||
/* gnu style long options can take the forms:
|
||||
* --option=arg
|
||||
@@ -256,7 +459,7 @@ UInt Options::parseLONG( string arg )
|
||||
size_t arg_opt_sep = arg.find_first_of( '=' );
|
||||
string option = arg.substr( arg_opt_start, arg_opt_sep - arg_opt_start );
|
||||
|
||||
unsigned extra_argc_consumed = 0;
|
||||
UInt extra_argc_consumed = 0;
|
||||
if( arg_opt_sep == string::npos )
|
||||
{
|
||||
/* no argument found => argument in argv[1] (maybe) */
|
||||
@@ -275,7 +478,7 @@ UInt Options::parseLONG( string arg )
|
||||
return extra_argc_consumed;
|
||||
}
|
||||
|
||||
unsigned Options::parseSHORT( unsigned argc, const char* argv[] )
|
||||
UInt PlaYUVerOptions::parseSHORT( UInt argc, Char* argv[] )
|
||||
{
|
||||
/* short options can take the forms:
|
||||
* --option arg
|
||||
@@ -301,12 +504,38 @@ unsigned Options::parseSHORT( unsigned argc, const char* argv[] )
|
||||
return 1;
|
||||
}
|
||||
|
||||
list<const char*> Options::scanArgv( unsigned argc, const char* argv[] )
|
||||
Bool PlaYUVerOptions::parse( UInt argc, Char *argv[] )
|
||||
{
|
||||
try
|
||||
{
|
||||
m_aUnhandledArgs = scanArgv( argc, argv );
|
||||
|
||||
if( checkListingOpts() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch( std::exception& e )
|
||||
{
|
||||
std::cerr << "error: "
|
||||
<< e.what()
|
||||
<< "\n";
|
||||
return false;
|
||||
}
|
||||
catch( ... )
|
||||
{
|
||||
std::cerr << "Exception of unknown type!\n";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
list<const Char*> PlaYUVerOptions::scanArgv( UInt argc, Char *argv[] )
|
||||
{
|
||||
/* a list for anything that didn't get handled as an option */
|
||||
list<const char*> non_option_arguments;
|
||||
list<const Char*> non_option_arguments;
|
||||
|
||||
for( unsigned i = 1; i < argc; i++ )
|
||||
for( UInt i = 1; i < argc; i++ )
|
||||
{
|
||||
if( argv[i][0] != '-' )
|
||||
{
|
||||
@@ -325,7 +554,7 @@ list<const char*> Options::scanArgv( unsigned argc, const char* argv[] )
|
||||
{
|
||||
/* handle short (single dash) options */
|
||||
#if 0
|
||||
i += parsePOSIX(opts, argc - i, &argv[i]);
|
||||
i += parsePOSIX( opts, argc - i, &argv[i] );
|
||||
#else
|
||||
i += parseSHORT( argc - i, &argv[i] );
|
||||
#endif
|
||||
@@ -347,9 +576,9 @@ list<const char*> Options::scanArgv( unsigned argc, const char* argv[] )
|
||||
return non_option_arguments;
|
||||
}
|
||||
|
||||
Void Options::scanArgs( std::vector<String> args_array)
|
||||
Void PlaYUVerOptions::parse( std::vector<String> args_array )
|
||||
{
|
||||
for( unsigned i = 0; i < args_array.size(); i++ )
|
||||
for( UInt i = 0; i < args_array.size(); i++ )
|
||||
{
|
||||
i += parseLONG( args_array[i] );
|
||||
}
|
||||
@@ -362,13 +591,13 @@ static const char spaces[41] = " ";
|
||||
* using the formatting: "-x, --long",
|
||||
* if a short/long option isn't specified, it is not printed
|
||||
*/
|
||||
static void doHelpOpt( ostream& out, const Options::Option& entry, unsigned pad_short = 0 )
|
||||
static void doHelpOpt( ostream& out, const PlaYUVerOptions::Option& entry, UInt pad_short = 0 )
|
||||
{
|
||||
pad_short = min( pad_short, 8u );
|
||||
|
||||
if( !entry.opt_short.empty() )
|
||||
{
|
||||
unsigned pad = max( ( int )pad_short - ( int )entry.opt_short.front().size(), 0 );
|
||||
UInt pad = max( ( int )pad_short - ( int )entry.opt_short.front().size(), 0 );
|
||||
out << "-"
|
||||
<< entry.opt_short.front();
|
||||
if( !entry.opt_long.empty() )
|
||||
@@ -391,27 +620,27 @@ static void doHelpOpt( ostream& out, const Options::Option& entry, unsigned pad_
|
||||
}
|
||||
|
||||
/* format the help text */
|
||||
Void Options::doHelp( ostream& out, unsigned columns )
|
||||
Void PlaYUVerOptions::doHelp( ostream& out, UInt columns )
|
||||
{
|
||||
const unsigned pad_short = 3;
|
||||
const UInt pad_short = 3;
|
||||
/* first pass: work out the longest option name */
|
||||
unsigned max_width = 0;
|
||||
for( Options::OptionsList::iterator it = opt_list.begin(); it != opt_list.end(); it++ )
|
||||
UInt max_width = 0;
|
||||
for( PlaYUVerOptions::OptionsList::iterator it = opt_list.begin(); it != opt_list.end(); it++ )
|
||||
{
|
||||
ostringstream line( ios_base::out );
|
||||
doHelpOpt( line, **it, pad_short );
|
||||
max_width = max( max_width, ( unsigned )line.tellp() );
|
||||
max_width = max( max_width, ( UInt )line.tellp() );
|
||||
}
|
||||
|
||||
unsigned opt_width = min( max_width + 2, 28u + pad_short ) + 2;
|
||||
unsigned desc_width = columns - opt_width;
|
||||
UInt opt_width = min( max_width + 2, 28u + pad_short ) + 2;
|
||||
UInt desc_width = columns - opt_width;
|
||||
|
||||
/* second pass: write out formatted option and help text.
|
||||
* - align start of help text to start at opt_width
|
||||
* - if the option text is longer than opt_width, place the help
|
||||
* text at opt_width on the next line.
|
||||
*/
|
||||
for( Options::OptionsList::iterator it = opt_list.begin(); it != opt_list.end(); it++ )
|
||||
for( PlaYUVerOptions::OptionsList::iterator it = opt_list.begin(); it != opt_list.end(); it++ )
|
||||
{
|
||||
ostringstream line( ios_base::out );
|
||||
line << " ";
|
||||
@@ -489,5 +718,97 @@ Void Options::doHelp( ostream& out, unsigned columns )
|
||||
}
|
||||
}
|
||||
|
||||
Bool PlaYUVerOptions::checkListingOpts()
|
||||
{
|
||||
Bool bRet = false;
|
||||
|
||||
if( hasOpt( "version" ) )
|
||||
{
|
||||
std::cout << "PlaYUVer version "
|
||||
<< PLAYUVER_VERSION_STRING
|
||||
<< "\n";
|
||||
bRet |= true;
|
||||
}
|
||||
if( hasOpt( "pel_fmts" ) )
|
||||
{
|
||||
printf( "PlaYUVer supported pixel formats: \n" );
|
||||
for( UInt i = 0; i < PlaYUVerFrame::supportedPixelFormatListNames().size(); i++ )
|
||||
{
|
||||
printf( " %s\n", PlaYUVerFrame::supportedPixelFormatListNames()[i].c_str() );
|
||||
}
|
||||
bRet |= true;
|
||||
}
|
||||
if( hasOpt( "quality_metrics" ) )
|
||||
{
|
||||
printf( "PlaYUVer supported quality metrics: \n" );
|
||||
for( UInt i = 0; i < PlaYUVerFrame::supportedQualityMetricsList().size(); i++ )
|
||||
{
|
||||
printf( " %s\n", PlaYUVerFrame::supportedQualityMetricsList()[i].c_str() );
|
||||
}
|
||||
bRet |= true;
|
||||
}
|
||||
if( hasOpt( "module_list" ) || hasOpt( "module_list_full" ) )
|
||||
{
|
||||
listModules();
|
||||
bRet |= true;
|
||||
}
|
||||
return bRet;
|
||||
}
|
||||
|
||||
Void PlaYUVerOptions::listModules()
|
||||
{
|
||||
Bool bDetailed = false;
|
||||
|
||||
if( hasOpt( "module_list_full" ) )
|
||||
bDetailed = true;
|
||||
|
||||
PlaYUVerModuleIf* pcCurrModuleIf;
|
||||
PlaYUVerModuleFactoryMap& PlaYUVerModuleFactoryMap = PlaYUVerModuleFactory::Get()->getMap();
|
||||
PlaYUVerModuleFactoryMap::iterator it = PlaYUVerModuleFactoryMap.begin();
|
||||
|
||||
printf( "PlaYUVer available modules: \n" );
|
||||
printf( " [Internal Name] " );
|
||||
if( bDetailed )
|
||||
{
|
||||
printf( " [Full Name] " );
|
||||
printf( " [Type] " );
|
||||
printf( " [Description]" );
|
||||
}
|
||||
printf( " \n" );
|
||||
|
||||
Char ModuleNameString[40];
|
||||
|
||||
for( UInt i = 0; it != PlaYUVerModuleFactoryMap.end(); ++it, i++ )
|
||||
{
|
||||
printf( " " );
|
||||
printf( "%-30s", it->first );
|
||||
if( bDetailed )
|
||||
{
|
||||
ModuleNameString[0] = '\0';
|
||||
pcCurrModuleIf = it->second();
|
||||
|
||||
if( pcCurrModuleIf->m_pchModuleCategory )
|
||||
{
|
||||
strcat( ModuleNameString, pcCurrModuleIf->m_pchModuleCategory );
|
||||
strcat( ModuleNameString, "/" );
|
||||
}
|
||||
strcat( ModuleNameString, pcCurrModuleIf->m_pchModuleName );
|
||||
printf( " %-40s", ModuleNameString );
|
||||
switch( pcCurrModuleIf->m_iModuleType )
|
||||
{
|
||||
case FRAME_PROCESSING_MODULE:
|
||||
printf( " Processing " );
|
||||
break;
|
||||
case FRAME_MEASUREMENT_MODULE:
|
||||
printf( " Measurement " );
|
||||
break;
|
||||
}
|
||||
printf( " %s", pcCurrModuleIf->m_pchModuleTooltip );
|
||||
pcCurrModuleIf->Delete();
|
||||
}
|
||||
printf( "\n" );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+66
-258
@@ -45,53 +45,28 @@
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include "PlaYUVerDefs.h"
|
||||
|
||||
|
||||
struct Options;
|
||||
|
||||
struct ParseFailure: public std::exception
|
||||
{
|
||||
ParseFailure( String arg0, String val0 ) throw() :
|
||||
arg( arg0 ),
|
||||
val( val0 )
|
||||
{
|
||||
}
|
||||
|
||||
~ParseFailure() throw()
|
||||
{
|
||||
}
|
||||
|
||||
String arg;
|
||||
String val;
|
||||
|
||||
const char* what() const throw()
|
||||
{
|
||||
return "Option Parse Failure";
|
||||
}
|
||||
};
|
||||
|
||||
/** OptionBase: Virtual base class for storing information relating to a
|
||||
* specific option This base class describes common elements. Type specific
|
||||
* information should be stored in a derived class. */
|
||||
struct OptionBase
|
||||
* specific option This base class describes common elements.
|
||||
* Type specific information should be stored in a derived class.
|
||||
*/
|
||||
class OptionBase
|
||||
{
|
||||
public:
|
||||
OptionBase( const String& name, const String& desc ) :
|
||||
arg_count( 0 ),
|
||||
opt_string( name ),
|
||||
opt_desc( desc )
|
||||
{
|
||||
}
|
||||
arg_count( 0 ),
|
||||
opt_string( name ),
|
||||
opt_desc( desc )
|
||||
{ }
|
||||
|
||||
virtual ~OptionBase()
|
||||
{
|
||||
}
|
||||
virtual ~OptionBase() {}
|
||||
|
||||
/* parse argument arg, to obtain a value for the option */
|
||||
virtual void parse( const String& arg ) = 0;
|
||||
/* set the argument to the default value */
|
||||
//virtual void setDefault() = 0;
|
||||
int count()
|
||||
Int count()
|
||||
{
|
||||
return arg_count;
|
||||
}
|
||||
@@ -106,162 +81,17 @@ struct OptionBase
|
||||
Bool is_binary;
|
||||
};
|
||||
|
||||
/** Type specific option storage */
|
||||
struct FlagOpt: public OptionBase
|
||||
{
|
||||
FlagOpt( const String& name, Bool default_val, const String& desc ) :
|
||||
OptionBase( name, desc ),
|
||||
opt_storage( false ),
|
||||
opt_default_val( default_val )
|
||||
{
|
||||
is_binary = true;
|
||||
}
|
||||
|
||||
void parse( const String& arg )
|
||||
{
|
||||
opt_storage = true;
|
||||
arg_count++;
|
||||
}
|
||||
|
||||
void setDefault()
|
||||
{
|
||||
opt_storage = opt_default_val;
|
||||
}
|
||||
Bool opt_storage;
|
||||
Bool opt_default_val;
|
||||
};
|
||||
|
||||
/** Type specific option storage */
|
||||
template<typename T>
|
||||
struct StandardOpt: public OptionBase
|
||||
{
|
||||
StandardOpt( const String& name, T& storage, const String& desc ) :
|
||||
OptionBase( name, desc ),
|
||||
opt_storage( storage )
|
||||
{
|
||||
is_binary = false;
|
||||
}
|
||||
|
||||
void parse( const String& arg );
|
||||
|
||||
// void setDefault()
|
||||
// {
|
||||
// opt_storage = opt_default_val;
|
||||
// }
|
||||
|
||||
T& opt_storage;
|
||||
};
|
||||
|
||||
/* Generic parsing */
|
||||
template<typename T>
|
||||
inline void StandardOpt<T>::parse( const String& arg )
|
||||
{
|
||||
std::istringstream arg_ss( arg, std::istringstream::in );
|
||||
arg_ss.exceptions( std::ios::failbit );
|
||||
try
|
||||
{
|
||||
arg_ss >> opt_storage;
|
||||
}
|
||||
catch( ... )
|
||||
{
|
||||
throw ParseFailure( opt_string, arg );
|
||||
}
|
||||
arg_count++;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline void StandardOpt< std::vector<UInt> >::parse( const String& arg )
|
||||
{
|
||||
UInt aux_opt_storage;
|
||||
std::istringstream arg_ss( arg, std::istringstream::in );
|
||||
arg_ss.exceptions( std::ios::failbit );
|
||||
try
|
||||
{
|
||||
arg_ss >> aux_opt_storage;
|
||||
opt_storage.push_back( aux_opt_storage );
|
||||
}
|
||||
catch( ... )
|
||||
{
|
||||
throw ParseFailure( opt_string, arg );
|
||||
}
|
||||
arg_count++;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline void StandardOpt< std::vector<Int> >::parse( const String& arg )
|
||||
{
|
||||
Int aux_opt_storage;
|
||||
std::istringstream arg_ss( arg, std::istringstream::in );
|
||||
arg_ss.exceptions( std::ios::failbit );
|
||||
try
|
||||
{
|
||||
arg_ss >> aux_opt_storage;
|
||||
opt_storage.push_back( aux_opt_storage );
|
||||
}
|
||||
catch( ... )
|
||||
{
|
||||
throw ParseFailure( opt_string, arg );
|
||||
}
|
||||
arg_count++;
|
||||
}
|
||||
|
||||
/* string parsing is specialized */
|
||||
template<>
|
||||
inline void StandardOpt<String>::parse( const String& arg )
|
||||
{
|
||||
opt_storage = arg;
|
||||
arg_count++;
|
||||
}
|
||||
|
||||
/* string vector parsing is specialized */
|
||||
template<>
|
||||
inline void StandardOpt<std::vector<String> >::parse( const String& arg )
|
||||
{
|
||||
opt_storage.push_back( arg );
|
||||
arg_count++;
|
||||
}
|
||||
|
||||
/** Option class for argument handling using a user provided function */
|
||||
struct OptionFunc: public OptionBase
|
||||
{
|
||||
typedef Void (Func)( Options&, const String& );
|
||||
|
||||
OptionFunc( const String& name, Options& parent_, Func *func_, const String& desc ) :
|
||||
OptionBase( name, desc ),
|
||||
parent( parent_ ),
|
||||
func( func_ )
|
||||
{
|
||||
is_binary = false;
|
||||
}
|
||||
|
||||
void parse( const String& arg )
|
||||
{
|
||||
func( parent, arg );
|
||||
arg_count++;
|
||||
}
|
||||
|
||||
void setDefault()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
private:
|
||||
Options& parent;
|
||||
void (*func)( Options&, const String& );
|
||||
};
|
||||
|
||||
class OptionSpecific;
|
||||
class Options
|
||||
class PlaYUVerOptions
|
||||
{
|
||||
public:
|
||||
|
||||
struct Option
|
||||
{
|
||||
Option() :
|
||||
opt( 0 )
|
||||
opt( 0 )
|
||||
{
|
||||
}
|
||||
;
|
||||
~Option()
|
||||
{
|
||||
if( opt )
|
||||
@@ -271,56 +101,45 @@ public:
|
||||
std::list<String> opt_short;
|
||||
OptionBase* opt;
|
||||
};
|
||||
|
||||
|
||||
typedef std::list<Option*> OptionsList;
|
||||
|
||||
Options( const String& name = "" );
|
||||
~Options();
|
||||
PlaYUVerOptions( const String& name = "" );
|
||||
~PlaYUVerOptions();
|
||||
|
||||
Bool parse( UInt argc, Char *argv[] );
|
||||
Void parse( std::vector<String> args_array );
|
||||
|
||||
std::list<const Char*>& getUnhandledArgs()
|
||||
{
|
||||
return m_aUnhandledArgs;
|
||||
}
|
||||
|
||||
std::list<const char*> scanArgv( unsigned argc, const char* argv[] );
|
||||
Void scanArgs( std::vector<String> args_array);
|
||||
Void doHelp( std::ostream& out, unsigned columns = 80 );
|
||||
|
||||
OptionSpecific addOptions();
|
||||
Void setDefaults();
|
||||
|
||||
OptionBase* operator[]( const String& optName );
|
||||
OptionBase* getOption( const String& optName );
|
||||
|
||||
OptionsList& getOptionList()
|
||||
Bool hasOpt( const String& optName );
|
||||
|
||||
OptionsList getOptionList()
|
||||
{
|
||||
return opt_list;
|
||||
}
|
||||
|
||||
Bool hasOpt( const String& optName );
|
||||
|
||||
Void addDefaultOptions();
|
||||
PlaYUVerOptions& addOptions();
|
||||
void addOption( OptionBase *opt );
|
||||
|
||||
private:
|
||||
|
||||
typedef std::map<String, OptionsList> OptionMap;
|
||||
OptionMap opt_long_map;
|
||||
OptionMap opt_short_map;
|
||||
|
||||
OptionsList opt_list;
|
||||
|
||||
String m_cOptionGroupName;
|
||||
Bool m_bAllowUnkonw;
|
||||
|
||||
Bool storePair( Bool allow_long, Bool allow_short, const String& name, const String& value );
|
||||
Bool storePair( const String& name, const String& value );
|
||||
UInt parseLONG( unsigned argc, const char* argv[] );
|
||||
UInt parseLONG( String arg );
|
||||
unsigned parseSHORT( unsigned argc, const char* argv[] );
|
||||
};
|
||||
|
||||
/* Class with templated overloaded operator(), for use by Options::addOptions() */
|
||||
class OptionSpecific
|
||||
{
|
||||
public:
|
||||
OptionSpecific( Options& parent_ ) :
|
||||
parent( parent_ )
|
||||
{
|
||||
}
|
||||
/**
|
||||
* Add option described by name to the parent Options list,
|
||||
* with storage for the option's value
|
||||
* with default_val as the default value
|
||||
* with desc as an optional help description
|
||||
*/
|
||||
PlaYUVerOptions&
|
||||
operator()( const String& name, const String& desc );
|
||||
|
||||
/**
|
||||
* Add option described by name to the parent Options list,
|
||||
@@ -329,38 +148,9 @@ public:
|
||||
* with desc as an optional help description
|
||||
*/
|
||||
template<typename T>
|
||||
OptionSpecific&
|
||||
operator()( const String& name, T& storage, const String& desc )
|
||||
{
|
||||
parent.addOption( new StandardOpt<T>( name, storage, desc ) );
|
||||
return *this;
|
||||
}
|
||||
PlaYUVerOptions&
|
||||
operator()( const String& name, T& storage, const String& desc );
|
||||
|
||||
/**
|
||||
* Add option described by name to the parent Options list,
|
||||
* with storage for the option's value
|
||||
* with default_val as the default value
|
||||
* with desc as an optional help description
|
||||
*/
|
||||
OptionSpecific&
|
||||
operator()( const String& name, const String& desc )
|
||||
{
|
||||
parent.addOption( new FlagOpt( name, false, desc ) );
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add option described by name to the parent Options list,
|
||||
* with storage for the option's value
|
||||
* with default_val as the default value
|
||||
* with desc as an optional help description
|
||||
*/
|
||||
OptionSpecific&
|
||||
operator()( const String& name, Bool default_val, const String& desc )
|
||||
{
|
||||
parent.addOption( new FlagOpt( name, default_val, desc ) );
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add option described by name to the parent Options list,
|
||||
@@ -369,14 +159,32 @@ public:
|
||||
* OptionFunc::Func is called. It is upto this function to correctly
|
||||
* handle evaluating the option's value.
|
||||
*/
|
||||
OptionSpecific&
|
||||
operator()( const String& name, OptionFunc::Func *func, const String& desc )
|
||||
{
|
||||
parent.addOption( new OptionFunc( name, parent, func, desc ) );
|
||||
return *this;
|
||||
}
|
||||
// PlaYUVerOptions&
|
||||
// operator()( const String& name, OptionFunc::Func *func, const String& desc );
|
||||
|
||||
|
||||
Bool checkListingOpts();
|
||||
Void listModules();
|
||||
|
||||
private:
|
||||
Options& parent;
|
||||
typedef std::map<String, OptionsList> OptionMap;
|
||||
OptionMap opt_long_map;
|
||||
OptionMap opt_short_map;
|
||||
|
||||
OptionsList opt_list;
|
||||
|
||||
String m_cOptionGroupName;
|
||||
Bool m_bAllowUnkonw;
|
||||
std::list<const Char*> m_aUnhandledArgs;
|
||||
|
||||
Bool storePair( Bool allow_long, Bool allow_short, const String& name, const String& value );
|
||||
Bool storePair( const String& name, const String& value );
|
||||
UInt parseLONG( UInt argc, Char* argv[] );
|
||||
UInt parseLONG( String arg );
|
||||
UInt parseSHORT( UInt argc, Char* argv[] );
|
||||
std::list<const char*> scanArgv( UInt argc, Char* argv[] );
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // __PROGRAMOPTIONS_H__
|
||||
+11
-11
@@ -196,14 +196,14 @@ Bool PlaYUVerStream::open( String filename, UInt width, UInt height, Int input_f
|
||||
m_pfctCreateHandler = PlaYUVerStream::findStreamHandler( filename, m_bIsInput );
|
||||
if( !m_pfctCreateHandler )
|
||||
{
|
||||
throw "[PlaYUVerStream] Invalid handler";
|
||||
throw PlaYUVerFailure("PlaYUVerStream", "Invalid handler");
|
||||
}
|
||||
|
||||
m_pcHandler = m_pfctCreateHandler();
|
||||
|
||||
if( !m_pcHandler )
|
||||
{
|
||||
throw "[PlaYUVerStream] Cannot create handler";
|
||||
throw PlaYUVerFailure("PlaYUVerStream", "Cannot create handler");
|
||||
}
|
||||
|
||||
m_cFilename = filename;
|
||||
@@ -220,7 +220,7 @@ Bool PlaYUVerStream::open( String filename, UInt width, UInt height, Int input_f
|
||||
if( !m_pcHandler->openHandler( m_cFilename, m_bIsInput ) )
|
||||
{
|
||||
close();
|
||||
throw "[PlaYUVerStream] Cannot open file";
|
||||
throw PlaYUVerFailure("PlaYUVerStream", "Cannot open file " + m_cFilename );
|
||||
return m_bInit;
|
||||
}
|
||||
|
||||
@@ -228,7 +228,7 @@ Bool PlaYUVerStream::open( String filename, UInt width, UInt height, Int input_f
|
||||
if( m_pcHandler->m_uiWidth <= 0 || m_pcHandler->m_uiHeight <= 0 || m_pcHandler->m_iPixelFormat < 0 )
|
||||
{
|
||||
close();
|
||||
throw "[PlaYUVerStream] Incorrect configuration";
|
||||
throw PlaYUVerFailure("PlaYUVerStream", "Incorrect configuration");
|
||||
return m_bInit;
|
||||
}
|
||||
|
||||
@@ -244,7 +244,7 @@ Bool PlaYUVerStream::open( String filename, UInt width, UInt height, Int input_f
|
||||
catch( const char *msg )
|
||||
{
|
||||
close();
|
||||
throw "[PlaYUVerStream] Cannot allocated frame buffer";
|
||||
throw PlaYUVerFailure("PlaYUVerStream", "Cannot allocated frame buffer");
|
||||
return m_bInit;
|
||||
}
|
||||
}
|
||||
@@ -261,14 +261,14 @@ Bool PlaYUVerStream::open( String filename, UInt width, UInt height, Int input_f
|
||||
if( m_bIsInput && m_uiTotalFrameNum <= 0 )
|
||||
{
|
||||
close();
|
||||
throw "[PlaYUVerStream] Incorrect configuration: less than one frame";
|
||||
throw PlaYUVerFailure("PlaYUVerStream", "Incorrect configuration: less than one frame");
|
||||
return m_bInit;
|
||||
}
|
||||
|
||||
if( !m_pcHandler->configureBuffer( m_pcCurrFrame ) )
|
||||
{
|
||||
close();
|
||||
throw "[PlaYUVerStream] Cannot allocated memory";
|
||||
throw PlaYUVerFailure("PlaYUVerStream", "Cannot allocated memory");
|
||||
return m_bInit;
|
||||
}
|
||||
|
||||
@@ -286,7 +286,7 @@ Bool PlaYUVerStream::reload()
|
||||
m_pcHandler->closeHandler();
|
||||
if( !m_pcHandler->openHandler( m_cFilename, m_bIsInput ) )
|
||||
{
|
||||
throw "[PlaYUVerStream] Cannot open file using FFmpeg libs";
|
||||
throw PlaYUVerFailure("PlaYUVerStream", "Cannot open file");
|
||||
}
|
||||
m_pcHandler->setBytesPerFrame( m_pcCurrFrame->getBytesPerFrame() );
|
||||
m_uiTotalFrameNum = m_pcHandler->calculateFrameNumber();
|
||||
@@ -466,7 +466,7 @@ Void PlaYUVerStream::readFrame()
|
||||
|
||||
if( !m_pcHandler->read( m_pcNextFrame ) )
|
||||
{
|
||||
throw "[PlaYUVerStream] Cannot read file";
|
||||
throw PlaYUVerFailure("PlaYUVerStream", "Cannot read file");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -483,7 +483,7 @@ Void PlaYUVerStream::writeFrame( PlaYUVerFrame *pcFrame )
|
||||
{
|
||||
if( !m_pcHandler->write( pcFrame ) )
|
||||
{
|
||||
throw "[PlaYUVerStream] Cannot write into the file";
|
||||
throw PlaYUVerFailure("PlaYUVerStream", "Cannot write into the file");
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -588,7 +588,7 @@ Bool PlaYUVerStream::seekInput( UInt64 new_frame_num )
|
||||
|
||||
if( !m_pcHandler->seek( new_frame_num ) )
|
||||
{
|
||||
throw "[PlaYUVerStream] Cannot write into the file";
|
||||
throw PlaYUVerFailure("PlaYUVerStream", "Cannot write into the file");
|
||||
}
|
||||
|
||||
m_uiCurrFrameFileIdx = new_frame_num;
|
||||
|
||||
@@ -103,8 +103,8 @@ public:
|
||||
String getFormatName();
|
||||
String getCodecName();
|
||||
|
||||
Bool open( String filename, String resolution, String input_format, UInt bitsPel, Int endianness, UInt frame_rate, Bool bInput = true );
|
||||
Bool open( String filename, UInt width, UInt height, Int input_format, UInt bitsPel, Int endianness, UInt frame_rate, Bool bInput = true );
|
||||
Bool open( String filename, String resolution, String input_format, UInt bitsPel, Int endianness, UInt frame_rate, Bool bInput );
|
||||
Bool open( String filename, UInt width, UInt height, Int input_format, UInt bitsPel, Int endianness, UInt frame_rate, Bool bInput );
|
||||
Bool reload();
|
||||
Void close();
|
||||
|
||||
|
||||
@@ -216,7 +216,7 @@ Bool StreamHandlerLibav::openHandler( String strFilename, Bool bInput )
|
||||
}
|
||||
if( m_iPixelFormat == PlaYUVerFrame::NO_FMT )
|
||||
{
|
||||
throw "Cannot open file using FFmpeg libs - unsupported pixel format";
|
||||
throw PlaYUVerFailure("Cannot open file using FFmpeg libs - unsupported pixel format");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user