Level.h
Go to the documentation of this file.
1 #ifndef canvas_Utilities_Level_h
2 #define canvas_Utilities_Level_h
3 // vim: set sw=2 expandtab :
4 
5 #include <cassert>
6 #include <cstdint>
7 #include <ostream>
8 #include <type_traits>
9 
10 namespace art {
11 
12  // The outer-most level must be 0.
13  enum class Level {
14  Job = 0,
15  InputFile,
16  Run,
17  SubRun,
18  Event,
21  };
22 
23  // The following facility is to translate from the scoped enumerator
24  // to the value represented by the underlying type.
25  constexpr auto
26  underlying_value(Level const l) noexcept
27  {
28  return static_cast<std::underlying_type_t<Level>>(l);
29  }
30 
31  constexpr auto
32  highest_level() noexcept
33  {
34  return Level{0};
35  }
36 
37  constexpr auto
38  level_up(Level const l) noexcept
39  {
40  return Level{underlying_value(l) - 1};
41  }
42 
43  constexpr auto
45  {
47  }
48 
49  constexpr auto
50  level_down(Level const l) noexcept
51  {
52  return Level{underlying_value(l) + 1};
53  }
54 
55  constexpr bool
57  {
59  }
60 
61  constexpr bool
63  {
64  return l == most_deeply_nested_level();
65  }
66 
67  constexpr bool
68  is_highest_level(Level const l) noexcept
69  {
70  return l == highest_level();
71  }
72 
73  constexpr bool
74  is_level_contained_by(Level const l1, Level const l2) noexcept
75  {
76  return underlying_value(l1) > underlying_value(l2);
77  }
78 
79  inline std::ostream&
80  operator<<(std::ostream& os, Level const l)
81  {
82  switch (l) {
83  case Level::Job:
84  os << "Job";
85  break;
86  case Level::InputFile:
87  os << "InputFile";
88  break;
89  case Level::Run:
90  os << "Run";
91  break;
92  case Level::SubRun:
93  os << "SubRun";
94  break;
95  case Level::Event:
96  os << "Event";
97  break;
100  break;
102  os << "ReadyToAdvance";
103  break;
104  }
105  return os;
106  }
107 
108 } // namespace art
109 
110 #endif /* canvas_Utilities_Level_h */
111 
112 // Local variables:
113 // mode: c++
114 // End:
constexpr auto most_deeply_nested_level() noexcept
Definition: Level.h:44
constexpr auto underlying_value(Level const l) noexcept
Definition: Level.h:26
Level
Definition: Level.h:13
static QStrList * l
Definition: config.cpp:1044
std::ostream & operator<<(std::ostream &os, const GroupSelector &gs)
constexpr bool is_most_deeply_nested_level(Level const l) noexcept
Definition: Level.h:62
constexpr auto level_up(Level const l) noexcept
Definition: Level.h:38
constexpr bool is_above_most_deeply_nested_level(Level const l) noexcept
Definition: Level.h:56
constexpr bool is_level_contained_by(Level const l1, Level const l2) noexcept
Definition: Level.h:74
constexpr auto highest_level() noexcept
Definition: Level.h:32
constexpr bool is_highest_level(Level const l) noexcept
Definition: Level.h:68
constexpr auto level_down(Level const l) noexcept
Definition: Level.h:50