]> git.ipfire.org Git - thirdparty/squid.git/blame - src/anyp/ProtocolVersion.h
Source Format Enforcement (#763)
[thirdparty/squid.git] / src / anyp / ProtocolVersion.h
CommitLineData
bbc27441 1/*
f70aedc4 2 * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
bbc27441
AJ
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
c9fd01b4
AJ
9#ifndef SQUID_ANYP_PROTOCOLVERSION_H
10#define SQUID_ANYP_PROTOCOLVERSION_H
11
12#include "anyp/ProtocolType.h"
13
c9fd01b4 14#include <ostream>
c9fd01b4
AJ
15
16namespace AnyP
17{
18
526ed14e
AJ
19/**
20 * Stores a protocol version label.
21 * For example HTTP/1.1 or ICY/1.0 or FTP/2.0
22 */
c9fd01b4
AJ
23class ProtocolVersion
24{
25
26public:
27 // BUG: major() and minor() are macros.
28 // we can't use a fast constructor syntax without renaming them globally
29 ProtocolVersion() : protocol(PROTO_NONE) {
2c61ab6e
A
30 major = 0;
31 minor = 0;
c9fd01b4
AJ
32 }
33
34 ProtocolVersion(ProtocolType which, unsigned int aMajor, unsigned int aMinor) : protocol(which) {
35 major = aMajor;
36 minor = aMinor;
37 }
38
526ed14e
AJ
39 ProtocolType protocol; ///< which protocol this version is for
40 unsigned int major; ///< major version number
41 unsigned int minor; ///< minor version number
c9fd01b4 42
cd29a421
CT
43 /// whether the version is "known" (e.g., has been parsed or explicitly set)
44 explicit operator bool() const { return protocol != PROTO_NONE; }
45
c9fd01b4
AJ
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
c9fd01b4
AJ
94inline std::ostream &
95operator << (std::ostream &os, const AnyP::ProtocolVersion &v)
96{
eb6ac808 97 return (os << AnyP::ProtocolType_str[v.protocol] << '/' << v.major << '.' << v.minor);
c9fd01b4
AJ
98}
99
be683c55
AJ
100} // namespace AnyP
101
c9fd01b4 102#endif /* SQUID_ANYP_PROTOCOLVERSION_H */
f53969cc 103