]> git.ipfire.org Git - thirdparty/squid.git/blame - src/anyp/ProtocolVersion.h
Streamline ./configure handling of optional libraries (#606)
[thirdparty/squid.git] / src / anyp / ProtocolVersion.h
CommitLineData
bbc27441 1/*
77b1029d 2 * Copyright (C) 1996-2020 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
AJ
42
43 bool operator==(const ProtocolVersion& that) const {
44 if (this->protocol != that.protocol)
45 return false;
46
47 if (this->major != that.major)
48 return false;
49
50 if (this->minor != that.minor)
51 return false;
52
53 return true;
54 }
55
56 bool operator!=(const ProtocolVersion& that) const {
57 return (((this->protocol != that.protocol) || this->major != that.major) || (this->minor != that.minor));
58 }
59
60 bool operator <(const ProtocolVersion& that) const {
61 if (this->protocol != that.protocol)
62 return false; // throw?
63
64 return (this->major < that.major ||
65 (this->major == that.major && this->minor < that.minor));
66 }
67
68 bool operator >(const ProtocolVersion& that) const {
69 if (this->protocol != that.protocol)
70 return false; // throw?
71
72 return (this->major > that.major ||
73 (this->major == that.major && this->minor > that.minor));
74 }
75
76 bool operator <=(const ProtocolVersion& that) const {
77 if (this->protocol != that.protocol)
78 return false; // throw?
79
80 return !(*this > that);
81 }
82
83 bool operator >=(const ProtocolVersion& that) const {
84 if (this->protocol != that.protocol)
85 return false; // throw?
86
87 return !(*this < that);
88 }
89};
90
c9fd01b4
AJ
91inline std::ostream &
92operator << (std::ostream &os, const AnyP::ProtocolVersion &v)
93{
eb6ac808 94 return (os << AnyP::ProtocolType_str[v.protocol] << '/' << v.major << '.' << v.minor);
c9fd01b4
AJ
95}
96
be683c55
AJ
97} // namespace AnyP
98
c9fd01b4 99#endif /* SQUID_ANYP_PROTOCOLVERSION_H */
f53969cc 100