29 #ifndef MU_PARSER_TOKEN_H
30 #define MU_PARSER_TOKEN_H
37 #include <type_traits>
42 #pragma warning(disable : 26812)
74 template <std::size_t NbParams,
typename... Args>
77 static_assert(NbParams ==
sizeof...(Args),
"mismatch between NbParams and Args");
78 if (_pUserData ==
nullptr)
81 return (*fun_typed_ptr)(std::forward<Args>(args)...);
86 return (*fun_userdata_typed_ptr)(_pUserData, std::forward<Args>(args)...);
90 template <std::size_t NbParams,
typename... Args>
93 static_assert(NbParams ==
sizeof...(Args) - 2,
"mismatch between NbParams and Args");
94 if (_pUserData ==
nullptr) {
96 return (*bulkfun_typed_ptr)(std::forward<Args>(args)...);
99 return (*bulkfun_userdata_typed_ptr)(_pUserData, std::forward<Args>(args)...);
105 if (_pUserData ==
nullptr) {
106 auto multfun_typed_ptr =
reinterpret_cast<multfun_type>(_pRawFun);
107 return (*multfun_typed_ptr)(a_afArg, a_iArgc);
110 return (*multfun_userdata_typed_ptr)(_pUserData, a_afArg, a_iArgc);
114 template <std::size_t NbParams,
typename... Args>
117 static_assert(NbParams ==
sizeof...(Args),
"mismatch between NbParams and Args");
118 if (_pUserData ==
nullptr)
121 return (*strfun_typed_ptr)(std::forward<Args>(args)...);
126 return (*strfun_userdata_typed_ptr)(_pUserData, std::forward<Args>(args)...);
132 return _pRawFun == other._pRawFun && _pUserData == other._pUserData;
135 explicit operator bool()
const
137 return _pRawFun !=
nullptr;
140 bool operator==(std::nullptr_t)
const
142 return _pRawFun ==
nullptr;
145 bool operator!=(std::nullptr_t)
const
147 return _pRawFun !=
nullptr;
151 static_assert(std::is_trivial<generic_callable_type>::value,
"generic_callable_type shall be trivial");
152 static_assert(std::is_standard_layout<generic_callable_type>::value,
"generic_callable_type shall have standard layout");
169 template<
typename TBase,
typename TString>
181 std::unique_ptr<ParserCallback> m_pCallback;
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;
243 m_pCallback.reset(a_Tok.m_pCallback.get() ? a_Tok.m_pCallback->Clone() : 0);
279 m_iCode = a_pCallback.
GetCode();
305 m_pCallback.reset(0);
322 m_pTok = (
void*)a_pVar;
323 m_pCallback.reset(0);
338 m_iIdx =
static_cast<int>(a_iSize);
341 m_pCallback.reset(0);
354 if (m_iCode !=
cmSTRING || a_iIdx < 0)
370 if (m_iIdx < 0 || m_iCode !=
cmSTRING)
384 if (m_pCallback.get())
386 return m_pCallback->GetCode();
397 if (m_pCallback.get())
399 return m_pCallback->GetType();
410 if (!m_pCallback.get())
416 return m_pCallback->GetPri();
422 if (m_pCallback.get() ==
nullptr || m_pCallback->GetCode() !=
cmOPRT_BIN)
425 return m_pCallback->GetAssociativity();
445 return (m_pCallback.get())
447 m_pCallback->GetUserData()}
461 case cmVAL:
return m_fVal;
462 case cmVAR:
return *((TBase*)m_pTok);
475 if (m_iCode !=
cmVAR)
478 return (TBase*)m_pTok;
490 if (!m_pCallback->IsValid())
493 return m_pCallback->GetArgc();
501 return m_pCallback->IsValid() && m_pCallback->IsOptimizable();
520 #if defined(_MSC_VER)
value_type(* multfun_userdata_type)(void *, const value_type *, int)
Callback type with user data (not null) used for functions and a variable argument list...
value_type(* strfun_type1)(const char_type *)
Callback type used for functions taking a string as an argument.
user defined binary operator
value_type(* bulkfun_type1)(int, int, value_type)
Callback type used for functions with a single arguments.
value_type(* strfun_type6)(const char_type *, value_type, value_type, value_type, value_type, value_type)
Callback type used for functions taking a string and five values as arguments.
ParserToken & SetVar(TBase *a_pVar, const TString &a_strTok)
make this token a variable token.
int GetArgCount() const
Return the number of function arguments.
value_type(* bulkfun_userdata_type10)(void *, int, int, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type)
Callback type with user data (not null) used for functions with ten arguments.
value_type(* fun_userdata_type8)(void *, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type)
Callback type with user data (not null) used for functions with eight arguments.
TBase * GetVar() const
Get address of a variable token.
bool IsValid() const
Check that the callback looks valid.
value_type(* bulkfun_userdata_type0)(void *, int, int)
Callback type with user data (not null) used for functions without arguments.
Internal error of any kind.
value_type(* bulkfun_type8)(int, int, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type)
Callback type used for functions with eight arguments.
value_type(* fun_type5)(value_type, value_type, value_type, value_type, value_type)
Callback type used for functions with five arguments.
value_type(* fun_userdata_type7)(void *, value_type, value_type, value_type, value_type, value_type, value_type, value_type)
Callback type with user data (not null) used for functions with seven arguments.
value_type(* bulkfun_type2)(int, int, value_type, value_type)
Callback type used for functions with two arguments.
value_type(* fun_type1)(value_type)
Callback type used for functions with a single arguments.
value_type(* bulkfun_userdata_type9)(void *, int, int, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type)
Callback type with user data (not null) used for functions with nine arguments.
ParserToken & SetVal(TBase a_fVal, const TString &a_strTok=TString())
Make this token a value token.
value_type(* strfun_type4)(const char_type *, value_type, value_type, value_type)
Callback type used for functions taking a string and three values as arguments.
void Assign(const ParserToken &a_Tok)
Copy token information from argument.
value_type(* fun_userdata_type0)(void *)
Callback type with user data (not null) used for functions without arguments.
value_type(* strfun_userdata_type4)(void *, const char_type *, value_type, value_type, value_type)
Callback type with user data (not null) used for functions taking a string and a value as arguments...
value_type(* bulkfun_type9)(int, int, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type)
Callback type used for functions with nine arguments.
generic_callable_type GetFuncAddr() const
Return the address of the callback function assoziated with function and operator tokens...
ParserToken & operator=(const ParserToken &a_Tok)
Assignment operator.
bool IsOptimizable() const
Return true if the token is a function token that can be optimized.
value_type(* strfun_type3)(const char_type *, value_type, value_type)
Callback type used for functions taking a string and two values as arguments.
value_type(* bulkfun_userdata_type3)(void *, int, int, value_type, value_type, value_type)
Callback type with user data (not null) used for functions with three arguments.
value_type(* fun_userdata_type6)(void *, value_type, value_type, value_type, value_type, value_type, value_type)
Callback type with user data (not null) used for functions with six arguments.
ECmdCode GetCode() const
Return the callback code.
ParserToken & SetString(const TString &a_strTok, std::size_t a_iSize)
Make this token a variable token.
value_type(* strfun_userdata_type2)(void *, const char_type *, value_type)
Callback type with user data (not null) used for functions taking a string and a value as arguments...
value_type(* multfun_type)(const value_type *, int)
Callback type used for functions with a variable argument list.
value_type(* fun_userdata_type9)(void *, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type)
Callback type with user data (not null) used for functions with nine arguments.
value_type(* bulkfun_userdata_type5)(void *, int, int, value_type, value_type, value_type, value_type, value_type)
Callback type with user data (not null) used for functions with five arguments.
Code for a generic function item.
EOprtAssociativity
Parser operator precedence values.
value_type(* fun_type8)(value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type)
Callback type used for functions with eight arguments.
value_type(* bulkfun_type5)(int, int, value_type, value_type, value_type, value_type, value_type)
Callback type used for functions with five arguments.
value_type(* bulkfun_type6)(int, int, value_type, value_type, value_type, value_type, value_type, value_type)
Callback type used for functions with six arguments.
value_type(* strfun_type5)(const char_type *, value_type, value_type, value_type, value_type)
Callback type used for functions taking a string and four values as arguments.
int GetIdx() const
Return Index associated with the token related data.
value_type(* fun_type10)(value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type)
Callback type used for functions with ten arguments.
value_type(* fun_type9)(value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type)
Callback type used for functions with nine arguments.
ETypeCode
Types internally used by the parser.
ParserToken()
Constructor (default).
value_type(* bulkfun_userdata_type1)(void *, int, int, value_type)
Callback type with user data (not null) used for functions with a single arguments.
value_type(* fun_userdata_type5)(void *, value_type, value_type, value_type, value_type, value_type)
Callback type with user data (not null) used for functions with five arguments.
value_type(* fun_type2)(value_type, value_type)
Callback type used for functions with two arguments.
Error class of the parser.
value_type(* fun_userdata_type3)(void *, value_type, value_type, value_type)
Callback type with user data (not null) used for functions with three arguments.
value_type(* fun_userdata_type1)(void *, value_type)
Callback type with user data (not null) used for functions with a single arguments.
#define MUP_ASSERT(COND)
An assertion that does not kill the program.
MUP_BASETYPE value_type
The numeric datatype used by the parser.
String type (Function arguments and constants only, no string variables)
value_type(* strfun_type2)(const char_type *, value_type)
Callback type used for functions taking a string and a value as arguments.
A numerical function has been called with a non value type of argument.
value_type(* bulkfun_userdata_type6)(void *, int, int, value_type, value_type, value_type, value_type, value_type, value_type)
Callback type with user data (not null) used for functions with six arguments.
ECmdCode GetCode() const
Return the token type.
Namespace for mathematical applications.
ParserToken & Set(ECmdCode a_iType, const TString &a_strTok=TString())
Assign a token type.
value_type(* fun_type3)(value_type, value_type, value_type)
Callback type used for functions with three arguments.
value_type(* fun_type0)()
Callback type used for functions without arguments.
Definition of the parser callback class.
value_type(* bulkfun_userdata_type8)(void *, int, int, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type)
Callback type with user data (not null) used for functions with eight arguments.
value_type(* bulkfun_type7)(int, int, value_type, value_type, value_type, value_type, value_type, value_type, value_type)
Callback type used for functions with seven arguments.
void SetIdx(int a_iIdx)
Set an index associated with the token related data.
value_type(* fun_userdata_type4)(void *, value_type, value_type, value_type, value_type)
Callback type with user data (not null) used for functions with four arguments.
value_type(* bulkfun_userdata_type2)(void *, int, int, value_type, value_type)
Callback type with user data (not null) used for functions with two arguments.
value_type(* strfun_userdata_type3)(void *, const char_type *, value_type, value_type)
Callback type with user data (not null) used for functions taking a string and two values as argument...
void(* erased_fun_type)()
Function type used to erase type. Voluntarily needs explicit cast with all other fun_type.
value_type(* fun_type4)(value_type, value_type, value_type, value_type)
Callback type used for functions with four arguments.
value_type(* strfun_userdata_type1)(void *, const char_type *)
Callback type with user data (not null) used for functions taking a string as an argument.
value_type(* fun_type7)(value_type, value_type, value_type, value_type, value_type, value_type, value_type)
Callback type used for functions with seven arguments.
value_type(* bulkfun_type4)(int, int, value_type, value_type, value_type, value_type)
Callback type used for functions with four arguments.
value_type(* bulkfun_userdata_type4)(void *, int, int, value_type, value_type, value_type, value_type)
Callback type with user data (not null) used for functions with four arguments.
value_type(* strfun_userdata_type5)(void *, const char_type *, value_type, value_type, value_type, value_type)
Callback type with user data (not null) used for functions taking a string and two values as argument...
Encapsulation of the data for a single formula token.
value_type(* fun_userdata_type2)(void *, value_type, value_type)
Callback type with user data (not null) used for functions with two arguments.
value_type(* fun_userdata_type10)(void *, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type)
Callback type with user data (not null) used for functions with ten arguments.
const TString & GetAsString() const
Return the token identifier.
value_type(* bulkfun_type0)(int, int)
Callback type used for functions without arguments.
Floating point variables.
value_type(* bulkfun_type3)(int, int, value_type, value_type, value_type)
Callback type used for functions with three arguments.
value_type(* bulkfun_userdata_type7)(void *, int, int, value_type, value_type, value_type, value_type, value_type, value_type, value_type)
Callback type with user data (not null) used for functions with seven arguments.
ParserToken(const ParserToken &a_Tok)
Create token from another one.
Encapsulation of prototypes for a numerical parser function.
ParserToken & Set(const ParserCallback &a_pCallback, const TString &a_sTok)
Set Callback type.
value_type(* fun_type6)(value_type, value_type, value_type, value_type, value_type, value_type)
Callback type used for functions with six arguments.
value_type(* strfun_userdata_type6)(void *, const char_type *, value_type, value_type, value_type, value_type, value_type)
Callback type with user data (not null) used for functions taking a string and five values as argumen...
This file defines the error class used by the parser.
value_type(* bulkfun_type10)(int, int, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type)
Callback type used for functions with ten arguments.