Lunchbox  1.12.0
Multi-threaded C++ toolbox library for all application developers creating high-performance multi-threaded programs.
plugin.h
1 
2 /* Copyright (c) 2013-2015, 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_PLUGIN_H
23 #define LUNCHBOX_PLUGIN_H
24 
25 #include <servus/uint128_t.h> // member
26 #include <boost/function.hpp> // Plugin functions
27 #include <boost/function_equal.hpp> // operator ==
28 
29 namespace lunchbox
30 {
47 template< class PluginT, class InitDataT = servus::URI > class Plugin
48 {
49 public:
54  typedef boost::function< PluginT* ( const InitDataT& ) > Constructor;
55 
60  typedef boost::function< bool ( const InitDataT& ) > HandlesFunc;
61 
69  Plugin( const Constructor& constructor_, const HandlesFunc& handles_ )
70  : constructor( constructor_ ), handles( handles_ )
71  , tag( servus::make_UUID( )) {}
72 
74  bool operator == ( const Plugin& rhs ) const
75  { return tag == rhs.tag; }
76 
78  bool operator != ( const Plugin& rhs ) const { return !(*this == rhs); }
79 
80 private:
81  friend class PluginFactory< PluginT, InitDataT >;
82  Constructor constructor;
83  HandlesFunc handles;
84 
85  // Makes Plugin comparable. See http://stackoverflow.com/questions/18665515
86  servus::uint128_t tag;
87 };
88 
89 }
90 
91 #endif
boost::function< bool(const InitDataT &) > HandlesFunc
The method to check if the plugin can handle a given initData.
Definition: plugin.h:60
Factory for Plugin classes.
Definition: pluginFactory.h:59
boost::function< PluginT *(const InitDataT &) > Constructor
The constructor method / concrete factory for Plugin objects.
Definition: plugin.h:54
Abstraction layer and common utilities for multi-threaded programming.
Definition: algorithm.h:32
Manages a class deriving from a PluginT interface.
Definition: plugin.h:47
bool operator!=(const Plugin &rhs) const
Definition: plugin.h:78
bool operator==(const Plugin &rhs) const
Definition: plugin.h:74
Plugin(const Constructor &constructor_, const HandlesFunc &handles_)
Construct a new Plugin.
Definition: plugin.h:69