Tulip  4.4.0
Better Visualization Through Research
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Groups Pages
Plugin.h
1 /*
2  *
3  * This file is part of Tulip (www.tulip-software.org)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux 1 and Inria Bordeaux - Sud Ouest
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  */
19 
20 #ifndef TULIP_PLUGIN_H
21 #define TULIP_PLUGIN_H
22 
23 #include <string>
24 
25 #include <tulip/WithParameter.h>
26 #include <tulip/WithDependency.h>
27 #include <tulip/PluginContext.h>
28 #include <tulip/TulipRelease.h>
29 
30 #ifdef __EMSCRIPTEN__
31 
32 #ifdef major
33 #undef major
34 #endif
35 
36 #ifdef minor
37 #undef minor
38 #endif
39 
40 #endif
41 
42 namespace tlp {
43 
44 /**
45  * @ingroup Plugins
46  * @brief Splits the string and returns everything befor the first dot ('.').
47  * This is used to return major version number, as version numbers are formatted as X.Y.Z,
48  * X being the major, Y the minor, and Z the patch version.
49  *
50  * @return string The part of the string before the first dot.
51  */
52 TLP_SCOPE std::string getMajor(const std::string &release);
53 
54 /**
55  * @ingroup Plugins
56  * @brief Splits the string and return the minor version.
57  * If the string does not contain any dot, then 0 is returned.
58  * If the string contains only one dot (X.Y), then everything after the first dot is returned (Y).
59  * If the string is a full version with two dots (X.Y.Z), everything between the first and last dots is returned (Y).
60  * If there are more than two dots, everything between the first and last dots is returned.
61  */
62 TLP_SCOPE std::string getMinor(const std::string &release);
63 
64 /**
65  * @ingroup Plugins
66  * @brief Top-level interface for plug-ins.
67  *
68  * This class holds meta-information about a plug-in (group/author/version...). It stands as a unique base-class for every plugin type.
69  * This interface is not intended to be directly sublassed. Plugin objects are mainly used internally into the plugin lister system.
70  *
71  * This classe also holds extra information about the Tulip system such as the library version the plugin was built against.
72  * Plugin creation is handled by factories generated by the PLUGIN macro and the default Plugin constructor should never be called as is.
73  *
74  * @see tlp::FactoryInterface for more advanced operation such as plugin creation and retrieving dependencies.
75  * @see tlp::PluginContext and its subclasses for parameters handling.
76  *
77  * @see tlp::Algorithm for plugins operating on the tlp::Graph structure.
78  * @see tlp::TemplateAlgorithm and its subclasses for plugins operating on graph properties
79  * @see tlp::View for panel plugins
80  * @see tlp::Interactor for plugins responisble for user interactions.
81  * @see tlp::Perspective for plugins handling the main GUI
82  */
83 class TLP_SCOPE Plugin : public tlp::WithParameter, public tlp::WithDependency {
84 public:
85  virtual ~Plugin() {}
86 
87  /**
88  @brief The icon (preferably a thumbnail) of the plugin
89  @return std::string the icon path
90  */
91  virtual std::string icon() const;
92 
93  /**
94  @brief A string identifier for a plugin used for categorization purposes.
95  @returns std::string the category of the plugin.
96  */
97  virtual std::string category() const=0;
98 
99  /**
100  * @brief Returns the name of the plug-in, as registered in the Tulip plug-in system.
101  * This name must be unique, and if multiple plug-ins have the same name,
102  * only the latest encountered will be considered.
103  * @return string the name of the plug-in.
104  */
105  virtual std::string name() const=0;
106 
107  /**
108  * @brief Returns the name of the group this plug-in belongs to.
109  * Groups and sub-groups are separated by two colons.
110  * e.g. trees::planar trees
111  * @return the group name of this plug-in.
112  */
113  virtual std::string group() const=0;
114 
115  /**
116  * @brief The name of the author of this plug-in.
117  * @return the name of the author.
118  */
119  virtual std::string author() const=0;
120 
121  /**
122  * @brief The creation date of the plug-in.
123  * This date is in a free format, but most Tulip plug-ins use a DD/MM/YYYY
124  * @return the creation date.
125  */
126  virtual std::string date() const=0;
127 
128  /**
129  * @brief Information about the plug-in, from the plug-in author.
130  * This information can contains anything, and the developer is completely free to put anything here.
131  * Most plug-ins by the Tulip team use an html format to generate help from these information.
132  * @return string The information associated with this plug-in.
133  */
134  virtual std::string info() const=0;
135 
136  /**
137  * @brief The release version of the plug-in, including major and minor.
138  * The version should be X.Y, X being the major, and Y the minor.
139  * @return string The release version.
140  */
141  virtual std::string release() const=0;
142 
143  /**
144  * @brief The version of Tulip this plug-in was built with.
145  * Tulip versions are X.Y.Z, X eing the major, Y the minor, and Z the patch.
146  *
147  * @return The Tulip version the plug-in was built with.
148  */
149  virtual std::string tulipRelease() const=0;
150 
151  /**
152  * @brief Only the major of the plug-in version.
153  * A version should be X.Y, X being the major.
154  *
155  * @return The major part of the plug-in version.
156  */
157  virtual std::string major() const;
158 
159  /**
160  * @brief Only the minor of the plug-in version.
161  * A version should be X.Y, Y being the major.
162  *
163  * @return The minor part of the plug-in version.
164  */
165  virtual std::string minor() const;
166 
167  /**
168  * @return The major Tulip version the plug-in was built with.
169  */
170  virtual std::string tulipMajor() const;
171 
172  /**
173  * @return Return the minor Tulip version this plug-in was built with.
174  */
175  virtual std::string tulipMinor() const;
176 
177  /**
178  * @brief Returns the ID of the glyph this factory builds.
179  * @TODO this member should be removed once there is a system in Tulip to handle glyphs.
180  *
181  * @return int the id of the glyph.
182  **/
183  virtual int id() const;
184 
185  virtual std::string programmingLanguage() const;
186 
187 };
188 
189 /**
190  * @ingroup Plugins
191  * @def PLUGININFORMATION(NAME, AUTHOR, DATE, INFO, RELEASE, GROUP)
192  * @brief Declare meta-information for a plugin
193  * This is an helper macro that defines every function related to a plugin meta-information (Plugin name, author, etc).
194  * When creating a new plugin, this macro avoids having to define pure-virtual methods located into the Plugin interface and put them on the same line.
195  * @note PLUGINIFORMATION should be declared into the Plugin's class body into the public scope
196  *
197  * @param NAME The plugin name as it will be registered into the plugins system (tlp::Plugin::name())
198  * @param AUTHOR The author of the plugin (tlp::Plugin::author())
199  * @param DATE The creation date (tlp::Plugin::date())
200  * @param INFO The plugin's description (tlp::Plugin::info())
201  * @param RELEASE The plugin's version number (tlp::Plugin::version())
202  * @param GROUP The plugin's group (tlp::Plugin::group()). If the plugin does not belong to any group, set GROUP to "".
203  *
204  * @see tlp::Plugin
205  * @see PLUGIN
206  */
207 #define PLUGININFORMATION(NAME, AUTHOR, DATE, INFO, RELEASE, GROUP)\
208 std::string name() const { return NAME; } \
209 std::string author() const { return AUTHOR; }\
210 std::string date() const { return DATE; } \
211 std::string info() const { return INFO; } \
212 std::string release() const { return RELEASE; }\
213 std::string tulipRelease() const { return TULIP_MM_RELEASE; }\
214 std::string group() const { return GROUP; }
215 
216 #define PLUGININFORMATIONS(NAME, AUTHOR, DATE, INFO, RELEASE, GROUP)\
217 PLUGININFORMATION(NAME, AUTHOR, DATE, INFO, RELEASE, GROUP)
218 }
219 
220 //This include is here because the PluginLister needs to know the Plugin type, and the PLUGIN macro needs to know the PluginLister.
221 #include <tulip/PluginLister.h>
222 namespace tlp {
223 /**
224  * @ingroup Plugins
225  * @def PLUGIN(C)
226  * @brief Register a plugin into the plugin system.
227  * This macro is mandatory in order to register a plugin into Tulip. This will generate a Factory that will handle the plugin's creation.
228  * @param C The classname of the plugin.
229  * @note This macro should be called outside of the class body @endnote
230  *
231 @code{.cpp}
232 // This sample shows a basic skeleton for a plugin class declaration:
233 class MyPlugin: public tlp::PluginBase { // tlp::PluginBase is replaced by the acutal Plugin interface (tlp::Algorithm, tlp::View, etc)
234  public:
235  PLUGININFORMATION("My plugin", "Me", "28/09/2012", "My first plugin example", "1.0", "")
236  // Class declaration and extra methods
237 };
238 
239 PLUGIN(MyPlugin) // Register MyPlugin into Tulip
240 @endcode
241  *
242  * @see tlp::Plugin
243  * @see PLUGININFORMATION
244  */
245 #define PLUGIN(C) \
246 class C##Factory : public tlp::FactoryInterface { \
247 public: \
248  C##Factory() { \
249  tlp::PluginLister::registerPlugin(this); \
250 } \
251 ~C##Factory(){} \
252 tlp::Plugin* createPluginObject(tlp::PluginContext* context) { \
253 C* tmp = new C(context); \
254 return tmp; \
255 } \
256 }; \
257 \
258 extern "C" { \
259 C##Factory C##FactoryInitializer; \
260 }
261 
262 
263 }
264 
265 #endif //TULIP_PLUGIN_H