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 
17 #include <memory>
18 
19 namespace fhicl {
20  class ParameterSet;
21 }
22 
23 namespace art {
24 
25  class ActivityRegistry;
26 
27  namespace detail {
28 
29  struct ServiceHelperBase;
30  struct ServiceImplHelper;
31  struct ServiceInterfaceImplHelper;
32  struct ServiceInterfaceHelper;
33  struct ServiceLGMHelper;
34  struct ServiceLGRHelper;
35  template <typename SERVICE>
36  struct ServiceHelper;
37 
38  // Base class. Note virtual inheritance below.
40  virtual ~ServiceHelperBase() noexcept = default;
41  virtual TypeID get_typeid() const = 0;
42  virtual ServiceScope scope() const = 0;
43  virtual bool is_interface() const = 0;
44  virtual bool is_interface_impl() const = 0;
45  };
46 
47  // For a "real" service (not an interface).
48  struct ServiceImplHelper : public virtual ServiceHelperBase {
49  bool
50  is_interface() const override
51  {
52  return false;
53  }
54  };
55 
56  // For a service implementing an interface.
58  bool
59  is_interface_impl() const final override
60  {
61  return true;
62  }
63  virtual TypeID get_interface_typeid() const = 0;
64  virtual std::unique_ptr<ServiceWrapperBase> convert(
65  std::shared_ptr<ServiceWrapperBase> const& swb) const = 0;
66  };
67 
68  // For the service interface itself.
69  struct ServiceInterfaceHelper : public virtual ServiceHelperBase {
70  bool
71  is_interface() const final override
72  {
73  return true;
74  }
75  bool
76  is_interface_impl() const final override
77  {
78  return false;
79  }
80  };
81 
82  // LegacyOrGlobalMaker
83  // For a global or legacy service
85  virtual ~ServiceLGMHelper() noexcept = default;
86  virtual std::unique_ptr<ServiceWrapperBase> make(
87  fhicl::ParameterSet const& cfg,
88  ActivityRegistry& reg) const = 0;
89  };
90 
91  // LegacyOrGlobalRetriever
93  virtual ~ServiceLGRHelper() noexcept = default;
94  virtual void* retrieve(
95  std::shared_ptr<ServiceWrapperBase>& swb) const = 0;
96  };
97 
98  } // namespace detail
99 } // namespace art
100 
101 #endif /* art_Framework_Services_Registry_detail_ServiceHelper_h */
102 
103 // Local Variables:
104 // mode: c++
105 // End:
std::unique_ptr< InputSource > make(fhicl::ParameterSet const &, InputSourceDescription &)
ServiceScope
Definition: ServiceScope.h:7
void convert(std::string dir="cc_numu/C12")
Definition: convert.C:107
bool is_interface() const override
Definition: ServiceHelper.h:50
bool is_interface_impl() const final override
Definition: ServiceHelper.h:76
bool is_interface() const final override
Definition: ServiceHelper.h:71
bool is_interface_impl() const final override
Definition: ServiceHelper.h:59
Service to store calibration data products (CDP) in the SQLite3 metadatabase of a file...
Definition: FillParentInfo.h:8