bpp-core
2.2.0
|
This class provides some common tools for developping applications. More...
#include <Bpp/App/ApplicationTools.h>
Public Member Functions | |
ApplicationTools () | |
virtual | ~ApplicationTools () |
Static Public Member Functions | |
static bool | parameterExists (const std::string ¶meterName, std::map< std::string, std::string > ¶ms) |
Tells if a parameter have been specified. More... | |
static bool | parameterExists (const std::string ¶meterName, std::vector< std::string > ¶ms) |
static std::vector< std::string > | matchingParameters (const std::string &pattern, std::map< std::string, std::string > ¶ms) |
Returns a vector of parameter names that match a given pattern. More... | |
static std::vector< std::string > | matchingParameters (const std::string &pattern, std::vector< std::string > ¶ms) |
static double | getDoubleParameter (const std::string ¶meterName, std::map< std::string, std::string > ¶ms, double defaultValue, const std::string &suffix="", bool suffixIsOptional=true, int warn=0) |
Get a double parameter. More... | |
static int | getIntParameter (const std::string ¶meterName, std::map< std::string, std::string > ¶ms, int defaultValue, const std::string &suffix="", bool suffixIsOptional=true, int warn=0) |
Get an integer parameter. More... | |
static std::string | getStringParameter (const std::string ¶meterName, std::map< std::string, std::string > ¶ms, const std::string &defaultValue, const std::string &suffix="", bool suffixIsOptional=true, int warn=0) |
Get a string parameter. More... | |
static bool | getBooleanParameter (const std::string ¶meterName, std::map< std::string, std::string > ¶ms, bool defaultValue, const std::string &suffix="", bool suffixIsOptional=true, int warn=0) |
Get a boolean parameter. More... | |
template<class T > | |
static T | getParameter (const std::string ¶meterName, std::map< std::string, std::string > ¶ms, T defaultValue, const std::string &suffix="", bool suffixIsOptional=true, int warn=0) |
Get a parameter. More... | |
static std::string | getAFilePath (const std::string ¶meter, std::map< std::string, std::string > ¶ms, bool isRequired=true, bool mustExist=true, const std::string &suffix="", bool suffixIsOptional=false, const std::string &defaultPath="none", int warn=0) throw (Exception) |
Get a file path. More... | |
template<class T > | |
static std::vector< T > | getVectorParameter (const std::string ¶meterName, std::map< std::string, std::string > ¶ms, char separator, const std::string &defaultValue, const std::string &suffix="", bool suffixIsOptional=true, int warn=0) |
Get a vector. More... | |
template<class T > | |
static std::vector< T > | getVectorParameter (const std::string ¶meterName, std::map< std::string, std::string > ¶ms, char separator, char rangeOperator, const std::string &defaultValue, const std::string &suffix="", bool suffixIsOptional=true, bool warn=true) |
Get a vector. More... | |
template<class T > | |
static RowMatrix< T > | getMatrixParameter (const std::string ¶meterName, std::map< std::string, std::string > ¶ms, char separator, const std::string &defaultValue, const std::string &suffix="", bool suffixIsOptional=true, bool warn=true) |
Get a RowMatrix. The input is made of embedded parenthesis, such as ((1,2),(3,4)), where the matrix is filled by lines. Here, the matrix would be:
. More... | |
static void | startTimer () |
Starts the timer. More... | |
static void | displayTime (const std::string &msg) |
Display the current timer value to the 'message' stream. More... | |
static double | getTime () |
Get the current timer value. More... | |
Output methods. | |
static void | displayMessage (const std::string &text) |
Print a message. More... | |
static void | displayError (const std::string &text) |
Print an error message. More... | |
static void | displayWarning (const std::string &text) |
Print a warning message. More... | |
static void | displayTask (const std::string &text, bool eof=false) |
Print a task message. More... | |
static void | displayTaskDone () |
Print a task ended message. More... | |
template<class T > | |
static void | displayResult (const std::string &text, const T &result) |
Print a result message. More... | |
static void | displayBooleanResult (const std::string &text, bool result) |
Print a boolean result message ("yes" or "no"). More... | |
static void | displayGauge (size_t iter, size_t total, char symbol='>', const std::string &mes="") |
Display a gauge. More... | |
static void | displayUnlimitedGauge (size_t iter, const std::string &mes="") |
Display a gauge for unefined amount of iterations. More... | |
Static Public Attributes | |
static OutputStream * | error = new StdErr() |
The output stream where errors have to be displayed. More... | |
static OutputStream * | message = new StdOut() |
The output stream where messages have to be displayed. More... | |
static OutputStream * | warning = new StdOut() |
The output stream where warnings have to be displayed. More... | |
static time_t | startTime |
Timer variable. More... | |
static size_t | terminalWidth = 80 |
The width of the output terminal (in character). More... | |
static float | terminalSplit = 0.5 |
The fraction of terminal width dedicated to messages. More... | |
static bool | interactive = true |
Tell if the program is interactive (typically run in foreground). Default to yes. More... | |
static int | warningLevel = 0 |
Specify the amount of warning to display. More... | |
This class provides some common tools for developping applications.
These functions are designed for helping to parse an option file.
The option files are supposed to follow this simple format:
with one parameter per line.
In files, shell comments:
C comments:
and C++ comments:
are allowed, and ignored while parsing.
Some methods for displaying information (messages, errors, warnings...) are also provided.
Methods dealing with parameters takes as argument a map<string, string> object containing the parameters (names are the keys of the map, and values are... the values of the map!). These map objects may be obtained from the AttributesTools utilitary class.
Definition at line 92 of file ApplicationTools.h.
|
inline |
Definition at line 135 of file ApplicationTools.h.
|
inlinevirtual |
Definition at line 136 of file ApplicationTools.h.
|
inlinestatic |
Print a boolean result message ("yes" or "no").
Result will be aligned to 30 character from the begining of the message.
text | The text of the message. |
result | The result. |
Definition at line 524 of file ApplicationTools.h.
References displayResult().
|
static |
Print an error message.
text | The text of the message. |
Definition at line 302 of file ApplicationTools.cpp.
|
static |
Display a gauge.
Show progress status.
will result in something like:
* [************************************] *
iter | The current iteration number. |
total | The total number of iteration. |
symbol | The character to display in the gauge. |
mes | A message to print before the gauge. |
Definition at line 320 of file ApplicationTools.cpp.
References bpp::TextTools::resizeLeft(), bpp::TextTools::resizeRight(), and bpp::TextTools::toString().
Referenced by bpp::FunctionTools::computeGrid().
|
static |
Print a message.
text | The text of the message. |
Definition at line 300 of file ApplicationTools.cpp.
Referenced by bpp::FunctionTools::computeGrid(), displayResult(), and bpp::ReparametrizationFunctionWrapper::init_().
|
inlinestatic |
Print a result message.
Result will be aligned to 30 character from the begining of the message. ex: text = "Here is what you get:" and result = "THAT" gives "Here is what you get: THAT".
text | The text of the message. |
result | The result. |
Definition at line 512 of file ApplicationTools.h.
References displayMessage(), bpp::TextTools::resizeRight(), terminalSplit, and terminalWidth.
Referenced by bpp::AbstractParameterAliasable::aliasParameters(), bpp::BppApplication::BppApplication(), displayBooleanResult(), bpp::BppODiscreteDistributionFormat::initialize_(), and bpp::BppODiscreteDistributionFormat::read().
|
static |
Print a task message.
Display the message and flush the buffer, but do not end the current line.
text | The text of the message. |
eof | Insert a carriage return after displaying the message. |
Definition at line 306 of file ApplicationTools.cpp.
|
static |
Print a task ended message.
Print "Done." and go to next line.
Definition at line 316 of file ApplicationTools.cpp.
|
static |
Display the current timer value to the 'message' stream.
msg | Message to display before time. |
Definition at line 381 of file ApplicationTools.cpp.
Referenced by bpp::BppApplication::done().
|
static |
Display a gauge for unefined amount of iterations.
Show progress status.
will result in something like:
* - 1 * / 2 * - 3 * \ 4 * - 5 * etc *
iter | The current iteration number. |
mes | A message to print before the gauge. |
Definition at line 358 of file ApplicationTools.cpp.
References bpp::TextTools::toString().
Referenced by bpp::AbstractOptimizer::optimize().
|
static |
Print a warning message.
text | The text of the message. |
Definition at line 304 of file ApplicationTools.cpp.
Referenced by bpp::DualityDiagram::compute_(), bpp::ContingencyTableTest::ContingencyTableTest(), getParameter(), and bpp::ReparametrizationFunctionWrapper::init_().
|
static |
Get a file path.
parameter | The name of the corresponding parameter. |
params | The attribute map where options may be found. |
isRequired | Tell if this path is strictly required or is optional (in the first case, if the parameter is not found, the programm will send an error and exit). |
mustExist | Tell if the corresponding file must already exist. |
suffix | A suffix to be applied to the parameter name. |
suffixIsOptional | Tell if the suffix is absolutely required. |
defaultPath | Path to use if no argument is provided. |
warn | Tell if a warning must be sent in case the parameter is not found. |
Exception | If no file path is specified and isRequired is true, or the file does not exist and mustExist is set to true. |
Definition at line 154 of file ApplicationTools.cpp.
References bpp::FileTools::fileExists().
|
static |
Get a boolean parameter.
parameterName | The name of the corresponding parameter. |
params | The attribute map where options may be found. |
defaultValue | The default value to use if the parameter is not found. |
suffix | A suffix to be applied to the parameter name. |
suffixIsOptional | Tell if the suffix is absolutely required. |
warn | Tell if a warning must be sent in case the parameter is not found. |
Definition at line 248 of file ApplicationTools.cpp.
References bpp::TextTools::toString().
Referenced by bpp::BppApplication::BppApplication().
|
static |
Get a double parameter.
parameterName | The name of the corresponding parameter. |
params | The attribute map where options may be found. |
defaultValue | The default value to use if the parameter is not found. |
suffix | A suffix to be applied to the parameter name. |
suffixIsOptional | Tell if the suffix is absolutely required. |
warn | Tell if a warning must be sent in case the parameter is not found. |
Definition at line 180 of file ApplicationTools.cpp.
References bpp::TextTools::toDouble(), and bpp::TextTools::toString().
Referenced by bpp::BppODiscreteDistributionFormat::initialize_().
|
static |
Get an integer parameter.
parameterName | The name of the corresponding parameter. |
params | The attribute map where options may be found. |
defaultValue | The default value to use if the parameter is not found. |
suffix | A suffix to be applied to the parameter name. |
suffixIsOptional | Tell if the suffix is absolutely required. |
warn | Tell if a warning must be sent in case the parameter is not found. |
Definition at line 206 of file ApplicationTools.cpp.
References bpp::TextTools::toInt(), and bpp::TextTools::toString().
Referenced by bpp::BppApplication::BppApplication().
|
inlinestatic |
Get a RowMatrix. The input is made of embedded parenthesis, such as ((1,2),(3,4)), where the matrix is filled by lines. Here, the matrix would be:
.
parameterName | The name of the corresponding parameter. |
params | The attribute map where options may be found. |
separator | The character used to delimit values. |
defaultValue | The default value to use if the parameter is not found. |
suffix | A suffix to be applied to the parameter name. |
suffixIsOptional | Tell if the suffix is absolutely required. |
warn | Tell if a warning must be sent in case the parameter is not found. |
Definition at line 417 of file ApplicationTools.h.
References bpp::RowMatrix< Scalar >::addRow(), getStringParameter(), bpp::StringTokenizer::hasMoreToken(), bpp::TextTools::isEmpty(), bpp::StringTokenizer::nextToken(), bpp::StringTokenizer::numberOfRemainingTokens(), and bpp::TextTools::toString().
|
inlinestatic |
Get a parameter.
parameterName | The name of the corresponding parameter. |
params | The attribute map where options may be found. |
defaultValue | The default value to use if the parameter is not found. |
suffix | A suffix to be applied to the parameter name. |
suffixIsOptional | Tell if the suffix is absolutely required. |
warn | Tell if a warning must be sent in case the parameter is not found. |
Definition at line 251 of file ApplicationTools.h.
References displayWarning(), parameterExists(), bpp::TextTools::toString(), and warningLevel.
|
static |
Get a string parameter.
parameterName | The name of the corresponding parameter. |
params | The attribute map where options may be found. |
defaultValue | The default value to use if the parameter is not found. |
suffix | A suffix to be applied to the parameter name. |
suffixIsOptional | Tell if the suffix is absolutely required. |
warn | Tell if a warning must be sent in case the parameter is not found. |
Definition at line 227 of file ApplicationTools.cpp.
Referenced by getMatrixParameter(), bpp::NumCalcApplicationTools::getParameterGrid(), and getVectorParameter().
|
static |
Get the current timer value.
Definition at line 405 of file ApplicationTools.cpp.
|
inlinestatic |
Get a vector.
parameterName | The name of the corresponding parameter. |
params | The attribute map where options may be found. |
separator | The character used to delimit values. |
defaultValue | The default value to use if the parameter is not found. |
suffix | A suffix to be applied to the parameter name. |
suffixIsOptional | Tell if the suffix is absolutely required. |
warn | Tell if a warning must be sent in case the parameter is not found. |
Definition at line 315 of file ApplicationTools.h.
References getStringParameter(), bpp::TextTools::isEmpty(), bpp::NestedStringTokenizer::nextToken(), bpp::StringTokenizer::numberOfRemainingTokens(), and bpp::TextTools::toString().
|
inlinestatic |
Get a vector.
Similar to getVectorParameter, but dedicated to numerical values. It allows the possibility to set range of values, which will be incremented by 1 (like the : operator in R).
parameterName | The name of the corresponding parameter. |
params | The attribute map where options may be found. |
separator | The character used to delimit values. |
rangeOperator | The character used to delimit ranges (the + 1 operator must be available for T). |
defaultValue | The default value to use if the parameter is not found. |
suffix | A suffix to be applied to the parameter name. |
suffixIsOptional | Tell if the suffix is absolutely required. |
warn | Tell if a warning must be sent in case the parameter is not found. |
Definition at line 357 of file ApplicationTools.h.
References getStringParameter(), bpp::TextTools::isEmpty(), bpp::StringTokenizer::nextToken(), bpp::StringTokenizer::numberOfRemainingTokens(), and bpp::TextTools::toString().
|
static |
Returns a vector of parameter names that match a given pattern.
Only "*" wildcard is implemented now.
pattern | The pattern. |
params | The parameter list. |
Definition at line 83 of file ApplicationTools.cpp.
References bpp::StringTokenizer::hasMoreToken(), and bpp::StringTokenizer::nextToken().
|
static |
Definition at line 118 of file ApplicationTools.cpp.
References bpp::StringTokenizer::hasMoreToken(), and bpp::StringTokenizer::nextToken().
|
static |
Tells if a parameter have been specified.
parameterName | The name of the parameter. |
params | The parameter list. |
Definition at line 63 of file ApplicationTools.cpp.
References bpp::TextTools::isEmpty().
Referenced by getParameter().
|
static |
Definition at line 70 of file ApplicationTools.cpp.
|
inlinestatic |
Starts the timer.
Definition at line 584 of file ApplicationTools.h.
References startTime.
Referenced by bpp::BppApplication::startTimer().
|
static |
The output stream where errors have to be displayed.
Definition at line 99 of file ApplicationTools.h.
Referenced by bpp::ReparametrizationFunctionWrapper::fireParameterChanged().
|
static |
Tell if the program is interactive (typically run in foreground). Default to yes.
Definition at line 127 of file ApplicationTools.h.
Referenced by bpp::BppApplication::BppApplication().
|
static |
The output stream where messages have to be displayed.
Definition at line 103 of file ApplicationTools.h.
Referenced by bpp::MetaOptimizer::doStep().
|
static |
|
static |
The fraction of terminal width dedicated to messages.
Definition at line 122 of file ApplicationTools.h.
Referenced by displayResult().
|
static |
The width of the output terminal (in character).
Definition at line 117 of file ApplicationTools.h.
Referenced by displayResult().
|
static |
The output stream where warnings have to be displayed.
Definition at line 107 of file ApplicationTools.h.
Referenced by bpp::RescaledHmmLikelihood::computeForward_(), and bpp::BppODiscreteDistributionFormat::initialize_().
|
static |
Specify the amount of warning to display.
Definition at line 132 of file ApplicationTools.h.
Referenced by bpp::BppApplication::BppApplication(), and getParameter().