20#include "../../kernel.hpp"
37 if (sComponent.front() !=
'"' && sComponent.find_first_of(
"+-*/^!&|<>=% ?:,") != string::npos)
39 if ((sComponent.front() ==
'(' || sComponent.front() ==
'{') &&
getMatchingParenthesis(sComponent) == sComponent.length()-1)
60 if (!vStringVector.size())
69 if (vStringVector.size() == 1 && vStringVector.front().find(strVectName) != std::string::npos)
115 throw std::out_of_range(
"Could not find " + sVarName +
" in the string vectors.");
138 if (sLine.find(iter->first) != string::npos)
146 if (sLine.find(iter->first) != string::npos)
171 g_logger.
info(
"Evaluating string vector for '" + sLine +
"'");
176 while (sLine.length())
189 size_t nCurrentComponent = 0;
194 string currentline = sCurrentComponent;
195 bool bHasComponents =
false;
198 for (
auto iter = mNumVectorVars.begin(); iter != mNumVectorVars.end(); ++iter)
203 while ((nMatch = currentline.find(iter->first, nMatch)) != string::npos)
209 || (nMatch + iter->first.length() < currentline.length() && !
isDelimiter(currentline[nMatch+iter->first.length()])))
216 if ((iter->second).size() > nCurrentComponent)
218 bHasComponents =
true;
219 currentline.replace(nMatch, (iter->first).length(),
toCmdString((iter->second)[nCurrentComponent]));
221 else if ((iter->second).size() == 1)
222 currentline.replace(nMatch, (iter->first).length(),
toCmdString((iter->second)[0]));
224 currentline.replace(nMatch, (iter->first).length(),
"nan");
268 if (vStringVector.size() == 1)
269 return vStringVector.front();
274 for (
size_t i = 1; i < vStringVector.size(); i++)
276 vRet.insert(vRet.end(), vStringVector[i].begin(), vStringVector[i].end());
314 if (!vStringVector.size())
320 if (strVectName.length())
361 static const string sDELIMITER =
"+-*/ ()={}^&|!<>,\\%#[]?:\";";
365 if (sToken.back() ==
'(')
371 return sDELIMITER.find(sToken.front()) != string::npos && (sDELIMITER.find(sToken.back()) != string::npos || sToken.back() ==
'.');
390 for (
auto iter = mVectorVarMap.begin(); iter != mVectorVarMap.end(); ++iter)
395 while ((nMatch = currentline.find(iter->first)) != string::npos)
398 if ((iter->second).size() > nCurrentComponent)
400 bHasComponents =
true;
402 if (!iter->second.is_string(nCurrentComponent))
403 currentline.replace(nMatch, (iter->first).length(),
"(" + (iter->second).getMasked(nCurrentComponent) +
")");
405 currentline.replace(nMatch, (iter->first).length(), (iter->second).getMasked(nCurrentComponent));
407 else if ((iter->second).size() == 1)
409 if (!iter->second.is_string(0))
410 currentline.replace(nMatch, (iter->first).length(),
"(" + (iter->second).getMasked(0) +
")");
412 currentline.replace(nMatch, (iter->first).length(), (iter->second).getMasked(0));
415 currentline.replace(nMatch, (iter->first).length(),
"\"\"");
435 for (
auto iter = mVectorVarMap.begin(); iter != mVectorVarMap.end(); ++iter)
438 if (iter->second.size() == vStringVector.size() && iter->second[0] == vStringVector[0])
442 for (
size_t i = 1; i < vStringVector.size(); i++)
445 if (vStringVector[i] != iter->second.at(i))
450 if (i == vStringVector.size()-1)
477 string sLine =
" " + _sLine +
" ";
486 while ((pos = sLine.find(iter->first, pos)) != std::string::npos)
490 if (sLine[pos+(iter->first).length()] !=
'('
545 std::string sVectVar;
549 while ((__nPos = sLine.find(iter->first, __nPos)) != string::npos)
554 if (sLine[__nPos+(iter->first).length()-1] ==
'('
555 || sLine[__nPos+(iter->first).length()-1] ==
'{')
559 if (!sVectVar.length())
574 if (sLine[(iter->first).length()] ==
'.')
577 sLine.replace(0, (iter->first).length(), sVectVar);
588 if (sLine[__nPos+(iter->first).length()-1] ==
'.')
591 sLine.replace(__nPos-1, (iter->first).length(), sVectVar);
623 std::string sVectVar;
627 while ((__nPos = sLine.find(iter->first, __nPos)) != string::npos)
632 if (sLine[__nPos+(iter->first).length()-1] ==
'('
633 || sLine[__nPos+(iter->first).length()-1] ==
'{')
637 if (!sVectVar.length())
638 sVectVar =
"\""+iter->second+
"\"";
651 if (sLine[(iter->first).length()] ==
'.')
654 sLine.replace(0, (iter->first).length(), sVectVar);
665 if (sLine[__nPos+(iter->first).length()-1] ==
'.')
668 sLine.replace(__nPos-1, (iter->first).length(), sVectVar);
706 static const string sVALIDCHARACTERS =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_1234567890~";
709 if (sVar[0] >=
'0' && sVar[0] <=
'9')
714 for (
unsigned int i = 0; i < sVar.length(); i++)
716 if (sVALIDCHARACTERS.find(sVar[i]) == string::npos)
722 if (sValue[0] ==
'"' && sValue[sValue.length()-1] ==
'"')
void info(const std::string &sMessage)
Convenience member function.
std::map< std::string, StringVector > m_mTempStringVectorVars
StringVector evaluateStringVectors(std::string sLine)
This member function evaluates the passed string vector and returns it's evaluated components in sepa...
const StringVector & getStringVectorVar(const std::string &sVarName) const
Return a reference to the identified string vector variable or throw if it does not exist.
bool containsStringVars(const std::string &sLine) const
This public member function determines, whether the passed string line contains string variables as p...
void removeStringVectorVars()
This member function removes all internal string vector variables.
std::map< std::string, StringVector > m_mStringVectorVars
bool isStringVectorVar(const std::string &sVarName) const
Check, whether the passed string identifies a string vector variable.
bool isStringVar(const std::string &sVarName) const
Determine, whether the passed string is the identifier of a string variable.
bool checkStringvarDelimiter(const std::string &sToken) const
This private member function examines the first and the last character of the passed string and deter...
std::map< std::string, std::string > m_mStringVars
StringVector expandStringVectorComponents(std::vector< StringVector > &vStringVector)
This member function expands the internal multi-expressions in the veector into separate components b...
bool containsStringVectorVars(const std::string &sLine)
This member function determines, whether there are string vector variables in the passed command line...
void setStringValue(const std::string &sVar, const std::string &sValue)
This public member function creates or updates a string variable and fills it with the passed value.
void replaceStringVectorVars(std::map< std::string, StringVector > &mVectorVarMap, std::string ¤tline, size_t nCurrentComponent, bool &bHasComponents)
Replaces all found vectors of the passed map with their nCurrentComponent component.
std::string findVectorInMap(const std::map< std::string, StringVector > &mVectorVarMap, const std::vector< std::string > &vStringVector)
Searches for the passed string in the passed map and returns the key string from the map,...
void getStringValues(std::string &sLine)
This public member function resolves all string variable occurences and replaces them with their valu...
std::string createStringVectorVar(const std::vector< std::string > &vStringVector)
This member function is used to create a string vector variable.
void removeTempStringVectorVars()
This member function removes all temporary string vector variables.
std::string createTempStringVectorVar(const std::vector< std::string > &vStringVector)
This member function is used to create a temporary string vector variable.
bool isNumericCandidate(const std::string &sComponent)
This member function is used to determine, whether a string vector component is numerical parsable.
std::string getStringValue(const std::string &sVar) const
Returns the value of the selected string variable.
void removeStringVar(const std::string &sVar)
This public member function removes the selected string variable from memory.
void getStringValuesAsInternalVar(std::string &sLine, unsigned int nPos=0)
This public member function resolves all string variable occurences and replaces them with an interna...
static NumeReKernel * getInstance()
This static member function returns a a pointer to the singleton instance of the kernel.
This class is an extension to the std::vector<std::string> to provide the vector-like functionalities...
void push_generic(const std::string &sStr)
Append a generic string value to the end of this vector. Depending on the existence of surrounding qu...
Common exception class for all exceptions thrown in NumeRe.
@ STRINGVARS_MUSTNT_CONTAIN
@ STRINGVARS_MUSTNT_BEGIN_WITH_A_NUMBER
static size_t invalid_position
const std::map< std::string, std::vector< mu::value_type > > & GetVectors() const
unsigned int getMatchingParenthesis(const StringView &)
Returns the position of the closing parenthesis.
std::string toString(int)
Converts an integer to a string without the Settings bloat.