NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
CommandLineParser Class Reference

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>

Collaboration diagram for CommandLineParser:

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_typeparseExprAsNumericalValues () 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_typegetParameterValueAsNumericalValue (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
 

Detailed Description

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.

Member Enumeration Documentation

◆ CommandSignature

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.

Constructor & Destructor Documentation

◆ CommandLineParser() [1/2]

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.

Parameters
sCommandLineconst std::string&
signatureCommandLineParser::CommandSignature

Definition at line 39 of file commandlineparser.cpp.

References extractCommandString(), findCommand(), m_cmd, m_returnValueStatement, Match::nPos, parse(), and Match::sString.

Here is the call graph for this function:

◆ CommandLineParser() [2/2]

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.

Parameters
sCommandLineconst std::string&
sCommandconst std::string&
signatureCommandLineParser::CommandSignature

Definition at line 68 of file commandlineparser.cpp.

References extractCommandString(), findCommand(), m_cmd, m_returnValueStatement, Match::nPos, parse(), and Match::sString.

Here is the call graph for this function:

Member Function Documentation

◆ clearReturnValue()

void CommandLineParser::clearReturnValue ( )
inline

Removes the return value statement.

Returns
void

Definition at line 130 of file commandlineparser.hpp.

References m_returnValueStatement.

Referenced by createDatagrid(), moveOrCopyFiles(), shortTimeFourierAnalysis(), sortClusters(), sortData(), and sortStrings().

◆ exprContainsDataObjects()

bool CommandLineParser::exprContainsDataObjects ( ) const

Simply returns, whether the expression contains any data objects.

Returns
bool

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().

Here is the call graph for this function:

◆ getAllParametersWithValues()

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.

Returns
std::vector<std::string>

Definition at line 502 of file commandlineparser.cpp.

References isInQuotes(), and m_parlist.

Referenced by evalPoints(), and taylor().

Here is the call graph for this function:

◆ getCommand()

const std::string & CommandLineParser::getCommand ( ) const
inline

Returns the command.

Returns
const std::string&

Definition at line 68 of file commandlineparser.hpp.

References m_cmd.

Referenced by cmd_integrate(), cmd_show(), fastFourierTransform(), moveOrCopyFiles(), rotateTable(), and saveDataObject().

◆ getCommandLine()

◆ getExpr()

◆ getExprAsDataObject()

DataAccessParser CommandLineParser::getExprAsDataObject ( ) const

Parses the expression to a DataAccessParser, which will extract the needed information for the current data object.

Returns
DataAccessParser

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().

Here is the call graph for this function:

◆ getExprAsFileName()

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.

Parameters
sFileExtstd::string
sBasePathconst std::string&
Returns
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().

Here is the call graph for this function:

◆ getExprAsMathExpression()

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.

Parameters
parseDataObjectsbool
Returns
std::string

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().

Here is the call graph for this function:

◆ getFileParameterValue()

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.

Parameters
sFileExtstd::string
sBaseFolderconst std::string&
sDefaultNameconst std::string&
Returns
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().

Here is the call graph for this function:

◆ getFileParameterValueForSaving()

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.

Parameters
sFileExtstd::string
sBaseFolderconst std::string&
sDefaultNameconst std::string&
Returns
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().

Here is the call graph for this function:

◆ getParameterList()

const std::string & CommandLineParser::getParameterList ( ) const
inline

◆ getParameterValue()

std::string CommandLineParser::getParameterValue ( const std::string &  sParameter) const

Simply returns the parameter value or an empty string. Does not do any parsing steps.

Parameters
sParameterconst std::string&
Returns
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().

Here is the call graph for this function:

◆ getParameterValueAsNumericalValue()

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.

Parameters
sParameterconst std::string&
Returns
std::vector<mu::value_type>

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().

Here is the call graph for this function:

◆ getParameterValueAsString()

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.

Parameters
sParameterconst std::string&
sDefaultValueconst std::string&
stripAlwaysbool Always strip quotation marks
onlyStringEvaluationbool
Returns
std::string

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().

Here is the call graph for this function:

◆ getReturnValueStatement()

const std::string & CommandLineParser::getReturnValueStatement ( ) const
inline

◆ getTargetTable()

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.

Parameters
_targetIndicesIndices&
sDefaultTableNameconst std::string&
Returns
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().

Here is the call graph for this function:

◆ hasParam()

bool CommandLineParser::hasParam ( const std::string &  sParameter) const

Simple wrapper around findParameter(), if used as a boolean flag.

Parameters
sParameterconst std::string&
Returns
bool

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().

Here is the call graph for this function:

◆ parse()

void CommandLineParser::parse ( const std::string &  sCommandString,
CommandLineParser::CommandSignature  signature 
)
private

Private helper member function used for parsing the command line as specified by the command line signature.

Parameters
sCommandStringconst std::string&
signatureCommandLineParser::CommandSignature
Returns
void

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().

Here is the call graph for this function:

◆ parseExprAsNumericalValues()

std::vector< mu::value_type > CommandLineParser::parseExprAsNumericalValues ( ) const

Parses the expression into numerical values, returned as a vector of doubles.

Returns
std::vector<mu::value_type>

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().

Here is the call graph for this function:

◆ parseExprAsString()

std::string CommandLineParser::parseExprAsString ( ) const

Prepares the expression by handling all string operations and removing the surrounding quotation marks.

Returns
std::string

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().

Here is the call graph for this function:

◆ parseFileName()

std::string CommandLineParser::parseFileName ( std::string &  sFileName,
std::string &  sFileExt,
const std::string &  sBasePath 
) const
private

Common method to convert a prepared string into a valid file or folder name.

Parameters
sFileNamestd::string&
sFileExtstd::string&
sBasePathconst std::string&
Returns
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().

Here is the call graph for this function:

◆ parseIntervals()

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.

Parameters
bErasebool
Returns
IntervalSet

Definition at line 469 of file commandlineparser.cpp.

References m_parlist.

Referenced by cmd_integrate(), createDatagrid(), evalPoints(), integrate(), integrate2d(), integrateSingleDimensionData(), and particleSwarmOptimizer().

◆ setReturnValue() [1/3]

◆ setReturnValue() [2/3]

void CommandLineParser::setReturnValue ( const std::vector< mu::value_type > &  vRetVal)

Simple wrapper around the vector variable creation functionality of the parser.

Parameters
vRetValconst std::vector<mu::value_type>&
Returns
void

Definition at line 245 of file commandlineparser.cpp.

References mu::ParserBase::CreateTempVectorVar(), NumeReKernel::getInstance(), NumeReKernel::getParser(), and m_returnValueStatement.

Here is the call graph for this function:

◆ setReturnValue() [3/3]

void CommandLineParser::setReturnValue ( const std::vector< std::string > &  vRetVal)

Simple wrapper around the vector variable creation functionality of the string parser.

Parameters
vRetValconst std::vector<std::string>&
Returns
void

Definition at line 260 of file commandlineparser.cpp.

References NumeRe::StringVarFactory::createTempStringVectorVar(), NumeReKernel::getInstance(), NumeReKernel::getStringParser(), and m_returnValueStatement.

Here is the call graph for this function:

Member Data Documentation

◆ m_cmd

std::string CommandLineParser::m_cmd
private

Definition at line 49 of file commandlineparser.hpp.

Referenced by CommandLineParser(), getCommand(), and parse().

◆ m_commandLine

std::string CommandLineParser::m_commandLine
private

◆ m_expr

◆ m_parlist

◆ m_returnValueStatement

std::string CommandLineParser::m_returnValueStatement
private

The documentation for this class was generated from the following files: