NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
commandlineparser.hpp
Go to the documentation of this file.
1/*****************************************************************************
2 NumeRe: Framework fuer Numerische Rechnungen
3 Copyright (C) 2021 Erik Haenel et al.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17******************************************************************************/
18
19#ifndef COMMANDLINEPARSER_HPP
20#define COMMANDLINEPARSER_HPP
21
22#include <string>
23#include <vector>
24
25#include "structures.hpp"
27
39{
40 public:
42 {
46 };
47
48 private:
49 std::string m_cmd;
50 std::string m_expr;
51 std::string m_parlist;
53 std::string m_commandLine;
54
55 void parse(const std::string& sCommandString, CommandSignature signature);
56 std::string parseFileName(std::string& sFileName, std::string& sFileExt, const std::string& sBasePath) const;
57
58 public:
59 CommandLineParser(const std::string& sCommandLine, CommandSignature signature);
60 CommandLineParser(const std::string& sCommandLine, const std::string& sCommand, CommandSignature signature);
61
68 inline const std::string& getCommand() const
69 {
70 return m_cmd;
71 }
72
79 inline const std::string& getExpr() const
80 {
81 return m_expr;
82 }
83
90 inline const std::string& getParameterList() const
91 {
92 return m_parlist;
93 }
94
102 inline const std::string& getReturnValueStatement() const
103 {
105 }
106
116 inline void setReturnValue(const std::string& sRetVal)
117 {
118 m_returnValueStatement += sRetVal;
119 }
120
121 void setReturnValue(const std::vector<mu::value_type>& vRetVal);
122 void setReturnValue(const std::vector<std::string>& vRetVal);
123
130 inline void clearReturnValue()
131 {
133 }
134
142 inline const std::string& getCommandLine() const
143 {
144 return m_commandLine;
145 }
146
147 bool exprContainsDataObjects() const;
148 std::string getExprAsFileName(std::string sFileExt, const std::string& sBasePath = "") const;
150 std::string getExprAsMathExpression(bool parseDataObjects = false) const;
151 std::string parseExprAsString() const;
152 std::vector<mu::value_type> parseExprAsNumericalValues() const;
153 IntervalSet parseIntervals(bool bErase = false);
154 std::string getTargetTable(Indices& _targetIndices, const std::string& sDefaultTableName);
155 std::vector<std::string> getAllParametersWithValues() const;
156 std::string getParameterValue(const std::string& sParameter) const;
157 std::string getFileParameterValue(std::string sFileExt, const std::string& sBaseFolder = "", const std::string& sDefaultName = "") const;
158 std::string getFileParameterValueForSaving(std::string sFileExt, const std::string& sBaseFolder = "", const std::string& sDefaultName = "") const;
159 std::string getParameterValueAsString(const std::string& sParameter, const std::string& sDefaultValue, bool stripAlways = false, bool onlyStringEvaluation = false) const;
160 std::vector<mu::value_type> getParameterValueAsNumericalValue(const std::string& sParameter) const;
161 bool hasParam(const std::string& sParameter) const;
162};
163
164#endif // COMMANDLINEPARSER_HPP
165
This class provides the functionality to extract the different components of a command line into the ...
std::vector< mu::value_type > parseExprAsNumericalValues() const
Parses the expression into numerical values, returned as a vector of doubles.
void parse(const std::string &sCommandString, CommandSignature signature)
Private helper member function used for parsing the command line as specified by the command line sig...
std::string m_returnValueStatement
DataAccessParser getExprAsDataObject() const
Parses the expression to a DataAccessParser, which will extract the needed information for the curren...
const std::string & getReturnValueStatement() const
Returns the return value statement for commands with return values.
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.
const std::string & getCommandLine() const
Returns the command line used for constructing this instance (e.g. for errors).
std::string getExprAsMathExpression(bool parseDataObjects=false) const
Prepares the expression by calling custom function definitions and resolving vector braces so that th...
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 dou...
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,...
const std::string & getExpr() const
Returns the expression as plain value.
const std::string & getParameterList() const
Returns the parameter list.
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....
std::string getTargetTable(Indices &_targetIndices, const std::string &sDefaultTableName)
Evaluates any target=TABLE() statements in the parameter list and returns the needed information....
void setReturnValue(const std::string &sRetVal)
Sets the return value of the current command by simply appending it to the return value statement.
void clearReturnValue()
Removes the return value statement.
const std::string & getCommand() const
Returns the command.
std::string parseExprAsString() const
Prepares the expression by handling all string operations and removing the surrounding quotation mark...
std::string getParameterValue(const std::string &sParameter) const
Simply returns the parameter value or an empty string. Does not do any parsing steps.
@ CMD_PAR
Command-parameter sequence.
@ CMD_DAT_PAR
Command-dataobject-parameter sequence (e.g. fit)
@ CMD_EXPR_set_PAR
Command-expression-set-parameter sequence.
std::vector< std::string > getAllParametersWithValues() const
Returns a vector containing all parameters with values in the current parameter list....
CommandLineParser(const std::string &sCommandLine, CommandSignature signature)
CommandLineParser constructor from a command line and the command signature. Will use the standard fi...
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.
std::string getExprAsFileName(std::string sFileExt, const std::string &sBasePath="") const
Converts the expression to a file name and removes the surrounding quotation marks,...
bool exprContainsDataObjects() const
Simply returns, whether the expression contains any data objects.
IntervalSet parseIntervals(bool bErase=false)
Parses intervals in the parameter list and returns them as a vector. The interval may be deleted,...
bool hasParam(const std::string &sParameter) const
Simple wrapper around findParameter(), if used as a boolean flag.
This class is defined to abstrahize the determination of the correct data object and the calculation ...
Definition: dataaccess.hpp:38
This structure is central for managing the indices of a table or cluster read or write data access....
This class represents a set of intervals used together for calculations and simulations.
Definition: interval.hpp:84