LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
ServiceProviderWrappers.h
Go to the documentation of this file.
1 
20 #ifndef LARCORE_COREUTILS_SERVICEPROVIDERWRAPPERS_H
21 #define LARCORE_COREUTILS_SERVICEPROVIDERWRAPPERS_H 1
22 
23 // LArSoft libraries
24 #include "larcore/CoreUtils/ServiceUtil.h" // lar::providerFrom() (for includers)
25 
26 // framework and support libraries
28 
29 // C/C++ standard libraries
30 #include <memory> // std::unique_ptr<>
31 
32 // forward declarations
33 namespace art {
34  class ActivityRegistry;
35 }
36 namespace fhicl {
37  class ParameterSet;
38 }
39 
40 namespace lar {
41 
88  template <class PROVIDER>
90 
91  public:
92  using provider_type = PROVIDER;
93 
96 
99  : prov(std::make_unique<provider_type>(config()))
100  {}
101 
103  provider_type const* provider() const { return prov.get(); }
104 
105  private:
106  std::unique_ptr<provider_type> prov;
107 
108  }; // SimpleServiceProviderWrapper<>
109 
125  template <class PROVIDER>
127 
128  public:
129  using provider_type = PROVIDER;
130 
132  virtual ~ServiceProviderInterfaceWrapper() = default;
133 
135  provider_type const* provider() const { return do_provider(); }
136 
137  protected:
139  virtual provider_type const* do_provider() const = 0;
140 
141  }; // ServiceProviderInterfaceWrapper<>
142 
223  template <typename PROVIDER, typename INTERFACE>
224  class ServiceProviderImplementationWrapper : public INTERFACE {
225 
226  public:
228  using concrete_provider_type = PROVIDER;
229 
231  using service_interface_type = INTERFACE;
232 
234  using provider_type = typename service_interface_type::provider_type;
235 
238 
241  : prov(std::make_unique<concrete_provider_type>(config()))
242  {}
243 
244  private:
245  std::unique_ptr<concrete_provider_type> prov;
246 
248  virtual provider_type const* do_provider() const override { return prov.get(); }
249 
250  }; // ServiceProviderImplementationWrapper
251 
252 } // namespace lar
253 
254 #endif // LARCORE_COREUTILS_SERVICEPROVIDERWRAPPERS_H
Utilities related to art service access.
PROVIDER concrete_provider_type
type of service provider implementation
STL namespace.
typename service_interface_type::provider_type provider_type
type of service provider interface
INTERFACE service_interface_type
art service interface class
SimpleServiceProviderWrapper(Parameters const &config, art::ActivityRegistry &)
Constructor (using a configuration table)
parameter set interface
PROVIDER provider_type
type of the service provider
virtual provider_type const * do_provider() const override
Returns a constant pointer to the service provider.
LArSoft-specific namespace.
provider_type const * provider() const
Returns a constant pointer to the service provider interface.
provider_type const * provider() const
Returns a constant pointer to the service provider.
std::unique_ptr< concrete_provider_type > prov
service provider
Definition: MVAAlg.h:12
std::unique_ptr< provider_type > prov
service provider
Service implementation returning a provider.
Service returning a provider interface.
Service returning a provider.
PROVIDER provider_type
type of the service provider
ServiceProviderImplementationWrapper(Parameters const &config, art::ActivityRegistry &)
Constructor (using a configuration table)