LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
PluginSuffixes.h
Go to the documentation of this file.
1 #ifndef art_Utilities_PluginSuffixes_h
2 #define art_Utilities_PluginSuffixes_h
3 
4 /*
5  'PluginSuffixes' is a static-member only class that contains all
6  supported plugins within art (proper).
7 
8  ===============
9  Developer notes
10  ===============
11 
12  This class was introduced to support the '--print-description' art
13  program option, which queries the list of supported plugin suffixes
14  for a given plugin spec as provided by the user. This way users can
15  type:
16 
17  art --print-description EmptyEvent TFileService IntProducer RPTest <MyTool>
18 
19  where
20 
21  EmptyEvent = source
22  TFileService = service
23  IntProducer = module
24  RPTest = plugin
25 
26  without having to tell the system what the expected type of each
27  specification is.
28 
29  Having a container that contains each of these plugin suffixes is
30  thus required. For type-safety reasons, the enum class
31  'suffix_type' is used as the map key.
32 
33  This class is an all-static member class. Wherever the
34  string-rendered suffix is required within art, it is desirable to do
35  something like 'Suffixes::module()'. This could be achieved,
36  clearly, by introducing a "Suffixes" namespace and just using free
37  functions. However, doing so would:
38 
39  1. Introduce potential confusion via a using directive, such as
40  'using namespace art::Suffixes'. A call to 'module()' could be
41  unclear to the developer.
42 
43  2. Require creating a free function that returns the full list of
44  allowed suffixes. Then for each
45 
46  'Suffixes::{module,service,source,plugin,tool,mfPlugin,mfStatsPlugin}()'
47 
48  free function call, the full-list function would be called each
49  time, which seems unnecessary.
50 */
51 
52 #include <ostream>
53 #include <string>
54 #include <type_traits>
55 #include <vector>
56 
57 namespace art {
58 
59  enum class suffix_type : std::size_t {
60  module,
61  plugin,
62  service,
63  source,
64  tool,
65  mfPlugin,
67  };
68 
69  inline std::ostream&
70  operator<<(std::ostream& os, suffix_type const st)
71  {
72  return os << static_cast<std::underlying_type_t<suffix_type>>(st);
73  }
74 
75  class Suffixes {
76  static constexpr auto
78  {
79  return static_cast<std::underlying_type_t<suffix_type>>(st);
80  }
81 
82  public:
83  static std::string const&
85  {
86  return suffixes_[index_for(suffix_type::module)];
87  }
88  static std::string const&
90  {
91  return suffixes_[index_for(suffix_type::plugin)];
92  }
93  static std::string const&
95  {
96  return suffixes_[index_for(suffix_type::service)];
97  }
98  static std::string const&
100  {
101  return suffixes_[index_for(suffix_type::source)];
102  }
103  static std::string const&
105  {
106  return suffixes_[index_for(suffix_type::tool)];
107  }
108  static std::string const&
110  {
111  return suffixes_[index_for(suffix_type::mfPlugin)];
112  }
113  static std::string const&
115  {
116  return suffixes_[index_for(suffix_type::mfStatsPlugin)];
117  }
118 
119  static std::string
121  {
122  std::string result;
123  for (auto const& suffix : suffixes_)
124  result += "\n '" + suffix + "'";
125  return result;
126  }
127 
128  static std::vector<std::string> const&
129  all()
130  {
131  return suffixes_;
132  }
133 
134  private:
135  static std::vector<std::string> const suffixes_;
136  };
137 
138 } // namespace art
139 
140 #endif /* art_Utilities_PluginSuffixes_h */
141 
142 // Local variables:
143 // mode: c++
144 // End:
static std::string const & mfStatsPlugin()
static std::vector< std::string > const & all()
static std::string print()
static std::string const & source()
static std::vector< std::string > const suffixes_
static constexpr auto index_for(suffix_type const st)
std::ostream & operator<<(std::ostream &os, const GroupSelector &gs)
static std::string const & plugin()
static std::string const & tool()
static std::string const & mfPlugin()
static std::string const & service()
Definition: MVAAlg.h:12
static std::string const & module()