MCPcopy Create free account
hub / github.com/IBAMR/IBAMR / ApplyStrFunc

Method ApplyStrFunc

ibtk/contrib/muparser/src/muParserBase.cpp:780–815  ·  view source on GitHub ↗

--------------------------------------------------------------------------- \brief Execute a function that takes a single string argument. \param a_FunTok Function token. \throw exception_type If the function token is not a string function */

Source from the content-addressed store, hash-verified

778 \throw exception_type If the function token is not a string function
779 */
780 ParserBase::token_type ParserBase::ApplyStrFunc(
781 const token_type& a_FunTok,
782 const std::vector<token_type>& a_vArg) const
783 {
784 if (a_vArg.back().GetCode() != cmSTRING)
785 Error(ecSTRING_EXPECTED, m_pTokenReader->GetPos(), a_FunTok.GetAsString());
786
787 token_type valTok;
788 generic_callable_type pFunc = a_FunTok.GetFuncAddr();
789 MUP_ASSERT(pFunc);
790
791 try
792 {
793 // Check function arguments; write dummy value into valtok to represent the result
794 switch (a_FunTok.GetArgCount())
795 {
796 case 0: valTok.SetVal(1); a_vArg[0].GetAsString(); break;
797 case 1: valTok.SetVal(1); a_vArg[1].GetAsString(); a_vArg[0].GetVal(); break;
798 case 2: valTok.SetVal(1); a_vArg[2].GetAsString(); a_vArg[1].GetVal(); a_vArg[0].GetVal(); break;
799 case 3: valTok.SetVal(1); a_vArg[3].GetAsString(); a_vArg[2].GetVal(); a_vArg[1].GetVal(); a_vArg[0].GetVal(); break;
800 case 4: valTok.SetVal(1); a_vArg[4].GetAsString(); a_vArg[3].GetVal(); a_vArg[2].GetVal(); a_vArg[1].GetVal(); a_vArg[0].GetVal(); break;
801 case 5: valTok.SetVal(1); a_vArg[5].GetAsString(); a_vArg[4].GetVal(); a_vArg[3].GetVal(); a_vArg[2].GetVal(); a_vArg[1].GetVal(); a_vArg[0].GetVal(); break;
802 default: Error(ecINTERNAL_ERROR);
803 }
804 }
805 catch (ParserError&)
806 {
807 Error(ecVAL_EXPECTED, m_pTokenReader->GetPos(), a_FunTok.GetAsString());
808 }
809
810 // string functions won't be optimized
811 m_vRPN.AddStrFun(pFunc, a_FunTok.GetArgCount(), a_vArg.back().GetIdx());
812
813 // Push dummy value representing the function result to the stack
814 return valTok;
815 }
816
817 //---------------------------------------------------------------------------
818 /** \brief Apply a function token.

Callers

nothing calls this directly

Calls 8

GetFuncAddrMethod · 0.80
GetArgCountMethod · 0.80
GetValMethod · 0.80
AddStrFunMethod · 0.80
GetIdxMethod · 0.80
GetCodeMethod · 0.45
backMethod · 0.45
GetPosMethod · 0.45

Tested by

no test coverage detected