muParser API -  1.35
Public Member Functions | List of all members
mu::ParserToken< TBase, TString > Class Template Referencefinal

Encapsulation of the data for a single formula token. More...

#include <muParserToken.h>

Public Member Functions

 ParserToken ()
 Constructor (default). More...
 
 ParserToken (const ParserToken &a_Tok)
 Create token from another one. More...
 
ParserTokenoperator= (const ParserToken &a_Tok)
 Assignment operator. More...
 
void Assign (const ParserToken &a_Tok)
 Copy token information from argument. More...
 
ParserTokenSet (ECmdCode a_iType, const TString &a_strTok=TString())
 Assign a token type. More...
 
ParserTokenSet (const ParserCallback &a_pCallback, const TString &a_sTok)
 Set Callback type.
 
ParserTokenSetVal (TBase a_fVal, const TString &a_strTok=TString())
 Make this token a value token. More...
 
ParserTokenSetVar (TBase *a_pVar, const TString &a_strTok)
 make this token a variable token. More...
 
ParserTokenSetString (const TString &a_strTok, std::size_t a_iSize)
 Make this token a variable token. More...
 
void SetIdx (int a_iIdx)
 Set an index associated with the token related data. More...
 
int GetIdx () const
 Return Index associated with the token related data. More...
 
ECmdCode GetCode () const
 Return the token type. More...
 
ETypeCode GetType () const
 
int GetPri () const
 
EOprtAssociativity GetAssociativity () const
 
generic_callable_type GetFuncAddr () const
 Return the address of the callback function assoziated with function and operator tokens. More...
 
TBase GetVal () const
 
TBase * GetVar () const
 Get address of a variable token. More...
 
int GetArgCount () const
 Return the number of function arguments. More...
 
bool IsOptimizable () const
 Return true if the token is a function token that can be optimized.
 
const TString & GetAsString () const
 Return the token identifier. More...
 

Detailed Description

template<typename TBase, typename TString>
class mu::ParserToken< TBase, TString >

Encapsulation of the data for a single formula token.

Formula token implementation. Part of the Math Parser Package. Formula tokens can be either one of the following:

Definition at line 170 of file muParserToken.h.

Constructor & Destructor Documentation

template<typename TBase, typename TString>
mu::ParserToken< TBase, TString >::ParserToken ( )
inline

Constructor (default).

Sets token to an neutral state of type cmUNKNOWN.

Exceptions
nothrow
See also
ECmdCode

Definition at line 191 of file muParserToken.h.

192  :m_iCode(cmUNKNOWN)
193  , m_iType(tpVOID)
194  , m_pTok(0)
195  , m_iIdx(-1)
196  , m_strTok()
197  , m_strVal()
198  , m_fVal(0)
199  , m_pCallback()
200  {}
Undefined type.
Definition: muParserDef.h:187
uninitialized item
Definition: muParserDef.h:178
template<typename TBase, typename TString>
mu::ParserToken< TBase, TString >::ParserToken ( const ParserToken< TBase, TString > &  a_Tok)
inline

Create token from another one.

Implemented by calling Assign(...)

Exceptions
nothrow
Postcondition
m_iType==cmUNKNOWN
See also
Assign

Definition at line 210 of file muParserToken.h.

211  {
212  Assign(a_Tok);
213  }
void Assign(const ParserToken &a_Tok)
Copy token information from argument.

Member Function Documentation

template<typename TBase, typename TString>
void mu::ParserToken< TBase, TString >::Assign ( const ParserToken< TBase, TString > &  a_Tok)
inline

Copy token information from argument.

Exceptions
nothrow

Definition at line 233 of file muParserToken.h.

Referenced by mu::ParserToken< value_type, string_type >::operator=(), and mu::ParserToken< value_type, string_type >::ParserToken().

234  {
235  m_iCode = a_Tok.m_iCode;
236  m_pTok = a_Tok.m_pTok;
237  m_strTok = a_Tok.m_strTok;
238  m_iIdx = a_Tok.m_iIdx;
239  m_strVal = a_Tok.m_strVal;
240  m_iType = a_Tok.m_iType;
241  m_fVal = a_Tok.m_fVal;
242  // create new callback object if a_Tok has one
243  m_pCallback.reset(a_Tok.m_pCallback.get() ? a_Tok.m_pCallback->Clone() : 0);
244  }
template<typename TBase, typename TString>
int mu::ParserToken< TBase, TString >::GetArgCount ( ) const
inline

Return the number of function arguments.

Valid only if m_iType==CmdFUNC.

Definition at line 486 of file muParserToken.h.

487  {
488  MUP_ASSERT(m_pCallback.get());
489 
490  if (!m_pCallback->IsValid())
491  throw ParserError(ecINTERNAL_ERROR);
492 
493  return m_pCallback->GetArgc();
494  }
Internal error of any kind.
Definition: muParserDef.h:279
#define MUP_ASSERT(COND)
An assertion that does not kill the program.
Definition: muParserDef.h:77
template<typename TBase, typename TString>
const TString& mu::ParserToken< TBase, TString >::GetAsString ( ) const
inline

Return the token identifier.

If #m_iType is cmSTRING the token identifier is the value of the string argument for a string function.

Returns
#m_strTok
Exceptions
nothrow
See also
m_strTok

Definition at line 513 of file muParserToken.h.

514  {
515  return m_strTok;
516  }
template<typename TBase, typename TString>
ECmdCode mu::ParserToken< TBase, TString >::GetCode ( ) const
inline

Return the token type.

Returns
#m_iType
Exceptions
nothrow

Definition at line 382 of file muParserToken.h.

383  {
384  if (m_pCallback.get())
385  {
386  return m_pCallback->GetCode();
387  }
388  else
389  {
390  return m_iCode;
391  }
392  }
template<typename TBase, typename TString>
generic_callable_type mu::ParserToken< TBase, TString >::GetFuncAddr ( ) const
inline

Return the address of the callback function assoziated with function and operator tokens.

Returns
The pointer stored in #m_pTok.
Exceptions
exception_typeif token type is non of:
  • cmFUNC
  • cmSTRFUNC
  • cmPOSTOP
  • cmINFIXOP
  • cmOPRT_BIN
See also
ECmdCode

Definition at line 443 of file muParserToken.h.

444  {
445  return (m_pCallback.get())
446  ? generic_callable_type{(erased_fun_type)m_pCallback->GetAddr(),
447  m_pCallback->GetUserData()}
448  : generic_callable_type{};
449  }
void(* erased_fun_type)()
Function type used to erase type. Voluntarily needs explicit cast with all other fun_type.
Definition: muParserDef.h:325
template<typename TBase, typename TString>
int mu::ParserToken< TBase, TString >::GetIdx ( ) const
inline

Return Index associated with the token related data.

In cmSTRFUNC - This is the index to a string table in the main parser.

Exceptions
exception_typeif #m_iIdx<0 or #m_iType!=cmSTRING
Returns
The index the result will take in the Bytecode calculatin array (#m_iIdx).

Definition at line 368 of file muParserToken.h.

369  {
370  if (m_iIdx < 0 || m_iCode != cmSTRING)
371  throw ParserError(ecINTERNAL_ERROR);
372 
373  return m_iIdx;
374  }
Internal error of any kind.
Definition: muParserDef.h:279
Code for a string token.
Definition: muParserDef.h:173
template<typename TBase, typename TString>
TBase mu::ParserToken< TBase, TString >::GetVal ( ) const
inline

Get value of the token.

        Only applicable to variable and value tokens.
        \throw exception_type if token is no value/variable token.

Definition at line 457 of file muParserToken.h.

458  {
459  switch (m_iCode)
460  {
461  case cmVAL: return m_fVal;
462  case cmVAR: return *((TBase*)m_pTok);
463  default: throw ParserError(ecVAL_EXPECTED);
464  }
465  }
A numerical function has been called with a non value type of argument.
Definition: muParserDef.h:239
value item
Definition: muParserDef.h:161
variable item
Definition: muParserDef.h:160
template<typename TBase, typename TString>
TBase* mu::ParserToken< TBase, TString >::GetVar ( ) const
inline

Get address of a variable token.

Valid only if m_iType==CmdVar.

Exceptions
exception_typeif token is no variable token.

Definition at line 473 of file muParserToken.h.

474  {
475  if (m_iCode != cmVAR)
476  throw ParserError(ecINTERNAL_ERROR);
477 
478  return (TBase*)m_pTok;
479  }
Internal error of any kind.
Definition: muParserDef.h:279
variable item
Definition: muParserDef.h:160
template<typename TBase, typename TString>
ParserToken& mu::ParserToken< TBase, TString >::operator= ( const ParserToken< TBase, TString > &  a_Tok)
inline

Assignment operator.

Copy token state from another token and return this. Implemented by calling Assign(...).

Exceptions
nothrow

Definition at line 222 of file muParserToken.h.

223  {
224  Assign(a_Tok);
225  return *this;
226  }
void Assign(const ParserToken &a_Tok)
Copy token information from argument.
template<typename TBase, typename TString>
ParserToken& mu::ParserToken< TBase, TString >::Set ( ECmdCode  a_iType,
const TString &  a_strTok = TString() 
)
inline

Assign a token type.

Token may not be of type value, variable or function. Those have separate set functions.

Precondition
[assert] a_iType!=cmVAR
[assert] a_iType!=cmVAL
[assert] a_iType!=cmFUNC
Postcondition
m_fVal = 0
m_pTok = 0

Definition at line 257 of file muParserToken.h.

258  {
259  // The following types can't be set this way, they have special Set functions
260  MUP_ASSERT(a_iType != cmVAR);
261  MUP_ASSERT(a_iType != cmVAL);
262  MUP_ASSERT(a_iType != cmFUNC);
263 
264  m_iCode = a_iType;
265  m_iType = tpVOID;
266  m_pTok = 0;
267  m_strTok = a_strTok;
268  m_iIdx = -1;
269 
270  return *this;
271  }
Code for a generic function item.
Definition: muParserDef.h:170
#define MUP_ASSERT(COND)
An assertion that does not kill the program.
Definition: muParserDef.h:77
value item
Definition: muParserDef.h:161
Undefined type.
Definition: muParserDef.h:187
variable item
Definition: muParserDef.h:160
template<typename TBase, typename TString>
void mu::ParserToken< TBase, TString >::SetIdx ( int  a_iIdx)
inline

Set an index associated with the token related data.

In cmSTRFUNC - This is the index to a string table in the main parser.

Parameters
a_iIdxThe index the string function result will take in the bytecode parser.
Exceptions
exception_typeif #a_iIdx<0 or #m_iType!=cmSTRING

Definition at line 352 of file muParserToken.h.

353  {
354  if (m_iCode != cmSTRING || a_iIdx < 0)
355  throw ParserError(ecINTERNAL_ERROR);
356 
357  m_iIdx = a_iIdx;
358  }
Internal error of any kind.
Definition: muParserDef.h:279
Code for a string token.
Definition: muParserDef.h:173
template<typename TBase, typename TString>
ParserToken& mu::ParserToken< TBase, TString >::SetString ( const TString &  a_strTok,
std::size_t  a_iSize 
)
inline

Make this token a variable token.

Member variables not necessary for variable tokens will be invalidated.

Exceptions
nothrow

Definition at line 333 of file muParserToken.h.

334  {
335  m_iCode = cmSTRING;
336  m_iType = tpSTR;
337  m_strTok = a_strTok;
338  m_iIdx = static_cast<int>(a_iSize);
339 
340  m_pTok = 0;
341  m_pCallback.reset(0);
342  return *this;
343  }
String type (Function arguments and constants only, no string variables)
Definition: muParserDef.h:185
Code for a string token.
Definition: muParserDef.h:173
template<typename TBase, typename TString>
ParserToken& mu::ParserToken< TBase, TString >::SetVal ( TBase  a_fVal,
const TString &  a_strTok = TString() 
)
inline

Make this token a value token.

Member variables not necessary for value tokens will be invalidated.

Exceptions
nothrow

Definition at line 296 of file muParserToken.h.

297  {
298  m_iCode = cmVAL;
299  m_iType = tpDBL;
300  m_fVal = a_fVal;
301  m_strTok = a_strTok;
302  m_iIdx = -1;
303 
304  m_pTok = 0;
305  m_pCallback.reset(0);
306 
307  return *this;
308  }
value item
Definition: muParserDef.h:161
Floating point variables.
Definition: muParserDef.h:186
template<typename TBase, typename TString>
ParserToken& mu::ParserToken< TBase, TString >::SetVar ( TBase *  a_pVar,
const TString &  a_strTok 
)
inline

make this token a variable token.

Member variables not necessary for variable tokens will be invalidated.

Exceptions
nothrow

Definition at line 316 of file muParserToken.h.

317  {
318  m_iCode = cmVAR;
319  m_iType = tpDBL;
320  m_strTok = a_strTok;
321  m_iIdx = -1;
322  m_pTok = (void*)a_pVar;
323  m_pCallback.reset(0);
324  return *this;
325  }
variable item
Definition: muParserDef.h:160
Floating point variables.
Definition: muParserDef.h:186

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