NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
plugin.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
21
22
23// CLASS Plugin
24
25
26#ifndef PLUGIN_HPP
27#define PLUGIN_HPP
28
29#include <iostream>
30#include <fstream>
31#include <string>
32
33#include "../io/filesystem.hpp"
34#include "../ui/error.hpp"
35
36
45{
46 private:
47 std::string getOptionValue(const std::string& sInstallInfoString, const std::string& sOption, const std::string& sDefault);
48
57 std::string stripParentheses(const std::string& sString) const
58 {
59 if (sString.front() == '(' && sString.back() == ')')
60 return sString.substr(1, sString.length()-2);
61
62 return sString;
63 }
64
65 public:
66 std::string sCommand;
67 std::string sMainProcedure;
68 std::string sArgumentList;
69 std::string sType;
70 std::string sLicense;
71 std::string sName;
72 std::string sVersion;
73 std::string sAuthor;
74 std::string sDescription;
75 std::string sMenuEntry;
77 std::string sKeyWords;
78 std::string sChangesLog;
79
80 Package();
81 Package(const std::string& sInstallInfoString);
82
83 std::string exportDefinition() const;
84 void importDefinition(std::string sDefinitionString);
85
86 bool isPlugin() const;
87 bool operator==(const Package& _plugin) const;
88 bool operator!=(const Package& _plugin) const;
89 void update(const Package& _plugin);
90 void incrementVersion();
91 std::string getName() const;
92 std::string getAuthor() const;
93 std::string getDescription() const;
94 std::string getKeyWords() const;
95 std::string getLicense() const;
96 std::string getMenuEntry() const;
97 std::string getCommandSignature() const;
98 std::string getChangesLog() const;
99};
100
101
115{
116 private:
117 std::fstream fPlugins;
118 std::vector<Package> vPackageInfo;
120
121 std::string sPluginProcName;
122 std::string sPluginVarList;
123 void assign(const PackageManager& _manager);
124 void updatePluginFile();
125
126 public:
128 PackageManager(const PackageManager& _manager);
130 PackageManager& operator= (const PackageManager& _manager);
131
132 bool loadPlugins();
133 bool evalPluginCmd(std::string& sCmd);
134 bool declareNewPackage(const std::string& sInstallInfoString);
135 bool isPluginCmd(const std::string& sCmd) const;
136 std::string deletePackage(const std::string& sPackage);
137 std::map<std::string, std::string> getMenuMap() const;
138
146 inline unsigned int getPackageCount() const
147 {return vPackageInfo.size();}
148
149 std::string getPluginInfoPath();
150 void addHelpIndex(const std::string& _sPluginName, std::string _sHelpId);
151
159 const std::vector<Package>& getPackages() const
160 {
161 return vPackageInfo;
162 }
163
171 inline std::string getPluginNames() const
172 {
173 std::string sReturn = ";";
174
175 for (unsigned int i = 0; i < vPackageInfo.size(); i++)
176 sReturn += vPackageInfo[i].getName() + ";";
177
178 return sReturn;
179 }
180
188 inline std::string getPluginProcName() const
189 {return sPluginProcName;}
190
198 inline std::string getPluginVarList() const
199 {return sPluginVarList;}
200
209 inline std::string getPluginCommand(unsigned int i = 0) const
210 {
211 if (i < vPackageInfo.size())
212 return vPackageInfo[i].sCommand;
213
214 return "";
215 }
216
225 inline std::string getPluginCommandSignature(unsigned int i = 0) const
226 {
227 if (i < vPackageInfo.size())
228 return vPackageInfo[i].getCommandSignature();
229
230 return "";
231 }
232
241 inline std::string getPackageName(unsigned int i = 0) const
242 {
243 if (i < vPackageInfo.size())
244 return vPackageInfo[i].getName();
245
246 return "";
247 }
248
257 inline std::string getPackageVersion(unsigned int i = 0) const
258 {
259 if (i < vPackageInfo.size())
260 return vPackageInfo[i].sVersion;
261
262 return "";
263 }
264
272 inline std::string getPackageAuthor(unsigned int i = 0) const
273 {
274 if (i < vPackageInfo.size())
275 return vPackageInfo[i].getAuthor();
276
277 return "";
278 }
279
288 inline std::string getPackageDescription(unsigned int i = 0) const
289 {
290 if (i < vPackageInfo.size())
291 return vPackageInfo[i].getDescription();
292
293 return "";
294 }
295
304 inline std::string getPackageLicense(unsigned int i = 0) const
305 {
306 if (i < vPackageInfo.size())
307 return vPackageInfo[i].getLicense();
308
309 return "";
310 }
311
320 inline std::string getPluginMenuEntry(unsigned int i = 0) const
321 {
322 if (i < vPackageInfo.size())
323 return vPackageInfo[i].getMenuEntry();
324
325 return "";
326 }
327};
328
329#endif
330
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 declared package. It can be constructed directly from an install infor...
Definition: plugin.hpp:45
std::string sKeyWords
Definition: plugin.hpp:77
std::string getCommandSignature() const
Creates a command signature for a plugin depending on the selected command line exraction tags of the...
Definition: plugin.cpp:357
std::string sDocumentationIndexID
Definition: plugin.hpp:76
std::string sMainProcedure
Definition: plugin.hpp:67
Package()
Default constructor.
Definition: plugin.cpp:33
std::string sAuthor
Definition: plugin.hpp:73
bool operator!=(const Package &_plugin) const
This member function is an overload for the inequality comparison operator.
Definition: plugin.cpp:229
std::string sVersion
Definition: plugin.hpp:72
std::string getLicense() const
Returns the package license.
Definition: plugin.cpp:331
std::string getChangesLog() const
Returns the package changeslog.
Definition: plugin.cpp:386
std::string sLicense
Definition: plugin.hpp:70
void importDefinition(std::string sDefinitionString)
This member function will import the package definition from the passed definition string.
Definition: plugin.cpp:144
std::string sType
Definition: plugin.hpp:69
std::string sName
Definition: plugin.hpp:71
std::string getOptionValue(const std::string &sInstallInfoString, const std::string &sOption, const std::string &sDefault)
This private member function extracts the option value of the passed option and replaces it by its de...
Definition: plugin.cpp:90
std::string getName() const
Returns the package name.
Definition: plugin.cpp:283
std::string sArgumentList
Definition: plugin.hpp:68
bool operator==(const Package &_plugin) const
This member function is an overload for the equality comparison operator.
Definition: plugin.cpp:215
std::string getDescription() const
Returns the package description.
Definition: plugin.cpp:307
std::string exportDefinition() const
This member function will create the definition export string to be written to the plugin definition ...
Definition: plugin.cpp:126
void update(const Package &_plugin)
This member function can be used to update a package definition with a newer definition....
Definition: plugin.cpp:245
std::string stripParentheses(const std::string &sString) const
This private member function removes the surrounding parentheses, if available.
Definition: plugin.hpp:57
bool isPlugin() const
Returns, whether the current package provides plugin functionalities.
Definition: plugin.cpp:201
std::string getMenuEntry() const
Returns the menu entry of this plugin.
Definition: plugin.cpp:343
std::string sDescription
Definition: plugin.hpp:74
std::string sCommand
Definition: plugin.hpp:66
std::string sChangesLog
Definition: plugin.hpp:78
void incrementVersion()
This member function will increment the package version number by a build count.
Definition: plugin.cpp:271
std::string getKeyWords() const
Returns the package keywords.
Definition: plugin.cpp:319
std::string sMenuEntry
Definition: plugin.hpp:75
std::string getAuthor() const
Returns the package author.
Definition: plugin.cpp:295
This class implements the procedure plugin system. It will be a parent class of the procedure class.
Definition: plugin.hpp:115
std::string getPackageName(unsigned int i=0) const
Returns the plugin name of the ith plugin.
Definition: plugin.hpp:241
std::string getPackageDescription(unsigned int i=0) const
Returns the description of the ith plugin.
Definition: plugin.hpp:288
PackageManager()
PluginManager default constructor.
Definition: plugin.cpp:404
std::string getPluginCommandSignature(unsigned int i=0) const
Returns the plugin command signature of the ith plugin.
Definition: plugin.hpp:225
void addHelpIndex(const std::string &_sPluginName, std::string _sHelpId)
This member function adds the passed documentation index ID to the plugin definition.
Definition: plugin.cpp:770
std::string getPluginProcName() const
Returns the current plugin's procedure name.
Definition: plugin.hpp:188
std::string deletePackage(const std::string &sPackage)
This member function deletes the plugin with the passed name from the internal set of definitions and...
Definition: plugin.cpp:857
std::fstream fPlugins
Definition: plugin.hpp:117
std::vector< Package > vPackageInfo
Definition: plugin.hpp:118
std::string getPluginInfoPath()
This member function simply returns the plugin definition file path.
Definition: plugin.cpp:913
std::string sPluginProcName
Definition: plugin.hpp:121
bool loadPlugins()
This member function will read the plugin definitions from the definitions file and create the intern...
Definition: plugin.cpp:501
std::string getPackageLicense(unsigned int i=0) const
Returns the license information of the ith plugin.
Definition: plugin.hpp:304
std::string getPluginVarList() const
Returns the current plugin's procedure argument list.
Definition: plugin.hpp:198
std::string getPackageVersion(unsigned int i=0) const
Returns the version number string of the ith plugin.
Definition: plugin.hpp:257
const std::vector< Package > & getPackages() const
Returns a const reference to the currently installed packages.
Definition: plugin.hpp:159
bool isPluginCmd(const std::string &sCmd) const
This member function determines, whether the passed command line contains a plugin command.
Definition: plugin.cpp:829
bool evalPluginCmd(std::string &sCmd)
This member function converts the call to a plugin in the passed command line into a call to the corr...
Definition: plugin.cpp:544
~PackageManager()
PluginManager destructor. Will close the internal file stream if it is still open.
Definition: plugin.cpp:442
std::string getPluginNames() const
Returns the names of the installed plugins.
Definition: plugin.hpp:171
std::string getPluginMenuEntry(unsigned int i=0) const
Returns the menu entry of the ith plugin.
Definition: plugin.hpp:320
void updatePluginFile()
This member function will update the plugin definition file with the internal plugin definitions.
Definition: plugin.cpp:472
std::string sPluginDefinitionFile
Definition: plugin.hpp:119
unsigned int getPackageCount() const
Returns the number of installed plugins.
Definition: plugin.hpp:146
std::string getPackageAuthor(unsigned int i=0) const
Returns the author of the ith plugin.
Definition: plugin.hpp:272
bool declareNewPackage(const std::string &sInstallInfoString)
This member function declares a new plugin from the passed install information string.
Definition: plugin.cpp:664
PackageManager & operator=(const PackageManager &_manager)
This is the overload for the assignment operator.
Definition: plugin.cpp:457
std::map< std::string, std::string > getMenuMap() const
Returns the menu map connecting menu entry names with their corresponding procedure,...
Definition: plugin.cpp:892
std::string sPluginVarList
Definition: plugin.hpp:122
std::string getPluginCommand(unsigned int i=0) const
Returns the plugin command of the ith plugin.
Definition: plugin.hpp:209
void assign(const PackageManager &_manager)
This private member function handles the actual copy process.
Definition: plugin.cpp:432