bpp-core  2.1.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:

List of all members.

Public Member Functions

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

Static Public Attributes

static const IntervalConstraint R_PLUS
static const IntervalConstraint R_PLUS_STAR
static const IntervalConstraint R_MINUS
static const IntervalConstraint R_MINUS_STAR
static const IntervalConstraint PROP_CONSTRAINT_IN
static const IntervalConstraint PROP_CONSTRAINT_EX

Protected Member Functions

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

Protected Attributes

std::string name_
double value_
double precision_
Constraintconstraint_
bool attach_
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 135 of file Parameter.h.


Constructor & Destructor Documentation

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

Definition at line 152 of file Parameter.h.

Referenced by clone().

Parameter::Parameter ( const std::string &  name,
double  value,
Constraint constraint,
bool  attachConstraint,
double  precision = 0 
) throw (ConstraintException)

Build a new parameter.

Parameters:
nameThe parameter name.
valueThe parameter value.
constraintA pointer toward a constraint Object.
attachConstraintTell if the constraint must be attached to this parameter, or shared
precisionAn optional parameter precision (default 0) between different objects (the default behavior, for backward compatibility). If the first case, the constraint object will be destroyed when the parameter is destroyed, and duplicated when the parameter is copied.
Exceptions:
ConstraintExceptionIf the parameter value does not match the contraint.

Constructors:

Definition at line 57 of file Parameter.cpp.

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

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.

Definition at line 66 of file Parameter.cpp.

Parameter::Parameter ( const Parameter param)

Copy constructor.

Definition at line 75 of file Parameter.cpp.

References attach_, bpp::Constraint::clone(), constraint_, listenerAttach_, and listeners_.

Parameter::~Parameter ( ) [virtual]

Destructor:

Definition at line 113 of file Parameter.cpp.

References attach_, constraint_, listenerAttach_, and listeners_.


Member Function Documentation

virtual void bpp::Parameter::addParameterListener ( ParameterListener listener,
bool  attachListener = true 
) [inline, virtual]

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 299 of file Parameter.h.

References listenerAttach_, and listeners_.

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

Parameter* bpp::Parameter::clone ( ) const [inline, virtual]

Create a copy of this object and send a pointer to it.

Returns:
A pointer toward the copy object.

Implements bpp::Clonable.

Reimplemented in bpp::PlaceboTransformedParameter, bpp::IntervalTransformedParameter, bpp::RTransformedParameter, bpp::AutoParameter, and bpp::TransformedParameter.

Definition at line 199 of file Parameter.h.

References Parameter().

Referenced by bpp::AbstractParameterAliasable::addParameter_(), and bpp::ParameterList::getCommonParametersWith().

void bpp::Parameter::fireParameterNameChanged ( ParameterEvent event) [inline, protected]

Definition at line 321 of file Parameter.h.

References listeners_.

Referenced by setName().

void bpp::Parameter::fireParameterValueChanged ( ParameterEvent event) [inline, protected]

Definition at line 326 of file Parameter.h.

References listeners_.

virtual const Constraint* bpp::Parameter::getConstraint ( ) const [inline, virtual]

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

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

Definition at line 255 of file Parameter.h.

References constraint_.

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

virtual Constraint* bpp::Parameter::getConstraint ( ) [inline, virtual]

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

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

Definition at line 262 of file Parameter.h.

References constraint_.

virtual double bpp::Parameter::getPrecision ( ) const [inline, virtual]

Get the precision of this parameter.

Returns:
The precision value.

Definition at line 248 of file Parameter.h.

References precision_.

virtual bool bpp::Parameter::hasConstraint ( ) const [inline, virtual]

Tells if this parameter has a constraint.

Returns:
True if this parameter has a contraint.

Definition at line 269 of file Parameter.h.

References constraint_.

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

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 187 of file Parameter.cpp.

References listeners_.

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

Assignment operator.

Definition at line 93 of file Parameter.cpp.

References attach_, bpp::Constraint::clone(), constraint_, listenerAttach_, listeners_, name_, precision_, and value_.

const 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 163 of file Parameter.cpp.

References constraint_.

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

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 172 of file Parameter.cpp.

References listenerAttach_, and listeners_.

void Parameter::setConstraint ( Constraint constraint,
bool  attach = false 
) [virtual]

Set a constraint to this parameter.

Parameters:
constrainta pointer to the constraint (may be null)
attachsays if the constraint is attached to the Parameter (default: false).
Returns:
A pointer toward the formerly used contraint.

Constraint:

Definition at line 143 of file Parameter.cpp.

References attach_, constraint_, bpp::Constraint::isCorrect(), and value_.

Referenced by bpp::ConstantDistribution::restrictToConstraint(), bpp::TruncatedExponentialDiscreteDistribution::restrictToConstraint(), and bpp::SimpleDiscreteDistribution::restrictToConstraint().

virtual void bpp::Parameter::setName ( const std::string &  name) [inline, virtual]

Set the name of this parameter.

Parameters:
namethe new parameter name.

Definition at line 208 of file Parameter.h.

References fireParameterNameChanged(), and name_.

void Parameter::setPrecision ( double  precision)

Set the precision of this parameter.

Parameters:
precisionthe new parameter precision.

Precision:

Definition at line 136 of file Parameter.cpp.

References precision_.


Member Data Documentation

bool bpp::Parameter::attach_ [protected]

Definition at line 143 of file Parameter.h.

Referenced by operator=(), Parameter(), setConstraint(), and ~Parameter().

std::vector<bool> bpp::Parameter::listenerAttach_ [protected]
std::string bpp::Parameter::name_ [protected]

Definition at line 139 of file Parameter.h.

Referenced by getName(), operator=(), and setName().

double bpp::Parameter::precision_ [protected]

Definition at line 141 of file Parameter.h.

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

Definition at line 338 of file Parameter.h.

Definition at line 335 of file Parameter.h.

Definition at line 336 of file Parameter.h.

double bpp::Parameter::value_ [protected]

Definition at line 140 of file Parameter.h.

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


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Friends