declaration_helper_macros.h
Go to the documentation of this file.
1 #ifndef art_Framework_Services_Registry_detail_declaration_helper_macros_h
2 #define art_Framework_Services_Registry_detail_declaration_helper_macros_h
3 // vim: set sw=2 expandtab :
4 
14 
15 #include <memory>
16 
17 ////////////////////////////////////////////////////////////////////////
18 // Utility for including the service type in a static_assert
19 #define ART_DETAIL_STRINGIZED_VALUE(value) #value
20 #define ART_DETAIL_STRINGIZED_TYPE(svc) ART_DETAIL_STRINGIZED_VALUE(svc)
21 
22 #define DEFINE_ART_SERVICE_MAKER(svc, scopeArg) \
23  std::unique_ptr<ServiceWrapperBase> make(fhicl::ParameterSet const& pset, \
24  ActivityRegistry& reg, \
25  detail::SharedResources& resources) \
26  const final override \
27  { \
28  if constexpr (is_shared(ServiceScope::scopeArg) && \
29  detail::handle_allowed_v<svc>) { \
30  resources.registerSharedResource(SharedResource<svc>); \
31  } else if constexpr (is_legacy(ServiceScope::scopeArg)) { \
32  ensure_only_one_thread(pset); \
33  } \
34  return std::make_unique<ServiceWrapper<svc>>(pset, reg); \
35  }
36 
37 // CreateHelper.
38 #define DEFINE_ART_SERVICE_HELPER_CREATE(svc) \
39  static std::unique_ptr<ServiceHelperBase> createHelper() \
40  { \
41  return std::make_unique<ServiceHelper<svc>>(); \
42  }
43 
44 // Declare a service with scope.
45 #define ART_DETAIL_DECLARE_SERVICE(svc, scopeArg) \
46  namespace art::detail { \
47  template <> \
48  struct ServiceHelper<svc> : public ServiceImplHelper, \
49  public ServiceLGMHelper, \
50  public ServiceLGRHelper { \
51  DEFINE_ART_SERVICE_TYPEID(svc) \
52  DEFINE_ART_SERVICE_SCOPE(scopeArg) \
53  DEFINE_ART_SERVICE_RETRIEVER(svc) \
54  DEFINE_ART_SERVICE_MAKER(svc, scopeArg) \
55  bool \
56  is_interface_impl() const override \
57  { \
58  return false; \
59  } \
60  }; \
61  }
62 
63 // Declare an interface for a service with scope.
64 #define ART_DETAIL_DECLARE_SERVICE_INTERFACE(iface, scopeArg) \
65  namespace art::detail { \
66  template <> \
67  struct ServiceHelper<iface> : public ServiceInterfaceHelper, \
68  public ServiceLGRHelper { \
69  DEFINE_ART_SERVICE_TYPEID(iface) \
70  DEFINE_ART_SERVICE_SCOPE(scopeArg) \
71  DEFINE_ART_SERVICE_RETRIEVER(iface) \
72  }; \
73  }
74 
75 // Define a service with scope implementing an interface.
76 #define ART_DETAIL_DECLARE_SERVICE_INTERFACE_IMPL(svc, iface, scopeArg) \
77  namespace art::detail { \
78  template <> \
79  struct ServiceHelper<svc> : public ServiceInterfaceImplHelper, \
80  public ServiceLGMHelper, \
81  public ServiceLGRHelper { \
82  DEFINE_ART_SERVICE_TYPEID(svc) \
83  DEFINE_ART_SERVICE_SCOPE(scopeArg) \
84  DEFINE_ART_SERVICE_RETRIEVER(svc) \
85  DEFINE_ART_SERVICE_MAKER(svc, scopeArg) \
86  art::TypeID \
87  get_interface_typeid() const final override \
88  { \
89  return TypeID{typeid(iface)}; \
90  } \
91  std::unique_ptr<ServiceWrapperBase> \
92  convert( \
93  std::shared_ptr<ServiceWrapperBase> const& swb) const final override \
94  { \
95  return std::dynamic_pointer_cast<ServiceWrapper<svc>>(swb) \
96  ->getAs<iface>(); \
97  } \
98  static_assert(is_shared(ServiceHelper<iface>::scope_val) || \
99  is_legacy(ServiceHelper<svc>::scope_val), \
100  "\n\nart error: An implementation that inherits from a " \
101  "LEGACY interface\n" \
102  " must be a LEGACY service\n\n"); \
103  }; \
104  }
105 
106 #endif /* art_Framework_Services_Registry_detail_declaration_helper_macros_h */
107 
108 // Local Variables:
109 // mode: c++
110 // End: