21#include "../kernel.hpp"
54 if (sCommand ==
"find" || sCommand ==
"search")
56 else if (sCommand ==
"help" || sCommand ==
"man" || sCommand ==
"doc")
64 for (
auto iter = mCommandsWithReturnValue.begin(); iter != mCommandsWithReturnValue.end(); ++iter)
67 return iter->second(sCmd);
72 auto iter = mCommands.find(sCommand);
74 if (iter != mCommands.end())
75 return iter->second(sCmd);
115 for (
unsigned int i = 0; i < sTemp.length(); i++)
136 for (
int j = (
int)i; j >= 0; j--)
140 if (sTemp[j] ==
'(' && j && (isalnum(sTemp[j - 1]) || sTemp[j - 1] ==
'_'))
142 while (j && (isalnum(sTemp[j - 1]) || sTemp[j - 1] ==
'_'))
175 if (sArgument.find(
'<') != string::npos && sArgument.find(
'>', sArgument.find(
'<')) != string::npos)
177 for (
unsigned int i = 0; i < sArgument.length(); i++)
179 if (sArgument.find(
'<', i) == string::npos)
182 if (sArgument[i] ==
'<' && sArgument.find(
'>', i) != string::npos)
184 string sToken = sArgument.substr(i, sArgument.find(
'>', i) + 1 - i);
186 if (sToken ==
"<this>")
189 if (sToken.find(
'/') == string::npos)
196 i = sArgument.find(
'>', i);
206 sArgument = sArgument.substr(1, sArgument.length() - 2);
228 string sReturn = sCmd;
231 unsigned int nPos = 0;
232 unsigned int nLength = 0;
233 vector<double> vInterval;
236 if (sReturn.back() !=
' ')
240 if (sReturn.find(
'-') != string::npos
241 && (sReturn.find(
'[') != string::npos
248 if (sReturn.find(
"-set") != string::npos)
250 sTemp = sReturn.substr(sReturn.find(
"-set"));
251 sReturn.erase(sReturn.find(
"-set"));
253 else if (sReturn.find(
"--") != string::npos)
255 sTemp = sReturn.substr(sReturn.find(
"--"));
256 sReturn.erase(sReturn.find(
"--"));
260 sTemp = sReturn.substr(sReturn.find(
'-'));
261 sReturn.erase(sReturn.find(
"-"));
277 while (sReturn.find(
'=', nPos) != string::npos)
280 nPos = sReturn.find(
'=', nPos) + 1;
290 while (nPos < sReturn.length() - 1 && sReturn[nPos] ==
' ')
294 if (
NumeReKernel::getInstance()->getStringParser().isStringExpression(sReturn.substr(nPos, sReturn.find(
' ', nPos) - nPos)))
301 nLength = sTemp.length();
308 sReturn.replace(nPos, nLength, sTemp);
310 else if ((nPos > 5 && sReturn.substr(nPos - 5, 5) ==
"save=")
311 || (nPos > 7 && sReturn.substr(nPos - 7, 7) ==
"export="))
315 sTemp = sReturn.substr(nPos, sReturn.find(
' ', nPos) - nPos);
316 nLength = sTemp.length();
319 sTemp =
"\"" + sTemp +
"\"";
320 sReturn.replace(nPos, nLength, sTemp);
322 else if ((nPos > 8 && sReturn.substr(nPos - 8, 8) ==
"tocache=")
323 || (nPos > 8 && sReturn.substr(nPos - 8, 8) ==
"totable=")
324 || (nPos > 5 && sReturn.substr(nPos - 5, 5) ==
"type=")
325 || (nPos > 5 && sReturn.substr(nPos - 5, 5) ==
"icon=")
326 || (nPos > 7 && sReturn.substr(nPos - 7, 7) ==
"method=")
327 || (nPos > 7 && sReturn.substr(nPos - 7, 7) ==
"target=")
328 || (nPos > 8 && sReturn.substr(nPos - 8, 8) ==
"buttons="))
339 sTemp = sReturn.substr(nPos, sReturn.find(
' ', nPos) - nPos);
340 nLength = sTemp.length();
343 if (!_functions.
call(sTemp))
355 if (sTemp.find(
':') != string::npos)
357 string sTemp_2 = sTemp;
359 sTemp +=
", " + sTemp_2;
364 v = _parser.
Eval(nResult);
370 for (
int i = 0; i < nResult; i++)
376 sReturn.replace(nPos, nLength, sTemp);
382 if (vInterval.size())
385 if (vInterval.size() >= 2)
387 if (!
isnan(vInterval[0]) && !
isnan(vInterval[1]))
392 if (vInterval.size() >= 4)
394 if (!
isnan(vInterval[2]) && !
isnan(vInterval[3]))
399 if (vInterval.size() >= 6)
401 if (!
isnan(vInterval[4]) && !
isnan(vInterval[5]))
424 if (!sCmd.length() || !nPos)
427 while (nPos < sCmd.length() - 1 && sCmd[nPos] ==
' ')
430 if (sCmd[nPos] ==
' ' || nPos >= sCmd.length() - 1)
433 string sArg = sCmd.substr(nPos);
438 sArg = sArg.substr(0, sArg.find(
' '));
bool extractFirstParameterStringValue(const string &sCmd, string &sArgument)
This function returns the string argument for a single parameter in the command line.
bool parseCmdArg(const string &sCmd, size_t nPos, Parser &_parser, size_t &nArgument)
This function finds the numerical argument to the selected command line parameter and evaluates it.
string evaluateParameterValues(const string &sCmd)
This function evaluates a passed parameter string, so that the values of the parameters are only valu...
CommandReturnValues commandHandler(string &sCmd)
This function is the main command handling function.
This class implements the function definition managing instance.
bool call(std::string &sExpr, int nRecursion=0)
This function searches for known custom definitions in the passed expression and replaces them with t...
This class represents the central memory managing instance. It will handle all tables and clusters,...
bool containsTablesOrClusters(const std::string &sCmdLine)
This member function evaluates, whether the passed command line contains tables or clusters.
virtual bool isStringExpression(const std::string &sExpression) override
Returns true, if the passed expression is an expression containing strings, string variables or strin...
StringParserRetVal evalAndFormat(std::string &sLine, std::string &sCache, bool bSilent=false, bool bCheckAssertions=false)
This public member function evaluates the passed string expression and formats the results for the co...
void getStringValues(std::string &sLine)
This public member function resolves all string variable occurences and replaces them with their valu...
static NumeReKernel * getInstance()
This static member function returns a a pointer to the singleton instance of the kernel.
NumeRe::StringParser & getStringParser()
MemoryManager & getMemoryManager()
FunctionDefinitionManager & getDefinitions()
This class manages the setting values of the internal (kernel) settings of this application.
size_t getPrecision() const
Returns the precision for displaying floating numbers in the terminal. This value determines the numb...
std::string getTokenPaths() const
Returns a semicolon-separated list of the current defined path placeholders and their values.
std::string getExePath() const
Returns the current application root folder path.
Common exception class for all exceptions thrown in NumeRe.
@ UNKNOWN_PATH_TOKEN
INSERT HERE.
void SetExpr(StringView a_sExpr)
Set the expression. Triggers first time calculation thus the creation of the bytecode and scanning of...
value_type Eval()
Single-value wrapper around the vectorized overload of this member function.
Mathematical expressions parser.
static std::map< std::string, CommandFunc > getCommandFunctionsWithReturnValues()
This static function returns a map of commands with return values linked to their function implementa...
static CommandReturnValues cmd_find(string &sCmd)
This static function implements the "find" command.
static CommandReturnValues cmd_help(string &sCmd)
This static function implements the "help" command.
static std::map< std::string, CommandFunc > getCommandFunctions()
This static function returns a map of commands linked to their function implementation.
static CommandReturnValues cmd_get(string &sCmd)
This static function implements the "get" command.
string getDataElements(string &sLine, Parser &_parser, MemoryManager &_data, const Settings &_option, int options)
Searches the passed string for calls to any table or cluster and replaces them with internal vectors ...
unsigned int getMatchingParenthesis(const StringView &)
Returns the position of the closing parenthesis.
CONSTCD11 std::chrono::duration< Rep, Period > abs(std::chrono::duration< Rep, Period > d)
MUP_BASETYPE value_type
The numeric datatype used by the parser.
bool isnan(const value_type &v)
bool isinf(const value_type &v)
vector< double > readAndParseIntervals(string &sExpr, Parser &_parser, MemoryManager &_data, FunctionDefinitionManager &_functions, const Settings &_option, bool bEraseInterval)
This function will read the interval syntax in commands and return their values in a single vector.
void StripSpaces(std::string &)
Removes leading and trailing white spaces and tabulator characters.
int findParameter(const std::string &sCmd, const std::string &sParam, const char cFollowing)
This function searches the passed parameter in the passed command string. If something is found,...
long long int intCast(const std::complex< double > &)
Casts the real part of the complex number to an integer and avoids rounding errors.
std::string toString(int)
Converts an integer to a string without the Settings bloat.