NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
|
This class provides the functionality to extract the different components of a command line into the single elements: command, expression and parameter list. Furthermore, it shall simplify the interpretation of the values in the expression and the parameter list. This shall avoid code duplication. More...
#include <commandlineparser.hpp>
Public Types | |
enum | CommandSignature { CMD_PAR , CMD_DAT_PAR , CMD_EXPR_set_PAR } |
Public Member Functions | |
CommandLineParser (const std::string &sCommandLine, CommandSignature signature) | |
CommandLineParser constructor from a command line and the command signature. Will use the standard findCommand() function to detect a command. More... | |
CommandLineParser (const std::string &sCommandLine, const std::string &sCommand, CommandSignature signature) | |
CommandLineParser constructor from the command line, a specified command and the signature. Will use the standard findCommand() function in combination with the specified command to locate it in the command line. More... | |
const std::string & | getCommand () const |
Returns the command. More... | |
const std::string & | getExpr () const |
Returns the expression as plain value. More... | |
const std::string & | getParameterList () const |
Returns the parameter list. More... | |
const std::string & | getReturnValueStatement () const |
Returns the return value statement for commands with return values. More... | |
void | setReturnValue (const std::string &sRetVal) |
Sets the return value of the current command by simply appending it to the return value statement. More... | |
void | setReturnValue (const std::vector< mu::value_type > &vRetVal) |
Simple wrapper around the vector variable creation functionality of the parser. More... | |
void | setReturnValue (const std::vector< std::string > &vRetVal) |
Simple wrapper around the vector variable creation functionality of the string parser. More... | |
void | clearReturnValue () |
Removes the return value statement. More... | |
const std::string & | getCommandLine () const |
Returns the command line used for constructing this instance (e.g. for errors). More... | |
bool | exprContainsDataObjects () const |
Simply returns, whether the expression contains any data objects. More... | |
std::string | getExprAsFileName (std::string sFileExt, const std::string &sBasePath="") const |
Converts the expression to a file name and removes the surrounding quotation marks, if any. The passed extension is used to validate the file name. More... | |
DataAccessParser | getExprAsDataObject () const |
Parses the expression to a DataAccessParser, which will extract the needed information for the current data object. More... | |
std::string | getExprAsMathExpression (bool parseDataObjects=false) const |
Prepares the expression by calling custom function definitions and resolving vector braces so that the expression may be used for numerical evaluation. More... | |
std::string | parseExprAsString () const |
Prepares the expression by handling all string operations and removing the surrounding quotation marks. More... | |
std::vector< mu::value_type > | parseExprAsNumericalValues () const |
Parses the expression into numerical values, returned as a vector of doubles. More... | |
IntervalSet | parseIntervals (bool bErase=false) |
Parses intervals in the parameter list and returns them as a vector. The interval may be deleted, if the corresponding flag is set to true. More... | |
std::string | getTargetTable (Indices &_targetIndices, const std::string &sDefaultTableName) |
Evaluates any target=TABLE() statements in the parameter list and returns the needed information. Wraps the evaluateTargetOptionInCommand() function. More... | |
std::vector< std::string > | getAllParametersWithValues () const |
Returns a vector containing all parameters with values in the current parameter list. Does not return parameters, which do not have any value. More... | |
std::string | getParameterValue (const std::string &sParameter) const |
Simply returns the parameter value or an empty string. Does not do any parsing steps. More... | |
std::string | getFileParameterValue (std::string sFileExt, const std::string &sBaseFolder="", const std::string &sDefaultName="") const |
Parses the value of the common "file" command line parameter and returns a valid filename. More... | |
std::string | getFileParameterValueForSaving (std::string sFileExt, const std::string &sBaseFolder="", const std::string &sDefaultName="") const |
Parses the value of the common "file" command line parameter and returns a valid filename. Ensures that the target folder actually exists. More... | |
std::string | getParameterValueAsString (const std::string &sParameter, const std::string &sDefaultValue, bool stripAlways=false, bool onlyStringEvaluation=false) const |
Parses the selected parameter value as a string and returns it. If the parameter is not found, the default value is returned. More... | |
std::vector< mu::value_type > | getParameterValueAsNumericalValue (const std::string &sParameter) const |
Parses the selected parameter as (one or more) numerical value(s) and returns them as a vector of doubles. If the parameter is not found, an empty vector is returned. More... | |
bool | hasParam (const std::string &sParameter) const |
Simple wrapper around findParameter(), if used as a boolean flag. More... | |
Private Member Functions | |
void | parse (const std::string &sCommandString, CommandSignature signature) |
Private helper member function used for parsing the command line as specified by the command line signature. More... | |
std::string | parseFileName (std::string &sFileName, std::string &sFileExt, const std::string &sBasePath) const |
Common method to convert a prepared string into a valid file or folder name. More... | |
Private Attributes | |
std::string | m_cmd |
std::string | m_expr |
std::string | m_parlist |
std::string | m_returnValueStatement |
std::string | m_commandLine |
This class provides the functionality to extract the different components of a command line into the single elements: command, expression and parameter list. Furthermore, it shall simplify the interpretation of the values in the expression and the parameter list. This shall avoid code duplication.
Definition at line 38 of file commandlineparser.hpp.
Enumerator | |
---|---|
CMD_PAR | Command-parameter sequence. |
CMD_DAT_PAR | Command-dataobject-parameter sequence (e.g. fit) |
CMD_EXPR_set_PAR | Command-expression-set-parameter sequence. |
Definition at line 41 of file commandlineparser.hpp.
CommandLineParser::CommandLineParser | ( | const std::string & | sCommandLine, |
CommandLineParser::CommandSignature | signature | ||
) |
CommandLineParser constructor from a command line and the command signature. Will use the standard findCommand() function to detect a command.
sCommandLine | const std::string& |
signature | CommandLineParser::CommandSignature |
Definition at line 39 of file commandlineparser.cpp.
References extractCommandString(), findCommand(), m_cmd, m_returnValueStatement, Match::nPos, parse(), and Match::sString.
CommandLineParser::CommandLineParser | ( | const std::string & | sCommandLine, |
const std::string & | sCommand, | ||
CommandLineParser::CommandSignature | signature | ||
) |
CommandLineParser constructor from the command line, a specified command and the signature. Will use the standard findCommand() function in combination with the specified command to locate it in the command line.
sCommandLine | const std::string& |
sCommand | const std::string& |
signature | CommandLineParser::CommandSignature |
Definition at line 68 of file commandlineparser.cpp.
References extractCommandString(), findCommand(), m_cmd, m_returnValueStatement, Match::nPos, parse(), and Match::sString.
|
inline |
Removes the return value statement.
Definition at line 130 of file commandlineparser.hpp.
References m_returnValueStatement.
Referenced by createDatagrid(), moveOrCopyFiles(), shortTimeFourierAnalysis(), sortClusters(), sortData(), and sortStrings().
bool CommandLineParser::exprContainsDataObjects | ( | ) | const |
Simply returns, whether the expression contains any data objects.
Definition at line 273 of file commandlineparser.cpp.
References MemoryManager::containsTablesOrClusters(), NumeReKernel::getInstance(), NumeReKernel::getMemoryManager(), and m_expr.
Referenced by cmd_copy(), cmd_move(), cmd_remove(), cmd_resample(), cmd_smooth(), createDatagrid(), findExtrema(), findZeroes(), and getSamplesForDatagrid().
std::vector< std::string > CommandLineParser::getAllParametersWithValues | ( | ) | const |
Returns a vector containing all parameters with values in the current parameter list. Does not return parameters, which do not have any value.
Definition at line 502 of file commandlineparser.cpp.
References isInQuotes(), and m_parlist.
Referenced by evalPoints(), and taylor().
|
inline |
Returns the command.
Definition at line 68 of file commandlineparser.hpp.
References m_cmd.
Referenced by cmd_integrate(), cmd_show(), fastFourierTransform(), moveOrCopyFiles(), rotateTable(), and saveDataObject().
|
inline |
Returns the command line used for constructing this instance (e.g. for errors).
Definition at line 142 of file commandlineparser.hpp.
References m_commandLine.
Referenced by analyzePulse(), append_data(), boneDetection(), calculateSplines(), createDatagrid(), dialogCommand(), differentiate(), evalPoints(), fastFourierTransform(), fastWaveletTransform(), findExtrema(), findExtremaInData(), findZeroes(), findZeroesInData(), getParametersFromWindow(), getSamplesForDatagrid(), integrate(), integrate2d(), moveOrCopyFiles(), readFromFile(), readImage(), regularizeDataSet(), setParametersInWindow(), sortData(), taylor(), urlExecute(), windowCommand(), and writeToFile().
|
inline |
Returns the expression as plain value.
Definition at line 79 of file commandlineparser.hpp.
References m_expr.
Referenced by cmd_append(), cmd_clear(), cmd_copy(), cmd_delete(), cmd_diff(), cmd_extrema(), cmd_find(), cmd_load(), cmd_move(), cmd_pack(), cmd_progress(), cmd_read(), cmd_remove(), cmd_taylor(), cmd_unpack(), cmd_warn(), cmd_window(), cmd_workpath(), cmd_write(), cmd_zeroes(), deleteCacheEntry(), dialogCommand(), fastFourierTransform(), findExtrema(), findZeroes(), moveOrCopyFiles(), newObject(), removeFile(), taylor(), windowCommand(), and writeToFile().
DataAccessParser CommandLineParser::getExprAsDataObject | ( | ) | const |
Parses the expression to a DataAccessParser, which will extract the needed information for the current data object.
Definition at line 334 of file commandlineparser.cpp.
References SyntaxError::FUNCTION_ERROR, NumeReKernel::getInstance(), m_commandLine, m_expr, and promptForUserInput().
Referenced by analyzePulse(), boneDetection(), calculateSplines(), cmd_delete(), cmd_resample(), cmd_show(), cmd_smooth(), CopyData(), createDatagrid(), differentiate(), fastFourierTransform(), fastWaveletTransform(), getSamplesForDatagrid(), integrateSingleDimensionData(), moveData(), regularizeDataSet(), rotateTable(), saveDataObject(), shortTimeFourierAnalysis(), sortData(), and writeAudioFile().
std::string CommandLineParser::getExprAsFileName | ( | std::string | sFileExt, |
const std::string & | sBasePath = "" |
||
) | const |
Converts the expression to a file name and removes the surrounding quotation marks, if any. The passed extension is used to validate the file name.
sFileExt | std::string |
sBasePath | const std::string& |
Definition at line 290 of file commandlineparser.cpp.
References NumeRe::StringParser::evalAndFormat(), SyntaxError::FUNCTION_ERROR, getDataElements(), NumeReKernel::getInstance(), NumeReKernel::getStringParser(), NumeRe::StringVarFactory::getStringValues(), SyntaxError::invalid_position, m_expr, parseFileName(), removeQuotationMarks(), and StripSpaces().
Referenced by cmd_audioread(), cmd_seek(), cmd_start(), cmd_unpack(), cmd_workpath(), readAudioFile(), readFromFile(), and readImage().
std::string CommandLineParser::getExprAsMathExpression | ( | bool | parseDataObjects = false | ) | const |
Prepares the expression by calling custom function definitions and resolving vector braces so that the expression may be used for numerical evaluation.
parseDataObjects | bool |
Definition at line 359 of file commandlineparser.cpp.
References FunctionDefinitionManager::call(), MemoryManager::containsTablesOrClusters(), convertVectorToExpression(), SyntaxError::FUNCTION_ERROR, getDataElements(), NumeReKernel::getDefinitions(), NumeReKernel::getInstance(), NumeReKernel::getMemoryManager(), NumeReKernel::getParser(), NumeReKernel::getSettings(), m_commandLine, m_expr, promptForUserInput(), and StripSpaces().
Referenced by createDatagrid(), differentiate(), evalPoints(), integrate(), integrate2d(), particleSwarmOptimizer(), and taylor().
std::string CommandLineParser::getFileParameterValue | ( | std::string | sFileExt, |
const std::string & | sBaseFolder = "" , |
||
const std::string & | sDefaultName = "" |
||
) | const |
Parses the value of the common "file" command line parameter and returns a valid filename.
sFileExt | std::string |
sBaseFolder | const std::string& |
sDefaultName | const std::string& |
Definition at line 558 of file commandlineparser.cpp.
References ARGEXTRACT_NONE, NumeRe::StringParser::evalAndFormat(), findParameter(), SyntaxError::FUNCTION_ERROR, getArgAtPos(), getDataElements(), NumeReKernel::getInstance(), NumeReKernel::getStringParser(), NumeRe::StringVarFactory::getStringValues(), FileSystem::initializeFromKernel(), SyntaxError::invalid_position, NumeRe::StringParser::isStringExpression(), m_parlist, parseFileName(), removeQuotationMarks(), and FileSystem::ValidFileName().
Referenced by getFileParameterValueForSaving(), saveDataObject(), seekInAudioFile(), and urlExecute().
std::string CommandLineParser::getFileParameterValueForSaving | ( | std::string | sFileExt, |
const std::string & | sBaseFolder = "" , |
||
const std::string & | sDefaultName = "" |
||
) | const |
Parses the value of the common "file" command line parameter and returns a valid filename. Ensures that the target folder actually exists.
sFileExt | std::string |
sBaseFolder | const std::string& |
sDefaultName | const std::string& |
Definition at line 616 of file commandlineparser.cpp.
References getFileParameterValue(), FileSystem::initializeFromKernel(), and FileSystem::ValidizeAndPrepareName().
Referenced by cmd_pack(), urlExecute(), writeAudioFile(), and writeToFile().
|
inline |
Returns the parameter list.
Definition at line 90 of file commandlineparser.hpp.
References m_parlist.
Referenced by cmd_find(), cmd_load(), cmd_window(), dialogCommand(), differentiate(), evalPoints(), findExtrema(), findZeroes(), getParametersFromWindow(), setParametersInWindow(), sortClusters(), sortData(), sortStrings(), taylor(), windowCommand(), and writeToFile().
std::string CommandLineParser::getParameterValue | ( | const std::string & | sParameter | ) | const |
Simply returns the parameter value or an empty string. Does not do any parsing steps.
sParameter | const std::string& |
Definition at line 536 of file commandlineparser.cpp.
References ARGEXTRACT_NONE, findParameter(), getArgAtPos(), and m_parlist.
Referenced by cmd_load(), cmd_pack(), cmd_progress(), cmd_resample(), cmd_smooth(), evalPoints(), fastWaveletTransform(), integrate(), integrate2d(), and writeToFile().
std::vector< mu::value_type > CommandLineParser::getParameterValueAsNumericalValue | ( | const std::string & | sParameter | ) | const |
Parses the selected parameter as (one or more) numerical value(s) and returns them as a vector of doubles. If the parameter is not found, an empty vector is returned.
sParameter | const std::string& |
Definition at line 668 of file commandlineparser.cpp.
References ARGEXTRACT_PARSED, ARGEXTRACT_STRIPPED, findParameter(), getArgAtPos(), getNextArgument(), m_parlist, and StrToDb().
Referenced by append_data(), boneDetection(), cmd_load(), cmd_progress(), cmd_resample(), cmd_smooth(), createDatagrid(), differentiate(), evalPoints(), fastWaveletTransform(), integrate(), integrate2d(), particleSwarmOptimizer(), regularizeDataSet(), rotateTable(), saveDataObject(), shortTimeFourierAnalysis(), taylor(), and writeAudioFile().
std::string CommandLineParser::getParameterValueAsString | ( | const std::string & | sParameter, |
const std::string & | sDefaultValue, | ||
bool | stripAlways = false , |
||
bool | onlyStringEvaluation = false |
||
) | const |
Parses the selected parameter value as a string and returns it. If the parameter is not found, the default value is returned.
sParameter | const std::string& |
sDefaultValue | const std::string& |
stripAlways | bool Always strip quotation marks |
onlyStringEvaluation | bool |
Definition at line 637 of file commandlineparser.cpp.
References ARGEXTRACT_ASSTRING, ARGEXTRACT_NONE, ARGEXTRACT_PARSED, findParameter(), getArgAtPos(), m_parlist, removeQuotationMarks(), and StripSpaces().
Referenced by cmd_progress(), cmd_readline(), cmd_unpack(), dialogCommand(), executeCommand(), moveOrCopyFiles(), newObject(), readFromFile(), readImage(), setParametersInWindow(), and urlExecute().
|
inline |
Returns the return value statement for commands with return values.
Definition at line 102 of file commandlineparser.hpp.
References m_returnValueStatement.
Referenced by cmd_append(), cmd_audioread(), cmd_copy(), cmd_datagrid(), cmd_dialog(), cmd_diff(), cmd_eval(), cmd_extrema(), cmd_imread(), cmd_integrate(), cmd_load(), cmd_move(), cmd_pso(), cmd_pulse(), cmd_read(), cmd_readline(), cmd_seek(), cmd_sort(), cmd_stfa(), cmd_taylor(), cmd_unpack(), cmd_url(), cmd_window(), and cmd_zeroes().
std::string CommandLineParser::getTargetTable | ( | Indices & | _targetIndices, |
const std::string & | sDefaultTableName | ||
) |
Evaluates any target=TABLE() statements in the parameter list and returns the needed information. Wraps the evaluateTargetOptionInCommand() function.
_targetIndices | Indices& |
sDefaultTableName | const std::string& |
Definition at line 486 of file commandlineparser.cpp.
References evaluateTargetOptionInCommand(), NumeReKernel::getInstance(), NumeReKernel::getMemoryManager(), NumeReKernel::getParser(), NumeReKernel::getSettings(), and m_parlist.
Referenced by boneDetection(), CopyData(), createDatagrid(), fastFourierTransform(), fastWaveletTransform(), getParametersFromWindow(), moveData(), readAudioFile(), readImage(), rotateTable(), seekInAudioFile(), and shortTimeFourierAnalysis().
bool CommandLineParser::hasParam | ( | const std::string & | sParameter | ) | const |
Simple wrapper around findParameter(), if used as a boolean flag.
sParameter | const std::string& |
Definition at line 695 of file commandlineparser.cpp.
References findParameter(), and m_parlist.
Referenced by append_data(), cmd_clear(), cmd_copy(), cmd_delete(), cmd_load(), cmd_move(), cmd_pack(), cmd_readline(), cmd_remove(), cmd_resample(), cmd_smooth(), cmd_write(), CopyData(), createDatagrid(), differentiate(), evalPoints(), executeCommand(), fastFourierTransform(), fastWaveletTransform(), integrate(), integrateSingleDimensionData(), moveData(), moveOrCopyFiles(), newObject(), readFromFile(), readImage(), removeFile(), taylor(), urlExecute(), and writeToFile().
|
private |
Private helper member function used for parsing the command line as specified by the command line signature.
sCommandString | const std::string& |
signature | CommandLineParser::CommandSignature |
Definition at line 94 of file commandlineparser.cpp.
References CMD_DAT_PAR, CMD_EXPR_set_PAR, CMD_PAR, getMatchingParenthesis(), m_cmd, m_expr, m_parlist, and StripSpaces().
Referenced by CommandLineParser().
std::vector< mu::value_type > CommandLineParser::parseExprAsNumericalValues | ( | ) | const |
Parses the expression into numerical values, returned as a vector of doubles.
Definition at line 426 of file commandlineparser.cpp.
References FunctionDefinitionManager::call(), MemoryManager::containsTablesOrClusters(), mu::ParserBase::Eval(), NumeRe::StringParser::evalAndFormat(), SyntaxError::FUNCTION_ERROR, getDataElements(), NumeReKernel::getDefinitions(), NumeReKernel::getInstance(), NumeReKernel::getMemoryManager(), NumeReKernel::getParser(), NumeReKernel::getSettings(), NumeReKernel::getStringParser(), SyntaxError::invalid_position, NumeRe::StringParser::isStringExpression(), m_expr, and mu::ParserBase::SetExpr().
Referenced by cmd_progress(), cmd_warn(), and seekInAudioFile().
std::string CommandLineParser::parseExprAsString | ( | ) | const |
Prepares the expression by handling all string operations and removing the surrounding quotation marks.
Definition at line 392 of file commandlineparser.cpp.
References FunctionDefinitionManager::call(), NumeRe::StringParser::evalAndFormat(), SyntaxError::FUNCTION_ERROR, NumeReKernel::getDefinitions(), NumeReKernel::getInstance(), NumeReKernel::getStringParser(), m_commandLine, m_expr, promptForUserInput(), StripSpaces(), and toInternalString().
Referenced by append_data(), cmd_load(), cmd_remove(), cmd_warn(), executeCommand(), newObject(), removeFile(), and urlExecute().
|
private |
Common method to convert a prepared string into a valid file or folder name.
sFileName | std::string& |
sFileExt | std::string& |
sBasePath | const std::string& |
Definition at line 198 of file commandlineparser.cpp.
References FileSystem::declareFileType(), SyntaxError::FILETYPE_MAY_NOT_BE_WRITTEN, FileSystem::initializeFromKernel(), SyntaxError::invalid_position, m_commandLine, FileSystem::ValidFileName(), and FileSystem::ValidFolderName().
Referenced by getExprAsFileName(), and getFileParameterValue().
IntervalSet CommandLineParser::parseIntervals | ( | bool | bErase = false | ) |
Parses intervals in the parameter list and returns them as a vector. The interval may be deleted, if the corresponding flag is set to true.
bErase | bool |
Definition at line 469 of file commandlineparser.cpp.
References m_parlist.
Referenced by cmd_integrate(), createDatagrid(), evalPoints(), integrate(), integrate2d(), integrateSingleDimensionData(), and particleSwarmOptimizer().
|
inline |
Sets the return value of the current command by simply appending it to the return value statement.
sRetVal | const std::string& |
Definition at line 116 of file commandlineparser.hpp.
References m_returnValueStatement.
Referenced by analyzePulse(), cmd_append(), cmd_load(), cmd_readline(), cmd_unpack(), createDatagrid(), dialogCommand(), differentiate(), evalPoints(), findExtrema(), findExtremaInData(), findExtremaInMultiResult(), findZeroes(), findZeroesInData(), findZeroesInMultiResult(), getParametersFromWindow(), integrate(), integrate2d(), moveOrCopyFiles(), particleSwarmOptimizer(), readAudioFile(), readFromFile(), readImage(), seekInAudioFile(), setParametersInWindow(), shortTimeFourierAnalysis(), sortClusters(), sortData(), sortStrings(), taylor(), urlExecute(), and windowCommand().
void CommandLineParser::setReturnValue | ( | const std::vector< mu::value_type > & | vRetVal | ) |
Simple wrapper around the vector variable creation functionality of the parser.
vRetVal | const std::vector<mu::value_type>& |
Definition at line 245 of file commandlineparser.cpp.
References mu::ParserBase::CreateTempVectorVar(), NumeReKernel::getInstance(), NumeReKernel::getParser(), and m_returnValueStatement.
void CommandLineParser::setReturnValue | ( | const std::vector< std::string > & | vRetVal | ) |
Simple wrapper around the vector variable creation functionality of the string parser.
vRetVal | const std::vector<std::string>& |
Definition at line 260 of file commandlineparser.cpp.
References NumeRe::StringVarFactory::createTempStringVectorVar(), NumeReKernel::getInstance(), NumeReKernel::getStringParser(), and m_returnValueStatement.
|
private |
Definition at line 49 of file commandlineparser.hpp.
Referenced by CommandLineParser(), getCommand(), and parse().
|
private |
Definition at line 53 of file commandlineparser.hpp.
Referenced by getCommandLine(), getExprAsDataObject(), getExprAsMathExpression(), parseExprAsString(), and parseFileName().
|
private |
Definition at line 50 of file commandlineparser.hpp.
Referenced by exprContainsDataObjects(), getExpr(), getExprAsDataObject(), getExprAsFileName(), getExprAsMathExpression(), parse(), parseExprAsNumericalValues(), and parseExprAsString().
|
private |
Definition at line 51 of file commandlineparser.hpp.
Referenced by getAllParametersWithValues(), getFileParameterValue(), getParameterList(), getParameterValue(), getParameterValueAsNumericalValue(), getParameterValueAsString(), getTargetTable(), hasParam(), parse(), and parseIntervals().
|
private |
Definition at line 52 of file commandlineparser.hpp.
Referenced by clearReturnValue(), CommandLineParser(), getReturnValueStatement(), and setReturnValue().