NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
define.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: DEFINE <--
21#ifndef DEFINE_HPP
22#define DEFINE_HPP
23
24//#include <cstring>
25#include <string>
26#include <iostream>
27#include <fstream>
28#include <map>
29#include <vector>
30
31#include "../ui/error.hpp"
32#include "../io/filesystem.hpp"
33#include "../settings.hpp"
34#include "../utils/tools.hpp"
35
36
43{
44 public:
45 std::string sName;
46 std::string sSignature;
47 std::string sDefinitionString;
49 std::string sComment;
50 std::vector<std::string> vArguments;
51
52 FunctionDefinition(const std::string& _sDefinitionString = "");
54 std::string parse(const std::string& _sArgList);
55 std::string exportFunction() const;
56 bool importFunction(const std::string& _sExportedString);
57 std::string getDefinition() const;
58 bool appendComment(const std::string& _sComment);
59
60 private:
61 bool decodeDefinition();
63 bool convertToValues();
65};
66
67
68
74{
75 private:
76 std::map<std::string, FunctionDefinition> mFunctionsMap;
77 std::string sFileName; // Dateinamen fuer die Speichern-Funktion
78
79 std::string sBuilt_In; // String, der die Namen der Built-In-Funktionen speichert
80 std::string sCommands; // String, der alle NumeRe-Kommandos speichert
81 std::string sTables;
82 bool isLocal;
83
84 std::string resolveRecursiveDefinitions(std::string sDefinition);
85 std::map<std::string, FunctionDefinition>::const_iterator findItemById(size_t id) const;
86
87 public:
88 FunctionDefinitionManager(bool _isLocal); // Standard-Konstruktor
89 FunctionDefinitionManager(const FunctionDefinitionManager& _defined); // Kopierkonstruktor
90
91 // --> TRUE, wenn es eine Funktion mit dem angegeben Funktionsnamen gibt <--
92 bool isDefined(const std::string& sFunc);
93
94 // --> Zentrale Methode: Definiert eine eigene Funktion <--
95 bool defineFunc(const std::string& sExpr, bool bRedefine = false, bool bFallback = false);
96
97 // --> Entfernt eine definierte Funktion aus dem Funktionenspeicher <--
98 bool undefineFunc(const std::string& sFunc);
99
100 // --> Ruft zuvor definierte Funktionen auf <--
101 bool call(std::string& sExpr, int nRecursion = 0);
102
103 // --> Gibt die Zahl der definierten Funktionen zurueck <--
104 size_t getDefinedFunctions() const;
105
106 // --> Gibt die zur Definition der _i-ten Funktion verwendete Definition zurueck <--
107 std::string getDefinitionString(size_t _i) const;
108 std::string getFunctionSignature(size_t _i) const;
109 std::string getImplementation(size_t _i) const;
110 std::string getComment(size_t _i) const;
111
112 bool reset();
113
114 // --> Speichern der Funktionsdefinitionen <--
115 bool save(const Settings& _option);
116
117 // --> Laden gespeicherter Funktionsdefinitionen <--
118 bool load(const Settings& _option, bool bAutoLoad = false);
119
127 inline std::string getNamesOfDefinedFunctions() const
128 {
129 std::string sReturn = ";";
130
131 for (auto iter = mFunctionsMap.begin(); iter != mFunctionsMap.end(); ++iter)
132 {
133 sReturn += iter->first + ";";
134 }
135
136 return sReturn;
137 }
138
148 inline void setTableList(const std::string& sTableList)
149 {
150 sTables = sTableList;
151 }
152
153 void setPredefinedFuncs(const std::string& sPredefined);
154
162 inline std::string getPredefinedFuncs() const
163 {
164 return sBuilt_In;
165 }
166
179 inline size_t getFunctionIndex(const std::string& sFuncName)
180 {
181 if (!mFunctionsMap.size())
182 return (size_t)-1;
183
184 size_t i = 0;
185
186 for (auto iter = mFunctionsMap.begin(); iter != mFunctionsMap.end(); ++iter)
187 {
188 if (iter->first == sFuncName.substr(0, sFuncName.find('(')))
189 return i;
190
191 i++;
192 }
193
194 return (size_t)-1;
195 }
196};
197
198#endif
This class implements the basic input/ output file system and provides functionalities to work with f...
Definition: filesystem.hpp:92
This class implements a single function definition. It is managed by the Define class.
Definition: define.hpp:43
bool splitAndValidateArguments()
This private member function validates the arguments of the function definition.
Definition: define.cpp:373
std::vector< std::string > vArguments
Definition: define.hpp:50
FunctionDefinition(const std::string &_sDefinitionString="")
Constructor of the FunctionDefinition class. Creates a definition from the passed definition string.
Definition: define.cpp:37
bool convertToValues()
This private member function converts the selected of the passed variables into their values.
Definition: define.cpp:422
std::string getDefinition() const
This member function returns the definition of the function without the appended parameters.
Definition: define.cpp:278
bool appendComment(const std::string &_sComment)
This member function appends a comment, which might be set after the definition.
Definition: define.cpp:250
std::string sSignature
Definition: define.hpp:46
std::string sDefinitionString
Definition: define.hpp:47
std::string sName
Definition: define.hpp:45
FunctionDefinition & operator=(const FunctionDefinition &)
Assignment operator overload for the Function definition class.
Definition: define.cpp:54
bool importFunction(const std::string &_sExportedString)
This member function imports a previously exported definition string and distributes its contents alo...
Definition: define.cpp:195
std::string sComment
Definition: define.hpp:49
std::string parse(const std::string &_sArgList)
This member function parses the call to the contained function definition and returns a function defi...
Definition: define.cpp:77
bool decodeDefinition()
This private member function decodes the definition in the private member variable "sDefinitionString...
Definition: define.cpp:302
bool replaceArgumentOccurences()
This private member function replaces all occurences of the passed arguments with the corresponding n...
Definition: define.cpp:465
std::string exportFunction() const
This member function creates the save string used for writing to the definition file.
Definition: define.cpp:173
std::string sParsedDefinitionString
Definition: define.hpp:48
This class implements the function definition managing instance.
Definition: define.hpp:74
std::string getFunctionSignature(size_t _i) const
Returns the function signature of the ith defined custom function.
Definition: define.cpp:983
void setTableList(const std::string &sTableList)
Sets the internal table list. This list is used to avoid redefinition of an already existing table as...
Definition: define.hpp:148
bool reset()
This member function resets the FunctionDefinitionManager object to a state before any function was d...
Definition: define.cpp:1040
std::string getDefinitionString(size_t _i) const
Returns the definition string of the ith defined custom function.
Definition: define.cpp:964
std::string sCommands
Definition: define.hpp:80
bool defineFunc(const std::string &sExpr, bool bRedefine=false, bool bFallback=false)
This function defines a custom function, by passing it to a new FunctionDefinition class instance.
Definition: define.cpp:655
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
bool undefineFunc(const std::string &sFunc)
This function removes a previously defined function from the internal memory.
Definition: define.cpp:772
std::string getPredefinedFuncs() const
Return a list of the internal defined default functions.
Definition: define.hpp:162
std::string getComment(size_t _i) const
Returns the comment of the ith defined function.
Definition: define.cpp:1021
std::string resolveRecursiveDefinitions(std::string sDefinition)
This private member function resolves recursive definitions, which are handled by replacing the occur...
Definition: define.cpp:545
bool call(std::string &sExpr, int nRecursion=0)
This function searches for known custom definitions in the passed expression and replaces them with t...
Definition: define.cpp:801
std::map< std::string, FunctionDefinition >::const_iterator findItemById(size_t id) const
This private member function returns the iterator to the function pointed by the passed ID.
Definition: define.cpp:590
bool isDefined(const std::string &sFunc)
This method checks, whether the passed function is already defined.
Definition: define.cpp:625
size_t getFunctionIndex(const std::string &sFuncName)
Returns the numerical index of the selected custom defined functions.
Definition: define.hpp:179
FunctionDefinitionManager(bool _isLocal)
Default constructor of the FunctionDefinitionManager class. Prepares the list of protected command st...
Definition: define.cpp:507
bool load(const Settings &_option, bool bAutoLoad=false)
This function loads previously saved function definitions to memory.
Definition: define.cpp:1104
std::map< std::string, FunctionDefinition > mFunctionsMap
Definition: define.hpp:76
std::string sFileName
Definition: define.hpp:77
bool save(const Settings &_option)
This function saves the function definitions to the definition file.
Definition: define.cpp:1056
std::string getNamesOfDefinedFunctions() const
Returns a list of the names of the custom defined functions.
Definition: define.hpp:127
std::string sBuilt_In
Definition: define.hpp:79
std::string getImplementation(size_t _i) const
Returns the implementation of the ith defined custom function.
Definition: define.cpp:1002
size_t getDefinedFunctions() const
Returns the number of defined functions.
Definition: define.cpp:950
This class manages the setting values of the internal (kernel) settings of this application.
Definition: settings.hpp:663