Lunchbox  1.16.0
Multi-threaded C++ toolbox library for all application developers creating high-performance multi-threaded programs.
plugin.h
1 
2 /* Copyright (c) 2013-2016, 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 <functional>
26 #include <servus/uint128_t.h> // member
27 
28 namespace lunchbox
29 {
31 template <class T>
32 class Plugin
33 {
34 public:
36  using Constructor = std::function<T*(const typename T::InitDataT&)>;
37 
42  using HandlesFunc = std::function<bool(const typename T::InitDataT&)>;
43 
45  using DescriptionFunc = std::function<std::string()>;
46 
55  Plugin(const Constructor& constructor, const HandlesFunc& handles_,
56  const DescriptionFunc& description)
57  : _constructor(constructor)
58  , _handles(handles_)
59  , _description(description)
60  {
61  }
62 
64  T* construct(const typename T::InitDataT& data) const
65  {
66  return _constructor(data);
67  }
68 
70  bool handles(const typename T::InitDataT& data) const
71  {
72  return _handles(data);
73  }
74 
76  std::string getDescription() const { return _description(); }
77 private:
78  Constructor _constructor;
79  HandlesFunc _handles;
80  DescriptionFunc _description;
81 
82  bool operator==(const Plugin& rhs) const = delete;
83  bool operator!=(const Plugin& rhs) const = delete;
84 };
85 }
86 
87 #endif
T * construct(const typename T::InitDataT &data) const
Construct a new plugin instance.
Definition: plugin.h:64
std::function< std::string()> DescriptionFunc
The method to get the plugin&#39;s description.
Definition: plugin.h:45
Plugin(const Constructor &constructor, const HandlesFunc &handles_, const DescriptionFunc &description)
Construct a new Plugin.
Definition: plugin.h:55
std::function< T *(const typename T::InitDataT &)> Constructor
The constructor method for Plugin objects.
Definition: plugin.h:36
Abstraction layer and common utilities for multi-threaded programming.
Definition: algorithm.h:29
std::string getDescription() const
Definition: plugin.h:76
std::function< bool(const typename T::InitDataT &)> HandlesFunc
The method to check if the plugin can handle a given initData.
Definition: plugin.h:42
bool handles(const typename T::InitDataT &data) const
Definition: plugin.h:70