BasicPluginFactory.h
Go to the documentation of this file.
1 #ifndef cetlib_BasicPluginFactory_h
2 #define cetlib_BasicPluginFactory_h
3 ////////////////////////////////////////////////////////////////////////
4 // BasicPluginFactory
5 //
6 // Refinement of PluginFactory for a common class of plugins featuring a
7 // "pluginType" function and a "makePlugin" function. The pluginType
8 // function must be compatible with the following signature:
9 //
10 // std::string ()
11 //
12 // For a useful class template / macro combination to formalize the
13 // pluginType, see cetlib/PluginTypeDeducer.h
14 //
15 // The make function is arbitrary in signature: the result type must be
16 // specified but the arguments (if any) may be deduced.
17 //
18 ////////////////////////////////////////////////////////////////////////
19 
20 #include "cetlib/PluginFactory.h"
21 
22 #include <string>
23 #include <type_traits>
24 
25 namespace cet {
26  class BasicPluginFactory;
27  class search_path;
28 }
29 
31 public:
32  explicit BasicPluginFactory(
34  std::string const& suffix = "plugin",
35  std::string const& makerName = "makePlugin",
36  std::string const& pluginTypeFuncName = "pluginType");
37 
38  explicit BasicPluginFactory(
39  std::string const& suffix = "plugin",
40  std::string const& makerName = "makePlugin",
41  std::string const& pluginTypeFuncName = "pluginType");
42 
43  // Find and call the makePlugin() function in the plugin library.
44  template <typename RESULT_TYPE, typename... ARGS>
45  std::enable_if_t<!std::is_function_v<RESULT_TYPE>, RESULT_TYPE> makePlugin(
46  std::string const& libspec,
47  ARGS&&... args) const;
48 
49  template <typename FUNCTION_TYPE>
50  std::enable_if_t<std::is_function_v<FUNCTION_TYPE>,
51  std::function<FUNCTION_TYPE>>
52  makePlugin(std::string const& libspec) const;
53 
54  // Find and call the pluginType() function in the plugin library.
55  std::string pluginType(std::string const& libspec) const;
56 
57 private:
60 };
61 
62 inline std::string
64 {
65  return call<std::string>(libspec, pluginTypeFuncName_);
66 }
67 
68 template <typename RESULT_TYPE, typename... ARGS>
69 inline std::enable_if_t<!std::is_function_v<RESULT_TYPE>, RESULT_TYPE>
71  ARGS&&... args) const
72 {
73  return call<RESULT_TYPE>(libspec, makerName_, std::forward<ARGS>(args)...);
74 }
75 
76 template <typename FUNCTION_TYPE>
77 inline std::enable_if_t<std::is_function_v<FUNCTION_TYPE>,
78  std::function<FUNCTION_TYPE>>
80 {
81  return find<FUNCTION_TYPE>(libspec, makerName_);
82 }
83 
84 #endif /* cetlib_BasicPluginFactory_h */
85 
86 // Local Variables:
87 // mode: c++
88 // End:
std::string const pluginTypeFuncName_
std::string string
Definition: nybbler.cc:12
std::enable_if_t<!std::is_function_v< RESULT_TYPE >, RESULT_TYPE > makePlugin(std::string const &libspec, ARGS &&...args) const
static QCString args
Definition: declinfo.cpp:674
std::string const makerName_
BasicPluginFactory(cet::search_path const &search_path, std::string const &suffix="plugin", std::string const &makerName="makePlugin", std::string const &pluginTypeFuncName="pluginType")
std::string pluginType(std::string const &libspec) const