ScheduleID.h
Go to the documentation of this file.
1 #ifndef art_Utilities_ScheduleID_h
2 #define art_Utilities_ScheduleID_h
3 // vim: set sw=2 expandtab :
4 
5 // Entity for identification of schedules and items attached thereto.
6 
7 #include <cstdint>
8 #include <functional>
9 #include <iosfwd>
10 #include <limits>
11 #include <type_traits>
12 
13 namespace art {
14 
15  // A severely limited version of uint16_t intended as the index
16  // into a PerScheduleContainer.
17  class ScheduleID {
18  template <typename T>
19  friend class PerScheduleContainer;
20 
21  public: // Types
22  using id_type = uint16_t;
23  // Must be unsigned type, enforce this.
24  static_assert(std::is_unsigned_v<id_type>);
25  using size_type = id_type;
26 
27  private: // Types
28  enum class PremadeTypeFlag { First, Last };
29 
30  private: // Static API -- Implementation Details -- Constants
31  static constexpr id_type
32  invalid_id_() noexcept
33  {
35  }
36  static constexpr id_type
37  min_id_() noexcept
38  {
40  }
41  static constexpr id_type
42  max_id_() noexcept
43  {
44  return invalid_id_() - 1;
45  }
46 
47  public: // Static API for the user -- Constants
48  // First allowed and last allowed ScheduleIDs.
49  static constexpr ScheduleID
51  {
53  }
54  static constexpr ScheduleID
55  last()
56  {
58  }
59 
60  public: // Special Member Functions
61  constexpr ScheduleID() noexcept = default;
62  explicit ScheduleID(id_type id);
63  ScheduleID(ScheduleID const&) noexcept = default;
64  ScheduleID(ScheduleID&&) noexcept = default;
65  ScheduleID& operator=(ScheduleID const&) noexcept = default;
66  ScheduleID& operator=(ScheduleID&&) noexcept = default;
67 
68  public: // API for the user.
69  // Validity check.
70  constexpr bool
71  isValid() const noexcept
72  {
73  return !(id_ == invalid_id_());
74  }
75  // Value accessor (use should be rare).
76  constexpr id_type
77  id() const noexcept
78  {
79  return id_;
80  }
81  // Return the next scheduleID.
82  ScheduleID next() const;
83  // Comparison operators.
84  bool operator==(ScheduleID const& other) const noexcept;
85  bool operator<(ScheduleID const& other) const noexcept;
86 
87  private: // Implementation Details
88  constexpr ScheduleID(PremadeTypeFlag flag)
89  : id_{(flag == PremadeTypeFlag::First) ? min_id_() : max_id_()}
90  {}
91 
92  private: // Data Members
94  };
95 
96  bool operator!=(ScheduleID left, ScheduleID right) noexcept;
97  bool operator<=(ScheduleID left, ScheduleID right) noexcept;
98  bool operator>(ScheduleID left, ScheduleID right) noexcept;
99  bool operator>=(ScheduleID left, ScheduleID right) noexcept;
100  std::ostream& operator<<(std::ostream&, ScheduleID scheduleID);
101 
102 } // namespace art
103 
104 namespace std {
105  template <>
106  struct hash<art::ScheduleID> {
107  std::size_t
109  {
110  static hash<typename art::ScheduleID::id_type> hasher{};
111  return hasher(sid.id());
112  }
113  };
114 }
115 
116 #endif /* art_Utilities_ScheduleID_h */
117 
118 // Local Variables:
119 // mode: c++
120 // End:
constexpr auto const & right(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:102
bool operator>(ScheduleID const left, ScheduleID const right) noexcept
Definition: ScheduleID.cc:53
static constexpr ScheduleID first()
Definition: ScheduleID.h:50
STL namespace.
constexpr bool isValid() const noexcept
Definition: ScheduleID.h:71
bool operator!=(debugging_allocator< X > const &, debugging_allocator< Y > const &)
std::size_t operator()(art::ScheduleID sid) const
Definition: ScheduleID.h:108
ScheduleID & operator=(ScheduleID const &) noexcept=default
std::ostream & operator<<(std::ostream &os, const GroupSelector &gs)
bool operator<=(ScheduleID const left, ScheduleID const right) noexcept
Definition: ScheduleID.cc:47
static constexpr id_type invalid_id_() noexcept
Definition: ScheduleID.h:32
constexpr ScheduleID(PremadeTypeFlag flag)
Definition: ScheduleID.h:88
bool operator==(ScheduleID const &other) const noexcept
Definition: ScheduleID.cc:29
static int max(int a, int b)
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:94
constexpr id_type id() const noexcept
Definition: ScheduleID.h:77
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
id_type size_type
Definition: ScheduleID.h:25
constexpr ScheduleID() noexcept=default
static constexpr id_type max_id_() noexcept
Definition: ScheduleID.h:42
bool operator<(ScheduleID const &other) const noexcept
Definition: ScheduleID.cc:35
bool operator>=(ScheduleID const left, ScheduleID const right) noexcept
Definition: ScheduleID.cc:59
static constexpr id_type min_id_() noexcept
Definition: ScheduleID.h:37
static constexpr ScheduleID last()
Definition: ScheduleID.h:55
ScheduleID next() const
Definition: ScheduleID.cc:23