Lunchbox  1.15.0
Multi-threaded C++ toolbox library for all application developers creating high-performance multi-threaded programs.
pluginFactory.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_PLUGINFACTORY_H
23 #define LUNCHBOX_PLUGINFACTORY_H
24 
25 #include <lunchbox/types.h>
26 #include <lunchbox/algorithm.h> // used inline
27 #include <lunchbox/debug.h> // LBTHROW
28 #include <lunchbox/dso.h> // used inline
29 #include <lunchbox/file.h> // searchDirectory() used inline
30 #include <servus/uri.h> // Default template type
31 
32 #include <unordered_map>
33 
34 namespace lunchbox
35 {
36 
55 template< class T > class PluginFactory
56 {
57 public:
58  typedef Plugin< T > PluginT;
59  typedef std::vector< PluginT > Plugins;
60 
62  static PluginFactory& getInstance();
63 
72  T* create( const typename T::InitDataT& initData );
73 
75  void register_( const PluginT& plugin );
76 
78  bool deregister( const PluginT& plugin );
79 
81  void deregisterAll();
82 
101  void load( const int version, const std::string& path,
102  const std::string& pattern );
103  void load( const int version, const Strings& paths,
104  const std::string& pattern );
106 
107 private:
108  PluginFactory() {}
109  PluginFactory( const PluginFactory& ) = delete;
110  PluginFactory( PluginFactory&& ) = delete;
111  PluginFactory& operator = ( const PluginFactory& ) = delete;
112  PluginFactory& operator = ( PluginFactory&& ) = delete;
113 
114 #pragma warning( disable: 4251 )
115  Plugins _plugins;
116  typedef std::unordered_map< DSO*, PluginT > PluginMap;
117  PluginMap _libraries;
118 #pragma warning( default: 4251 )
119 
120  ~PluginFactory();
121 };
122 
123 }
124 
125 #include "pluginFactory.ipp" // template implementation
126 
127 #endif // LUNCHBOX_PLUGINFACTORY_H
Basic type definitions not provided by the operating system.
void deregisterAll()
Unregister all plugin types.
std::vector< std::string > Strings
A vector of std::strings.
Definition: types.h:215
Factory for Plugin classes.
Definition: pluginFactory.h:55
T * create(const typename T::InitDataT &initData)
Create a plugin instance.
void register_(const PluginT &plugin)
Register a plugin type.
void load(const int version, const std::string &path, const std::string &pattern)
Load all compatible plugin libraries from a directory matching a pattern.
Abstraction layer and common utilities for multi-threaded programming.
Definition: algorithm.h:32
Manages a class deriving from a T interface.
Definition: plugin.h:47
static PluginFactory & getInstance()
Get the single class instance.
bool deregister(const PluginT &plugin)
Deregister a plugin type.