bpp-core3  3.0.0
BppApplication.cpp
Go to the documentation of this file.
1 //
2 // File: BppApplication.cpp
3 // Authors:
4 // Julien Dutheil
5 // Created: 2009-08-08 08:21:00
6 //
7 
8 /*
9  Copyright or © or Copr. Bio++ Development Team, (November 17, 2004)
10 
11  This software is a computer program whose purpose is to provide basal and
12  utilitary classes. This file belongs to the Bio++ Project.
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 
42 #include "../Numeric/Random/RandomTools.h"
43 #include "../Utils/AttributesTools.h"
44 #include "ApplicationTools.h"
45 #include "BppApplication.h"
46 
47 // From the STL:
48 #include <iostream>
49 
50 using namespace bpp;
51 using namespace std;
52 
53 BppApplication::BppApplication(int argc, char* argv[], const std::string& name, bool verbose, int warningLevel) :
54  appName_(name), params_(), timerStarted_(false), verbose_(verbose), warn_(warningLevel)
55 {
56  if (verbose_)
57  cout << "Parsing options:" << endl;
60  bool noint = ApplicationTools::getBooleanParameter("--noninteractive", params_, false, "", true, 3);
62  long seed = ApplicationTools::getParameter<long>("--seed", params_, -1, "", true, 3);
63  if (seed >= 0)
64  {
66  if (verbose_)
67  ApplicationTools::displayResult("Random seed set to", seed);
68  }
69 }
70 
72 {
74  timerStarted_ = true;
75 }
76 
78 {
79  if (verbose_)
80  {
81  cout << appName_ << "'s done. Bye." << endl;
82  if (timerStarted_)
83  ApplicationTools::displayTime("Total execution time:");
84  }
85 }
86 
87 void BppApplication::help(const string& program) const
88 {
89  (*ApplicationTools::message << "__________________________________________________________________________").endLine();
90  (*ApplicationTools::message << program << " parameter1_name=parameter1_value parameter2_name=parameter2_value").endLine();
91  (*ApplicationTools::message << " ... param=option_file").endLine();
92  (*ApplicationTools::message).endLine();
93  (*ApplicationTools::message << " Refer to the Bio++ Program Suite Manual for a list of available options.").endLine();
94  (*ApplicationTools::message << "__________________________________________________________________________").endLine();
95 }
static int warningLevel
Specify the amount of warning to display.
static std::shared_ptr< OutputStream > message
The output stream where messages have to be displayed.
static void startTimer()
Starts the timer.
static bool getBooleanParameter(const std::string &parameterName, const std::map< std::string, std::string > &params, bool defaultValue, const std::string &suffix="", bool suffixIsOptional=true, int warn=0)
Get a boolean parameter.
static bool interactive
Tell if the program is interactive (typically run in foreground). Default to yes.
static int getIntParameter(const std::string &parameterName, const std::map< std::string, std::string > &params, int defaultValue, const std::string &suffix="", bool suffixIsOptional=true, int warn=0)
Get an integer parameter.
static void displayResult(const std::string &text, const T &result)
Print a result message.
static void displayTime(const std::string &msg)
Display the current timer value to the 'message' stream.
static std::map< std::string, std::string > parseOptions(int args, char **argv)
Global function that reads all parameters from command line and files, and set the values in a map.
virtual void help(const std::string &program) const
std::string appName_
BppApplication(int argc, char *argv[], const std::string &name, bool verbose=true, int warningLevel=1)
virtual void done()
std::map< std::string, std::string > params_
virtual void startTimer()
static void setSeed(long seed)
Set the default generator seed.
Definition: RandomTools.cpp:56