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 namespace cet {
23  class BasicPluginFactory;
24 }
25 
27 public:
28  explicit BasicPluginFactory(
30  std::string const& suffix = "plugin",
31  std::string const& makerName = "makePlugin",
32  std::string const& pluginTypeFuncName = "pluginType");
33 
34  explicit BasicPluginFactory(
35  std::string const& suffix = "plugin",
36  std::string const& makerName = "makePlugin",
37  std::string const& pluginTypeFuncName = "pluginType");
38 
39  // Find and call the makePlugin() function in the plugin library.
40  template <typename RESULT_TYPE, typename... ARGS>
41  std::enable_if_t<!std::is_function_v<RESULT_TYPE>, RESULT_TYPE> makePlugin(
42  std::string const& libspec,
43  ARGS&&... args) const;
44 
45  template <typename FUNCTION_TYPE>
46  std::enable_if_t<std::is_function_v<FUNCTION_TYPE>,
47  std::function<FUNCTION_TYPE>>
48  makePlugin(std::string const& libspec) const;
49 
50  // Find and call the pluginType() function in the plugin library.
51  std::string pluginType(std::string const& libspec) const;
52 
53 private:
56 };
57 
58 inline std::string
60 {
61  return call<std::string>(libspec, pluginTypeFuncName_);
62 }
63 
64 template <typename RESULT_TYPE, typename... ARGS>
65 inline std::enable_if_t<!std::is_function_v<RESULT_TYPE>, RESULT_TYPE>
67  ARGS&&... args) const
68 {
69  return call<RESULT_TYPE>(libspec, makerName_, std::forward<ARGS>(args)...);
70 }
71 
72 template <typename FUNCTION_TYPE>
73 inline std::enable_if_t<std::is_function_v<FUNCTION_TYPE>,
74  std::function<FUNCTION_TYPE>>
76 {
77  return find<FUNCTION_TYPE>(libspec, makerName_);
78 }
79 
80 #endif /* cetlib_BasicPluginFactory_h */
81 
82 // Local Variables:
83 // mode: c++
84 // End:
std::string const pluginTypeFuncName_
std::enable_if_t<!std::is_function_v< RESULT_TYPE >, RESULT_TYPE > makePlugin(std::string const &libspec, ARGS &&...args) const
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
enum BeamMode string