ReservationId.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3  *
4  * Squid software is distributed under GPLv2+ license and includes
5  * contributions from numerous individuals and organizations.
6  * Please see the COPYING and CONTRIBUTORS files for details.
7  */
8 
9 #ifndef SQUID_SRC_HELPER_RESERVATIONID_H
10 #define SQUID_SRC_HELPER_RESERVATIONID_H
11 
12 #include <ostream>
13 
14 namespace Helper
15 {
18 {
19 public:
20  static ReservationId Next();
21 
22  bool reserved() const { return id > 0; }
23 
24  explicit operator bool() const { return reserved(); }
25  bool operator !() const { return !reserved(); }
26  bool operator ==(const Helper::ReservationId &other) const { return id == other.id; }
27  bool operator !=(const Helper::ReservationId &other) const { return !(*this == other); }
28 
29  void clear() { id = 0; }
30  uint64_t value() const {return id;}
31 
33  std::ostream &print(std::ostream &os) const;
34 
35 private:
36  uint64_t id = 0;
37 };
38 
39 inline std::ostream &
40 operator <<(std::ostream &os, const ReservationId &id)
41 {
42  return id.print(os);
43 }
44 
45 }; // namespace Helper
46 
47 namespace std {
49 template <>
50 struct hash<Helper::ReservationId>
51 {
54  result_type operator()(const argument_type &reservation) const noexcept
55  {
56  std::hash<uint64_t> aHash;
57  return aHash(reservation.value());
58  }
59 };
60 }
61 
62 #endif /* SQUID_SRC_HELPER_RESERVATIONID_H */
63 
bool reserved() const
Definition: ReservationId.h:22
bool operator==(const Helper::ReservationId &other) const
Definition: ReservationId.h:26
std::ostream & operator<<(std::ostream &, const Reply &)
Definition: Reply.cc:255
uint64_t value() const
Definition: ReservationId.h:30
uint64_t id
uniquely identifies this reservation
Definition: ReservationId.h:36
Helper::ReservationId argument_type
Definition: ReservationId.h:52
int const char size_t
Definition: stub_liblog.cc:83
result_type operator()(const argument_type &reservation) const noexcept
Definition: ReservationId.h:54
static ReservationId Next()
a (temporary) lock on a (stateful) helper channel
Definition: ReservationId.h:17
helper protocol primitives
Definition: ChildConfig.h:12
static hash_table * hash
Definition: text_backend.cc:41
bool operator!=(const Helper::ReservationId &other) const
Definition: ReservationId.h:27
std::ostream & print(std::ostream &os) const
dumps the reservation info for debugging
bool operator!() const
Definition: ReservationId.h:25

 

Introduction

Documentation

Support

Miscellaneous