LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
tool_type.h
Go to the documentation of this file.
1 #ifndef art_Utilities_detail_tool_type_h
2 #define art_Utilities_detail_tool_type_h
3 
5 #include "cetlib/BasicPluginFactory.h"
6 
7 #include <functional>
8 #include <memory>
9 #include <string>
10 #include <type_traits>
11 
12 namespace fhicl {
13  class ParameterSet;
14 }
15 
16 namespace art::detail {
17 
18  template <typename T, typename = void>
19  struct tool_type;
20 
21  template <typename T>
22  struct tool_type<T, std::enable_if_t<std::is_class<T>::value>> {
23  using return_type = std::unique_ptr<T>;
24 
25  static auto
26  make_plugin(cet::BasicPluginFactory& factory,
27  std::string const& libspec,
28  fhicl::ParameterSet const& pset)
29  {
30  return factory.makePlugin<std::unique_ptr<T>>(libspec, pset);
31  }
32  };
33 
34  template <typename T>
35  struct tool_type<T, std::enable_if_t<std::is_function<T>::value>> {
36  using return_type = std::function<T>;
37 
38  static auto
39  make_plugin(cet::BasicPluginFactory& factory,
40  std::string const& libspec,
41  fhicl::ParameterSet const&,
42  std::string const& function_plugin_type)
43  {
44  auto const pluginType = factory.pluginType(libspec);
45  return pluginType == function_plugin_type ?
46  factory.makePlugin<T>(libspec) :
48  "tool_type::make_plugin: ")
49  << "Unrecognized function-tool type \"" << function_plugin_type
50  << "\" for plugin \"" << libspec << "\".\n"
51  << "Allowed function-tool type for above plugin is: \""
52  << pluginType << "\".\n";
53  }
54  };
55 
56 } // namespace art::detail
57 
58 #endif /* art_Utilities_detail_tool_type_h */
59 
60 // Local variables:
61 // mode: c++
62 // End:
STL namespace.
parameter set interface
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
static auto make_plugin(cet::BasicPluginFactory &factory, std::string const &libspec, fhicl::ParameterSet const &, std::string const &function_plugin_type)
Definition: tool_type.h:39
static auto make_plugin(cet::BasicPluginFactory &factory, std::string const &libspec, fhicl::ParameterSet const &pset)
Definition: tool_type.h:26