bpp-core3  3.0.0
Parametrizable.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
5 #ifndef BPP_NUMERIC_PARAMETRIZABLE_H
6 #define BPP_NUMERIC_PARAMETRIZABLE_H
7 
8 
9 // From Utils:
10 #include "../Clonable.h"
11 
12 // From the STL:
13 #include <string>
14 
15 #include "ParameterList.h"
16 
17 namespace bpp
18 {
25  public virtual Clonable
26 {
27 public:
29  virtual ~Parametrizable() {}
30 
31 public:
38  virtual bool hasParameter(const std::string& name) const = 0;
39 
46  virtual const ParameterList& getParameters() const = 0;
47 
55  virtual const Parameter& parameter(const std::string& name) const = 0;
56 
63  virtual double getParameterValue(const std::string& name) const
64  = 0;
65 
77  virtual void setAllParametersValues(const ParameterList& parameters) = 0;
78 
88  virtual void setParameterValue(const std::string& name, double value) = 0;
89 
100  virtual void setParametersValues(const ParameterList& parameters) = 0;
101 
112  virtual bool matchParametersValues(const ParameterList& parameters) = 0;
113 
120  virtual void removeConstraint(const std::string& name) = 0;
121 
129  virtual void setConstraint(const std::string& name, std::shared_ptr<ConstraintInterface> constraint) = 0;
130 
137  virtual size_t getNumberOfParameters() const = 0;
138 
145  virtual void setNamespace(const std::string& prefix) = 0;
146 
150  virtual std::string getNamespace() const = 0;
151 
157  virtual std::string getParameterNameWithoutNamespace(const std::string& name) const = 0;
158 
159 protected:
167  virtual ParameterList& getParameters_() = 0;
168 };
169 
176  public virtual Parametrizable
177 {
178 protected:
181 
182 public:
183  ParametrizableAdapter() : parameters_(), parameter_() {}
185 
186 public:
192  bool hasParameter(const std::string& name) const override { return parameters_.hasParameter(name); }
193  const ParameterList& getParameters() const override { return parameters_; }
194  const Parameter& parameter(const std::string& name) const override { return parameter_; }
195  double getParameterValue(const std::string& name) const override { return 0; }
196  void setAllParametersValues(const ParameterList& parameters) override {}
197  void setParameterValue(const std::string& name, double value) override {}
198  void setParametersValues(const ParameterList& parameters) override {}
199  bool matchParametersValues(const ParameterList& parameters) override { return false; }
200  void removeConstraint(const std::string& name) override {}
201  void setConstraint(const std::string& name, std::shared_ptr<ConstraintInterface> constraint) override {}
202  size_t getNumberOfParameters() const override { return 0; }
203  void setNamespace(const std::string& prefix) override {}
204  std::string getNamespace() const override { return ""; }
205  std::string getParameterNameWithoutNamespace(const std::string& name) const override { return name; }
207 };
208 } // end of namespace bpp.
209 #endif // BPP_NUMERIC_PARAMETRIZABLE_H
virtual bool matchParametersValues(const ParameterList &parameters)=0
Update the parameters from parameters.
std::string getNamespace() const override
void setAllParametersValues(const ParameterList &parameters) override
Set the parameters values to be equals to those of parameters.
virtual void setParameterValue(const std::string &name, double value)=0
Set the value of parameter with name name to be equal to value.
virtual double getParameterValue(const std::string &name) const =0
Get the value for parameter of name &#39;name&#39;.
virtual std::string getNamespace() const =0
virtual const ParameterList & getParameters() const =0
Get all parameters available.
This class is designed to facilitate the manipulation of parameters.
Definition: Parameter.h:97
virtual void setParametersValues(const ParameterList &parameters)=0
Update the parameters from parameters.
virtual const Parameter & parameter(const std::string &name) const =0
Get the parameter with specified name.
bool hasParameter(const std::string &name) const override
Tell if there is a parameter with specified name.
void setParameterValue(const std::string &name, double value) override
Set the value of parameter with name name to be equal to value.
A low-level implementation of the Parametrizable interface with void functions.
void setParametersValues(const ParameterList &parameters) override
Update the parameters from parameters.
This is the interface for all objects that imply parameters.
The parameter list object.
Definition: ParameterList.h:27
bool matchParametersValues(const ParameterList &parameters) override
Update the parameters from parameters.
virtual bool hasParameter(const std::string &name) const
void setConstraint(const std::string &name, std::shared_ptr< ConstraintInterface > constraint) override
Set/Change the constraint associated with one parameter.
std::string getParameterNameWithoutNamespace(const std::string &name) const override
Resolves a parameter name according to the current namespace.
virtual ParameterList & getParameters_()=0
Get all parameters available.
virtual void setAllParametersValues(const ParameterList &parameters)=0
Set the parameters values to be equals to those of parameters.
size_t getNumberOfParameters() const override
Get the number of parameters.
const Parameter & parameter(const std::string &name) const override
Get the parameter with specified name.
virtual std::string getParameterNameWithoutNamespace(const std::string &name) const =0
Resolves a parameter name according to the current namespace.
void setNamespace(const std::string &prefix) override
Set the namespace for the parameter names.
The Clonable interface (allow an object to be cloned).
Definition: Clonable.h:63
virtual ~Parametrizable()
virtual void setConstraint(const std::string &name, std::shared_ptr< ConstraintInterface > constraint)=0
Set/Change the constraint associated with one parameter.
virtual void setNamespace(const std::string &prefix)=0
Set the namespace for the parameter names.
void removeConstraint(const std::string &name) override
Remove the constraint associated with one parameter, if any.
virtual bool hasParameter(const std::string &name) const =0
Tell if there is a parameter with specified name.
virtual size_t getNumberOfParameters() const =0
Get the number of parameters.
double getParameterValue(const std::string &name) const override
Get the value for parameter of name &#39;name&#39;.
const ParameterList & getParameters() const override
Get all parameters available.
virtual void removeConstraint(const std::string &name)=0
Remove the constraint associated with one parameter, if any.