muParser API -  1.35
Public Member Functions | List of all members
mu::ParserTokenReader Class Referencefinal

Token reader for the ParserBase class. More...

#include <muParserTokenReader.h>

Public Member Functions

 ParserTokenReader (ParserBase *a_pParent)
 Constructor. More...
 
ParserTokenReaderClone (ParserBase *a_pParent) const
 Create instance of a ParserTokenReader identical with this and return its pointer. More...
 
void AddValIdent (identfun_type a_pCallback)
 
void SetVarCreator (facfun_type a_pFactory, void *pUserData)
 
void SetFormula (const string_type &a_strFormula)
 Initialize the token Reader. More...
 
void SetArgSep (char_type cArgSep)
 
int GetPos () const
 Return the current position of the token reader in the formula string. More...
 
const string_typeGetExpr () const
 Return a reference to the formula. More...
 
varmap_typeGetUsedVar ()
 Return a map containing the used variables only.
 
char_type GetArgSep () const
 
void IgnoreUndefVar (bool bIgnore)
 Set Flag that controls behaviour in case of undefined variables being found. More...
 
void ReInit ()
 Reset the token reader to the start of the formula. More...
 
token_type ReadNextToken ()
 Read the next token from the string.
 

Detailed Description

Token reader for the ParserBase class.

Definition at line 54 of file muParserTokenReader.h.

Constructor & Destructor Documentation

mu::ParserTokenReader::ParserTokenReader ( ParserBase a_pParent)

Constructor.

Create a Token reader and bind it to a parser object.

Precondition
[assert] a_pParser may not be NULL
Postcondition
#m_pParser==a_pParser
Parameters
a_pParentParent parser object of the token reader.

Definition at line 120 of file muParserTokenReader.cpp.

Referenced by Clone().

121  :m_pParser(a_pParent)
122  , m_strFormula()
123  , m_iPos(0)
124  , m_iSynFlags(0)
125  , m_bIgnoreUndefVar(false)
126  , m_pFunDef(nullptr)
127  , m_pPostOprtDef(nullptr)
128  , m_pInfixOprtDef(nullptr)
129  , m_pOprtDef(nullptr)
130  , m_pConstDef(nullptr)
131  , m_pStrVarDef(nullptr)
132  , m_pVarDef(nullptr)
133  , m_pFactory(nullptr)
134  , m_pFactoryData(nullptr)
135  , m_vIdentFun()
136  , m_UsedVar()
137  , m_fZero(0)
138  , m_bracketStack()
139  , m_lastTok()
140  , m_cArgSep(',')
141  {
142  MUP_ASSERT(m_pParser != nullptr);
143  SetParent(m_pParser);
144  }
#define MUP_ASSERT(COND)
An assertion that does not kill the program.
Definition: muParserDef.h:77

Member Function Documentation

ParserTokenReader * mu::ParserTokenReader::Clone ( ParserBase a_pParent) const

Create instance of a ParserTokenReader identical with this and return its pointer.

This is a factory method the calling function must take care of the object destruction.

Returns
A new ParserTokenReader object.
Exceptions
nothrow

Definition at line 155 of file muParserTokenReader.cpp.

156  {
157  std::unique_ptr<ParserTokenReader> ptr(new ParserTokenReader(*this));
158  ptr->SetParent(a_pParent);
159  return ptr.release();
160  }
ParserTokenReader(ParserBase *a_pParent)
Constructor.
const string_type & mu::ParserTokenReader::GetExpr ( ) const

Return a reference to the formula.

Returns
#m_strFormula
Exceptions
nothrow

Definition at line 205 of file muParserTokenReader.cpp.

206  {
207  return m_strFormula;
208  }
int mu::ParserTokenReader::GetPos ( ) const

Return the current position of the token reader in the formula string.

Returns
#m_iPos
Exceptions
nothrow

Definition at line 194 of file muParserTokenReader.cpp.

195  {
196  return m_iPos;
197  }
void mu::ParserTokenReader::IgnoreUndefVar ( bool  bIgnore)

Set Flag that controls behaviour in case of undefined variables being 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 suppresses 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.

Definition at line 238 of file muParserTokenReader.cpp.

239  {
240  m_bIgnoreUndefVar = bIgnore;
241  }
void mu::ParserTokenReader::ReInit ( )

Reset the token reader to the start of the formula.

The syntax flags will be reset to a value appropriate for the start of a formula.

Postcondition
#m_iPos==0, #m_iSynFlags = noOPT | noBC | noPOSTOP | noSTR
Exceptions
nothrow
See also
ESynCodes

Definition at line 252 of file muParserTokenReader.cpp.

Referenced by SetFormula().

253  {
254  m_iPos = 0;
255  m_iSynFlags = sfSTART_OF_LINE;
256  m_bracketStack = std::stack<int>();
257  m_UsedVar.clear();
258  m_lastTok = token_type();
259  }
void mu::ParserTokenReader::SetFormula ( const string_type a_strFormula)

Initialize the token Reader.

Sets the formula position index to zero and set Syntax flags to default for initial formula parsing.

Precondition
[assert] triggered if a_szFormula==0

Definition at line 223 of file muParserTokenReader.cpp.

224  {
225  m_strFormula = a_strFormula;
226  ReInit();
227  }
void ReInit()
Reset the token reader to the start of the formula.

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