bpp-core3  3.0.0
ParameterList.h
Go to the documentation of this file.
1 //
2 // File: ParameterList.h
3 // Authors:
4 // Julien Dutheil
5 // Created: 2003-10-15 18:17:29
6 //
7 
8 /*
9  Copyright or © or Copr. Bio++ Development Team, (November 19, 2004)
10 
11  This software is a computer program whose purpose is to provide classes
12  for numerical calculus.
13 
14  This software is governed by the CeCILL license under French law and
15  abiding by the rules of distribution of free software. You can use,
16  modify and/ or redistribute the software under the terms of the CeCILL
17  license as circulated by CEA, CNRS and INRIA at the following URL
18  "http://www.cecill.info".
19 
20  As a counterpart to the access to the source code and rights to copy,
21  modify and redistribute granted by the license, users are provided only
22  with a limited warranty and the software's author, the holder of the
23  economic rights, and the successive licensors have only limited
24  liability.
25 
26  In this respect, the user's attention is drawn to the risks associated
27  with loading, using, modifying and/or developing or reproducing the
28  software by the user in light of its specific status of free software,
29  that may mean that it is complicated to manipulate, and that also
30  therefore means that it is reserved for developers and experienced
31  professionals having in-depth computer knowledge. Users are therefore
32  encouraged to load and test the software's suitability as regards their
33  requirements in conditions enabling the security of their systems and/or
34  data to be ensured and, more generally, to use and operate it in the
35  same conditions as regards security.
36 
37  The fact that you are presently reading this means that you have had
38  knowledge of the CeCILL license and that you accept its terms.
39 */
40 
41 #ifndef BPP_NUMERIC_PARAMETERLIST_H
42 #define BPP_NUMERIC_PARAMETERLIST_H
43 
44 
45 #include "../Clonable.h"
46 #include "../Io/OutputStream.h"
47 #include "Parameter.h"
48 
49 // From STL:
50 #include <vector>
51 #include <string>
52 #include <iostream>
53 
54 namespace bpp
55 {
64  public Clonable
65 {
66 private:
67  std::vector<std::shared_ptr<Parameter> > parameters_;
68 
69 public:
74 
80  ParameterList(const ParameterList& pl);
81 
83 
84  ParameterList* clone() const { return new ParameterList(*this); }
85 
86  virtual ~ParameterList();
87 
88 public:
92  size_t size() const { return parameters_.size(); }
93 
98  virtual const Parameter& operator[](size_t i) const { return *parameters_[i]; }
99  virtual Parameter& operator[](size_t i) { return *parameters_[i]; }
100 
105  virtual const std::shared_ptr<Parameter>& getSharedParameter(size_t i) const { return parameters_[i]; }
106  virtual std::shared_ptr<Parameter>& getSharedParameter(size_t i) { return parameters_[i]; }
107 
115  virtual const Parameter& getParameter(const std::string& name) const;
116 
124  virtual const std::shared_ptr<Parameter>& getSharedParameter(const std::string& name) const;
125 
134  virtual double getParameterValue(const std::string& name) const;
135 
143  virtual Parameter& getParameter(const std::string& name);
144 
152  virtual std::shared_ptr<Parameter>& getSharedParameter(const std::string& name);
153 
161  virtual ParameterList createSubList(const std::vector<std::string>& names) const;
162 
171  virtual ParameterList shareSubList(const std::vector<std::string>& names) const;
172 
180  virtual ParameterList createSubList(const std::string& name) const;
181 
188  virtual ParameterList createSubList(const std::vector<size_t>& parameters) const;
189 
197  virtual ParameterList shareSubList(const std::vector<size_t>& parameters) const;
198 
205  virtual ParameterList createSubList(size_t parameter) const;
206 
213  virtual ParameterList getCommonParametersWith(const ParameterList& params) const;
214 
220  virtual std::vector<std::string> getParameterNames() const;
221 
230  virtual std::vector<std::string> getMatchingParameterNames(const std::string& pattern) const;
231 
237  virtual void addParameter(const Parameter& param);
238 
249  virtual void addParameter(Parameter* param);
250 
257  virtual void shareParameter(const std::shared_ptr<Parameter>& param);
258 
259 
268  virtual void setParameter(size_t index, const Parameter& param);
269 
270 // virtual void setParameter(size_t index, Parameter* param);
271 
278  virtual void addParameters(const ParameterList& params);
279 
287  virtual void shareParameters(const ParameterList& params);
288 
296  virtual void includeParameters(const ParameterList& params);
297 
306  virtual void setParameterValue(const std::string& name, double value);
307 
319  virtual void setAllParametersValues(const ParameterList& params);
320 
329  virtual void setParametersValues(const ParameterList& params);
330 
336  virtual bool hasParameter(const std::string& name) const;
337 
346  virtual bool testParametersValues(const ParameterList& params) const;
347 
361  virtual bool matchParametersValues(const ParameterList& params, std::vector<size_t>* updatedParameters = 0);
362 
372  virtual void setAllParameters(const ParameterList& params);
373 
382  virtual void setParameters(const ParameterList& params);
383 
392  virtual void matchParameters(const ParameterList& params);
393 
399  virtual void deleteParameter(const std::string& name);
400 
409  virtual void deleteParameters(const std::vector<std::string>& names, bool mustExist = true);
410 
416  virtual void deleteParameter(size_t index);
417 
424  virtual void deleteParameters(const std::vector<size_t>& indices);
425 
434  virtual size_t whichParameterHasName(const std::string& name) const;
435 
439  virtual void printParameters(OutputStream& out) const;
440 
441  virtual void printParameters(std::ostream& out) const
442  {
443  StlOutputStreamWrapper os(&out);
444  printParameters(os);
445  }
446 
450  virtual void reset();
451 };
452 } // end of namespace bpp.
453 #endif // BPP_NUMERIC_PARAMETERLIST_H
The Clonable interface (allow an object to be cloned).
Definition: Clonable.h:103
OutputStream interface.
Definition: OutputStream.h:67
The parameter list object.
Definition: ParameterList.h:65
virtual Parameter & operator[](size_t i)
Definition: ParameterList.h:99
virtual bool hasParameter(const std::string &name) const
virtual const Parameter & getParameter(const std::string &name) const
Get the parameter with name name.
ParameterList()
Build a new ParameterList object.
Definition: ParameterList.h:73
virtual void printParameters(std::ostream &out) const
virtual void addParameters(const ParameterList &params)
Add new parameters at the end of the list.
size_t size() const
Definition: ParameterList.h:92
virtual ParameterList getCommonParametersWith(const ParameterList &params) const
Get the sublist containing all common parameter between this list and pl.
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 void matchParameters(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 setParameters(const ParameterList &params)
Update the parameters from params.
virtual std::vector< std::string > getParameterNames() const
Get all parameter names in 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 double getParameterValue(const std::string &name) const
Get the value of the parameter with name name.
virtual void addParameter(const Parameter &param)
Add a new parameter at the end of the list.
ParameterList * clone() const
Create a copy of this object and send a pointer to it.
Definition: ParameterList.h:84
virtual void shareParameter(const std::shared_ptr< Parameter > &param)
Share a parameter at the end of the list.
virtual void includeParameters(const ParameterList &params)
Add parameters to the list. If the parameter already exists, only the value is updated,...
virtual void deleteParameter(const std::string &name)
Delete a parameter from the list.
virtual void setParametersValues(const ParameterList &params)
Update the parameters from the ones in params that have matching names.
virtual void reset()
Reset the list: delete all parameters.
virtual bool matchParametersValues(const ParameterList &params, std::vector< size_t > *updatedParameters=0)
Update the parameters from params.
virtual bool testParametersValues(const ParameterList &params) const
Tests the parameters from params.
virtual void shareParameters(const ParameterList &params)
Share parameters with a given list. They are added the end of this list.
ParameterList & operator=(const ParameterList &pl)
virtual void deleteParameters(const std::vector< std::string > &names, bool mustExist=true)
Delete several parameters from the list.
virtual void setAllParameters(const ParameterList &params)
Set the parameters to be equals to params.
virtual const std::shared_ptr< Parameter > & getSharedParameter(size_t i) const
virtual const Parameter & operator[](size_t i) const
Definition: ParameterList.h:98
virtual void setParameter(size_t index, const Parameter &param)
Change given parameter.
virtual void printParameters(OutputStream &out) const
Print all parameters.
virtual ~ParameterList()
virtual size_t whichParameterHasName(const std::string &name) const
Get the position of a given parameter according to its name.
virtual ParameterList createSubList(const std::vector< std::string > &names) const
Get given parameters as a sublist.
virtual void setAllParametersValues(const ParameterList &params)
Set the parameters to be equals to params.
std::vector< std::shared_ptr< Parameter > > parameters_
Definition: ParameterList.h:67
virtual std::shared_ptr< Parameter > & getSharedParameter(size_t i)
This class is designed to facilitate the manipulation of parameters.
Definition: Parameter.h:135
STL wrapper for output stream.
Definition: OutputStream.h:206