LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
ServiceHelper.h
Go to the documentation of this file.
1 #ifndef art_Framework_Services_Registry_detail_ServiceHelper_h
2 #define art_Framework_Services_Registry_detail_ServiceHelper_h
3 // vim: set sw=2 expandtab :
4 
5 //
6 // The ServiceHelper class and associated interface classes to simplify
7 // the service cache in the face of pre-made services,
8 // and services implementing interfaces.
9 //
10 // LG = Legacy/Global M = make R = retrieve
11 //
12 
16 #include "fhiclcpp/fwd.h"
17 
18 #include <memory>
19 
20 namespace art {
21 
22  class ActivityRegistry;
23 
24  namespace detail {
25  class SharedResources;
26  struct ServiceHelperBase;
27  struct ServiceImplHelper;
28  struct ServiceInterfaceImplHelper;
29  struct ServiceInterfaceHelper;
30  struct ServiceLGMHelper;
31  struct ServiceLGRHelper;
32  template <typename SERVICE>
33  struct ServiceHelper;
34 
35  // Base class. Note virtual inheritance below.
37  virtual ~ServiceHelperBase() noexcept = default;
38  virtual TypeID get_typeid() const = 0;
39  virtual ServiceScope scope() const = 0;
40  virtual bool is_interface() const = 0;
41  virtual bool is_interface_impl() const = 0;
42  };
43 
44  // For a "real" service (not an interface).
45  struct ServiceImplHelper : public virtual ServiceHelperBase {
46  bool
47  is_interface() const override
48  {
49  return false;
50  }
51  };
52 
53  // For a service implementing an interface.
55  bool
56  is_interface_impl() const final override
57  {
58  return true;
59  }
60  virtual TypeID get_interface_typeid() const = 0;
61  virtual std::unique_ptr<ServiceWrapperBase> convert(
62  std::shared_ptr<ServiceWrapperBase> const& swb) const = 0;
63  };
64 
65  // For the service interface itself.
66  struct ServiceInterfaceHelper : public virtual ServiceHelperBase {
67  bool
68  is_interface() const final override
69  {
70  return true;
71  }
72  bool
73  is_interface_impl() const final override
74  {
75  return false;
76  }
77  };
78 
79  // LegacyOrGlobalMaker
80  // For a global or legacy service
82  virtual ~ServiceLGMHelper() noexcept = default;
83  virtual std::unique_ptr<ServiceWrapperBase> make(
84  fhicl::ParameterSet const& cfg,
85  ActivityRegistry& reg,
86  detail::SharedResources& resources) const = 0;
87  };
88 
89  // LegacyOrGlobalRetriever
91  virtual ~ServiceLGRHelper() noexcept = default;
92  virtual void* retrieve(
93  std::shared_ptr<ServiceWrapperBase>& swb) const = 0;
94  };
95 
96  } // namespace detail
97 } // namespace art
98 
99 #endif /* art_Framework_Services_Registry_detail_ServiceHelper_h */
100 
101 // Local Variables:
102 // mode: c++
103 // End:
virtual bool is_interface() const =0
ServiceScope
Definition: ServiceScope.h:7
std::unique_ptr< InputSource > make(fhicl::ParameterSet const &conf, InputSourceDescription &desc)
virtual ~ServiceHelperBase() noexcept=default
virtual ServiceScope scope() const =0
bool is_interface() const override
Definition: ServiceHelper.h:47
virtual bool is_interface_impl() const =0
bool is_interface_impl() const final override
Definition: ServiceHelper.h:73
bool is_interface() const final override
Definition: ServiceHelper.h:68
bool is_interface_impl() const final override
Definition: ServiceHelper.h:56
Definition: MVAAlg.h:12
virtual TypeID get_typeid() const =0