bpp-core3  3.0.0
ParameterList.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_PARAMETERLIST_H
6 #define BPP_NUMERIC_PARAMETERLIST_H
7 
8 
9 #include "../Clonable.h"
10 #include "../Io/OutputStream.h"
11 #include "Parameter.h"
12 
13 // From STL:
14 #include <vector>
15 #include <string>
16 #include <iostream>
17 
18 namespace bpp
19 {
28  public Clonable
29 {
30 private:
31  std::vector<std::shared_ptr<Parameter>> parameters_;
32 
33 public:
37  ParameterList() : parameters_() {}
38 
44  ParameterList(const ParameterList& pl);
45 
47 
48  ParameterList* clone() const { return new ParameterList(*this); }
49 
50  virtual ~ParameterList();
51 
52 public:
56  size_t size() const { return parameters_.size(); }
57 
62  virtual const Parameter& operator[](size_t i) const { return *parameters_[i]; }
63  virtual Parameter& operator[](size_t i) { return *parameters_[i]; }
64 
69  virtual const std::shared_ptr<Parameter>& getParameter(size_t i) const { return parameters_[i]; }
70  virtual std::shared_ptr<Parameter>& getParameter(size_t i) { return parameters_[i]; }
71 
79  virtual const Parameter& parameter(const std::string& name) const;
80 
88  virtual const std::shared_ptr<Parameter>& getParameter(const std::string& name) const;
89 
98  virtual double getParameterValue(const std::string& name) const;
99 
107  virtual Parameter& parameter(const std::string& name);
108 
116  virtual std::shared_ptr<Parameter>& getParameter(const std::string& name);
117 
125  virtual ParameterList createSubList(const std::vector<std::string>& names) const;
126 
135  virtual ParameterList shareSubList(const std::vector<std::string>& names) const;
136 
144  virtual ParameterList createSubList(const std::string& name) const;
145 
152  virtual ParameterList createSubList(const std::vector<size_t>& parameters) const;
153 
161  virtual ParameterList shareSubList(const std::vector<size_t>& parameters) const;
162 
169  virtual ParameterList createSubList(size_t parameter) const;
170 
177  virtual ParameterList getCommonParametersWith(const ParameterList& params) const;
178 
184  virtual std::vector<std::string> getParameterNames() const;
185 
194  virtual std::vector<std::string> getMatchingParameterNames(const std::string& pattern) const;
195 
201  virtual void addParameter(const Parameter& param);
202 
212  virtual void addParameter(Parameter* param);
213 
219  virtual void shareParameter(const std::shared_ptr<Parameter>& param);
220 
221 
229  virtual void setParameter(size_t index, const Parameter& param);
230 
231 // virtual void setParameter(size_t index, Parameter* param);
232 
239  virtual void addParameters(const ParameterList& params);
240 
248  virtual void shareParameters(const ParameterList& params);
249 
257  virtual void includeParameters(const ParameterList& params);
258 
267  virtual void setParameterValue(const std::string& name, double value);
268 
280  virtual void setAllParametersValues(const ParameterList& params);
281 
290  virtual void setParametersValues(const ParameterList& params);
291 
297  virtual bool hasParameter(const std::string& name) const;
298 
307  virtual bool testParametersValues(const ParameterList& params) const;
308 
322  virtual bool matchParametersValues(const ParameterList& params, std::vector<size_t>* updatedParameters = 0);
323 
333  virtual void setAllParameters(const ParameterList& params);
334 
343  virtual void setParameters(const ParameterList& params);
344 
353  virtual void matchParameters(const ParameterList& params);
354 
360  virtual void deleteParameter(const std::string& name);
361 
370  virtual void deleteParameters(const std::vector<std::string>& names, bool mustExist = true);
371 
377  virtual void deleteParameter(size_t index);
378 
385  virtual void deleteParameters(const std::vector<size_t>& indices);
386 
395  virtual size_t whichParameterHasName(const std::string& name) const;
396 
400  virtual void printParameters(OutputStream& out) const;
401 
402  virtual void printParameters(std::ostream& out) const
403  {
404  StlOutputStreamWrapper os(&out);
405  printParameters(os);
406  }
407 
411  virtual void reset();
412 };
413 } // end of namespace bpp.
414 #endif // BPP_NUMERIC_PARAMETERLIST_H
virtual const Parameter & operator[](size_t i) const
Definition: ParameterList.h:62
virtual ~ParameterList()
virtual const Parameter & parameter(const std::string &name) const
Get the parameter with name name.
virtual void includeParameters(const ParameterList &params)
Add parameters to the list. If the parameter already exists, only the value is updated, otherwise the new parameter is added at the end of the list.
virtual bool testParametersValues(const ParameterList &params) const
Tests the parameters from params.
virtual void reset()
Reset the list: delete all parameters.
virtual std::vector< std::string > getMatchingParameterNames(const std::string &pattern) const
Get all parameter names matching with the given name. Up to now, only "*" jokers are available...
virtual ParameterList createSubList(const std::vector< std::string > &names) const
Get given parameters as a sublist.
virtual double getParameterValue(const std::string &name) const
Get the value of the parameter with name name.
virtual bool matchParametersValues(const ParameterList &params, std::vector< size_t > *updatedParameters=0)
Update the parameters from params.
virtual void setAllParameters(const ParameterList &params)
Set the parameters to be equals to params.
virtual void deleteParameters(const std::vector< std::string > &names, bool mustExist=true)
Delete several parameters from the list.
ParameterList & operator=(const ParameterList &pl)
ParameterList()
Build a new ParameterList object.
Definition: ParameterList.h:37
virtual void shareParameter(const std::shared_ptr< Parameter > &param)
Share a parameter at the end of the list.
size_t size() const
Definition: ParameterList.h:56
This class is designed to facilitate the manipulation of parameters.
Definition: Parameter.h:97
virtual void setAllParametersValues(const ParameterList &params)
Set the parameters to be equals to params.
virtual void deleteParameter(const std::string &name)
Delete a parameter from the list.
virtual void setParameterValue(const std::string &name, double value)
Set the value of parameter with name name to be equal to value.
virtual ParameterList getCommonParametersWith(const ParameterList &params) const
Get the sublist containing all common parameter between this list and pl.
virtual Parameter & operator[](size_t i)
Definition: ParameterList.h:63
The parameter list object.
Definition: ParameterList.h:27
virtual void addParameters(const ParameterList &params)
Add new parameters at the end of the list.
virtual void printParameters(std::ostream &out) const
virtual std::vector< std::string > getParameterNames() const
Get all parameter names in the list.
ParameterList * clone() const
Create a copy of this object and send a pointer to it.
Definition: ParameterList.h:48
virtual bool hasParameter(const std::string &name) const
virtual void shareParameters(const ParameterList &params)
Share parameters with a given list. They are added the end of this list.
virtual size_t whichParameterHasName(const std::string &name) const
Get the position of a given parameter according to its name.
OutputStream interface.
Definition: OutputStream.h:29
virtual void setParameter(size_t index, const Parameter &param)
Change given parameter.
virtual void setParameters(const ParameterList &params)
Update the parameters from params.
virtual ParameterList shareSubList(const std::vector< std::string > &names) const
Share given parameters as a sublist.
virtual void addParameter(const Parameter &param)
Add a new parameter at the end of the list.
STL wrapper for output stream.
Definition: OutputStream.h:168
The Clonable interface (allow an object to be cloned).
Definition: Clonable.h:63
virtual void matchParameters(const ParameterList &params)
Update the parameters from params.
virtual void printParameters(OutputStream &out) const
Print all parameters.
std::vector< std::shared_ptr< Parameter > > parameters_
Definition: ParameterList.h:31
virtual const std::shared_ptr< Parameter > & getParameter(size_t i) const
Definition: ParameterList.h:69
virtual void setParametersValues(const ParameterList &params)
Update the parameters from the ones in params that have matching names.
virtual std::shared_ptr< Parameter > & getParameter(size_t i)
Definition: ParameterList.h:70