bpp-core3  3.0.0
bpp::Parameter Class Reference

This class is designed to facilitate the manipulation of parameters. More...

#include <Bpp/Numeric/Parameter.h>

+ Inheritance diagram for bpp::Parameter:
+ Collaboration diagram for bpp::Parameter:

Public Member Functions

 Parameter ()
 Default contructor. Creates a parameter with no name, no constraint, and a value of 0. More...
 
 Parameter (const std::string &name, double value, std::shared_ptr< Constraint > constraint=0, double precision=0)
 Build a new parameter. More...
 
 Parameter (const std::string &name, double value, std::shared_ptr< Constraint > constraint, bool precision)=delete
 
 Parameter (const Parameter &param)
 Copy constructor. More...
 
Parameteroperator= (const Parameter &param)
 Assignment operator. More...
 
virtual ~Parameter ()
 
Parameterclone () const
 Create a copy of this object and send a pointer to it. More...
 
virtual void setName (const std::string &name)
 Set the name of this parameter. More...
 
virtual void setValue (double value)
 Set the value of this parameter. More...
 
void setPrecision (double precision)
 Set the precision of this parameter. More...
 
virtual const std::string & getName () const
 Get the name of this parameter. More...
 
virtual double getValue () const
 Get the value of this parameter. More...
 
virtual double getPrecision () const
 Get the precision of this parameter. More...
 
virtual const std::shared_ptr< ConstraintgetConstraint () const
 Return the constraint associated to this parameter if there is one. More...
 
virtual std::shared_ptr< ConstraintgetConstraint ()
 Return the constraint associated to this parameter if there is one. More...
 
virtual bool hasConstraint () const
 Tells if this parameter has a constraint. More...
 
virtual std::shared_ptr< ConstraintremoveConstraint ()
 Remove the constraint associated to this parameter. More...
 
virtual void setConstraint (std::shared_ptr< Constraint > constraint)
 Set a constraint to this parameter. More...
 
virtual void addParameterListener (ParameterListener *listener, bool attachListener=true)
 Add a new listener to this parameter. More...
 
virtual void removeParameterListener (const std::string &listenerId)
 Remove all listeners with a given id from this parameter. More...
 
virtual bool hasParameterListener (const std::string &listenerId)
 Tell is there is a listener with a given id from this parameter. More...
 

Static Public Attributes

static const std::shared_ptr< IntervalConstraintR_PLUS
 
static const std::shared_ptr< IntervalConstraintR_PLUS_STAR
 
static const std::shared_ptr< IntervalConstraintR_MINUS
 
static const std::shared_ptr< IntervalConstraintR_MINUS_STAR
 
static const std::shared_ptr< IntervalConstraintPROP_CONSTRAINT_IN
 
static const std::shared_ptr< IntervalConstraintPROP_CONSTRAINT_EX
 

Protected Member Functions

void fireParameterNameChanged (ParameterEvent &event)
 
void fireParameterValueChanged (ParameterEvent &event)
 
void fireParameterConstraintChanged (ParameterEvent &event)
 

Protected Attributes

std::string name_
 
double value_
 
double precision_
 
std::shared_ptr< Constraintconstraint_
 
std::vector< ParameterListener * > listeners_
 
std::vector< bool > listenerAttach_
 

Detailed Description

This class is designed to facilitate the manipulation of parameters.

A parameter object contains a value stored as a double. It also contains a name and optionaly a constraint. Constraint objects allows to apply restriction on the value of the parameter, for instance positive number, or a particular interval and so on.

See also
ParameterList, Parametrizable, Constraint.

Definition at line 133 of file Parameter.h.

Constructor & Destructor Documentation

◆ Parameter() [1/4]

bpp::Parameter::Parameter ( )
inline

Default contructor. Creates a parameter with no name, no constraint, and a value of 0.

Definition at line 150 of file Parameter.h.

Referenced by clone().

◆ Parameter() [2/4]

Parameter::Parameter ( const std::string &  name,
double  value,
std::shared_ptr< Constraint constraint = 0,
double  precision = 0 
)

Build a new parameter.

Parameters
nameThe parameter name.
valueThe parameter value.
constraintAn optional pointer toward a constraint Object. The constraint will be copied and attached to this instance.
precisionAn optional parameter precision (default 0)
Exceptions
ConstraintExceptionIf the parameter value does not match the contraint.

Constructors:

Definition at line 59 of file Parameter.cpp.

References setPrecision(), and setValue().

◆ Parameter() [3/4]

bpp::Parameter::Parameter ( const std::string &  name,
double  value,
std::shared_ptr< Constraint constraint,
bool  precision 
)
delete

◆ Parameter() [4/4]

Parameter::Parameter ( const Parameter param)

Copy constructor.

Definition at line 66 of file Parameter.cpp.

References listenerAttach_, and listeners_.

◆ ~Parameter()

Parameter::~Parameter ( )
virtual

Destructor:

Definition at line 99 of file Parameter.cpp.

References listenerAttach_, and listeners_.

Member Function Documentation

◆ addParameterListener()

virtual void bpp::Parameter::addParameterListener ( ParameterListener listener,
bool  attachListener = true 
)
inlinevirtual

Add a new listener to this parameter.

Parameters
listenerThe listener to add.
attachListenerTell if the parameter will own this listener. If so, deep copies will be made when cloning the parameter, and the listener will be destroyed upon destruction of the parameter or upon removal. Alternatively, only superficial copies will be made, and the listener will persist if the parameter is destroyed.

Definition at line 278 of file Parameter.h.

References listenerAttach_, and listeners_.

Referenced by bpp::AbstractParameterAliasable::aliasParameters().

◆ clone()

Parameter* bpp::Parameter::clone ( ) const
inlinevirtual

◆ fireParameterConstraintChanged()

void bpp::Parameter::fireParameterConstraintChanged ( ParameterEvent event)
inlineprotected

Definition at line 316 of file Parameter.h.

References listeners_.

◆ fireParameterNameChanged()

void bpp::Parameter::fireParameterNameChanged ( ParameterEvent event)
inlineprotected

Definition at line 300 of file Parameter.h.

References listeners_.

Referenced by setName().

◆ fireParameterValueChanged()

void bpp::Parameter::fireParameterValueChanged ( ParameterEvent event)
inlineprotected

Definition at line 308 of file Parameter.h.

References listeners_.

Referenced by setValue().

◆ getConstraint() [1/2]

virtual std::shared_ptr<Constraint> bpp::Parameter::getConstraint ( )
inlinevirtual

Return the constraint associated to this parameter if there is one.

Returns
A shared pointer toward the constraint, or NULL if there is no constraint.

Definition at line 242 of file Parameter.h.

References constraint_.

◆ getConstraint() [2/2]

virtual const std::shared_ptr<Constraint> bpp::Parameter::getConstraint ( ) const
inlinevirtual

Return the constraint associated to this parameter if there is one.

Returns
A shared pointer toward the constraint, or NULL if there is no constraint.

Definition at line 233 of file Parameter.h.

References constraint_.

Referenced by bpp::AbstractParameterAliasable::aliasParameters(), bpp::ReparametrizationFunctionWrapper::init_(), bpp::ParameterList::matchParametersValues(), bpp::AliasParameterListener::parameterConstraintChanged(), bpp::ParameterList::setParametersValues(), and bpp::ParameterList::testParametersValues().

◆ getName()

◆ getPrecision()

virtual double bpp::Parameter::getPrecision ( ) const
inlinevirtual

Get the precision of this parameter.

Returns
The precision value.

Definition at line 225 of file Parameter.h.

References precision_.

◆ getValue()

◆ hasConstraint()

virtual bool bpp::Parameter::hasConstraint ( ) const
inlinevirtual

Tells if this parameter has a constraint.

Returns
True if this parameter has a contraint.

Definition at line 249 of file Parameter.h.

References constraint_.

Referenced by bpp::AbstractParameterAliasable::aliasParameters(), bpp::ParameterList::matchParametersValues(), bpp::ParameterList::setParametersValues(), and bpp::ParameterList::testParametersValues().

◆ hasParameterListener()

bool Parameter::hasParameterListener ( const std::string &  listenerId)
virtual

Tell is there is a listener with a given id from this parameter.

Parameters
listenerIdThe id of listener to remove.
Returns
True if at list one listener with the given id was found.

Definition at line 165 of file Parameter.cpp.

References listeners_.

◆ operator=()

Parameter & Parameter::operator= ( const Parameter param)

Assignment operator.

Definition at line 81 of file Parameter.cpp.

References constraint_, listenerAttach_, listeners_, name_, precision_, and value_.

Referenced by bpp::AutoParameter::operator=().

◆ removeConstraint()

std::shared_ptr< Constraint > Parameter::removeConstraint ( )
virtual

Remove the constraint associated to this parameter.

Warning! The contraint objet is not deleted.

Returns
A pointer toward the formerly used contraint.

Definition at line 140 of file Parameter.cpp.

References constraint_.

Referenced by bpp::SimpleDiscreteDistribution::restrictToConstraint().

◆ removeParameterListener()

void Parameter::removeParameterListener ( const std::string &  listenerId)
virtual

Remove all listeners with a given id from this parameter.

Parameters
listenerIdThe id of listener to remove.

Definition at line 149 of file Parameter.cpp.

References listenerAttach_, and listeners_.

Referenced by bpp::AbstractParameterAliasable::unaliasParameters().

◆ setConstraint()

void Parameter::setConstraint ( std::shared_ptr< Constraint constraint)
virtual

◆ setName()

virtual void bpp::Parameter::setName ( const std::string &  name)
inlinevirtual

Set the name of this parameter.

Parameters
namethe new parameter name.

Definition at line 185 of file Parameter.h.

References fireParameterNameChanged(), and name_.

Referenced by bpp::ParametrizableCollection< N >::addObject(), and bpp::FullHmmTransitionMatrix::setTransitionProbabilities().

◆ setPrecision()

void Parameter::setPrecision ( double  precision)

Set the precision of this parameter.

Parameters
precisionthe new parameter precision.

Precision:

Definition at line 124 of file Parameter.cpp.

References precision_.

Referenced by Parameter().

◆ setValue()

Member Data Documentation

◆ constraint_

std::shared_ptr<Constraint> bpp::Parameter::constraint_
protected

◆ listenerAttach_

std::vector<bool> bpp::Parameter::listenerAttach_
protected

◆ listeners_

◆ name_

std::string bpp::Parameter::name_
protected

Definition at line 137 of file Parameter.h.

Referenced by getName(), operator=(), setName(), and bpp::AutoParameter::setValue().

◆ precision_

double bpp::Parameter::precision_
protected

Definition at line 139 of file Parameter.h.

Referenced by getPrecision(), operator=(), setPrecision(), and setValue().

◆ PROP_CONSTRAINT_EX

const std::shared_ptr< IntervalConstraint > Parameter::PROP_CONSTRAINT_EX
static

◆ PROP_CONSTRAINT_IN

◆ R_MINUS

const std::shared_ptr< IntervalConstraint > Parameter::R_MINUS
static

Definition at line 327 of file Parameter.h.

◆ R_MINUS_STAR

const std::shared_ptr< IntervalConstraint > Parameter::R_MINUS_STAR
static

Definition at line 328 of file Parameter.h.

◆ R_PLUS

◆ R_PLUS_STAR

const std::shared_ptr< IntervalConstraint > Parameter::R_PLUS_STAR
static

◆ value_

double bpp::Parameter::value_
protected

Definition at line 138 of file Parameter.h.

Referenced by getValue(), operator=(), setConstraint(), and setValue().


The documentation for this class was generated from the following files: