bpp-core  2.2.0
BppOParametrizableFormat.cpp
Go to the documentation of this file.
1 //
2 // File: BppOParametrizableFormat.cpp
3 // Created by: Laurent Guéguen
4 // Created on: lundi 3 septembre 2012, à 15h 37
5 //
6 
7 /*
8  Copyright or © or Copr. Bio++ Development Team, (November 16, 2004)
9 
10  This software is a computer program whose purpose is to provide classes
11  for phylogenetic data analysis.
12 
13  This software is governed by the CeCILL license under French law and
14  abiding by the rules of distribution of free software. You can use,
15  modify and/ or redistribute the software under the terms of the CeCILL
16  license as circulated by CEA, CNRS and INRIA at the following URL
17  "http://www.cecill.info".
18 
19  As a counterpart to the access to the source code and rights to copy,
20  modify and redistribute granted by the license, users are provided only
21  with a limited warranty and the software's author, the holder of the
22  economic rights, and the successive licensors have only limited
23  liability.
24 
25  In this respect, the user's attention is drawn to the risks associated
26  with loading, using, modifying and/or developing or reproducing the
27  software by the user in light of its specific status of free software,
28  that may mean that it is complicated to manipulate, and that also
29  therefore means that it is reserved for developers and experienced
30  professionals having in-depth computer knowledge. Users are therefore
31  encouraged to load and test the software's suitability as regards their
32  requirements in conditions enabling the security of their systems and/or
33  data to be ensured and, more generally, to use and operate it in the
34  same conditions as regards security.
35 
36  The fact that you are presently reading this means that you have had
37  knowledge of the CeCILL license and that you accept its terms.
38 */
39 
41 
42 using namespace bpp;
43 
44 // From the STL:
45 #include <iomanip>
46 #include <algorithm>
47 
48 
49 using namespace std;
50 
52  OutputStream& out,
53  std::vector<std::string>& writtenNames,
54  bool printComma) const
55 {
56  ParameterList pl = parametrizable->getParameters();
57  int p = out.getPrecision();
58  out.setPrecision(12);
59  bool flag = printComma;
60  for (size_t i = 0; i < pl.size(); ++i)
61  {
62  if (find(writtenNames.begin(), writtenNames.end(), pl[i].getName()) == writtenNames.end())
63  {
64  if (flag)
65  out << ",";
66  else
67  flag = true;
68  string pname = parametrizable->getParameterNameWithoutNamespace(pl[i].getName());
69 
70  (out << pname << "=").enableScientificNotation(false) << pl[i].getValue();
71 
72  }
73  }
74  out.setPrecision(p);
75 }
76 
78  OutputStream& out,
79  std::map<std::string, std::string>& globalAliases,
80  const std::vector<std::string>& names,
81  std::vector<std::string>& writtenNames,
82  bool printLocalAliases,
83  bool printComma) const
84 {
85  ParameterList pl = parametrizable->getIndependentParameters().subList(names);
86  int p = out.getPrecision();
87  out.setPrecision(12);
88  bool flag = printComma;
89  for (size_t i = 0; i < pl.size(); ++i)
90  {
91  if (find(writtenNames.begin(), writtenNames.end(), pl[i].getName()) == writtenNames.end())
92  {
93  if (flag)
94  out << ",";
95  else
96  flag = true;
97  string pname = parametrizable->getParameterNameWithoutNamespace(pl[i].getName());
98 
99  // Check for global aliases:
100  if (globalAliases.find(pl[i].getName()) == globalAliases.end())
101  {
102  (out << pname << "=").enableScientificNotation(false) << pl[i].getValue();
103  }
104  else
105  out << pname << "=" << globalAliases[pl[i].getName()];
106 
107  // Now check for local aliases:
108  if (printLocalAliases)
109  {
110  vector<string> aliases = parametrizable->getAlias(pname);
111  for (size_t j = 0; j < aliases.size(); ++j)
112  {
113  out << ", " << aliases[j] << "=" << pname;
114  }
115  }
116  writtenNames.push_back(pl[i].getName());
117  }
118  }
119  out.setPrecision(p);
120 }
void write(const Parametrizable *parametrizable, OutputStream &out, std::vector< std::string > &writtenNames, bool printComma=false) const
Write a Parametrizable to a stream.
virtual ParameterList subList(const std::vector< std::string > &names) const
Get given parameters as a sublist.
virtual int getPrecision() const =0
Extend the Parametrizable interface with support for parameter aliases.
This class allows to perform a correspondence analysis.
virtual std::vector< std::string > getAlias(const std::string &name) const =0
virtual const ParameterList & getParameters() const =0
Get all parameters available.
size_t size() const
Definition: ParameterList.h:90
STL namespace.
This is the interface for all objects that imply parameters.
The parameter list object.
Definition: ParameterList.h:61
virtual OutputStream & setPrecision(int digit)=0
virtual const ParameterList & getIndependentParameters() const =0
Get the minimal list of parameters to set the model.
OutputStream interface.
Definition: OutputStream.h:64
virtual std::string getParameterNameWithoutNamespace(const std::string &name) const =0
Resolves a parameter name according to the current namespace.