NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
procedure.hpp
Go to the documentation of this file.
1/*****************************************************************************
2 NumeRe: Framework fuer Numerische Rechnungen
3 Copyright (C) 2014 Erik Haenel et al.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17******************************************************************************/
18
19
20// Class: Procedure
21
22#ifndef PROCEDURE_HPP
23#define PROCEDURE_HPP
24
25#include <iostream>
26#include <string>
27#include <cmath>
28#include <iomanip>
29#include <fstream>
30
31#include "../ui/error.hpp"
32#include "../ParserLib/muParser.h"
33#include "../datamanagement/memorymanager.hpp"
34#include "../settings.hpp"
35#include "../utils/tools.hpp"
36#include "../built-in.hpp"
37#include "../maths/parser_functions.hpp"
38#include "../plotting/plotdata.hpp"
39#include "flowctrl.hpp"
40#include "plugin.hpp"
41#include "../maths/define.hpp"
42#include "../io/filesystem.hpp"
43#include "../io/output.hpp"
44#include "../script.hpp"
45
46// forward declaration of the var factory
48
49
55class Procedure : public FlowCtrl, public PackageManager
56{
57 private:
58 friend class NumeReDebugger;
59 friend class ProcedureVarFactory; // For FlowCtrl Enums
60
61 std::fstream fProcedure;
62 std::string sProcNames;
65 std::string sNameSpace;
66 std::string sCallingNameSpace;
67 std::string sThisNameSpace;
69 std::string sProcCommandLine;
72 int nFlags;
75
77
78 void init();
79
80 Returnvalue ProcCalc(std::string sLine, std::string sCurrentCommand, int& nByteCode, mu::Parser& _parser, FunctionDefinitionManager& _functions, MemoryManager& _data, Settings& _option, Output& _out, PlotData& _pData, Script& _script);
81 bool setProcName(const std::string& sProc, bool bInstallFileName = false);
82 void resetProcedure(mu::Parser& _parser, bool bSupressAnswer);
83 void extractCurrentNamespace(const std::string& sProc);
84 bool handleVariableDefinitions(std::string& sProcCommandLine, const std::string& sCommand);
85 int handleIncludeSyntax(std::string& sProcCommandLine, std::ifstream& fInclude, bool bReadingFromInclude);
86 void extractProcedureInformation(const std::string& sCmdLine, size_t nPos, std::string& sProcName, std::string& sArgList, std::string& sFileName);
87
88 virtual int procedureCmdInterface(std::string& sLine) override;
89 virtual std::vector<std::string> expandInlineProcedures(std::string& sLine) override;
90 int isInlineable(const std::string& sProc, const std::string& sFileName, int* nInlineFlag = nullptr);
91 int applyInliningRuleset(const std::string& sCommandLine, const std::string& sArgumentList);
92 size_t countProceduresInLine(const std::string& sCommandLine);
93 std::vector<std::string> getInlined(const std::string& sProc, const std::string& sArgumentList, const std::string& sFileName, size_t nProcedures);
94
95 public:
96 Procedure();
97 Procedure(const Procedure& _procedure);
98 ~Procedure();
99
100 Returnvalue execute(std::string sProc, std::string sVarList, mu::Parser& _parser, FunctionDefinitionManager& _functions, MemoryManager& _data, Settings& _option, Output& _out, PlotData& _pData, Script& _script, unsigned int nth_procedure = 0);
101 static std::string mangleName(std::string sProcedureName);
102 virtual FlowCtrl::ProcedureInterfaceRetVal procedureInterface(std::string& sLine, mu::Parser& _parser, FunctionDefinitionManager& _functions, MemoryManager& _data, Output& _out, PlotData& _pData, Script& _script, Settings& _option, int nth_command = 0) override;
103 bool writeProcedure(std::string sProcedureLine);
104 virtual int isInline(const std::string& sProc) override;
105 virtual int evalDebuggerBreakPoint(mu::Parser& _parser, Settings& _option) override;
106 virtual int getErrorInformationForDebugger() override;
107 virtual int catchExceptionForTest(std::exception_ptr e_ptr, bool bSupressAnswer_back, int nLine) override;
108
109 inline void setPredefinedFuncs(const std::string& sPredefined)
110 {
111 _localDef.setPredefinedFuncs(sPredefined);
112 }
113 inline std::string getCurrentProcedureName() const
114 {return sCurrentProcedureName;}
115 unsigned int GetCurrentLine() const;
116 inline int getReturnType() const
117 {return nReturnType;}
118 inline bool is_writing() const
119 {return bWritingTofile;}
120 inline int getProcedureFlags() const
121 {return nFlags;}
122 inline int& getDebuggerCode()
123 {
124 return nDebuggerCode;
125 }
126 size_t replaceReturnVal(std::string& sLine, mu::Parser& _parser, const Returnvalue& _return, unsigned int nPos, unsigned int nPos2, const std::string& sReplaceName);
127};
128
129#endif // PROCEDURE_HPP
130
131
int nReturnType
Definition: flowctrl.hpp:130
int nDebuggerCode
Definition: flowctrl.hpp:125
ProcedureInterfaceRetVal
Definition: flowctrl.hpp:85
This class implements the function definition managing instance.
Definition: define.hpp:74
void setPredefinedFuncs(const std::string &sPredefined)
This member function updates the internal list of predefined functions. If the list is whitespace-sep...
Definition: define.cpp:1158
This class represents the central memory managing instance. It will handle all tables and clusters,...
This class implements the procedure plugin system. It will be a parent class of the procedure class.
Definition: plugin.hpp:115
This class contains all the plot settings usable by the plotting algorithm.
Definition: plotdata.hpp:42
This class implements the logic to evaluate complex procedures, which may be called recursively.
Definition: procedure.hpp:56
~Procedure()
Destructor ensuring that the procedure output file stream will be closed, if it is still open.
Definition: procedure.cpp:78
virtual int catchExceptionForTest(std::exception_ptr e_ptr, bool bSupressAnswer_back, int nLine) override
This virtual member function is inserted in some automatically catchable locations to convert an erro...
Definition: procedure.cpp:2495
bool bWritingTofile
Definition: procedure.hpp:71
FunctionDefinitionManager _localDef
Definition: procedure.hpp:76
std::string sLastWrittenProcedureFile
Definition: procedure.hpp:68
Returnvalue execute(std::string sProc, std::string sVarList, mu::Parser &_parser, FunctionDefinitionManager &_functions, MemoryManager &_data, Settings &_option, Output &_out, PlotData &_pData, Script &_script, unsigned int nth_procedure=0)
This member function is central in the execution of the currently selected procedure as it handles al...
Definition: procedure.cpp:614
std::string sProcNames
Definition: procedure.hpp:62
std::string sCallingNameSpace
Definition: procedure.hpp:66
virtual int evalDebuggerBreakPoint(mu::Parser &_parser, Settings &_option) override
This virtual member function handles the gathering of all relevant information for the debugger for t...
Definition: procedure.cpp:2437
int applyInliningRuleset(const std::string &sCommandLine, const std::string &sArgumentList)
This private member function applies the internal inlining rule set for a single procedure command li...
Definition: procedure.cpp:2185
std::vector< std::string > getInlined(const std::string &sProc, const std::string &sArgumentList, const std::string &sFileName, size_t nProcedures)
This virtual private member function returns the inlined representation of the selected procedure as ...
Definition: procedure.cpp:2265
ProcedureVarFactory * _varFactory
Definition: procedure.hpp:74
int isInlineable(const std::string &sProc, const std::string &sFileName, int *nInlineFlag=nullptr)
This private member function evaluates, whether the current procedure is inlineable,...
Definition: procedure.cpp:2109
virtual FlowCtrl::ProcedureInterfaceRetVal procedureInterface(std::string &sLine, mu::Parser &_parser, FunctionDefinitionManager &_functions, MemoryManager &_data, Output &_out, PlotData &_pData, Script &_script, Settings &_option, int nth_command=0) override
This member function handles the calls for procedures and plugins, resolves them and executes the cal...
Definition: procedure.cpp:1250
std::string sProcCommandLine
Definition: procedure.hpp:69
bool is_writing() const
Definition: procedure.hpp:118
void init()
Private initializing member function. Sets all variables to a reasonable default value.
Definition: procedure.cpp:98
virtual int isInline(const std::string &sProc) override
This virtual member function checks, whether the procedures in the current line are declared as inlin...
Definition: procedure.cpp:1958
std::string sNameSpace
Definition: procedure.hpp:65
int handleIncludeSyntax(std::string &sProcCommandLine, std::ifstream &fInclude, bool bReadingFromInclude)
This member function handles the script include syntax, which one may use in other procedures.
Definition: procedure.cpp:2834
void extractProcedureInformation(const std::string &sCmdLine, size_t nPos, std::string &sProcName, std::string &sArgList, std::string &sFileName)
This private member function extracts procedure name, argument list and the corresponding file name f...
Definition: procedure.cpp:1880
std::fstream fProcedure
Definition: procedure.hpp:61
bool bProcSupressAnswer
Definition: procedure.hpp:70
Returnvalue ProcCalc(std::string sLine, std::string sCurrentCommand, int &nByteCode, mu::Parser &_parser, FunctionDefinitionManager &_functions, MemoryManager &_data, Settings &_option, Output &_out, PlotData &_pData, Script &_script)
This member function does the evaluation stuff regarding strings and numerical expressions for the cu...
Definition: procedure.cpp:130
int nthBlock
Definition: procedure.hpp:73
size_t replaceReturnVal(std::string &sLine, mu::Parser &_parser, const Returnvalue &_return, unsigned int nPos, unsigned int nPos2, const std::string &sReplaceName)
This member function replaces the procedure occurence between the both passed positions using akronym...
Definition: procedure.cpp:2591
bool setProcName(const std::string &sProc, bool bInstallFileName=false)
This member function is used to obtain the procedure file name from the selected procedure....
Definition: procedure.cpp:547
void setPredefinedFuncs(const std::string &sPredefined)
Definition: procedure.hpp:109
int getProcedureFlags() const
Definition: procedure.hpp:120
int nFlags
Definition: procedure.hpp:72
virtual int getErrorInformationForDebugger() override
This virtual member function handles the gathering of all relevant information for the debugger for t...
Definition: procedure.cpp:2464
int getReturnType() const
Definition: procedure.hpp:116
void resetProcedure(mu::Parser &_parser, bool bSupressAnswer)
This member function sets the current procedure object to its original state. It will be called at th...
Definition: procedure.cpp:2686
unsigned int GetCurrentLine() const
This member function will return the current line number depending on whether a flow control statemen...
Definition: procedure.cpp:2563
std::string sCurrentProcedureName
Definition: procedure.hpp:63
size_t countProceduresInLine(const std::string &sCommandLine)
This private member function simply counts the number of procedures, which may be found in the curren...
Definition: procedure.cpp:2224
virtual int procedureCmdInterface(std::string &sLine) override
Virtual member function allowing to identify and evaluate some special procedure commands....
Definition: procedure.cpp:1494
bool handleVariableDefinitions(std::string &sProcCommandLine, const std::string &sCommand)
This method handles the definitions of local variables.
Definition: procedure.cpp:2776
void extractCurrentNamespace(const std::string &sProc)
This member function extracts the namespace of the currently executed procedure.
Definition: procedure.cpp:2728
std::string getCurrentProcedureName() const
Definition: procedure.hpp:113
bool writeProcedure(std::string sProcedureLine)
This member function handles the procedure installation process by governing the file stream and pass...
Definition: procedure.cpp:1547
int nCurrentLine
Definition: procedure.hpp:64
static std::string mangleName(std::string sProcedureName)
Mangles a procedure name to be used as a usual variable.
Definition: procedure.cpp:2414
virtual std::vector< std::string > expandInlineProcedures(std::string &sLine) override
This virtual private member function expands all procedures in the current command line,...
Definition: procedure.cpp:2026
std::string sThisNameSpace
Definition: procedure.hpp:67
int & getDebuggerCode()
Definition: procedure.hpp:122
Procedure()
Default constructor.
Definition: procedure.cpp:34
This class is the variable factory used by procedure instances to create their local variables and re...
This class manages the setting values of the internal (kernel) settings of this application.
Definition: settings.hpp:663
Mathematical expressions parser.
Definition: muParser.h:51
Structure as wrapper for the return value of procedures (which may be numerical or string values or a...