ProtocolVersion.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_ANYP_PROTOCOLVERSION_H
10 #define SQUID_SRC_ANYP_PROTOCOLVERSION_H
11 
12 #include "anyp/ProtocolType.h"
13 
14 #include <ostream>
15 
16 namespace AnyP
17 {
18 
24 {
25 
26 public:
27  // BUG: major() and minor() are macros.
28  // we can't use a fast constructor syntax without renaming them globally
30  major = 0;
31  minor = 0;
32  }
33 
34  ProtocolVersion(ProtocolType which, unsigned int aMajor, unsigned int aMinor) : protocol(which) {
35  major = aMajor;
36  minor = aMinor;
37  }
38 
40  unsigned int major;
41  unsigned int minor;
42 
44  explicit operator bool() const { return protocol != PROTO_NONE; }
45 
46  bool operator==(const ProtocolVersion& that) const {
47  if (this->protocol != that.protocol)
48  return false;
49 
50  if (this->major != that.major)
51  return false;
52 
53  if (this->minor != that.minor)
54  return false;
55 
56  return true;
57  }
58 
59  bool operator!=(const ProtocolVersion& that) const {
60  return (((this->protocol != that.protocol) || this->major != that.major) || (this->minor != that.minor));
61  }
62 
63  bool operator <(const ProtocolVersion& that) const {
64  if (this->protocol != that.protocol)
65  return false; // throw?
66 
67  return (this->major < that.major ||
68  (this->major == that.major && this->minor < that.minor));
69  }
70 
71  bool operator >(const ProtocolVersion& that) const {
72  if (this->protocol != that.protocol)
73  return false; // throw?
74 
75  return (this->major > that.major ||
76  (this->major == that.major && this->minor > that.minor));
77  }
78 
79  bool operator <=(const ProtocolVersion& that) const {
80  if (this->protocol != that.protocol)
81  return false; // throw?
82 
83  return !(*this > that);
84  }
85 
86  bool operator >=(const ProtocolVersion& that) const {
87  if (this->protocol != that.protocol)
88  return false; // throw?
89 
90  return !(*this < that);
91  }
92 };
93 
94 inline std::ostream &
95 operator << (std::ostream &os, const ProtocolVersion &v)
96 {
97  return (os << AnyP::ProtocolType_str[v.protocol] << '/' << v.major << '.' << v.minor);
98 }
99 
100 } // namespace AnyP
101 
102 #endif /* SQUID_SRC_ANYP_PROTOCOLVERSION_H */
103 
unsigned int major
major version number
bool operator!=(const ProtocolVersion &that) const
@ PROTO_NONE
Definition: ProtocolType.h:24
unsigned int minor
minor version number
std::ostream & operator<<(std::ostream &, const Host &)
Definition: Host.cc:80
const char * ProtocolType_str[]
ProtocolType protocol
which protocol this version is for
ProtocolType
Definition: ProtocolType.h:23
bool operator==(const ProtocolVersion &that) const
Definition: forward.h:14
bool operator<=(const ProtocolVersion &that) const
ProtocolVersion(ProtocolType which, unsigned int aMajor, unsigned int aMinor)
bool operator<(const ProtocolVersion &that) const
bool operator>(const ProtocolVersion &that) const
bool operator>=(const ProtocolVersion &that) const

 

Introduction

Documentation

Support

Miscellaneous