From 6a8869bc1b8ec7d622fe88b5f9642841089cecf9 Mon Sep 17 00:00:00 2001 From: dismine Date: Tue, 6 May 2014 17:36:42 +0300 Subject: [PATCH] Made possible methods include. --HG-- branch : develop --- src/app/version.h | 1 - src/libs/qmuparser/qmuparser.cpp | 11 -- src/libs/qmuparser/qmuparser.h | 15 +- src/libs/qmuparser/qmuparserbase.cpp | 164 -------------------- src/libs/qmuparser/qmuparserbase.h | 164 ++++++++++++++++++++ src/libs/qmuparser/qmuparserbytecode.cpp | 22 --- src/libs/qmuparser/qmuparserbytecode.h | 23 +++ src/libs/qmuparser/qmuparsercallback.cpp | 83 ---------- src/libs/qmuparser/qmuparsercallback.h | 84 ++++++++++ src/libs/qmuparser/qmuparsererror.cpp | 73 +-------- src/libs/qmuparser/qmuparsererror.h | 86 +++++++++- src/libs/qmuparser/qmuparsertokenreader.cpp | 59 ------- src/libs/qmuparser/qmuparsertokenreader.h | 59 +++++++ 13 files changed, 424 insertions(+), 420 deletions(-) diff --git a/src/app/version.h b/src/app/version.h index 7ffb4371e..58600761e 100644 --- a/src/app/version.h +++ b/src/app/version.h @@ -29,7 +29,6 @@ #ifndef VERSION_H #define VERSION_H -#include extern const int MAJOR_VERSION; extern const int MINOR_VERSION; diff --git a/src/libs/qmuparser/qmuparser.cpp b/src/libs/qmuparser/qmuparser.cpp index 9c64c5e38..3f0ca1d08 100644 --- a/src/libs/qmuparser/qmuparser.cpp +++ b/src/libs/qmuparser/qmuparser.cpp @@ -110,17 +110,6 @@ qreal QmuParser::Sign(qreal v) return ((v<0) ? -1 : (v>0) ? 1 : 0); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief Callback for the unary minus operator. - * @param v The value to negate - * @return -v - */ -qreal QmuParser::UnaryMinus(qreal v) -{ - return -v; -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief Callback for adding multiple values. diff --git a/src/libs/qmuparser/qmuparser.h b/src/libs/qmuparser/qmuparser.h index e64178122..e36f52b5d 100644 --- a/src/libs/qmuparser/qmuparser.h +++ b/src/libs/qmuparser/qmuparser.h @@ -74,13 +74,24 @@ namespace qmu static qreal Sign(qreal); // Prefix operators // !!! Unary Minus is a MUST if you want to use negative signs !!! - static qreal UnaryMinus(qreal); + static qreal UnaryMinus(qreal v); // Functions with variable number of arguments static qreal Sum(const qreal*, int); // sum static qreal Avg(const qreal*, int); // mean value static qreal Min(const qreal*, int); // minimum static qreal Max(const qreal*, int); // maximum - }; +}; + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief Callback for the unary minus operator. + * @param v The value to negate + * @return -v + */ +inline qreal QmuParser::UnaryMinus(qreal v) +{ + return -v; +} } // namespace qmu diff --git a/src/libs/qmuparser/qmuparserbase.cpp b/src/libs/qmuparser/qmuparserbase.cpp index 1bbc2ffa2..386c0f87d 100644 --- a/src/libs/qmuparser/qmuparserbase.cpp +++ b/src/libs/qmuparser/qmuparserbase.cpp @@ -192,20 +192,6 @@ void QmuParserBase::ResetLocale() SetArgSep(','); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief Initialize the token reader. - * - * Create new token reader object and submit pointers to function, operator, constant and variable definitions. - * - * @post m_pTokenReader.get()!=0 - * @throw nothrow - */ -void QmuParserBase::InitTokenReader() Q_DECL_NOEXCEPT -{ - m_pTokenReader.reset(new token_reader_type(this)); -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief Reset parser to string parsing mode and clear internal buffers. @@ -283,30 +269,6 @@ QString QmuParserBase::GetVersion(EParserVersionInfo eInfo) return versionInfo; } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief Add a value parsing function. - * - * When parsing an expression muParser tries to detect values in the expression string using different valident - * callbacks. Thuis it's possible to parse for hex values, binary values and floating point values. - */ -void QmuParserBase::AddValIdent(identfun_type a_pCallback) -{ - m_pTokenReader->AddValIdent(a_pCallback); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief Set a function that can create variable pointer for unknown expression variables. - * @param a_pFactory A pointer to the variable factory. - * @param pUserData A user defined context pointer. - */ -// cppcheck-suppress unusedFunction -void QmuParserBase::SetVarFactory(facfun_type a_pFactory, void *pUserData) -{ - m_pTokenReader->SetVarCreator(a_pFactory, pUserData); -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief Add a function or operator callback to the parser. @@ -464,43 +426,6 @@ void QmuParserBase::SetExpr(const QString &a_sExpr) ReInit(); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief Get the default symbols used for the built in operators. - * @sa c_DefaultOprt - */ -const QStringList &QmuParserBase::GetOprtDef() -{ - return c_DefaultOprt; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief Define the set of valid characters to be used in names of functions, variables, constants. - */ -void QmuParserBase::DefineNameChars(const QString &a_szCharset) -{ - m_sNameChars = a_szCharset; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief Define the set of valid characters to be used in names of binary operators and postfix operators. - */ -void QmuParserBase::DefineOprtChars(const QString &a_szCharset) -{ - m_sOprtChars = a_szCharset; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief Define the set of valid characters to be used in names of infix operators. - */ -void QmuParserBase::DefineInfixOprtChars(const QString &a_szCharset) -{ - m_sInfixOprtChars = a_szCharset; -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief Virtual function that defines the characters allowed in name identifiers. @@ -809,49 +734,6 @@ const varmap_type& QmuParserBase::GetUsedVar() const return m_pTokenReader->GetUsedVar(); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief Return a map containing the used variables only. - */ -const varmap_type& QmuParserBase::GetVar() const -{ - return m_VarDef; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief Return a map containing all parser constants. - */ -const valmap_type& QmuParserBase::GetConst() const -{ - return m_ConstDef; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief Return prototypes of all parser functions. - * @return #m_FunDef - * @sa FunProt - * @throw nothrow - * - * The return type is a map of the public type #funmap_type containing the prototype definitions for all numerical - * parser functions. String functions are not part of this map. The Prototype definition is encapsulated in objects - * of the class FunProt one per parser function each associated with function names via a map construct. - */ -const funmap_type& QmuParserBase::GetFunDef() const Q_DECL_NOEXCEPT -{ - return m_FunDef; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief Retrieve the formula. - */ -const QString& QmuParserBase::GetExpr() const -{ - return m_pTokenReader->GetExpr(); -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief Execute a function that takes a single string argument. @@ -2003,17 +1885,6 @@ void QmuParserBase::EnableBuiltInOprt(bool a_bIsOn) Q_DECL_NOEXCEPT ReInit(); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief Query status of built in variables. - * @return #m_bBuiltInOp; true if built in operators are enabled. - * @throw nothrow - */ -bool QmuParserBase::HasBuiltInOprt() const Q_DECL_NOEXCEPT -{ - return m_bBuiltInOp; -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief Get the argument separator character. @@ -2160,41 +2031,6 @@ qreal* QmuParserBase::Eval(int &nStackSize) const return &m_vStackBuffer[1]; } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief Return the number of results on the calculation stack. - * - * If the expression contains comma seperated subexpressions (i.e. "sin(y), x+y"). There mey be more than one return - * value. This function returns the number of available results. - */ -// cppcheck-suppress unusedFunction -int QmuParserBase::GetNumResults() const -{ - return m_nFinalResultIdx; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief Calculate the result. - * - * A note on const correctness: - * I consider it important that Calc is a const function. - * Due to caching operations Calc changes only the state of internal variables with one exception - * m_UsedVar this is reset during string parsing and accessible from the outside. Instead of making - * Calc non const GetUsedVar is non const because it explicitely calls Eval() forcing this update. - * - * @pre A formula must be set. - * @pre Variables must have been set (if needed) - * - * @sa #m_pParseFormula - * @return The evaluation result - * @throw ParseException if no Formula is set or in case of any other error related to the formula. - */ -qreal QmuParserBase::Eval() const -{ - return (this->*m_pParseFormula)(); -} - //--------------------------------------------------------------------------------------------------------------------- void QmuParserBase::Eval(qreal *results, int nBulkSize) const { diff --git a/src/libs/qmuparser/qmuparserbase.h b/src/libs/qmuparser/qmuparserbase.h index ff79c0868..4e2c0ac23 100644 --- a/src/libs/qmuparser/qmuparserbase.h +++ b/src/libs/qmuparser/qmuparserbase.h @@ -255,6 +255,170 @@ private: void StackDump(const QStack &a_stVal, const QStack &a_stOprt) const; }; +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief Initialize the token reader. + * + * Create new token reader object and submit pointers to function, operator, constant and variable definitions. + * + * @post m_pTokenReader.get()!=0 + * @throw nothrow + */ +inline void QmuParserBase::InitTokenReader() Q_DECL_NOEXCEPT +{ + m_pTokenReader.reset(new token_reader_type(this)); +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief Add a value parsing function. + * + * When parsing an expression muParser tries to detect values in the expression string using different valident + * callbacks. Thuis it's possible to parse for hex values, binary values and floating point values. + */ +inline void QmuParserBase::AddValIdent(identfun_type a_pCallback) +{ + m_pTokenReader->AddValIdent(a_pCallback); +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief Set a function that can create variable pointer for unknown expression variables. + * @param a_pFactory A pointer to the variable factory. + * @param pUserData A user defined context pointer. + */ +// cppcheck-suppress unusedFunction +inline void QmuParserBase::SetVarFactory(facfun_type a_pFactory, void *pUserData) +{ + m_pTokenReader->SetVarCreator(a_pFactory, pUserData); +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief Get the default symbols used for the built in operators. + * @sa c_DefaultOprt + */ +inline const QStringList &QmuParserBase::GetOprtDef() +{ + return c_DefaultOprt; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief Define the set of valid characters to be used in names of functions, variables, constants. + */ +inline void QmuParserBase::DefineNameChars(const QString &a_szCharset) +{ + m_sNameChars = a_szCharset; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief Define the set of valid characters to be used in names of binary operators and postfix operators. + */ +inline void QmuParserBase::DefineOprtChars(const QString &a_szCharset) +{ + m_sOprtChars = a_szCharset; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief Define the set of valid characters to be used in names of infix operators. + */ +inline void QmuParserBase::DefineInfixOprtChars(const QString &a_szCharset) +{ + m_sInfixOprtChars = a_szCharset; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief Return a map containing the used variables only. + */ +inline const varmap_type &QmuParserBase::GetVar() const +{ + return m_VarDef; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief Return a map containing all parser constants. + */ +inline const valmap_type &QmuParserBase::GetConst() const +{ + return m_ConstDef; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief Return prototypes of all parser functions. + * @return #m_FunDef + * @sa FunProt + * @throw nothrow + * + * The return type is a map of the public type #funmap_type containing the prototype definitions for all numerical + * parser functions. String functions are not part of this map. The Prototype definition is encapsulated in objects + * of the class FunProt one per parser function each associated with function names via a map construct. + */ +inline const funmap_type &QmuParserBase::GetFunDef() const Q_DECL_NOEXCEPT +{ + return m_FunDef; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief Retrieve the formula. + */ +inline const QString& QmuParserBase::GetExpr() const +{ + return m_pTokenReader->GetExpr(); +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief Query status of built in variables. + * @return #m_bBuiltInOp; true if built in operators are enabled. + * @throw nothrow + */ +inline bool QmuParserBase::HasBuiltInOprt() const Q_DECL_NOEXCEPT +{ + return m_bBuiltInOp; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief Return the number of results on the calculation stack. + * + * If the expression contains comma seperated subexpressions (i.e. "sin(y), x+y"). There mey be more than one return + * value. This function returns the number of available results. + */ +// cppcheck-suppress unusedFunction +inline int QmuParserBase::GetNumResults() const +{ + return m_nFinalResultIdx; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief Calculate the result. + * + * A note on const correctness: + * I consider it important that Calc is a const function. + * Due to caching operations Calc changes only the state of internal variables with one exception + * m_UsedVar this is reset during string parsing and accessible from the outside. Instead of making + * Calc non const GetUsedVar is non const because it explicitely calls Eval() forcing this update. + * + * @pre A formula must be set. + * @pre Variables must have been set (if needed) + * + * @sa #m_pParseFormula + * @return The evaluation result + * @throw ParseException if no Formula is set or in case of any other error related to the formula. + */ +inline qreal QmuParserBase::Eval() const +{ + return (this->*m_pParseFormula)(); +} + } // namespace qmu #endif diff --git a/src/libs/qmuparser/qmuparserbytecode.cpp b/src/libs/qmuparser/qmuparserbytecode.cpp index 6153d1070..c61c90cd2 100644 --- a/src/libs/qmuparser/qmuparserbytecode.cpp +++ b/src/libs/qmuparser/qmuparserbytecode.cpp @@ -73,12 +73,6 @@ QmuParserByteCode& QmuParserByteCode::operator=(const QmuParserByteCode &a_ByteC return *this; } -//--------------------------------------------------------------------------------------------------------------------- -void QmuParserByteCode::EnableOptimizer(bool bStat) -{ - m_bEnableOptimizer = bStat; -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief Copy state of another object to this. @@ -659,22 +653,6 @@ const SToken* QmuParserByteCode::GetBase() const } } -//--------------------------------------------------------------------------------------------------------------------- -std::size_t QmuParserByteCode::GetMaxStackSize() const -{ - return m_iMaxStackSize+1; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief Returns the number of entries in the bytecode. - */ -// cppcheck-suppress unusedFunction -std::size_t QmuParserByteCode::GetSize() const -{ - return m_vRPN.size(); -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief Delete the bytecode. diff --git a/src/libs/qmuparser/qmuparserbytecode.h b/src/libs/qmuparser/qmuparserbytecode.h index 8c5153987..cf3af1832 100644 --- a/src/libs/qmuparser/qmuparserbytecode.h +++ b/src/libs/qmuparser/qmuparserbytecode.h @@ -120,5 +120,28 @@ private: void ConstantFolding(ECmdCode a_Oprt); }; + +//--------------------------------------------------------------------------------------------------------------------- +inline void QmuParserByteCode::EnableOptimizer(bool bStat) +{ + m_bEnableOptimizer = bStat; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline std::size_t QmuParserByteCode::GetMaxStackSize() const +{ + return m_iMaxStackSize+1; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief Returns the number of entries in the bytecode. + */ +// cppcheck-suppress unusedFunction +inline std::size_t QmuParserByteCode::GetSize() const +{ + return m_vRPN.size(); +} + } // namespace qmu #endif diff --git a/src/libs/qmuparser/qmuparsercallback.cpp b/src/libs/qmuparser/qmuparsercallback.cpp index 2af42b991..606c2952c 100644 --- a/src/libs/qmuparser/qmuparsercallback.cpp +++ b/src/libs/qmuparser/qmuparsercallback.cpp @@ -321,87 +321,4 @@ QmuParserCallback::QmuParserCallback ( const QmuParserCallback &ref ) m_eOprtAsct = ref.m_eOprtAsct; } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief Clone this instance and return a pointer to the new instance. - */ -QmuParserCallback* QmuParserCallback::Clone() const -{ - return new QmuParserCallback ( *this ); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief Return true if the function is conservative. - * - * Conservative functions return always the same result for the same argument. - * @throw nothrow - */ -// cppcheck-suppress unusedFunction -bool QmuParserCallback::IsOptimizable() const Q_DECL_NOEXCEPT -{ - return m_bAllowOpti; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief Get the callback address for the parser function. - * - * The type of the address is void. It needs to be recasted according to the argument number to the right type. - * - * @throw nothrow - * @return #pFun - */ -void* QmuParserCallback::GetAddr() const Q_DECL_NOEXCEPT -{ - return m_pFun; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief Return the callback code. -*/ -ECmdCode QmuParserCallback::GetCode() const -{ - return m_iCode; -} - -//--------------------------------------------------------------------------------------------------------------------- -ETypeCode QmuParserCallback::GetType() const -{ - return m_iType; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief Return the operator precedence. - * @throw nothrown - * - * Only valid if the callback token is an operator token (binary or infix). - */ -int QmuParserCallback::GetPri() const Q_DECL_NOEXCEPT -{ - return m_iPri; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief Return the operators associativity. - * @throw nothrown - * - * Only valid if the callback token is a binary operator token. - */ -EOprtAssociativity QmuParserCallback::GetAssociativity() const Q_DECL_NOEXCEPT -{ - return m_eOprtAsct; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief Returns the number of function Arguments. - */ -int QmuParserCallback::GetArgc() const -{ - return m_iArgc; -} } // namespace qmu diff --git a/src/libs/qmuparser/qmuparsercallback.h b/src/libs/qmuparser/qmuparsercallback.h index 4d45fb8f2..86bd89477 100644 --- a/src/libs/qmuparser/qmuparsercallback.h +++ b/src/libs/qmuparser/qmuparsercallback.h @@ -109,6 +109,90 @@ private: */ typedef std::map funmap_type; +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief Clone this instance and return a pointer to the new instance. + */ +inline QmuParserCallback* QmuParserCallback::Clone() const +{ + return new QmuParserCallback ( *this ); +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief Return true if the function is conservative. + * + * Conservative functions return always the same result for the same argument. + * @throw nothrow + */ +// cppcheck-suppress unusedFunction +inline bool QmuParserCallback::IsOptimizable() const Q_DECL_NOEXCEPT +{ + return m_bAllowOpti; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief Get the callback address for the parser function. + * + * The type of the address is void. It needs to be recasted according to the argument number to the right type. + * + * @throw nothrow + * @return #pFun + */ +inline void* QmuParserCallback::GetAddr() const Q_DECL_NOEXCEPT +{ + return m_pFun; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief Return the callback code. +*/ +inline ECmdCode QmuParserCallback::GetCode() const +{ + return m_iCode; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline ETypeCode QmuParserCallback::GetType() const +{ + return m_iType; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief Return the operator precedence. + * @throw nothrown + * + * Only valid if the callback token is an operator token (binary or infix). + */ +inline int QmuParserCallback::GetPri() const Q_DECL_NOEXCEPT +{ + return m_iPri; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief Return the operators associativity. + * @throw nothrown + * + * Only valid if the callback token is a binary operator token. + */ +inline EOprtAssociativity QmuParserCallback::GetAssociativity() const Q_DECL_NOEXCEPT +{ + return m_eOprtAsct; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief Returns the number of function Arguments. + */ +inline int QmuParserCallback::GetArgc() const +{ + return m_iArgc; +} + } // namespace qmu #endif diff --git a/src/libs/qmuparser/qmuparsererror.cpp b/src/libs/qmuparser/qmuparsererror.cpp index 0bdc28e81..e0bed1887 100644 --- a/src/libs/qmuparser/qmuparsererror.cpp +++ b/src/libs/qmuparser/qmuparsererror.cpp @@ -28,19 +28,6 @@ namespace qmu { const QmuParserErrorMsg QmuParserErrorMsg::m_Instance; -//--------------------------------------------------------------------------------------------------------------------- -// cppcheck-suppress unusedFunction -const QmuParserErrorMsg& QmuParserErrorMsg::Instance() -{ - return m_Instance; -} - -//--------------------------------------------------------------------------------------------------------------------- -QString QmuParserErrorMsg::operator[] ( unsigned a_iIdx ) const -{ - return ( a_iIdx < static_cast( m_vErrMsg.size() ) ) ? m_vErrMsg[a_iIdx] : QString(); -} - //--------------------------------------------------------------------------------------------------------------------- QmuParserErrorMsg::~QmuParserErrorMsg() {} @@ -185,7 +172,9 @@ QmuParserError::QmuParserError ( const QString &szMsg, int iPos, const QString & } //--------------------------------------------------------------------------------------------------------------------- -/** @brief Copy constructor. */ +/** + * @brief Copy constructor. + */ QmuParserError::QmuParserError ( const QmuParserError &a_Obj ) : QException(), m_sMsg ( a_Obj.m_sMsg ), m_sExpr ( a_Obj.m_sExpr ), m_sTok ( a_Obj.m_sTok ), m_iPos ( a_Obj.m_iPos ), m_iErrc ( a_Obj.m_iErrc ), m_ErrMsg ( QmuParserErrorMsg::Instance() ) @@ -250,60 +239,4 @@ void QmuParserError::Reset() m_iErrc = ecUNDEFINED; } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief Set the expression related to this error. - */ -void QmuParserError::SetFormula ( const QString &a_strFormula ) -{ - m_sExpr = a_strFormula; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief gets the expression related tp this error. - */ -const QString& QmuParserError::GetExpr() const -{ - return m_sExpr; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief Returns the message string for this error. - */ -const QString& QmuParserError::GetMsg() const -{ - return m_sMsg; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief Return the formula position related to the error. - * - * If the error is not related to a distinct position this will return -1 - */ -int QmuParserError::GetPos() const -{ - return m_iPos; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief Return string related with this token (if available). - */ -const QString& QmuParserError::GetToken() const -{ - return m_sTok; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief Return the error code. - */ -EErrorCodes QmuParserError::GetCode() const -{ - return m_iErrc; -} - } // namespace qmu diff --git a/src/libs/qmuparser/qmuparsererror.h b/src/libs/qmuparser/qmuparsererror.h index 249c654db..0231a0e79 100644 --- a/src/libs/qmuparser/qmuparsererror.h +++ b/src/libs/qmuparser/qmuparsererror.h @@ -109,6 +109,19 @@ private: static const self_type m_Instance; ///< The instance pointer }; +//--------------------------------------------------------------------------------------------------------------------- +// cppcheck-suppress unusedFunction +inline const QmuParserErrorMsg& QmuParserErrorMsg::Instance() +{ + return m_Instance; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline QString QmuParserErrorMsg::operator[] ( unsigned a_iIdx ) const +{ + return ( a_iIdx < static_cast( m_vErrMsg.size() ) ) ? m_vErrMsg[a_iIdx] : QString(); +} + //--------------------------------------------------------------------------- /** @brief Error class of the parser. @author Ingo Berg @@ -134,15 +147,7 @@ public: int GetPos() const; const QString& GetToken() const; EErrorCodes GetCode() const; - - /** - * @brief raise method raise for exception - */ virtual void raise() const; - /** - * @brief clone clone exception - * @return new exception - */ virtual QmuParserError *clone() const; private: QString m_sMsg; ///< The message string @@ -158,16 +163,81 @@ private: void Reset(); }; +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief raise method raise for exception + */ inline void QmuParserError::raise() const { throw *this; } +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief clone clone exception + * @return new exception + */ inline QmuParserError *QmuParserError::clone() const { return new QmuParserError(*this); } +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief Set the expression related to this error. + */ +inline void QmuParserError::SetFormula ( const QString &a_strFormula ) +{ + m_sExpr = a_strFormula; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief gets the expression related tp this error. + */ +inline const QString& QmuParserError::GetExpr() const +{ + return m_sExpr; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief Returns the message string for this error. + */ +inline const QString& QmuParserError::GetMsg() const +{ + return m_sMsg; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief Return the formula position related to the error. + * + * If the error is not related to a distinct position this will return -1 + */ +inline int QmuParserError::GetPos() const +{ + return m_iPos; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief Return string related with this token (if available). + */ +inline const QString& QmuParserError::GetToken() const +{ + return m_sTok; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief Return the error code. + */ +inline EErrorCodes QmuParserError::GetCode() const +{ + return m_iErrc; +} + } // namespace qmu #endif diff --git a/src/libs/qmuparser/qmuparsertokenreader.cpp b/src/libs/qmuparser/qmuparsertokenreader.cpp index 0ae8cb90d..3ab194177 100644 --- a/src/libs/qmuparser/qmuparsertokenreader.cpp +++ b/src/libs/qmuparser/qmuparsertokenreader.cpp @@ -169,39 +169,6 @@ void QmuParserTokenReader::SetVarCreator ( facfun_type a_pFactory, void *pUserDa m_pFactoryData = pUserData; } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief Return the current position of the token reader in the formula string. - * - * @return #m_iPos - * @throw nothrow - */ -int QmuParserTokenReader::GetPos() const Q_DECL_NOEXCEPT -{ - return m_iPos; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief Return a reference to the formula. - * - * @return #m_strFormula - * @throw nothrow - */ -const QString& QmuParserTokenReader::GetExpr() const Q_DECL_NOEXCEPT -{ - return m_strFormula; -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief Return a map containing the used variables only. - */ -varmap_type& QmuParserTokenReader::GetUsedVar() -{ - return m_UsedVar; -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief Initialize the token Reader. @@ -215,20 +182,6 @@ void QmuParserTokenReader::SetFormula ( const QString &a_strFormula ) ReInit(); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief Set Flag that contronls behaviour in case of undefined variables beeing found. - * - * If true, the parser does not throw an exception if an undefined variable is found. Otherwise it does. This variable - * is used internally only! It supresses a "undefined variable" exception in GetUsedVar(). - * Those function should return a complete list of variables including - * those the are not defined by the time of it's call. - */ -void QmuParserTokenReader::IgnoreUndefVar ( bool bIgnore ) -{ - m_bIgnoreUndefVar = bIgnore; -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief Reset the token reader to the start of the formula. @@ -1113,16 +1066,4 @@ void Q_NORETURN QmuParserTokenReader::Error ( EErrorCodes a_iErrc, int a_iPos, c { m_pParser->Error ( a_iErrc, a_iPos, a_sTok ); } - -//--------------------------------------------------------------------------------------------------------------------- -void QmuParserTokenReader::SetArgSep ( char_type cArgSep ) -{ - m_cArgSep = cArgSep; -} - -//--------------------------------------------------------------------------------------------------------------------- -QChar QmuParserTokenReader::GetArgSep() const -{ - return m_cArgSep; -} } // namespace qmu diff --git a/src/libs/qmuparser/qmuparsertokenreader.h b/src/libs/qmuparser/qmuparsertokenreader.h index 17ed8a50f..11492f36b 100644 --- a/src/libs/qmuparser/qmuparsertokenreader.h +++ b/src/libs/qmuparser/qmuparsertokenreader.h @@ -134,6 +134,65 @@ private: token_type m_lastTok; QChar m_cArgSep; ///< The character used for separating function arguments }; + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief Return the current position of the token reader in the formula string. + * + * @return #m_iPos + * @throw nothrow + */ +inline int QmuParserTokenReader::GetPos() const Q_DECL_NOEXCEPT +{ + return m_iPos; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief Return a reference to the formula. + * + * @return #m_strFormula + * @throw nothrow + */ +inline const QString& QmuParserTokenReader::GetExpr() const Q_DECL_NOEXCEPT +{ + return m_strFormula; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief Return a map containing the used variables only. + */ +inline varmap_type& QmuParserTokenReader::GetUsedVar() +{ + return m_UsedVar; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief Set Flag that contronls behaviour in case of undefined variables beeing found. + * + * If true, the parser does not throw an exception if an undefined variable is found. Otherwise it does. This variable + * is used internally only! It supresses a "undefined variable" exception in GetUsedVar(). + * Those function should return a complete list of variables including + * those the are not defined by the time of it's call. + */ +inline void QmuParserTokenReader::IgnoreUndefVar ( bool bIgnore ) +{ + m_bIgnoreUndefVar = bIgnore; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void QmuParserTokenReader::SetArgSep ( char_type cArgSep ) +{ + m_cArgSep = cArgSep; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline QChar QmuParserTokenReader::GetArgSep() const +{ + return m_cArgSep; +} } // namespace qmu #endif