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