bpp-core3  3.0.0
BppApplication.cpp
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
5 #include "../Numeric/Random/RandomTools.h"
6 #include "../Utils/AttributesTools.h"
7 #include "ApplicationTools.h"
8 #include "BppApplication.h"
9 
10 // From the STL:
11 #include <iostream>
12 
13 using namespace bpp;
14 using namespace std;
15 
16 BppApplication::BppApplication(int argc, char* argv[], const std::string& name, bool verbose, int warningLevel) :
17  appName_(name), params_(), timerStarted_(false), verbose_(verbose), warn_(warningLevel)
18 {
19  if (verbose_)
20  cout << "Parsing options:" << endl;
23  bool noint = ApplicationTools::getBooleanParameter("--noninteractive", params_, false, "", true, 3);
25  std::mt19937::result_type seed = ApplicationTools::getParameter<std::mt19937::result_type>("--seed", params_, 5489u, "", true, 3);
26  if (seed != 5489u)
27  {
29  if (verbose_)
30  ApplicationTools::displayResult("Random seed set to", seed);
31  }
32 }
33 
35 {
37  timerStarted_ = true;
38 }
39 
41 {
42  if (verbose_)
43  {
44  cout << appName_ << "'s done. Bye." << endl;
45  if (timerStarted_)
46  ApplicationTools::displayTime("Total execution time:");
47  }
48 }
49 
50 void BppApplication::help(const string& program) const
51 {
52  (*ApplicationTools::message << "__________________________________________________________________________").endLine();
53  (*ApplicationTools::message << program << " parameter1_name=parameter1_value parameter2_name=parameter2_value").endLine();
54  (*ApplicationTools::message << " ... param=option_file").endLine();
55  (*ApplicationTools::message).endLine();
56  (*ApplicationTools::message << " Refer to the Bio++ Program Suite Manual for a list of available options.").endLine();
57  (*ApplicationTools::message << "__________________________________________________________________________").endLine();
58 }
std::string appName_
virtual void done()
static int warningLevel
Specify the amount of warning to display.
static void displayTime(const std::string &msg)
Display the current timer value to the &#39;message&#39; 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...
static void displayResult(const std::string &text, const T &result)
Print a result message.
STL namespace.
static void setSeed(std::mt19937::result_type seed)
Set the default generator seed.
Definition: RandomTools.h:68
BppApplication(int argc, char *argv[], const std::string &name, bool verbose=true, int warningLevel=1)
static void startTimer()
Starts the timer.
std::map< std::string, std::string > params_
virtual void help(const std::string &program) const
static std::shared_ptr< OutputStream > message
The output stream where messages have to be displayed.
static bool interactive
Tell if the program is interactive (typically run in foreground). Default to yes. ...
virtual void startTimer()
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 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.