LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
ScheduleID.h
Go to the documentation of this file.
1 #ifndef art_Utilities_ScheduleID_h
2 #define art_Utilities_ScheduleID_h
3 
4 // Entity for identification of schedules and items attached thereto.
5 
6 #include <cstdint>
7 #include <limits>
8 #include <stdexcept>
9 #include <type_traits>
10 
11 namespace art {
12  class ScheduleID;
13 
14  bool operator!=(ScheduleID left, ScheduleID right);
15  bool operator<=(ScheduleID left, ScheduleID right);
16  bool operator>(ScheduleID left, ScheduleID right);
17  bool operator>=(ScheduleID left, ScheduleID right);
18 }
19 
21 private:
22  using id_type = uint16_t; // Must be unsigned type.
24  "ScheduleID::id_type must be unsigned!");
25 
26 public:
27  using size_type = id_type;
28 
29  constexpr ScheduleID() = default; // (invalid).
30  explicit ScheduleID(id_type id);
31 
32  // Validity check.
33  constexpr bool isValid() const;
34 
35  // Value accessor (use should be rare).
36  constexpr id_type id() const;
37 
38  // Return the next scheduleID.
39  ScheduleID next() const;
40 
41  // First allowed and last allowed ScheduleIDs.
42  static ScheduleID first();
43  static ScheduleID last();
44 
45  // Comparison operators.
46  bool operator==(ScheduleID const& other) const;
47  bool operator<(ScheduleID const& other) const;
48 
49 private:
50  static constexpr id_type min_id_();
51  static constexpr id_type max_id_();
52  static constexpr id_type invalid_id_();
53 
55 };
56 
58  : id_{(id < min_id_() || id > max_id_()) ?
59  throw std::out_of_range("art::ScheduleID: Invalid initializer.") :
60  id}
61 {}
62 
63 inline constexpr bool
65 {
66  return !(id_ == invalid_id_());
67 }
68 
69 inline constexpr art::ScheduleID::id_type
71 {
72  return id_;
73 }
74 
75 inline art::ScheduleID
77 {
78  return ScheduleID(id_ + 1);
79 }
80 
81 inline art::ScheduleID
83 {
84  return ScheduleID{min_id_()};
85 }
86 
87 inline art::ScheduleID
89 {
90  return ScheduleID{max_id_()};
91 }
92 
93 inline bool
95 {
96  return id_ == other.id_;
97 }
98 
99 inline bool
101 {
102  return id_ < other.id_;
103 }
104 
105 inline constexpr art::ScheduleID::id_type
107 {
109 }
110 
111 inline constexpr art::ScheduleID::id_type
113 {
114  return invalid_id_() - 1;
115 }
116 
117 inline constexpr art::ScheduleID::id_type
119 {
121 }
122 
123 inline bool
125 {
126  return !(left == right);
127 }
128 
129 inline bool
131 {
132  return (left < right || left == right);
133 }
134 
135 inline bool
137 {
138  return !(left <= right);
139 }
140 
141 inline bool
143 {
144  return !(left < right);
145 }
146 
147 #endif /* art_Utilities_ScheduleID_h */
148 
149 // Local Variables:
150 // mode: c++
151 // End:
bool operator==(ScheduleID const &other) const
Definition: ScheduleID.h:94
bool operator<=(ScheduleID left, ScheduleID right)
Definition: ScheduleID.h:130
constexpr auto const & right(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:112
constexpr bool isValid() const
Definition: ScheduleID.h:64
bool operator<(ScheduleID const &other) const
Definition: ScheduleID.h:100
bool operator>=(ScheduleID left, ScheduleID right)
Definition: ScheduleID.h:142
constexpr id_type id() const
Definition: ScheduleID.h:70
static constexpr id_type invalid_id_()
Definition: ScheduleID.h:118
static ScheduleID first()
Definition: ScheduleID.h:82
bool operator!=(debugging_allocator< X > const &, debugging_allocator< Y > const &)
bool operator>(ScheduleID left, ScheduleID right)
Definition: ScheduleID.h:136
ScheduleID next() const
Definition: ScheduleID.h:76
Int_t max
Definition: plot.C:27
static constexpr id_type max_id_()
Definition: ScheduleID.h:112
constexpr ScheduleID()=default
uint16_t id_type
Definition: ScheduleID.h:22
constexpr auto const & left(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:104
std::string value(boost::any const &)
id_type size_type
Definition: ScheduleID.h:27
Int_t min
Definition: plot.C:26
HLT enums.
static constexpr id_type min_id_()
Definition: ScheduleID.h:106
static ScheduleID last()
Definition: ScheduleID.h:88