]> git.ipfire.org Git - thirdparty/squid.git/blob - src/anyp/ProtocolVersion.h
merge from trunk
[thirdparty/squid.git] / src / anyp / ProtocolVersion.h
1 #ifndef SQUID_ANYP_PROTOCOLVERSION_H
2 #define SQUID_ANYP_PROTOCOLVERSION_H
3
4 #include "anyp/ProtocolType.h"
5
6 #include <ostream>
7
8 namespace AnyP
9 {
10
11 /**
12 * Stores a protocol version label.
13 * For example HTTP/1.1 or ICY/1.0 or FTP/2.0
14 */
15 class ProtocolVersion
16 {
17
18 public:
19 // BUG: major() and minor() are macros.
20 // we can't use a fast constructor syntax without renaming them globally
21 ProtocolVersion() : protocol(PROTO_NONE) {
22 major = 0;
23 minor = 0;
24 }
25
26 ProtocolVersion(ProtocolType which, unsigned int aMajor, unsigned int aMinor) : protocol(which) {
27 major = aMajor;
28 minor = aMinor;
29 }
30
31 ProtocolType protocol; ///< which protocol this version is for
32 unsigned int major; ///< major version number
33 unsigned int minor; ///< minor version number
34
35 bool operator==(const ProtocolVersion& that) const {
36 if (this->protocol != that.protocol)
37 return false;
38
39 if (this->major != that.major)
40 return false;
41
42 if (this->minor != that.minor)
43 return false;
44
45 return true;
46 }
47
48 bool operator!=(const ProtocolVersion& that) const {
49 return (((this->protocol != that.protocol) || this->major != that.major) || (this->minor != that.minor));
50 }
51
52 bool operator <(const ProtocolVersion& that) const {
53 if (this->protocol != that.protocol)
54 return false; // throw?
55
56 return (this->major < that.major ||
57 (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 > that);
73 }
74
75 bool operator >=(const ProtocolVersion& that) const {
76 if (this->protocol != that.protocol)
77 return false; // throw?
78
79 return !(*this < that);
80 }
81 };
82
83 } // namespace AnyP
84
85 inline std::ostream &
86 operator << (std::ostream &os, const AnyP::ProtocolVersion &v)
87 {
88 return (os << AnyP::ProtocolType_str[v.protocol] << '/' << v.major << '.' << v.minor);
89 }
90
91 #endif /* SQUID_ANYP_PROTOCOLVERSION_H */