Line data Source code
1 :
2 : /* Copyright (c) 2013-2017, EPFL/Blue Brain Project
3 : * Raphael Dumusc <raphael.dumusc@epfl.ch>
4 : * Stefan.Eilemann@epfl.ch
5 : *
6 : * This file is part of Lunchbox <https://github.com/Eyescale/Lunchbox>
7 : *
8 : * This library is free software; you can redistribute it and/or modify it under
9 : * the terms of the GNU Lesser General Public License version 2.1 as published
10 : * by the Free Software Foundation.
11 : *
12 : * This library is distributed in the hope that it will be useful, but WITHOUT
13 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 : * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
15 : * details.
16 : *
17 : * You should have received a copy of the GNU Lesser General Public License
18 : * along with this library; if not, write to the Free Software Foundation, Inc.,
19 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 : */
21 :
22 : #ifndef LUNCHBOX_PLUGINREGISTERER_H
23 : #define LUNCHBOX_PLUGINREGISTERER_H
24 :
25 : #include <lunchbox/plugin.h> // used inline
26 : #include <lunchbox/pluginFactory.h> // used inline
27 :
28 : #include <boost/functional/factory.hpp>
29 : #include <functional>
30 :
31 : namespace lunchbox
32 : {
33 : /**
34 : * Helper class to statically register derived plugin classes.
35 : *
36 : * The following code can be placed in a plugin's cpp file:
37 : * @code
38 : * namespace
39 : * {
40 : * PluginRegisterer< MyPlugin > registerer;
41 : * }
42 : * @endcode
43 : *
44 : * The plugin needs to conform to the following API:
45 : * @code
46 : * class MyPluginInterface
47 : * {
48 : * public:
49 : * typedef MyPluginInterface InterfaceT;
50 : * typedef MyPluginInitData InitDataT;
51 : * };
52 : *
53 : * class MyPlugin : public MyPluginInterface
54 : * {
55 : * public:
56 : * MyPlugin( const InitDataT& data );
57 : * static bool handles( const InitDataT& data );
58 : * static std::string getDescription();
59 : * };
60 : * @endcode
61 : *
62 : * @version 1.11.0
63 : */
64 :
65 : template <typename T>
66 : class PluginRegisterer
67 : {
68 : public:
69 : /** Construct and register the Plugin< T > class. @version 1.11.0 */
70 4 : PluginRegisterer()
71 : {
72 4 : PluginFactory<typename T::InterfaceT>::getInstance().register_(
73 : {std::bind(boost::factory<T*>(), std::placeholders::_1),
74 : std::bind(&T::handles, std::placeholders::_1),
75 : std::bind(&T::getDescription)});
76 4 : }
77 : };
78 : }
79 :
80 : #endif
|