Falaise  4.0.1
SuperNEMO Software Toolkit
service_traits.h
Go to the documentation of this file.
1 //! \file service_traits.h
2 //! \brief Types for defining service class traits
3 #ifndef SERVICE_TRAITS_HH
4 #define SERVICE_TRAITS_HH
5 
6 #include "boost/metaparse/string.hpp"
7 #include "boost/mpl/string.hpp"
8 
9 namespace snemo {
10 
11 //! Template struct for defining trait types and functions for a service
12 /*!
13  * No default implementation is replied, so all service classes must fully
14  * specialize `service_traits` as follows:
15  *
16  * ```cpp
17  * template <>
18  * struct service_traits<MyService> {
19  * // `label_type` is a compile time string, and should be equivalent to the
20  * // service's typename, including any namespace
21  * using label_type = BOOST_METAPARSE_STRING("MyService");
22  *
23  * // `service_type` is the type to be extracted from @ref datatools::service_manager
24  * // It is usually *not* the same as the instance type
25  * using service_type = AServiceType;
26  *
27  * // `instance_type` is the actual interface type that clients will use via
28  * // @ref falaise::service_handle
29  * using instance_type = MyService;
30  *
31  * // `get` is a static function taking a reference to the service_type
32  * // and returning a pointer to the served instance_type.
33  * // In most cases, it calls a member function on the service_type instance
34  * static instance_type* get(service_type& s) {
35  * // get_served returns a ptr to MyService...
36  * return s.get_served();
37  * }
38  * };
39  * ```
40  *
41  * \sa snemo::service_handle
42  */
43 template <typename T>
45 
46 //! Convenience type alias for extracting the label of a service
47 /*!
48  * ```cpp
49  * // get label for "Service" in string form
50  * std::string label = falaise::service_label<Service>::value;
51  * ```
52  *
53  */
54 template <typename T>
55 using service_label = typename boost::mpl::c_str<typename service_traits<T>::label_type>::type;
56 
57 } // namespace snemo
58 
59 #endif // SERVICE_TRAITS_HH
Template struct for defining trait types and functions for a service.
Definition: service_traits.h:44
typename boost::mpl::c_str< typename service_traits< T >::label_type >::type service_label
Convenience type alias for extracting the label of a service.
Definition: service_traits.h:55
Definition: calo_tapered_scin_box_model.h:54