[Developers] new constructors for the *Param* classes
Helene Huck
helene.huck at dgb-group.com
Mon Aug 4 15:49:18 CEST 2008
Hi all,
For those of you developing attribute-plugins to OpendTect, this might
be interesting to know: in release v3.2 some constructors have been
added for convenience in the *Param* classes [in
include/AttributeEngine/attribparam.h] . Those new constructors aim to
simplify the declarations of all the different parameters required for
one attribute, it sums up in one go the most commonly used settings:
the parameter name, its default value and whether it is required or not
(optional).
The scheme is always the same:
TypeParam( const char* paramname, Type defaultvalue, bool isreq=true)
for instance the BinIDParam new constructor is:
BinIDParam(const char*,const BinID&,bool isreq=true);
Let's just take a realistic example, for instance an abstract of the
Attrib::Frequency::initClass() [src/Attributes/frequency.cc] was:
> BoolParam* normalize = new BoolParam( normalizeStr() );
> normalize->setDefaultValue( false );
> desc->addParam( normalize );
>
> StringParam* window = new StringParam( windowStr() );
> window->setDefaultValue( "CosTaper" );
> desc->addParam( window );
>
> FloatParam* variable = new FloatParam( paramvalStr() );
> const float defval = 0.95;
> variable->setDefaultValue( defval );
> variable->setRequired( false );
> desc->addParam(variable);
>
> BoolParam* dumptofile = new BoolParam( dumptofileStr() );
> dumptofile->setDefaultValue( false );
> dumptofile->setValue( false );
> dumptofile->setRequired( false );
> desc->addParam( dumptofile );
and can now be replaced by only 4 lines:
> desc->addParam( new BoolParam( normalizeStr(), false ) );
> desc->addParam( new StringParam( windowStr(), "CosTaper" ) );
> desc->addParam( new FloatParam( paramvalStr(), 0.95, false ) );
> desc->addParam( new BoolParam( dumptofileStr(), false, false ) )
which saves quite some time!
Setting some limits to the parameters is also easier:
TypeParam::setLimits( Type minval, Type maxval )
We will of course keep the old contructors anyway, so you do not have to
update any of your code, this is only user-friendlier for the future
attributes makers!
Best regards,
Helene
--
-- Helene Huck
-- Geophysical software engineer
-- dGB Earth Sciences B.V.
-- Nijverheidstraat 11-2, 7511 JM Enschede, The Netherlands
-- mailto: helene.huck at dgb-group.com, http://www.dgb-group.com
-- Tel: +31 53 4315155 , Fax: +31 53 4315104
More information about the Developers
mailing list