ServiceRegistry.h
Go to the documentation of this file.
1 #ifndef art_Framework_Services_Registry_ServiceRegistry_h
2 #define art_Framework_Services_Registry_ServiceRegistry_h
3 // vim: set sw=2 expandtab :
4 
8 #include "cetlib/exempt_ptr.h"
9 
10 namespace art {
11 
13  // Allow EventProcessor to set the manager. Also, allow a testing
14  // function to set it.
15  friend class ServicesManager;
16 
17  template <typename T, art::ServiceScope>
18  friend class ServiceHandle;
19 
20  public:
21  ~ServiceRegistry() noexcept;
23  ServiceRegistry(ServiceRegistry&&) = delete;
24  ServiceRegistry& operator=(ServiceRegistry const&) = delete;
25  ServiceRegistry& operator=(ServiceRegistry&&) = delete;
26 
27  template <typename T>
28  static bool
30  {
31  if (auto& mgr = instance().manager_) {
32  return mgr->isAvailable<T>();
33  }
34  throw Exception(errors::ServiceNotFound, "Service")
35  << " no ServiceRegistry has been set for this thread";
36  }
37 
38  private:
39  ServiceRegistry() noexcept;
40  static ServiceRegistry& instance() noexcept;
41 
43 
44  template <typename T>
45  T&
46  get() const
47  {
48  if (!manager_) {
49  throw Exception(errors::ServiceNotFound, "Service")
50  << " no ServiceRegistry has been set for this thread";
51  }
52  return manager_->get<T>();
53  }
54 
56  };
57 
58 } // namespace art
59 
60 #endif /* art_Framework_Services_Registry_ServiceRegistry_h */
61 
62 // Local Variables:
63 // mode: c++
64 // End:
static ServiceRegistry & instance() noexcept
ServiceRegistry() noexcept
void setManager(ServicesManager *)
cet::exempt_ptr< ServicesManager > manager_
static bool isAvailable()
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
~ServiceRegistry() noexcept