service_helper_macros.h
Go to the documentation of this file.
1 #ifndef art_Framework_Services_Registry_detail_service_helper_macros_h
2 #define art_Framework_Services_Registry_detail_service_helper_macros_h
3 // vim: set sw=2 expandtab :
4 
9 
10 #include <memory>
11 
12 ////////////////////////////////////////////////////////////////////////
13 // Utility for including the service type in a static_assert
14 #define ART_DETAIL_STRINGIZED_VALUE(value) #value
15 #define ART_DETAIL_STRINGIZED_TYPE(svc) ART_DETAIL_STRINGIZED_VALUE(svc)
16 
17 // Define a member function returning the typeid of the service.
18 #define DEFINE_ART_SERVICE_TYPEID(svc) \
19  art::TypeID get_typeid() const override { return TypeID{typeid(svc)}; }
20 
21 // Define a member function to return the scope of the service, and a
22 // static to provide compile-time help when we have the concrete helper
23 // class instead of a base.
24 #define DEFINE_ART_SERVICE_SCOPE(scopeArg) \
25  ServiceScope scope() const override { return scope_val; } \
26  static constexpr ServiceScope scope_val{ServiceScope::scopeArg};
27 
28 #define DEFINE_ART_SERVICE_RETRIEVER(svc) \
29  void* retrieve(std::shared_ptr<ServiceWrapperBase>& swb) \
30  const final override \
31  { \
32  return &std::dynamic_pointer_cast<ServiceWrapper<svc>>(swb)->get(); \
33  }
34 
35 #endif /* art_Framework_Services_Registry_detail_service_helper_macros_h */
36 
37 // Local Variables:
38 // mode: c++
39 // End: